Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/schema/GlobalConceptStoreSchema.java |
— | — | @@ -1,11 +1,9 @@ |
2 | 2 | package de.brightbyte.wikiword.schema; |
3 | 3 | |
4 | 4 | import java.sql.Connection; |
5 | | -import java.sql.ResultSet; |
6 | 5 | import java.sql.SQLException; |
7 | 6 | import java.util.ArrayList; |
8 | 7 | import java.util.Arrays; |
9 | | -import java.util.List; |
10 | 8 | import java.util.Map; |
11 | 9 | |
12 | 10 | import javax.sql.DataSource; |
— | — | @@ -27,7 +25,7 @@ |
28 | 26 | protected RelationTable mergeTable; |
29 | 27 | protected RelationTable langprepTable; |
30 | 28 | |
31 | | - protected ConceptTypeSet conceptTypes; |
| 29 | + private ConceptTypeSet conceptTypes; |
32 | 30 | protected TweakSet tweaks; |
33 | 31 | |
34 | 32 | public GlobalConceptStoreSchema(DatasetIdentifier dataset, Connection connection, TweakSet tweaks, boolean useFlushQueue) throws SQLException { |
— | — | @@ -40,7 +38,7 @@ |
41 | 39 | init(tweaks); |
42 | 40 | } |
43 | 41 | |
44 | | - protected Corpus[] languages; |
| 42 | + private Corpus[] languages; |
45 | 43 | |
46 | 44 | private void init(TweakSet tweaks) throws SQLException { |
47 | 45 | int nameSize = 32*255+32*16; //TODO: from tweaks! |
— | — | @@ -100,7 +98,7 @@ |
101 | 99 | |
102 | 100 | //TODO: reference table (aka link) |
103 | 101 | |
104 | | - getLanguages(); //initialize knownlanguages, corpuses and content types# |
| 102 | + //getLanguages(); //initialize knownlanguages, corpuses and content types# |
105 | 103 | } |
106 | 104 | |
107 | 105 | /** |
— | — | @@ -166,6 +164,27 @@ |
167 | 165 | return null; |
168 | 166 | } |
169 | 167 | |
| 168 | + protected Corpus[] getCorpuses(String[] languages) throws SQLException { |
| 169 | + Corpus[] cc = new Corpus[languages.length]; |
| 170 | + |
| 171 | + int i = 0; |
| 172 | + for (String l: languages) { |
| 173 | + if (!getLanguageNames().containsKey(l)) { |
| 174 | + throw new SQLException("bad corpus prefix: "+l+" is not a language name. Hint: check tweaks languages.*AsLanguage"); |
| 175 | + } |
| 176 | + |
| 177 | + cc[i++] = Corpus.forName(getCollectionName(), l, tweaks); |
| 178 | + } |
| 179 | + |
| 180 | + return cc; |
| 181 | + } |
| 182 | + |
| 183 | + public Corpus[] setLanguages(String[] languages) throws SQLException { |
| 184 | + Corpus[] cc = getCorpuses(languages); |
| 185 | + setLanguages(cc); |
| 186 | + return cc; |
| 187 | + } |
| 188 | + |
170 | 189 | public void setLanguages(Corpus[] languages) { |
171 | 190 | if (languages.length>32) throw new IllegalArgumentException("only up to 32 languages are supported!"); |
172 | 191 | |
— | — | @@ -203,24 +222,19 @@ |
204 | 223 | |
205 | 224 | public Corpus[] getLanguages() throws SQLException { |
206 | 225 | if (languages!=null) return languages; |
| 226 | + setLanguages( detectLanguages() ); |
| 227 | + return languages; |
| 228 | + } |
| 229 | + |
| 230 | + private Corpus[] allLanguages = null; |
| 231 | + public Corpus[] detectLanguages() throws SQLException { |
| 232 | + if (allLanguages!=null) return allLanguages; |
207 | 233 | |
208 | 234 | String[] ll = listPrefixes("resource"); |
209 | | - if (ll.length>32) throw new IllegalArgumentException("only up to 32 languages are supported! found "+ll.length+" prefixes: "+Arrays.toString(ll)); |
210 | | - |
211 | 235 | Arrays.sort(ll); //FIXME: sort by size! |
212 | | - Corpus[] cc = new Corpus[ll.length]; |
213 | 236 | |
214 | | - int i = 0; |
215 | | - for (String l: ll) { |
216 | | - if (!getLanguageNames().containsKey(l)) { |
217 | | - throw new SQLException("database inconsistency: encountered bad corpus prefix: "+l+" is not a language name. Hint: check tweaks languages.*AsLanguage"); |
218 | | - } |
219 | | - |
220 | | - cc[i++] = Corpus.forName(getCollectionName(), l, tweaks); |
221 | | - } |
222 | | - |
223 | | - setLanguages(cc); |
224 | | - return languages; |
| 237 | + allLanguages = getCorpuses(ll); |
| 238 | + return allLanguages; |
225 | 239 | } |
226 | 240 | |
227 | 241 | @Override |
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildThesaurus.java |
— | — | @@ -71,21 +71,15 @@ |
72 | 72 | String lang = args.getStringOption("languages", null); |
73 | 73 | if (lang!=null) { |
74 | 74 | String[] ll = lang.split("[,;/|\\s+]+"); |
75 | | - languages = new Corpus[ll.length]; |
76 | | - |
77 | | - int i = 0; |
78 | | - for (String l: ll) { |
79 | | - languages[i++] = Corpus.forName(getConfiguredCollectionName(), l, tweaks); |
80 | | - } |
| 75 | + ((GlobalConceptStoreBuilder)this.conceptStore).setLanguages(ll); |
81 | 76 | } |
82 | 77 | |
83 | | - if (languages==null) { |
84 | | - languages = ((GlobalConceptStoreBuilder)this.conceptStore).detectLanguages(); |
85 | | - } |
| 78 | + languages = ((GlobalConceptStoreBuilder)this.conceptStore).getLanguages(); |
| 79 | + } else { |
| 80 | + ((GlobalConceptStoreBuilder)this.conceptStore).setLanguages(languages); |
86 | 81 | } |
87 | 82 | |
88 | 83 | info("Using languages: "+Arrays.toString(languages)); |
89 | | - this.conceptStore.setLanguages(languages); |
90 | 84 | |
91 | 85 | if (agenda.beginTask("BuildThesaurus.run", "importConcepts")) { |
92 | 86 | this.conceptStore.importConcepts(); |
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/GlobalConceptStoreBuilder.java |
— | — | @@ -20,5 +20,7 @@ |
21 | 21 | public void setLanguages(Corpus[] languages); |
22 | 22 | |
23 | 23 | public int getMaxConceptId() throws PersistenceException; |
| 24 | + |
| 25 | + public void setLanguages(String[] languages) throws PersistenceException; |
24 | 26 | |
25 | 27 | } |
\ No newline at end of file |
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseGlobalConceptStoreBuilder.java |
— | — | @@ -59,7 +59,6 @@ |
60 | 60 | protected TweakSet tweaks; |
61 | 61 | |
62 | 62 | protected int idOffsetGranularity; |
63 | | - private Corpus[] languages; |
64 | 63 | |
65 | 64 | /** |
66 | 65 | * Constructs a DatabaseWikiStore, soring information from/about the given Corpus |
— | — | @@ -136,7 +135,7 @@ |
137 | 136 | //------------------------------- |
138 | 137 | public Corpus[] detectLanguages() throws PersistenceException { |
139 | 138 | try { |
140 | | - Corpus[] languages = ((GlobalConceptStoreSchema)database).getLanguages(); |
| 139 | + Corpus[] languages = ((GlobalConceptStoreSchema)database).detectLanguages(); |
141 | 140 | return languages; |
142 | 141 | } catch (SQLException e) { |
143 | 142 | throw new PersistenceException(e); |
— | — | @@ -145,15 +144,24 @@ |
146 | 145 | |
147 | 146 | public void setLanguages(Corpus[] languages) { |
148 | 147 | if (languages==null) throw new NullPointerException(); |
149 | | - if (this.languages!=null) throw new IllegalStateException("languages already set"); |
150 | | - //XXX: set languages in GlobalConceptStoreSchema too? |
151 | | - |
152 | | - this.languages = languages; |
| 148 | + ((GlobalConceptStoreSchema)database).setLanguages(languages); |
153 | 149 | } |
154 | 150 | |
| 151 | + public void setLanguages(String[] languages) throws PersistenceException { |
| 152 | + if (languages==null) throw new NullPointerException(); |
| 153 | + try { |
| 154 | + ((GlobalConceptStoreSchema)database).setLanguages(languages); |
| 155 | + } catch (SQLException e) { |
| 156 | + throw new PersistenceException(e); |
| 157 | + } |
| 158 | + } |
| 159 | + |
155 | 160 | public Corpus[] getLanguages() throws PersistenceException { |
156 | | - if (languages==null) languages = detectLanguages(); |
157 | | - return languages; |
| 161 | + try { |
| 162 | + return ((GlobalConceptStoreSchema)database).getLanguages(); |
| 163 | + } catch (SQLException e) { |
| 164 | + throw new PersistenceException(e); |
| 165 | + } |
158 | 166 | } |
159 | 167 | |
160 | 168 | public int getNextIdOffset() throws PersistenceException { |