r65640 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65639‎ | r65640 | r65641 >
Date:21:53, 28 April 2010
Author:daniel
Status:deferred
Tags:
Comment:
fixed initial language detection sequence
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/schema/GlobalConceptStoreSchema.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildThesaurus.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseGlobalConceptStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/GlobalConceptStoreBuilder.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/schema/GlobalConceptStoreSchema.java
@@ -1,11 +1,9 @@
22 package de.brightbyte.wikiword.schema;
33
44 import java.sql.Connection;
5 -import java.sql.ResultSet;
65 import java.sql.SQLException;
76 import java.util.ArrayList;
87 import java.util.Arrays;
9 -import java.util.List;
108 import java.util.Map;
119
1210 import javax.sql.DataSource;
@@ -27,7 +25,7 @@
2826 protected RelationTable mergeTable;
2927 protected RelationTable langprepTable;
3028
31 - protected ConceptTypeSet conceptTypes;
 29+ private ConceptTypeSet conceptTypes;
3230 protected TweakSet tweaks;
3331
3432 public GlobalConceptStoreSchema(DatasetIdentifier dataset, Connection connection, TweakSet tweaks, boolean useFlushQueue) throws SQLException {
@@ -40,7 +38,7 @@
4139 init(tweaks);
4240 }
4341
44 - protected Corpus[] languages;
 42+ private Corpus[] languages;
4543
4644 private void init(TweakSet tweaks) throws SQLException {
4745 int nameSize = 32*255+32*16; //TODO: from tweaks!
@@ -100,7 +98,7 @@
10199
102100 //TODO: reference table (aka link)
103101
104 - getLanguages(); //initialize knownlanguages, corpuses and content types#
 102+ //getLanguages(); //initialize knownlanguages, corpuses and content types#
105103 }
106104
107105 /**
@@ -166,6 +164,27 @@
167165 return null;
168166 }
169167
 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+
170189 public void setLanguages(Corpus[] languages) {
171190 if (languages.length>32) throw new IllegalArgumentException("only up to 32 languages are supported!");
172191
@@ -203,24 +222,19 @@
204223
205224 public Corpus[] getLanguages() throws SQLException {
206225 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;
207233
208234 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 -
211235 Arrays.sort(ll); //FIXME: sort by size!
212 - Corpus[] cc = new Corpus[ll.length];
213236
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;
225239 }
226240
227241 @Override
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildThesaurus.java
@@ -71,21 +71,15 @@
7272 String lang = args.getStringOption("languages", null);
7373 if (lang!=null) {
7474 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);
8176 }
8277
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);
8681 }
8782
8883 info("Using languages: "+Arrays.toString(languages));
89 - this.conceptStore.setLanguages(languages);
9084
9185 if (agenda.beginTask("BuildThesaurus.run", "importConcepts")) {
9286 this.conceptStore.importConcepts();
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/GlobalConceptStoreBuilder.java
@@ -20,5 +20,7 @@
2121 public void setLanguages(Corpus[] languages);
2222
2323 public int getMaxConceptId() throws PersistenceException;
 24+
 25+ public void setLanguages(String[] languages) throws PersistenceException;
2426
2527 }
\ No newline at end of file
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseGlobalConceptStoreBuilder.java
@@ -59,7 +59,6 @@
6060 protected TweakSet tweaks;
6161
6262 protected int idOffsetGranularity;
63 - private Corpus[] languages;
6463
6564 /**
6665 * Constructs a DatabaseWikiStore, soring information from/about the given Corpus
@@ -136,7 +135,7 @@
137136 //-------------------------------
138137 public Corpus[] detectLanguages() throws PersistenceException {
139138 try {
140 - Corpus[] languages = ((GlobalConceptStoreSchema)database).getLanguages();
 139+ Corpus[] languages = ((GlobalConceptStoreSchema)database).detectLanguages();
141140 return languages;
142141 } catch (SQLException e) {
143142 throw new PersistenceException(e);
@@ -145,15 +144,24 @@
146145
147146 public void setLanguages(Corpus[] languages) {
148147 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);
153149 }
154150
 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+
155160 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+ }
158166 }
159167
160168 public int getNextIdOffset() throws PersistenceException {

Status & tagging log