r64347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64346‎ | r64347 | r64348 >
Date:16:22, 29 March 2010
Author:daniel
Status:deferred
Tags:
Comment:
working disambiguator
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/ConsoleApp.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/AbstractDisambiguator.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/CoherenceDisambiguator.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/Disambiguator.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/FeatureCache.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/FeatureFetcher.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/PopularityDisambiguator.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/SlidingCoherenceDisambiguator.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/StoredFeatureFetcher.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/StoredMeaningFetcher.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/TermRelatedness.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseLocalConceptStore.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/FeatureCache.java
@@ -1,6 +1,7 @@
22 package de.brightbyte.wikiword.disambig;
33
44 import java.util.ArrayList;
 5+import java.util.Collection;
56 import java.util.HashMap;
67 import java.util.List;
78 import java.util.Map;
@@ -33,7 +34,7 @@
3435 return f;
3536 }
3637
37 - public Map<Integer, ConceptFeatures<C, K>> getFeatures(List<C> concepts) throws PersistenceException {
 38+ public Map<Integer, ConceptFeatures<C, K>> getFeatures(Collection<C> concepts) throws PersistenceException {
3839 Map<Integer, ConceptFeatures<C, K>> features = new HashMap<Integer, ConceptFeatures<C, K>> ();
3940 List<C> todo = new ArrayList<C>(concepts.size());
4041 for (C c: concepts) {
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/SlidingCoherenceDisambiguator.java
@@ -40,12 +40,17 @@
4141 if (window < 2 || terms.size()<2 || meanings.size()<2)
4242 return popularityDisambiguator.disambiguate(terms, meanings);
4343
 44+ pruneMeanings(meanings);
 45+
 46+ if (meanings.size()<2)
 47+ return popularityDisambiguator.disambiguate(terms, meanings);
 48+
4449 //CAVEAT: because the map disambig can contain only one meaning per term, the same term can not occur with two meanings within the same term sequence.
4550
4651 Map<String, LocalConcept> disambig = new HashMap<String, LocalConcept>(meanings.size());
4752
4853 LabeledMatrix<LocalConcept, LocalConcept> similarities = new MapLabeledMatrix<LocalConcept, LocalConcept>(true);
49 - FeatureCache<LocalConcept, K> features = new FeatureCache<LocalConcept, K>(featureFetcher); //TODO: keep a chain of n caches, resulting in LRU logic.
 54+ FeatureCache<LocalConcept, K> features = getFeatureCache(meanings);
5055
5156 for (int i= window; ; i++) {
5257 int from = i-window;
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/StoredMeaningFetcher.java
@@ -3,6 +3,7 @@
44 import java.util.List;
55
66 import de.brightbyte.data.cursor.DataSet;
 7+import de.brightbyte.io.Output;
78 import de.brightbyte.util.PersistenceException;
89 import de.brightbyte.wikiword.model.LocalConcept;
910 import de.brightbyte.wikiword.store.LocalConceptStore;
@@ -11,6 +12,7 @@
1213 public class StoredMeaningFetcher implements MeaningFetcher<LocalConcept> {
1314 protected LocalConceptStore store;
1415 protected ConceptQuerySpec spec;
 16+ protected Output trace;
1517
1618 public StoredMeaningFetcher(LocalConceptStore store) {
1719 this(store, null);
@@ -24,8 +26,21 @@
2527 }
2628
2729 public List<LocalConcept> getMeanings(String term) throws PersistenceException {
 30+ trace("fetching meanings for \""+term+"\"");
2831 DataSet<LocalConcept> m = store.getMeanings(term, spec); //FIXME: filter/cut-off rules, sort order! //XXX: relevance value?
2932 return m.load();
3033 }
3134
 35+ public Output getTrace() {
 36+ return trace;
 37+ }
 38+
 39+ public void setTrace(Output trace) {
 40+ this.trace = trace;
 41+ }
 42+
 43+ protected void trace(String msg) {
 44+ if (trace!=null) trace.println(msg);
 45+ }
 46+
3247 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/TermRelatedness.java
@@ -60,8 +60,8 @@
6161 d = relatedness.similarity(ca, cb);
6262 }
6363 else {
64 - d = r.getCoherence();
65 - if (d<0) throw new RuntimeException("disambiguator did not provide a coherence score, and no concept similarity measure was defined!");
 64+ d = r.getScore();
 65+ if (d<0) throw new RuntimeException("disambiguator did not provide a score, and no concept similarity measure was defined!");
6666 }
6767
6868 return new Relatedness(d, ca, cb);
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/PopularityDisambiguator.java
@@ -31,7 +31,7 @@
3232 int pop = 0;
3333 for (String t: terms) {
3434 List<LocalConcept> m = meanings.get(t);
35 - if (m.size()==0) continue;
 35+ if (m==null || m.size()==0) continue;
3636
3737 if (m.size()>0) Collections.sort(m, popularityComparator);
3838
@@ -43,7 +43,7 @@
4444
4545 pop = pop / disambig.size();
4646
47 - Result r = new Result(disambig, pop, -1, pop);
 47+ Result r = new Result(disambig, pop, "pop="+pop);
4848 return r;
4949 }
5050
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/CoherenceDisambiguator.java
@@ -3,9 +3,12 @@
44 import java.util.ArrayList;
55 import java.util.Collections;
66 import java.util.HashMap;
 7+import java.util.Iterator;
78 import java.util.List;
89 import java.util.Map;
 10+import java.util.Map.Entry;
911
 12+import de.brightbyte.data.Functor;
1013 import de.brightbyte.data.LabeledMatrix;
1114 import de.brightbyte.data.LabeledVector;
1215 import de.brightbyte.data.MapLabeledMatrix;
@@ -20,15 +23,31 @@
2124
2225 public class CoherenceDisambiguator<K> extends AbstractDisambiguator {
2326
24 - protected int minPopularity = 2; //FIXME: use complex cutoff specifier!
25 - protected double scoreThreshold = 0.002; //FIXME: magic number
26 - protected double popularityBias = 0.01; //FIXME: magic number
 27+ protected int minPopularity = 2; //FIXME: use complex cutoff specifier!
 28+ protected int maxMeanings = 8; //FIXME: magic...
2729
 30+ protected double minScore = 0.1; //FIXME: magic number. should "somehow" match popularityFactor and similarityFactor
 31+ protected double popularityBias = 0.2; //FIXME: magic number. should "somehow" match popularityFactor and similarityFactor
 32+
2833 protected Similarity<LabeledVector<K>> similarityMeasure;
2934 protected FeatureFetcher<LocalConcept, K> featureFetcher;
3035 protected Measure<WikiWordConcept> popularityMeasure;
3136 protected PopularityDisambiguator popularityDisambiguator;
3237
 38+ private Functor.Double popularityFactor = new Functor.Double() { //NOTE: must map [0:inf] to [0:1] and grow monotonously
 39+
 40+ public double apply(double pop) {
 41+ return 1 - 1/(Math.sqrt(Math.log(pop))+1); //XXX: black voodoo magic ad hoc formula with no deeper meaing.
 42+ }
 43+
 44+ };
 45+
 46+ private Functor.Double similarityFactor = new Functor.Double() { //NOTE: must map [0:1] to [0:1] and grow monotonously
 47+ public double apply(double sim) {
 48+ return Math.sqrt(Math.sqrt(sim)); //XXX: black voodoo magic ad hoc formula with no deeper meaing.
 49+ }
 50+ };
 51+
3352 public CoherenceDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, FeatureFetcher<LocalConcept, K> featureFetcher, boolean featuresAreNormalized) {
3453 this(meaningFetcher, featureFetcher, WikiWordConcept.theCardinality,
3554 featuresAreNormalized ? ScalarVectorSimilarity.<K>getInstance() : CosineVectorSimilarity.<K>getInstance()); //if pre-normalized, use scalar to calc cosin
@@ -80,14 +99,37 @@
81100 this.minPopularity = min;
82101 }
83102
84 - public double getScoreThreshold() {
85 - return scoreThreshold;
 103+ public double getMinScore() {
 104+ return minScore;
86105 }
87106
88 - public void setScoreThreshold(double threshold) {
89 - this.scoreThreshold = threshold;
 107+ public void setMinScore(double threshold) {
 108+ this.minScore = threshold;
90109 }
91110
 111+ public int getMaxMeanings() {
 112+ return maxMeanings;
 113+ }
 114+
 115+ public void setMaxMeanings(int maxMeanings) {
 116+ this.maxMeanings = maxMeanings;
 117+ }
 118+
 119+ protected FeatureCache<LocalConcept, K> getFeatureCache(Map<String, List<LocalConcept>> meanings) throws PersistenceException {
 120+ //TODO: keep a chain of n caches, resulting in LRU logic.
 121+ FeatureCache<LocalConcept, K> features = new FeatureCache<LocalConcept, K>(featureFetcher);
 122+
 123+ //NOTE: pre-fetch all features in one go
 124+ List<LocalConcept> concepts = new ArrayList<LocalConcept>(meanings.size()*10);
 125+ for (List<LocalConcept> m: meanings.values()) {
 126+ concepts.addAll(m);
 127+ }
 128+
 129+ features.getFeatures(concepts);
 130+
 131+ return features;
 132+ }
 133+
92134 /* (non-Javadoc)
93135 * @see de.brightbyte.wikiword.disambig.Disambiguator#disambiguate(java.util.List)
94136 */
@@ -95,25 +137,64 @@
96138 if (terms.size()<2 || meanings.size()<2)
97139 return popularityDisambiguator.disambiguate(terms, meanings);
98140
 141+ pruneMeanings(meanings);
 142+
 143+ if (meanings.size()<2)
 144+ return popularityDisambiguator.disambiguate(terms, meanings);
 145+
 146+ //CAVEAT: because the map disambig can contain only one meaning per term, the same term can not occur with two meanings within the same term sequence.
 147+
99148 LabeledMatrix<LocalConcept, LocalConcept> similarities = new MapLabeledMatrix<LocalConcept, LocalConcept>(true);
100 - FeatureCache<LocalConcept, K> features = new FeatureCache<LocalConcept, K>(featureFetcher); //TODO: keep a chain of n caches, resulting in LRU logic.
 149+ FeatureCache<LocalConcept, K> features = getFeatureCache(meanings);
101150
102151 List<Map<String, LocalConcept>> interpretations = getInterpretations(terms, meanings);
103152
104153 return getBestInterpretation(terms, meanings, interpretations, similarities, features);
105154 }
106155
 156+ protected void pruneMeanings(Map<String, List<LocalConcept>> meanings) {
 157+ if (minPopularity<=1) return; //nothing to do
 158+
 159+ Iterator<Map.Entry<String, List<LocalConcept>>> eit = meanings.entrySet().iterator();
 160+ while (eit.hasNext()) {
 161+ Entry<String, List<LocalConcept>> e = eit.next();
 162+ List<LocalConcept> m = e.getValue();
 163+
 164+ Iterator<LocalConcept> cit = m.iterator();
 165+ while (cit.hasNext()) {
 166+ LocalConcept c = cit.next();
 167+ double p = popularityMeasure.measure(c);
 168+
 169+ if (p<minPopularity) {
 170+ cit.remove();
 171+ }
 172+ }
 173+
 174+ if (m.size()==0) eit.remove();
 175+ else if (m.size()>maxMeanings) {
 176+ Collections.sort(m, WikiWordConcept.byCardinality);
 177+ m = m.subList(0, maxMeanings);
 178+ e.setValue(m);
 179+ }
 180+ }
 181+ }
 182+
107183 protected Result getBestInterpretation(List<String> terms, Map<String, List<LocalConcept>> meanings,
108184 List<Map<String, LocalConcept>> interpretations,
109185 LabeledMatrix<LocalConcept, LocalConcept> similarities, FeatureCache<LocalConcept, K> features) throws PersistenceException {
110186
111187 List<Result> rankings = new ArrayList<Result>();
112188
 189+ double traceLimit = -1;
113190 for (Map<String, LocalConcept> interp: interpretations) {
114191 Result r = getScore(interp, similarities, features);
115 - if (r.getScore() <= scoreThreshold) continue;
116192
117 - rankings.add(r);
 193+ if (r.getScore() >= minScore) {
 194+ rankings.add(r);
 195+
 196+ if (traceLimit<0) traceLimit = r.getScore() / 2;
 197+ if (r.getScore() >= traceLimit && rankings.size()<=10) trace(" = "+r);
 198+ }
118199 }
119200
120201 if (rankings.size()==0) {
@@ -123,20 +204,6 @@
124205 Collections.sort(rankings);
125206 Collections.reverse(rankings);
126207
127 - if (trace!=null) {
128 - int c = 0;
129 - double limit = -1;
130 - for (Result r: rankings) {
131 - if (limit<0) limit = r.getScore() / 2;
132 - else if (r.getScore()<limit) break;
133 -
134 - trace(" = "+r);
135 - c++;
136 -
137 - if (c>10) break;
138 - }
139 - }
140 -
141208 //TODO: if result is tight (less than 50% distance), use more popularity score!
142209 Result r = rankings.get(0);
143210 return r;
@@ -158,9 +225,6 @@
159226
160227 for (Map<String, LocalConcept> be: base) {
161228 for (LocalConcept c: m) {
162 - double p = popularityMeasure.measure(c);
163 - if (p<minPopularity) continue;
164 -
165229 Map<String, LocalConcept> e = new HashMap<String, LocalConcept>();
166230 e.putAll(be);
167231 e.put(t, c);
@@ -169,7 +233,7 @@
170234 }
171235 }
172236
173 - trace(" ~ "+t+": "+interpretations.size()+" combinations");
 237+ trace(" ~ "+t+": "+m.size()+" meanings; collected "+interpretations.size()+" combinations");
174238 return interpretations;
175239 }
176240
@@ -222,13 +286,17 @@
223287 }
224288
225289 //normalize
226 - sim = sim / n;
227 - pop = pop / c;
 290+ sim = sim / n; //normalize
 291+ pop = pop / c; //normalize
228292
229 - double popf = 1 - 1/(Math.sqrt(pop)+1); //converge against 1 //XXX: black voodoo magic ad hoc formula with no deeper meaing.
 293+ double popf = popularityFactor.apply(pop);
 294+ double simf = similarityFactor.apply(sim);
230295
231 - double score = popf * popularityBias + sim * ( 1 - popularityBias );
232 - return new Result(interp, score, sim, pop);
 296+ //FIXME: functor!
 297+ double score = popf * popularityBias + simf * ( 1 - popularityBias );
 298+ //double score = Math.sqrt( popf * simf ); //FIXME: functor!
 299+
 300+ return new Result(interp, score, "simf="+simf+", popf="+popf+", sim="+sim+", pop="+pop);
233301 }
234302
235303 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/Disambiguator.java
@@ -12,15 +12,13 @@
1313 public static class Result implements Comparable {
1414 private Map<String, ? extends WikiWordConcept> meanings;
1515 private double score;
16 - private double coherence;
17 - private double popularity;
 16+ private String description;
1817
19 - public Result(Map<String, ? extends WikiWordConcept> meanings, double score, double coherence, double popularity) {
 18+ public Result(Map<String, ? extends WikiWordConcept> meanings, double score, String description) {
2019 super();
2120 this.meanings = meanings;
2221 this.score = score;
23 - this.coherence = coherence;
24 - this.popularity = popularity;
 22+ this.description = description;
2523 }
2624
2725 public Map<String, ? extends WikiWordConcept> getMeanings() {
@@ -31,17 +29,13 @@
3230 return score;
3331 }
3432
35 - public double getCoherence() {
36 - return coherence;
 33+ public String getDescription() {
 34+ return description;
3735 }
3836
39 - public double getPopularity() {
40 - return popularity;
41 - }
42 -
4337 @Override
4438 public String toString() {
45 - return "("+score+"|"+coherence+"&"+popularity+") "+meanings;
 39+ return "("+score+"|"+description+") "+meanings;
4640 }
4741
4842 public int compareTo(Object o) {
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/FeatureFetcher.java
@@ -1,5 +1,6 @@
22 package de.brightbyte.wikiword.disambig;
33
 4+import java.util.Collection;
45 import java.util.List;
56 import java.util.Map;
67
@@ -9,5 +10,5 @@
1011
1112 public interface FeatureFetcher<C extends WikiWordConcept, K> {
1213 public ConceptFeatures<C, K> getFeatures(C c) throws PersistenceException;
13 - public Map<Integer, ConceptFeatures<C, K>> getFeatures(List<C> c) throws PersistenceException;
 14+ public Map<Integer, ConceptFeatures<C, K>> getFeatures(Collection<C> c) throws PersistenceException;
1415 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/StoredFeatureFetcher.java
@@ -1,8 +1,9 @@
22 package de.brightbyte.wikiword.disambig;
33
4 -import java.util.List;
 4+import java.util.Collection;
55 import java.util.Map;
66
 7+import de.brightbyte.io.Output;
78 import de.brightbyte.util.PersistenceException;
89 import de.brightbyte.wikiword.model.ConceptFeatures;
910 import de.brightbyte.wikiword.model.WikiWordConcept;
@@ -10,6 +11,7 @@
1112
1213 public class StoredFeatureFetcher<C extends WikiWordConcept, K> implements FeatureFetcher<C, K> {
1314 protected FeatureStore<C, K> store;
 15+ protected Output trace;
1416
1517 public StoredFeatureFetcher(FeatureStore<C, K> store) {
1618 if (store==null) throw new NullPointerException();
@@ -18,14 +20,29 @@
1921 }
2022
2123 public ConceptFeatures<C, K> getFeatures(C c) throws PersistenceException {
 24+ trace("fetching features for "+c);
2225 return store.getConceptFeatures(c.getId());
2326 }
2427
25 - public Map<Integer, ConceptFeatures<C, K>> getFeatures(List<C> concepts) throws PersistenceException {
 28+ public Map<Integer, ConceptFeatures<C, K>> getFeatures(Collection<C> concepts) throws PersistenceException {
 29+ trace("fetching features for "+concepts);
 30+
2631 int[] ids = new int[concepts.size()];
2732 int i = 0;
2833 for (C c: concepts) ids[i++] = c.getId();
2934 return store.getConceptsFeatures(ids);
3035 }
3136
 37+ public Output getTrace() {
 38+ return trace;
 39+ }
 40+
 41+ public void setTrace(Output trace) {
 42+ this.trace = trace;
 43+ }
 44+
 45+ protected void trace(String msg) {
 46+ if (trace!=null) trace.println(msg);
 47+ }
 48+
3249 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/AbstractDisambiguator.java
@@ -1,13 +1,11 @@
22 package de.brightbyte.wikiword.disambig;
33
4 -import java.util.ArrayList;
54 import java.util.HashMap;
65 import java.util.List;
76 import java.util.Map;
87
98 import de.brightbyte.io.Output;
109 import de.brightbyte.util.PersistenceException;
11 -import de.brightbyte.wikiword.disambig.Disambiguator.Result;
1210 import de.brightbyte.wikiword.model.LocalConcept;
1311
1412 public abstract class AbstractDisambiguator implements Disambiguator {
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/ConsoleApp.java
@@ -1,21 +1,24 @@
22 package de.brightbyte.wikiword;
33
44 import java.util.ArrayList;
5 -import java.util.Arrays;
65 import java.util.Collections;
76 import java.util.List;
87
98 import de.brightbyte.io.Prompt;
109 import de.brightbyte.util.PersistenceException;
 10+import de.brightbyte.util.StructuredDataCodec;
1111 import de.brightbyte.wikiword.store.WikiWordConceptStoreBase;
1212
1313 public abstract class ConsoleApp<S extends WikiWordConceptStoreBase> extends StoreBackedApp<S> {
1414
1515 protected Prompt prompt;
 16+ protected StructuredDataCodec commandCodec;
1617
1718 public ConsoleApp(boolean allowGlobal, boolean allowLocal) {
1819 super(allowGlobal, allowLocal);
1920 prompt = new Prompt();
 21+ commandCodec = new StructuredDataCodec();
 22+ commandCodec.setLenient(true);
2023 }
2124
2225 @Override
@@ -27,13 +30,13 @@
2831 echo("hello");
2932
3033 while (true) {
31 - List<String> params= promptCommand();
 34+ List<Object> params= promptCommand();
3235 if (params==null) break;
3336 if (params.size()==0) continue;
3437
35 - params = new ArrayList<String>(params); //make modifiable
 38+ params = new ArrayList<Object>(params); //modifyable
3639
37 - String cmd = params.get(0);
 40+ String cmd = params.get(0).toString();
3841 cmd = cmd.trim().toLowerCase();
3942
4043 if (cmd.equals("quit") || cmd.equals("exit") || cmd.equals("q")) break;
@@ -58,15 +61,16 @@
5962 // noop
6063 }
6164
62 - public List<String> promptCommand() {
 65+ public List<Object> promptCommand() {
6366 String s = prompt.prompt(">", "");
6467 if (s==null) return null;
6568
6669 s = s.replaceAll("^\\s*|\\s*[;]\\s*$", "");
6770 if (s.length()==0) return Collections.emptyList();
6871
69 - String[] ss = s.split("\\s+");
70 - return Arrays.asList(ss);
 72+ if (s.startsWith("#") || s.startsWith(";") || s.startsWith("//")) return Collections.emptyList();
 73+
 74+ return commandCodec.decodeList(s);
7175 }
7276
7377 public String prompt(String m, List<String> options, String def) {
@@ -75,15 +79,15 @@
7680 return s;
7781 }
7882
79 - protected void beforeCommand(List<String> params) throws Exception {
 83+ protected void beforeCommand(List<Object> params) throws Exception {
8084 //noop
8185 }
8286
83 - protected void afterCommand(List<String> params) throws Exception {
 87+ protected void afterCommand(List<Object> params) throws Exception {
8488 //noop
8589 }
8690
87 - public abstract void runCommand(List<String> params) throws Exception;
 91+ public abstract void runCommand(List<Object> params) throws Exception;
8892
8993 protected void startEcho(String msg) {
9094 prompt.print(msg);
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseLocalConceptStore.java
@@ -307,6 +307,8 @@
308308 tables += " LEFT JOIN "+conceptDescriptionTable.getSQLName()+" as D ON D.concept = C.id ";
309309 }
310310
 311+ //TODO: include features!
 312+
311313 String sql = "SELECT " + fields + " FROM " + tables;
312314 return sql;
313315 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java
@@ -13,6 +13,8 @@
1414
1515 import de.brightbyte.data.LabeledVector;
1616 import de.brightbyte.data.cursor.DataSet;
 17+import de.brightbyte.db.DatabaseUtil;
 18+import de.brightbyte.io.LeveledOutput;
1719 import de.brightbyte.rdf.RdfException;
1820 import de.brightbyte.util.PersistenceException;
1921 import de.brightbyte.wikiword.ConsoleApp;
@@ -312,20 +314,20 @@
313315 }
314316
315317 @Override
316 - public void runCommand(List<String> params) throws Exception {
317 - String cmd = params.get(0);
 318+ public void runCommand(List<Object> params) throws Exception {
 319+ String cmd = params.get(0).toString();
318320 cmd = cmd.trim().toLowerCase();
319321
320322 String format = null;
321323 File target = null;
322324
323 - if (params.size()>1 && params.get(params.size()-1).startsWith(">")) {
324 - target = new File( params.get(params.size()-1).substring(1).trim() );
 325+ if (params.size()>1 && params.get(params.size()-1).toString().startsWith(">")) {
 326+ target = new File( params.get(params.size()-1).toString().substring(1).trim() );
325327 params = params.subList(0, params.size()-1);
326328 }
327329
328 - if (params.size()>1 && params.get(params.size()-1).startsWith("|")) {
329 - format = params.get(params.size()-1).substring(1).trim();
 330+ if (params.size()>1 && params.get(params.size()-1).toString().startsWith("|")) {
 331+ format = params.get(params.size()-1).toString().substring(1).trim();
330332 params = params.subList(0, params.size()-1);
331333 }
332334
@@ -337,43 +339,47 @@
338340 }
339341 else if (cmd.equals("m") || cmd.equals("mng") || cmd.equals("meanings")) {
340342 if (isGlobalThesaurus()) {
341 - String lang = params.get(1);
342 - String term = params.get(2);
 343+ String lang = params.get(1).toString();
 344+ String term = params.get(2).toString();
343345 listMeaningsGlobal(lang, term, out);
344346 }
345347 else {
346 - String term = params.get(1);
 348+ String term = params.get(1).toString();
347349 listMeaningsLocal(term, out);
348350 }
349351 }
350352 else if (cmd.equals("s") || cmd.equals("cat") || cmd.equals("show")) {
351353 if (params.size()>2 && isGlobalThesaurus()) {
352 - String id = params.get(1);
353 - String lang = params.get(2);
354 - showConcept(Integer.parseInt(id), lang, out);
 354+ int id = DatabaseUtil.asInt(params.get(1));
 355+ String lang = params.get(2).toString();
 356+ showConcept(id, lang, out);
355357 }
356358 else {
357 - String id = params.get(1);
358 - showConcept(Integer.parseInt(id), out);
 359+ int id = DatabaseUtil.asInt(params.get(1));
 360+ showConcept(id, out);
359361 }
360362 }
361363 else if (cmd.equals("e") || cmd.equals("env") || cmd.equals("environment")) {
362364 if (params.size()>2 ) {
363 - String id = params.get(1);
364 - String min = params.get(2);
365 - showEnvironment(Integer.parseInt(id), Double.parseDouble(min), out);
 365+ int id = DatabaseUtil.asInt(params.get(1));
 366+ String min = params.get(2).toString();
 367+ showEnvironment(id, Double.parseDouble(min), out);
366368 }
367369 else {
368 - String id = params.get(1);
369 - showEnvironment(Integer.parseInt(id), 0, out);
 370+ int id = DatabaseUtil.asInt(params.get(1));
 371+ showEnvironment(id, 0, out);
370372 }
371373 }
372374 else if (cmd.equals("f") || cmd.equals("feat") || cmd.equals("features")) {
373 - String id = params.get(1);
374 - showFeatureVector(Integer.parseInt(id), out);
 375+ int id = DatabaseUtil.asInt(params.get(1));
 376+ showFeatureVector(id, out);
375377 }
376378 else if (cmd.equals("d") || cmd.equals("dis") || cmd.equals("disambig") || cmd.equals("disambiguate")) {
377 - List<String> terms = params.subList(1,params.size());
 379+ List<String> terms = new ArrayList<String>(params.size()-1);
 380+ for (Object t: params.subList(1,params.size())) {
 381+ terms.add(t.toString());
 382+ }
 383+
378384 showDisambiguation(terms, out);
379385 }
380386 else if (cmd.equals("ls") || cmd.equals("list")) {
@@ -406,12 +412,16 @@
407413 }
408414
409415 protected Disambiguator getDisambiguator() throws PersistenceException {
410 - if (disambiguator==null) disambiguator =
411 - new SlidingCoherenceDisambiguator<Integer>(
412 - new StoredMeaningFetcher(getLocalConceptStore()),
413 - new StoredFeatureFetcher<LocalConcept, Integer>(getFeatureStore()),
414 - true
415 - );
 416+ if (disambiguator==null) {
 417+ StoredMeaningFetcher meaningFetcher = new StoredMeaningFetcher(getLocalConceptStore());
 418+ StoredFeatureFetcher<LocalConcept, Integer> featureFetcher = new StoredFeatureFetcher<LocalConcept, Integer>(getFeatureStore());
 419+ disambiguator = new SlidingCoherenceDisambiguator<Integer>( meaningFetcher, featureFetcher, true );
 420+
 421+ LeveledOutput.Trace trace = new LeveledOutput.Trace(out);
 422+ meaningFetcher.setTrace(trace);
 423+ featureFetcher.setTrace(trace);
 424+ disambiguator.setTrace(trace);
 425+ }
416426
417427 return disambiguator;
418428 }

Status & tagging log