r68160 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68159‎ | r68160 | r68161 >
Date:09:18, 17 June 2010
Author:daniel
Status:deferred
Tags:
Comment:
make disambiguation code work on the global thesaurus
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/AbstractDisambiguator.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/CachingFeatureFetcher.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/CachingMeaningFetcher.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/MeaningFetcher.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/StoredMeaningFetcher.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/WikiWordConcept.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/GlobalConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/LocalConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/test/java/de/brightbyte/wikiword/disambig/DisambiguatorTestBase.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/test/java/de/brightbyte/wikiword/disambig/PopularityDisambiguatorTest.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/test/java/de/brightbyte/wikiword/disambig/PopularityDisambiguatorTest.java
@@ -13,6 +13,7 @@
1414 import de.brightbyte.wikiword.model.PhraseOccurance;
1515 import de.brightbyte.wikiword.model.PhraseOccuranceSet;
1616 import de.brightbyte.wikiword.model.TermListNode;
 17+import de.brightbyte.wikiword.model.TermReference;
1718
1819 public class PopularityDisambiguatorTest extends DisambiguatorTestBase {
1920
@@ -21,7 +22,7 @@
2223 }
2324
2425 public void testGetTermsForList() throws PersistenceException {
25 - PopularityDisambiguator disambiguator = new PopularityDisambiguator(meaningFetcher, 10);
 26+ PopularityDisambiguator<TermReference, LocalConcept> disambiguator = new PopularityDisambiguator<TermReference, LocalConcept>(meaningFetcher, 10);
2627
2728 Term uk = new Term("UK");
2829 Term london = new Term("London");
@@ -47,7 +48,7 @@
4849
4950 //FIXME: Test case for getHorizon
5051
51 - PopularityDisambiguator disambiguator = new PopularityDisambiguator(meaningFetcher, 10);
 52+ PopularityDisambiguator<TermReference, LocalConcept> disambiguator = new PopularityDisambiguator<TermReference, LocalConcept>(meaningFetcher, 10);
5253
5354 Collection<PhraseOccurance> terms = disambiguator.getTerms(set.getRootNode(), 0);
5455 assertTrue("empty term set", sameElements( getBankAndMonumentTerms(0), terms) );
@@ -60,7 +61,7 @@
6162 }
6263
6364 public void testGetMeaningsForList() throws PersistenceException {
64 - PopularityDisambiguator disambiguator = new PopularityDisambiguator(meaningFetcher, 10);
 65+ PopularityDisambiguator<TermReference, LocalConcept> disambiguator = new PopularityDisambiguator<TermReference, LocalConcept>(meaningFetcher, 10);
6566
6667 Term uk = new Term("UK");
6768 Term london = new Term("London");
@@ -79,7 +80,7 @@
8081 }
8182
8283 public void testGetMeaningsForNode() throws PersistenceException {
83 - PopularityDisambiguator disambiguator = new PopularityDisambiguator(meaningFetcher, 10);
 84+ PopularityDisambiguator<TermReference, LocalConcept> disambiguator = new PopularityDisambiguator<TermReference, LocalConcept>(meaningFetcher, 10);
8485
8586 PhraseOccuranceSet set = getBankAndMonumentPhrases();
8687 Map<PhraseOccurance, List<? extends LocalConcept>> res = disambiguator.getMeanings(set.getRootNode());
@@ -94,7 +95,7 @@
9596 }
9697
9798 public void testGetSequences() throws PersistenceException {
98 - PopularityDisambiguator disambiguator = new PopularityDisambiguator(meaningFetcher, 10);
 99+ PopularityDisambiguator<TermReference, LocalConcept> disambiguator = new PopularityDisambiguator<TermReference, LocalConcept>(meaningFetcher, 10);
99100 PhraseOccuranceSet set = getBankAndMonumentPhrases();
100101
101102 Collection<List<PhraseOccurance>> res = disambiguator.getSequences(set.getRootNode(), 1);
@@ -108,7 +109,7 @@
109110 }
110111
111112 public void testDisambiguateTerms() throws PersistenceException {
112 - PopularityDisambiguator disambiguator = new PopularityDisambiguator(meaningFetcher, 10);
 113+ PopularityDisambiguator<TermReference, LocalConcept> disambiguator = new PopularityDisambiguator<TermReference, LocalConcept>(meaningFetcher, 10);
113114
114115 Term uk = new Term("UK");
115116 Term london = new Term("London");
@@ -127,7 +128,7 @@
128129 public void testDisambiguateNode() throws PersistenceException {
129130 PhraseOccuranceSet set = getBankAndMonumentPhrases();
130131
131 - PopularityDisambiguator disambiguator = new PopularityDisambiguator(meaningFetcher, 10);
 132+ PopularityDisambiguator<TermReference, LocalConcept> disambiguator = new PopularityDisambiguator<TermReference, LocalConcept>(meaningFetcher, 10);
132133 disambiguator.setTrace(traceOutput);
133134
134135 Disambiguation<PhraseOccurance, LocalConcept> result = disambiguator.disambiguate(set.getRootNode(), null);
Index: trunk/WikiWord/WikiWord/src/test/java/de/brightbyte/wikiword/disambig/DisambiguatorTestBase.java
@@ -28,10 +28,11 @@
2929 import de.brightbyte.wikiword.model.PhraseOccurance;
3030 import de.brightbyte.wikiword.model.PhraseOccuranceSet;
3131 import de.brightbyte.wikiword.model.TermReference;
 32+import de.brightbyte.wikiword.model.WikiWordConcept;
3233
3334 public class DisambiguatorTestBase extends TestCase {
3435
35 - protected Map<String, List<? extends LocalConcept>> meanings = new HashMap<String, List<? extends LocalConcept>>();
 36+ protected Map<String, List<LocalConcept>> meanings = new HashMap<String, List<LocalConcept>>();
3637 protected Map<Integer, ConceptFeatures<LocalConcept, Integer>> features = new HashMap<Integer, ConceptFeatures<LocalConcept, Integer>>();
3738 protected Map<Integer, LocalConcept> conceptsById = new HashMap<Integer, LocalConcept>();
3839 protected Map<String, LocalConcept> conceptsByName = new HashMap<String, LocalConcept>();
@@ -48,7 +49,7 @@
4950 return new GroupingCursor<List<String>, String>(c, new ListAbstractor.Accessor<String>(groupBy));
5051 }
5152
52 - protected static void readMeanings(Corpus corpus, InputStream in, Map<String, List<? extends LocalConcept>> meanings) throws IOException, PersistenceException {
 53+ protected static void readMeanings(Corpus corpus, InputStream in, Map<String, List<LocalConcept>> meanings) throws IOException, PersistenceException {
5354 DataCursor<List<List<String>>> cursor = openGroupedTableCursor(in, "UTF-8", 0, true);
5455
5556 List<List<String>> group;
@@ -112,19 +113,19 @@
113114
114115 protected MeaningFetcher<LocalConcept> meaningFetcher = new MeaningFetcher<LocalConcept>() {
115116
116 - public <X extends TermReference> Map<X, List<? extends LocalConcept>> getMeanings(
 117+ public <X extends TermReference> Map<X, List<LocalConcept>> getMeanings(
117118 Collection<X> terms) throws PersistenceException {
118 - Map<X, List<? extends LocalConcept>> m = new HashMap<X, List<? extends LocalConcept>>();
 119+ Map<X, List<LocalConcept>> m = new HashMap<X, List<LocalConcept>>();
119120
120121 for (X t: terms) {
121 - List<? extends LocalConcept> n = getMeanings(t.getTerm());
 122+ List<LocalConcept> n = getMeanings(t.getTerm());
122123 if (n!=null) m.put(t, n);
123124 }
124125
125126 return m;
126127 }
127128
128 - public List<? extends LocalConcept> getMeanings(String term)
 129+ public List<LocalConcept> getMeanings(String term)
129130 throws PersistenceException {
130131 return meanings.get(term);
131132 }
@@ -194,11 +195,11 @@
195196 return c;
196197 }
197198
198 - protected <X extends TermReference>Map<X, List<? extends LocalConcept>> getMeanings(Collection<List<X>> sequences) throws PersistenceException {
199 - Map<X, List<? extends LocalConcept>> m = new HashMap<X, List<? extends LocalConcept>>();
 199+ protected <X extends TermReference>Map<X, List<LocalConcept>> getMeanings(Collection<List<X>> sequences) throws PersistenceException {
 200+ Map<X, List<LocalConcept>> m = new HashMap<X, List<LocalConcept>>();
200201
201202 for (List<X> seq: sequences) {
202 - Map<X, List<? extends LocalConcept>> meanings = meaningFetcher.getMeanings(seq);
 203+ Map<X, List<LocalConcept>> meanings = meaningFetcher.getMeanings(seq);
203204 m.putAll(meanings);
204205 }
205206
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/StoredMeaningFetcher.java
@@ -8,40 +8,40 @@
99 import de.brightbyte.data.cursor.DataSet;
1010 import de.brightbyte.io.Output;
1111 import de.brightbyte.util.PersistenceException;
12 -import de.brightbyte.wikiword.model.LocalConcept;
 12+import de.brightbyte.wikiword.model.WikiWordConcept;
1313 import de.brightbyte.wikiword.model.TermReference;
14 -import de.brightbyte.wikiword.store.LocalConceptStore;
 14+import de.brightbyte.wikiword.store.WikiWordConceptStore;
1515 import de.brightbyte.wikiword.store.WikiWordConceptStore.ConceptQuerySpec;
1616
17 -public class StoredMeaningFetcher implements MeaningFetcher<LocalConcept> {
18 - protected LocalConceptStore store;
 17+public class StoredMeaningFetcher implements MeaningFetcher<WikiWordConcept> {
 18+ protected WikiWordConceptStore store;
1919 protected ConceptQuerySpec spec;
2020 protected Output trace;
2121
22 - public StoredMeaningFetcher(LocalConceptStore store) {
 22+ public StoredMeaningFetcher(WikiWordConceptStore store) {
2323 this(store, null);
2424 }
2525
26 - public StoredMeaningFetcher(LocalConceptStore store, ConceptQuerySpec type) {
 26+ public StoredMeaningFetcher(WikiWordConceptStore store, ConceptQuerySpec type) {
2727 if (store==null) throw new NullPointerException();
2828
2929 this.store = store;
3030 this.spec = type;
3131 }
3232
33 - public List<LocalConcept> getMeanings(String term) throws PersistenceException {
34 - DataSet<LocalConcept> m = store.getMeanings(term, spec); //FIXME: filter/cut-off rules, sort order! //XXX: relevance value?
35 - List<LocalConcept> meanigns = m.load();
 33+ public List<WikiWordConcept> getMeanings(String term) throws PersistenceException {
 34+ DataSet<WikiWordConcept> m = store.getMeanings(term, spec); //FIXME: filter/cut-off rules, sort order! //XXX: relevance value?
 35+ List<WikiWordConcept> meanigns = m.load();
3636
3737 trace("fetched "+meanigns.size()+" meanings for \""+term+"\"");
3838 return meanigns;
3939 }
4040
41 - public <X extends TermReference> Map<X, List<? extends LocalConcept>> getMeanings(Collection<X> terms) throws PersistenceException {
42 - Map<X, List<? extends LocalConcept>> meanings = new HashMap<X, List<? extends LocalConcept>>();
 41+ public <X extends TermReference> Map<X, List<WikiWordConcept>> getMeanings(Collection<X> terms) throws PersistenceException {
 42+ Map<X, List<WikiWordConcept>> meanings = new HashMap<X, List<WikiWordConcept>>();
4343
4444 for (X t: terms) {
45 - List<LocalConcept> m = getMeanings(t.getTerm());
 45+ List<WikiWordConcept> m = getMeanings(t.getTerm());
4646 if (m!=null && m.size()>0) meanings.put(t, m);
4747 }
4848
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/CoherenceDisambiguator.java
@@ -22,14 +22,13 @@
2323 import de.brightbyte.util.PersistenceException;
2424 import de.brightbyte.util.SanityException;
2525 import de.brightbyte.wikiword.model.ConceptFeatures;
26 -import de.brightbyte.wikiword.model.LocalConcept;
2726 import de.brightbyte.wikiword.model.PhraseNode;
2827 import de.brightbyte.wikiword.model.TermReference;
2928 import de.brightbyte.wikiword.model.WikiWordConcept;
3029
31 -public class CoherenceDisambiguator extends AbstractDisambiguator<TermReference, LocalConcept> {
 30+public class CoherenceDisambiguator<T extends TermReference, C extends WikiWordConcept> extends AbstractDisambiguator<T, C> {
3231
33 - public static class CoherenceDisambiguation<T extends TermReference, C extends LocalConcept> extends Disambiguator.Disambiguation<T, C> {
 32+ public static class CoherenceDisambiguation<T extends TermReference, C extends WikiWordConcept> extends Disambiguator.Disambiguation<T, C> {
3433 protected LabeledVector<Integer> centroid;
3534 protected Map<Integer, ConceptFeatures<C, Integer>> features;
3635
@@ -66,12 +65,12 @@
6766 //protected double popularityBias = 0.2; //FIXME: magic number. should "somehow" match popularityNormalizer and similarityNormalizer
6867 //protected double weightBias = 0.5; //FIXME: magic number. should "somehow" match popularityNormalizer
6968
70 - protected FeatureFetcher<LocalConcept, Integer> featureFetcher;
 69+ protected FeatureFetcher<C, Integer> featureFetcher;
7170
7271 protected Similarity<LabeledVector<Integer>> similarityMeasure;
73 - protected Measure<WikiWordConcept> popularityMeasure;
74 - protected PopularityDisambiguator popularityDisambiguator;
75 - protected Comparator<LocalConcept> popularityComparator;
 72+ protected Measure<? super C> popularityMeasure;
 73+ protected PopularityDisambiguator<T, C> popularityDisambiguator;
 74+ protected Comparator<? super C> popularityComparator;
7675
7776 private Functor.Double popularityNormalizer = new Functor.Double() { //NOTE: must map [0:inf] to [0:1] and grow monotonously
7877 public double apply(double pop) {
@@ -90,18 +89,18 @@
9190 protected Functor2.Double weightCombiner = ProductCombiner.instance;
9291 protected Functor.Double weightBooster = SquareBooster.instance;
9392
94 - public CoherenceDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, FeatureFetcher<LocalConcept, Integer> featureFetcher, int cacheCapacity) {
 93+ public CoherenceDisambiguator(MeaningFetcher<? extends C> meaningFetcher, FeatureFetcher<C, Integer> featureFetcher, int cacheCapacity) {
9594 this(meaningFetcher, featureFetcher, cacheCapacity, null, null);
9695 }
9796
98 - public CoherenceDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, FeatureFetcher<LocalConcept, Integer> featureFetcher, int cacheCapacity, Measure<WikiWordConcept> popularityMeasure, Similarity<LabeledVector<Integer>> sim) {
 97+ public CoherenceDisambiguator(MeaningFetcher<? extends C> meaningFetcher, FeatureFetcher<C, Integer> featureFetcher, int cacheCapacity, Measure<? super C> popularityMeasure, Similarity<LabeledVector<Integer>> sim) {
9998 super(meaningFetcher, cacheCapacity);
10099
101100 if (popularityMeasure==null) popularityMeasure = WikiWordConcept.theCardinality;
102101 if (sim==null) sim = featureFetcher.getFeaturesAreNormalized() ? ScalarVectorSimilarity.<Integer>getInstance() : CosineVectorSimilarity.<Integer>getInstance(); //if pre-normalized, use scalar to calc cosin
103102 if (featureFetcher==null) throw new NullPointerException();
104103
105 - if (cacheCapacity>0) featureFetcher = new CachingFeatureFetcher<LocalConcept, Integer>(featureFetcher, cacheCapacity);
 104+ if (cacheCapacity>0) featureFetcher = new CachingFeatureFetcher<C, Integer>(featureFetcher, cacheCapacity);
106105
107106 this.featureFetcher = featureFetcher;
108107 this.popularityDisambiguator = new PopularityDisambiguator(getMeaningFetcher(), 0, popularityMeasure);
@@ -110,7 +109,7 @@
111110 this.setSimilarityMeasure(sim);
112111 }
113112
114 - public FeatureFetcher<LocalConcept, Integer> getFeatureFetcher() {
 113+ public FeatureFetcher<C, Integer> getFeatureFetcher() {
115114 return featureFetcher;
116115 }
117116
@@ -123,7 +122,7 @@
124123 this.popularityNormalizer = popularityFactor;
125124 }
126125
127 - public Measure<WikiWordConcept> getPopularityMeasure() {
 126+ public Measure<? super C> getPopularityMeasure() {
128127 return popularityMeasure;
129128 }
130129
@@ -140,10 +139,10 @@
141140 return weightCombiner;
142141 }
143142
144 - public void setPopularityMeasure(Measure<WikiWordConcept> popularityMeasure) {
 143+ public void setPopularityMeasure(Measure<? super C> popularityMeasure) {
145144 this.popularityMeasure = popularityMeasure;
146145 this.popularityDisambiguator.setPopularityMeasure(popularityMeasure);
147 - this.popularityComparator = new Measure.Comparator<LocalConcept>(popularityMeasure, true);
 146+ this.popularityComparator = new Measure.Comparator<C>(popularityMeasure, true);
148147 }
149148
150149 public void setWeightCombiner(Functor2.Double weightCombiner) {
@@ -167,7 +166,7 @@
168167 this.similarityNormalizer = similarityFactor;
169168 }
170169
171 - public void setFeatureFetcher(FeatureFetcher<LocalConcept, Integer> featureFetcher) {
 170+ public void setFeatureFetcher(FeatureFetcher<C, Integer> featureFetcher) {
172171 this.featureFetcher = featureFetcher;
173172 }
174173
@@ -205,10 +204,10 @@
206205 this.maxMeanings = maxMeanings;
207206 }
208207
209 - protected FeatureFetcher<LocalConcept, Integer> getFeatureCache(Map<? extends TermReference, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context) throws PersistenceException {
 208+ protected FeatureFetcher<C, Integer> getFeatureCache(Map<? extends T, List<? extends C>> meanings, Collection<? extends C> context) throws PersistenceException {
210209 //NOTE: pre-fetch all features in one go
211 - List<LocalConcept> concepts = new ArrayList<LocalConcept>(meanings.size()*10);
212 - for (List<? extends LocalConcept> m: meanings.values()) {
 210+ List<C> concepts = new ArrayList<C>(meanings.size()*10);
 211+ for (List<? extends C> m: meanings.values()) {
213212 if (m!=null) concepts.addAll(m);
214213 }
215214
@@ -221,17 +220,17 @@
222221 /* (non-Javadoc)
223222 * @see de.brightbyte.wikiword.disambig.Disambiguator#disambiguate(java.util.List)
224223 */
225 - public <X extends TermReference>CoherenceDisambiguation<X, LocalConcept> disambiguate(PhraseNode<X> root, Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context) throws PersistenceException {
226 - if (meanings.isEmpty()) return new CoherenceDisambiguation<X, LocalConcept>(Collections.<X, LocalConcept>emptyMap(), Collections.<X>emptyList(), Collections.<Integer, ConceptFeatures<LocalConcept, Integer>>emptyMap(), ConceptFeatures.newIntFeaturVector(1), 0.0, "no terms or meanings");
 224+ public <X extends T>CoherenceDisambiguation<X, C> disambiguate(PhraseNode<X> root, Map<X, List<? extends C>> meanings, Collection<? extends C> context) throws PersistenceException {
 225+ if (meanings.isEmpty()) return new CoherenceDisambiguation<X, C>(Collections.<X, C>emptyMap(), Collections.<X>emptyList(), Collections.<Integer, ConceptFeatures<C, Integer>>emptyMap(), ConceptFeatures.newIntFeaturVector(1), 0.0, "no terms or meanings");
227226
228 - LabeledMatrix<LocalConcept, LocalConcept> similarities = new MapLabeledMatrix<LocalConcept, LocalConcept>(true);
229 - FeatureFetcher<LocalConcept, Integer> features = getFeatureCache(meanings, context);
 227+ LabeledMatrix<C, C> similarities = new MapLabeledMatrix<C, C>(true);
 228+ FeatureFetcher<C, Integer> features = getFeatureCache(meanings, context);
230229
231230 int sz = meanings.size();
232231 if (context!=null) sz += context.size();
233232
234233 if (sz<2) {
235 - Disambiguation<X, LocalConcept> r = popularityDisambiguator.disambiguate(root, meanings, context);
 234+ Disambiguation<X, C> r = popularityDisambiguator.disambiguate(root, meanings, context);
236235 return getScore(r.getInterpretation(), context, similarities, features);
237236 }
238237
@@ -240,7 +239,7 @@
241240 sz = meanings.size();
242241 if (context!=null) sz += context.size();
243242 if (sz <2) {
244 - Disambiguation<X, LocalConcept> r = popularityDisambiguator.disambiguate(root, meanings, context);
 243+ Disambiguation<X, C> r = popularityDisambiguator.disambiguate(root, meanings, context);
245244 return getScore(r.getInterpretation(), context, similarities, features);
246245 }
247246
@@ -248,34 +247,34 @@
249248 return disambiguate(sequences, root, meanings, context);
250249 }
251250
252 - public <X extends TermReference>CoherenceDisambiguation<X, LocalConcept> disambiguate(Collection<List<X>> sequences, PhraseNode<X> root, Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context) throws PersistenceException {
253 - LabeledMatrix<LocalConcept, LocalConcept> similarities = new MapLabeledMatrix<LocalConcept, LocalConcept>(true);
254 - FeatureFetcher<LocalConcept, Integer> features = getFeatureCache(meanings, context);
 251+ public <X extends T>CoherenceDisambiguation<X, C> disambiguate(Collection<List<X>> sequences, PhraseNode<X> root, Map<X, List<? extends C>> meanings, Collection<? extends C> context) throws PersistenceException {
 252+ LabeledMatrix<C, C> similarities = new MapLabeledMatrix<C, C>(true);
 253+ FeatureFetcher<C, Integer> features = getFeatureCache(meanings, context);
255254
256255 return disambiguate(sequences, root, meanings, context, similarities, features);
257256 }
258257
259 - private <X extends TermReference>CoherenceDisambiguation<X, LocalConcept> disambiguate(Collection<List<X>> sequences, PhraseNode<X> root, Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context, LabeledMatrix<LocalConcept, LocalConcept> similarities, FeatureFetcher<LocalConcept, Integer> features) throws PersistenceException {
 258+ private <X extends T>CoherenceDisambiguation<X, C> disambiguate(Collection<List<X>> sequences, PhraseNode<X> root, Map<X, List<? extends C>> meanings, Collection<? extends C> context, LabeledMatrix<C, C> similarities, FeatureFetcher<C, Integer> features) throws PersistenceException {
260259
261260 //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.
262261
263 - Collection<Disambiguator.Interpretation<X, LocalConcept>> interpretations = getInterpretations(sequences, meanings);
 262+ Collection<Disambiguator.Interpretation<X, C>> interpretations = getInterpretations(sequences, meanings);
264263
265264 return getBestInterpretation(root, meanings, context, interpretations, similarities, features);
266265 }
267266
268 - protected void pruneMeanings(Map<? extends TermReference, List<? extends LocalConcept>> meanings) {
 267+ protected void pruneMeanings(Map<? extends T, List<? extends C>> meanings) {
269268 if (minPopularity<=1) return; //nothing to do
270269
271270 Iterator<?> eit = meanings.entrySet().iterator();
272271 while (eit.hasNext()) {
273 - Entry<TermReference, List<? extends LocalConcept>> e = (Entry<TermReference, List<? extends LocalConcept>>) eit.next(); //XXX: ugly cast. got confused about generics. ugh.
274 - List<? extends LocalConcept> m = e.getValue();
 272+ Entry<T, List<? extends C>> e = (Entry<T, List<? extends C>>) eit.next(); //XXX: ugly cast. got confused about generics. ugh.
 273+ List<? extends C> m = e.getValue();
275274 if (m==null) continue;
276275
277 - Iterator<? extends LocalConcept> cit = m.iterator();
 276+ Iterator<? extends C> cit = m.iterator();
278277 while (cit.hasNext()) {
279 - LocalConcept c = cit.next();
 278+ C c = cit.next();
280279 double p = popularityMeasure.measure(c);
281280
282281 if (p<minPopularity) {
@@ -297,17 +296,17 @@
298297 }
299298 }
300299
301 - protected <X extends TermReference>CoherenceDisambiguation<X, LocalConcept> getBestInterpretation(PhraseNode<X> root, Map<X, List<? extends LocalConcept>> meanings,
302 - Collection<? extends LocalConcept> context, Collection<Disambiguator.Interpretation<X, LocalConcept>> interpretations,
303 - LabeledMatrix<LocalConcept, LocalConcept> similarities, FeatureFetcher<LocalConcept, Integer> features) throws PersistenceException {
 300+ protected <X extends T>CoherenceDisambiguation<X, C> getBestInterpretation(PhraseNode<X> root, Map<X, List<? extends C>> meanings,
 301+ Collection<? extends C> context, Collection<Disambiguator.Interpretation<X, C>> interpretations,
 302+ LabeledMatrix<C, C> similarities, FeatureFetcher<C, Integer> features) throws PersistenceException {
304303
305 - CoherenceDisambiguation<X, LocalConcept> best = null;
 304+ CoherenceDisambiguation<X, C> best = null;
306305 double bestScore = 0;
307306
308307 if ( interpretations.size() == 0 ) return null;
309308 else if ( interpretations.size() == 1 ) {
310 - Disambiguator.Interpretation<X, LocalConcept> interp = interpretations.iterator().next();
311 - CoherenceDisambiguation<X, LocalConcept> r = getScore(interp, context, similarities, features);
 309+ Disambiguator.Interpretation<X, C> interp = interpretations.iterator().next();
 310+ CoherenceDisambiguation<X, C> r = getScore(interp, context, similarities, features);
312311
313312 trace("only one interpretation available: "+r);
314313 return r;
@@ -315,8 +314,8 @@
316315
317316 trace("finding best of "+interpretations.size()+" interpretations.");
318317
319 - for (Disambiguator.Interpretation<X, LocalConcept> interp: interpretations) {
320 - CoherenceDisambiguation<X, LocalConcept> r = getScore(interp, context, similarities, features);
 318+ for (Disambiguator.Interpretation<X, C> interp: interpretations) {
 319+ CoherenceDisambiguation<X, C> r = getScore(interp, context, similarities, features);
321320
322321 if ( best == null || r.getScore() > bestScore) {
323322 best = r;
@@ -329,8 +328,8 @@
330329 if (best==null || bestScore<minScore) {
331330 trace("best score is not good enough ("+bestScore+"<"+minScore+"), using popularity disambiguator.");
332331
333 - Disambiguation<X, LocalConcept> p = popularityDisambiguator.disambiguate(root, meanings, context);
334 - CoherenceDisambiguation<X, LocalConcept> r = getScore(p.getInterpretation(), context, similarities, features);
 332+ Disambiguation<X, C> p = popularityDisambiguator.disambiguate(root, meanings, context);
 333+ CoherenceDisambiguation<X, C> r = getScore(p.getInterpretation(), context, similarities, features);
335334
336335 trace("best of "+interpretations.size()+" interpretations by popularity: "+r);
337336 return r;
@@ -342,40 +341,40 @@
343342 return best;
344343 }
345344
346 - public <X extends TermReference>Collection<Disambiguator.Interpretation<X, LocalConcept>> getInterpretations(Collection<List<X>> sequences, Map<X, List<? extends LocalConcept>> meanings) {
347 - List<Disambiguator.Interpretation<X, LocalConcept>> interpretations = new ArrayList<Disambiguator.Interpretation<X, LocalConcept>>();
 345+ public <X extends T>Collection<Disambiguator.Interpretation<X, C>> getInterpretations(Collection<List<X>> sequences, Map<X, List<? extends C>> meanings) {
 346+ List<Disambiguator.Interpretation<X, C>> interpretations = new ArrayList<Disambiguator.Interpretation<X, C>>();
348347 for (List<X> sq: sequences) {
349348 if (sq.isEmpty()) continue;
350 - Collection<Disambiguator.Interpretation<X, LocalConcept>> sqint = getSequenceInterpretations(sq, meanings);
 349+ Collection<Disambiguator.Interpretation<X, C>> sqint = getSequenceInterpretations(sq, meanings);
351350 interpretations.addAll(sqint);
352351 }
353352
354353 return interpretations;
355354 }
356355
357 - public <X extends TermReference>Collection<Disambiguator.Interpretation<X, LocalConcept>> getSequenceInterpretations(List<X> sequence, Map<X, List<? extends LocalConcept>> meanings) {
 356+ public <X extends T>Collection<Disambiguator.Interpretation<X, C>> getSequenceInterpretations(List<X> sequence, Map<X, List<? extends C>> meanings) {
358357 if (sequence.size()==0) {
359 - return Collections.singletonList(new Disambiguator.Interpretation<X, LocalConcept>(Collections.<X, LocalConcept>emptyMap(), sequence));
 358+ return Collections.singletonList(new Disambiguator.Interpretation<X, C>(Collections.<X, C>emptyMap(), sequence));
360359 }
361360
362361 X t = sequence.get(0);
363 - List<? extends LocalConcept> m = meanings.get(t);
 362+ List<? extends C> m = meanings.get(t);
364363
365 - Collection<Disambiguator.Interpretation<X, LocalConcept>> base = getSequenceInterpretations(sequence.subList(1, sequence.size()), meanings);
 364+ Collection<Disambiguator.Interpretation<X, C>> base = getSequenceInterpretations(sequence.subList(1, sequence.size()), meanings);
366365
367 - List<Disambiguator.Interpretation<X, LocalConcept>> interpretations = new ArrayList<Disambiguator.Interpretation<X, LocalConcept>>();
 366+ List<Disambiguator.Interpretation<X, C>> interpretations = new ArrayList<Disambiguator.Interpretation<X, C>>();
368367
369 - for (Disambiguator.Interpretation<X, LocalConcept> be: base) {
 368+ for (Disambiguator.Interpretation<X, C> be: base) {
370369 if (m==null || m.isEmpty()) {
371 - Disambiguator.Interpretation<X, LocalConcept>interp = new Disambiguator.Interpretation<X, LocalConcept>(be.getMeanings(), sequence);
 370+ Disambiguator.Interpretation<X, C>interp = new Disambiguator.Interpretation<X, C>(be.getMeanings(), sequence);
372371 interpretations.add(interp);
373372 } else {
374 - for (LocalConcept c: m) {
375 - Map<X, LocalConcept> e = new HashMap<X, LocalConcept>();
 373+ for (C c: m) {
 374+ Map<X, C> e = new HashMap<X, C>();
376375 e.putAll(be.getMeanings());
377376 e.put(t, c);
378377
379 - Disambiguator.Interpretation<X, LocalConcept>interp = new Disambiguator.Interpretation<X, LocalConcept>(e, sequence);
 378+ Disambiguator.Interpretation<X, C>interp = new Disambiguator.Interpretation<X, C>(e, sequence);
380379 interpretations.add(interp);
381380 }
382381 }
@@ -385,30 +384,30 @@
386385 return interpretations;
387386 }
388387
389 - protected <X extends TermReference>CoherenceDisambiguation<X, LocalConcept> getScore(Disambiguator.Interpretation<X, LocalConcept> interp, Collection<? extends LocalConcept> context, LabeledMatrix<LocalConcept, LocalConcept> similarities, FeatureFetcher<LocalConcept, Integer> features) throws PersistenceException {
390 - Map<? extends TermReference, LocalConcept> concepts;
 388+ protected <X extends T>CoherenceDisambiguation<X, C> getScore(Disambiguator.Interpretation<X, C> interp, Collection<? extends C> context, LabeledMatrix<C, C> similarities, FeatureFetcher<C, Integer> features) throws PersistenceException {
 389+ Map<TermReference, C> concepts;
391390
392391 if (context!=null || interp.getMeanings().size()!=interp.getSequence().size()) {
393 - concepts = new HashMap<TermReference, LocalConcept>();
 392+ concepts = new HashMap<TermReference, C>();
394393
395 - for (X t: interp.getSequence()) {
396 - LocalConcept m = interp.getMeanings().get(t);
397 - ((HashMap<TermReference, LocalConcept>)concepts).put(t, m);
 394+ for (TermReference t: interp.getSequence()) {
 395+ C m = interp.getMeanings().get(t);
 396+ ((HashMap<TermReference, C>)concepts).put(t, m);
398397 }
399398
400399 if (context != null) {
401 - for (LocalConcept con: context) {
402 - if (con!=null)((HashMap<TermReference, LocalConcept>)concepts).put(new Term(con.getName(), 1), con);
 400+ for (C con: context) {
 401+ if (con!=null)((HashMap<TermReference, C>)concepts).put(new Term(con.getName(), 1), con);
403402 }
404403 }
405404 } else {
406 - concepts = interp.getMeanings();
 405+ concepts = (HashMap<TermReference, C>)interp.getMeanings();
407406 }
408407
409408 int c = concepts.size();
410409
411410 if (c == 0) {
412 - CoherenceDisambiguation<X, LocalConcept> r = new CoherenceDisambiguation<X, LocalConcept>(interp.getMeanings(), interp.getSequence(), Collections.<Integer, ConceptFeatures<LocalConcept, Integer>>emptyMap(), ConceptFeatures.newIntFeaturVector(1), 0, "empty");
 411+ CoherenceDisambiguation<X, C> r = new CoherenceDisambiguation<X, C>(interp.getMeanings(), interp.getSequence(), Collections.<Integer, ConceptFeatures<C, Integer>>emptyMap(), ConceptFeatures.newIntFeaturVector(1), 0, "empty");
413412 return r;
414413 }
415414
@@ -420,23 +419,23 @@
421420 int simCount = 0; //simCount should be <= n in the end. count and check.
422421
423422 LabeledVector<Integer> sum = ConceptFeatures.newIntFeaturVector( concepts.size() * 200 ); //XXX: magic number
424 - Map<Integer, ConceptFeatures<LocalConcept, Integer>> disambigFeatures = new HashMap<Integer, ConceptFeatures<LocalConcept, Integer>>();
 423+ Map<Integer, ConceptFeatures<C, Integer>> disambigFeatures = new HashMap<Integer, ConceptFeatures<C, Integer>>();
425424 double sim = 0, pop = 0, weight = 0;
426425 int i=0, j=0;
427 - for (Map.Entry<? extends TermReference, LocalConcept> ea: concepts.entrySet()) {
428 - LocalConcept a = ea.getValue();
 426+ for (Map.Entry<TermReference, C> ea: concepts.entrySet()) {
 427+ C a = ea.getValue();
429428 TermReference term = ea.getKey();
430429
431430 i++;
432431 if (a==null) continue;
433432
434 - ConceptFeatures<LocalConcept, Integer> fa = features.getFeatures(a);
 433+ ConceptFeatures<C, Integer> fa = features.getFeatures(a);
435434 disambigFeatures.put(a.getId(), fa);
436435 sum.add(fa.getFeatureVector());
437436
438437 j=0;
439 - for (Map.Entry<? extends TermReference, LocalConcept> eb: concepts.entrySet()) {
440 - LocalConcept b = eb.getValue();
 438+ for (Map.Entry<TermReference, C> eb: concepts.entrySet()) {
 439+ C b = eb.getValue();
441440
442441 j++;
443442 if (i==j) break;
@@ -452,7 +451,7 @@
453452 d = similarities.get(a, b);
454453 }
455454 else {
456 - ConceptFeatures<LocalConcept, Integer> fb = features.getFeatures(b);
 455+ ConceptFeatures<C, Integer> fb = features.getFeatures(b);
457456
458457 if (fa==null || fb==null) d = 0;
459458 else {
@@ -522,7 +521,7 @@
523522 double score = scoreCombiner.apply(simf, popf);
524523 score = doubleSanity(score, "score", "check scoreCombiner!", 0, 0.1, 1, 0.1);
525524
526 - CoherenceDisambiguation<X, LocalConcept> r = new CoherenceDisambiguation<X, LocalConcept>(interp.getMeanings(), interp.getSequence(), disambigFeatures, centroid, score, "simf="+simf+", popf="+popf+", sim="+sim+", pop="+pop+", weight="+weight);
 525+ CoherenceDisambiguation<X, C> r = new CoherenceDisambiguation<X, C>(interp.getMeanings(), interp.getSequence(), disambigFeatures, centroid, score, "simf="+simf+", popf="+popf+", sim="+sim+", pop="+pop+", weight="+weight);
527526 return r;
528527 }
529528
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/CachingFeatureFetcher.java
@@ -31,7 +31,7 @@
3232 ConceptFeatures<C, K> f = cache.get(c.getId());
3333 if (f!=null) return f;
3434
35 - f = fetcher.getFeatures(c);
 35+ f = (ConceptFeatures<C, K>)fetcher.getFeatures(c);
3636 cache.put(c.getId(), f);
3737
3838 return f;
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/AbstractDisambiguator.java
@@ -15,20 +15,20 @@
1616
1717 public abstract class AbstractDisambiguator<T extends TermReference, C extends WikiWordConcept> implements Disambiguator<T, C> {
1818
19 - private MeaningFetcher<C> meaningFetcher;
 19+ private MeaningFetcher<? extends C> meaningFetcher;
2020
2121 private Output trace;
2222
2323 private Map<String, C> meaningOverrides;
2424
25 - public AbstractDisambiguator(MeaningFetcher<C> meaningFetcher, int cacheCapacity) {
 25+ public AbstractDisambiguator(MeaningFetcher<? extends C> meaningFetcher, int cacheCapacity) {
2626 if (meaningFetcher==null) throw new NullPointerException();
2727
2828 if (cacheCapacity>0) meaningFetcher = new CachingMeaningFetcher<C>(meaningFetcher, cacheCapacity);
2929 this.meaningFetcher = meaningFetcher;
3030 }
3131
32 - public MeaningFetcher<C> getMeaningFetcher() {
 32+ public MeaningFetcher<? extends C> getMeaningFetcher() {
3333 return meaningFetcher;
3434 }
3535
@@ -100,7 +100,7 @@
101101 }
102102 }
103103
104 - Map<X, List<? extends C>> meanings = meaningFetcher.getMeanings(todo);
 104+ Map<X, List<? extends C>> meanings = (Map<X, List<? extends C>>)(Object)meaningFetcher.getMeanings(todo); //FIXME: got confused by generics :(
105105
106106 if (meaningOverrides!=null && todo.size()!=terms.size()) {
107107 for (X t: terms) {
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/MeaningFetcher.java
@@ -9,7 +9,7 @@
1010 import de.brightbyte.wikiword.model.WikiWordConcept;
1111
1212 public interface MeaningFetcher<C extends WikiWordConcept> {
13 - public List<? extends C> getMeanings(String term) throws PersistenceException;
 13+ public List<C> getMeanings(String term) throws PersistenceException;
1414
15 - public <X extends TermReference>Map<X, List<? extends C>> getMeanings(Collection<X> terms) throws PersistenceException;
 15+ public <X extends TermReference>Map<X, List<C>> getMeanings(Collection<X> terms) throws PersistenceException;
1616 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/SlidingCoherenceDisambiguator.java
@@ -14,31 +14,30 @@
1515 import de.brightbyte.data.measure.Similarity;
1616 import de.brightbyte.util.PersistenceException;
1717 import de.brightbyte.wikiword.model.ConceptFeatures;
18 -import de.brightbyte.wikiword.model.LocalConcept;
1918 import de.brightbyte.wikiword.model.PhraseNode;
2019 import de.brightbyte.wikiword.model.TermReference;
2120 import de.brightbyte.wikiword.model.WikiWordConcept;
2221
23 -public class SlidingCoherenceDisambiguator extends CoherenceDisambiguator {
 22+public class SlidingCoherenceDisambiguator<T extends TermReference, C extends WikiWordConcept> extends CoherenceDisambiguator<T, C> {
2423
2524 protected int window;
2625 protected int initialWindow;
2726
28 - public SlidingCoherenceDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, FeatureFetcher<LocalConcept, Integer> featureFetcher, int cacheCapacity) {
 27+ public SlidingCoherenceDisambiguator(MeaningFetcher<? extends C> meaningFetcher, FeatureFetcher<C, Integer> featureFetcher, int cacheCapacity) {
2928 this(meaningFetcher, featureFetcher, cacheCapacity, null, null, 5, 5);
3029 }
3130
32 - public SlidingCoherenceDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, FeatureFetcher<LocalConcept, Integer> featureFetcher, int cacheCapacity, Measure<WikiWordConcept> popularityMeasure, Similarity<LabeledVector<Integer>> sim, int window, int initialWindow) {
 31+ public SlidingCoherenceDisambiguator(MeaningFetcher<? extends C> meaningFetcher, FeatureFetcher<C, Integer> featureFetcher, int cacheCapacity, Measure<C> popularityMeasure, Similarity<LabeledVector<Integer>> sim, int window, int initialWindow) {
3332 super(meaningFetcher, featureFetcher, cacheCapacity, popularityMeasure, sim);
3433
3534 this.window = window;
3635 this.initialWindow = initialWindow;
3736 }
3837
39 - public <X extends TermReference>Disambiguation<X, LocalConcept> evalStep(List<X> baseSequence, Map<X, LocalConcept> interpretation, PhraseNode<X> node,
40 - Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context,
41 - LabeledMatrix<LocalConcept, LocalConcept> similarities, FeatureFetcher<LocalConcept, Integer> features) throws PersistenceException {
42 - X term = node.getTermReference();
 38+ public <X extends T>Disambiguation<X, C> evalStep(List<X> baseSequence, Map<X, C> interpretation, PhraseNode<X> node,
 39+ Map<X, List<? extends C>> meanings, Collection<? extends C> context,
 40+ LabeledMatrix<C, C> similarities, FeatureFetcher<C, Integer> features) throws PersistenceException {
 41+ X term = node.getTermReference();
4342
4443 List<X> sequence = new ArrayList<X>(baseSequence);
4544 sequence.add(term);
@@ -49,12 +48,12 @@
5049
5150 List<X> frame = sequence.subList(from, to);
5251
53 - Disambiguation<X, LocalConcept> r ;
 52+ Disambiguation<X, C> r ;
5453
5554 if (to-from < 2) {
5655 r = popularityDisambiguator.disambiguate(frame, meanings, context);
5756 } else {
58 - Collection<Disambiguator.Interpretation<X, LocalConcept>> interpretations = getInterpretations(frame, interpretation, meanings);
 57+ Collection<Disambiguator.Interpretation<X, C>> interpretations = getInterpretations(frame, interpretation, meanings);
5958 r = getBestInterpretation(node, meanings, context, interpretations, similarities, features);
6059 }
6160
@@ -64,19 +63,19 @@
6564 /* (non-Javadoc)
6665 * @see de.brightbyte.wikiword.disambig.Disambiguator#disambiguate(java.util.List)
6766 */
68 - public <X extends TermReference>CoherenceDisambiguation<X, LocalConcept> disambiguate(PhraseNode<X> root, Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context) throws PersistenceException {
69 - if (meanings.isEmpty()) return new CoherenceDisambiguation<X, LocalConcept>(Collections.<X, LocalConcept>emptyMap(), Collections.<X>emptyList(), Collections.<Integer, ConceptFeatures<LocalConcept, Integer>>emptyMap(), ConceptFeatures.newIntFeaturVector(1), 0.0, "no terms or meanings");
 67+ public <X extends T>CoherenceDisambiguation<X, C> disambiguate(PhraseNode<X> root, Map<X, List<? extends C>> meanings, Collection<? extends C> context) throws PersistenceException {
 68+ if (meanings.isEmpty()) return new CoherenceDisambiguation<X, C>(Collections.<X, C>emptyMap(), Collections.<X>emptyList(), Collections.<Integer, ConceptFeatures<C, Integer>>emptyMap(), ConceptFeatures.newIntFeaturVector(1), 0.0, "no terms or meanings");
7069
7170 int sz = meanings.size();
7271 if (context!=null) sz += context.size();
7372
7473 //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.
7574
76 - LabeledMatrix<LocalConcept, LocalConcept> similarities = new MapLabeledMatrix<LocalConcept, LocalConcept>(true);
77 - FeatureFetcher<LocalConcept, Integer> features = getFeatureCache(meanings, context);
 75+ LabeledMatrix<C, C> similarities = new MapLabeledMatrix<C, C>(true);
 76+ FeatureFetcher<C, Integer> features = getFeatureCache(meanings, context);
7877
7978 if (window < 2 || sz<2) {
80 - Disambiguation<X, LocalConcept> r = popularityDisambiguator.disambiguate(root, meanings, context);
 79+ Disambiguation<X, C> r = popularityDisambiguator.disambiguate(root, meanings, context);
8180 return getScore(r.getInterpretation(), context, similarities, features);
8281 }
8382
@@ -86,17 +85,17 @@
8786 if (context!=null) sz += context.size();
8887
8988 if (sz<2) {
90 - Disambiguation<X, LocalConcept> r = popularityDisambiguator.disambiguate(root, meanings, context);
 89+ Disambiguation<X, C> r = popularityDisambiguator.disambiguate(root, meanings, context);
9190 return getScore(r.getInterpretation(), context, similarities, features);
9291 }
9392
94 - Map<X, LocalConcept> disambig = new HashMap<X, LocalConcept>(meanings.size());
 93+ Map<X, C> disambig = new HashMap<X, C>(meanings.size());
9594 PhraseNode<X> currentNode = root;
9695 List<X> sequence = new ArrayList<X>();
9796
9897 if (initialWindow > 0) { //apply full coherence disambig to initial window size. initialWindow == 1 will trigger a popularity disambig.
9998 Collection<List<X>> sequences = getSequences(root, initialWindow);
100 - Disambiguation<X, LocalConcept> r;
 99+ Disambiguation<X, C> r;
101100
102101 if (initialWindow == 1) r = popularityDisambiguator.disambiguate(sequences, root, meanings, context);
103102 else r = super.disambiguate(sequences, root, meanings, context);
@@ -110,11 +109,11 @@
111110 Collection<? extends PhraseNode<X>> successors = currentNode.getSuccessors();
112111 if (successors==null || successors.isEmpty()) break;
113112
114 - Disambiguation<X, LocalConcept> best = null;
 113+ Disambiguation<X, C> best = null;
115114 PhraseNode<X> bestNode = null;
116115
117116 for (PhraseNode<X> n: successors) {
118 - Disambiguation<X, LocalConcept> r = evalStep(sequence, disambig, n, meanings, context, similarities, features); //empty sequence will trigger popularity disambig
 117+ Disambiguation<X, C> r = evalStep(sequence, disambig, n, meanings, context, similarities, features); //empty sequence will trigger popularity disambig
119118 trace("evalStep("+n+"): " + r.toString());
120119 if (best == null || best.getScore() < r.getScore()) {
121120 best = r;
@@ -126,14 +125,14 @@
127126 currentNode = bestNode;
128127 sequence.add(term);
129128
130 - LocalConcept meaning = best.getMeanings().get(term);
 129+ C meaning = best.getMeanings().get(term);
131130 disambig.put(term, meaning);
132131 }
133132
134 - return getScore(new Disambiguator.Interpretation<X, LocalConcept>(disambig, sequence), context, similarities, features); //FIXME: this is unnecessarily expensive, we usually don't need the scores this calculates.
 133+ return getScore(new Disambiguator.Interpretation<X, C>(disambig, sequence), context, similarities, features); //FIXME: this is unnecessarily expensive, we usually don't need the scores this calculates.
135134 }
136135
137 - protected <X extends TermReference>Collection<Disambiguator.Interpretation<X, LocalConcept>> getInterpretations(List<X> frame, Map<X, ? extends LocalConcept> known, Map<? extends TermReference, List<? extends LocalConcept>> meanings) {
 136+ protected <X extends T>Collection<Disambiguator.Interpretation<X, C>> getInterpretations(List<X> frame, Map<X, ? extends C> known, Map<? extends T, List<? extends C>> meanings) {
138137 //strip out all terms with no known meaning
139138 if (meanings.keySet().size() != frame.size()) {
140139 List<X> t = new ArrayList<X>(frame.size());
@@ -142,12 +141,12 @@
143142 frame = t;
144143 }
145144
146 - Map<X, List<? extends LocalConcept>> mset = new HashMap<X, List<? extends LocalConcept>>();
 145+ Map<X, List<? extends C>> mset = new HashMap<X, List<? extends C>>();
147146
148147 for (X t: frame) {
149 - List<? extends LocalConcept> m;
 148+ List<? extends C> m;
150149
151 - LocalConcept c = known.get(t);
 150+ C c = known.get(t);
152151
153152 if (c!=null) m = Collections.singletonList(c);
154153 else m = meanings.get(t);
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/PopularityDisambiguator.java
@@ -10,36 +10,35 @@
1111 import de.brightbyte.data.Functor2;
1212 import de.brightbyte.data.measure.Measure;
1313 import de.brightbyte.data.measure.Measure.Comparator;
14 -import de.brightbyte.wikiword.model.LocalConcept;
1514 import de.brightbyte.wikiword.model.PhraseNode;
1615 import de.brightbyte.wikiword.model.TermReference;
1716 import de.brightbyte.wikiword.model.WikiWordConcept;
1817
19 -public class PopularityDisambiguator extends AbstractDisambiguator<TermReference, LocalConcept> {
 18+public class PopularityDisambiguator<T extends TermReference, C extends WikiWordConcept> extends AbstractDisambiguator<T, C> {
2019
21 - protected Measure<WikiWordConcept> popularityMeasure;
22 - protected Comparator<LocalConcept> popularityComparator;
 20+ protected Measure<? super C> popularityMeasure;
 21+ protected Comparator<? super C> popularityComparator;
2322
2423 protected Functor.Double weightBooster = SquareBooster.instance;
2524 protected Functor2.Double weigthCombiner = new ProductCombiner(); //NOTE: pop and weight are not in the same scale.
2625
27 - public PopularityDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, int cacheCapacity) {
 26+ public PopularityDisambiguator(MeaningFetcher<C> meaningFetcher, int cacheCapacity) {
2827 this(meaningFetcher, cacheCapacity, WikiWordConcept.theCardinality);
2928 }
3029
31 - public PopularityDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, int cacheCapacity, Measure<WikiWordConcept> popularityMeasure) {
 30+ public PopularityDisambiguator(MeaningFetcher<C> meaningFetcher, int cacheCapacity, Measure<? super C> popularityMeasure) {
3231 super(meaningFetcher, cacheCapacity);
3332
3433 this.setPopularityMeasure(popularityMeasure);
3534 }
3635
37 - public Measure<WikiWordConcept> getPopularityMeasure() {
 36+ public Measure<? super C> getPopularityMeasure() {
3837 return popularityMeasure;
3938 }
4039
41 - public void setPopularityMeasure(Measure<WikiWordConcept> popularityMeasure) {
 40+ public void setPopularityMeasure(Measure<? super C> popularityMeasure) {
4241 this.popularityMeasure = popularityMeasure;
43 - this.popularityComparator = new Measure.Comparator<LocalConcept>(popularityMeasure, true);
 42+ this.popularityComparator = new Measure.Comparator<C>(popularityMeasure, true);
4443 }
4544
4645 public void setWeightCombiner(Functor2.Double weightCombiner) {
@@ -62,16 +61,16 @@
6362 this.weigthCombiner = weigthCombiner;
6463 }
6564
66 - public <X extends TermReference>Disambiguation<X, LocalConcept> disambiguate(PhraseNode<X> root, Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context) {
 65+ public <X extends T>Disambiguation<X, C> disambiguate(PhraseNode<X> root, Map<X, List<? extends C>> meanings, Collection<? extends C> context) {
6766 Collection<List<X>> sequences = getSequences(root, Integer.MAX_VALUE);
6867 return disambiguate(sequences, root, meanings, context);
6968 }
7069
71 - public <X extends TermReference>Disambiguation<X, LocalConcept> disambiguate(Collection<List<X>> sequences, PhraseNode<X> root, Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context) {
72 - Disambiguation<X, LocalConcept> best = null;
 70+ public <X extends T>Disambiguation<X, C> disambiguate(Collection<List<X>> sequences, PhraseNode<X> root, Map<X, List<? extends C>> meanings, Collection<? extends C> context) {
 71+ Disambiguation<X, C> best = null;
7372
7473 for (List<X> sequence: sequences) {
75 - Disambiguation<X, LocalConcept> r = disambiguate(sequence, meanings, context);
 74+ Disambiguation<X, C> r = disambiguate(sequence, meanings, context);
7675 trace(r.toString());
7776 if (best == null || best.getScore() < r.getScore()) {
7877 best = r;
@@ -82,20 +81,20 @@
8382 return best;
8483 }
8584
86 - public <X extends TermReference>Disambiguation<X, LocalConcept> disambiguate(List<X> sequence, Map<X, List<? extends LocalConcept>> meanings, Collection<? extends LocalConcept> context) {
87 - if (sequence.isEmpty() || meanings.isEmpty()) return new Disambiguator.Disambiguation<X, LocalConcept>(Collections.<X, LocalConcept>emptyMap(), Collections.<X>emptyList(), 0.0, "no terms or meanings");
 85+ public <X extends T>Disambiguation<X, C> disambiguate(List<X> sequence, Map<X, List<? extends C>> meanings, Collection<? extends C> context) {
 86+ if (sequence.isEmpty() || meanings.isEmpty()) return new Disambiguator.Disambiguation<X, C>(Collections.<X, C>emptyMap(), Collections.<X>emptyList(), 0.0, "no terms or meanings");
8887
89 - Map<X, LocalConcept> disambig = new HashMap<X, LocalConcept>();
 88+ Map<X, C> disambig = new HashMap<X, C>();
9089 double score = 0;
9190 int totalPop = 0;
9291
9392 for (X t: sequence) {
94 - List<? extends LocalConcept> m = meanings.get(t);
 93+ List<? extends C> m = meanings.get(t);
9594 if (m==null || m.size()==0) continue;
9695
9796 if (m.size()>1) Collections.sort(m, popularityComparator);
9897
99 - LocalConcept c = m.get(0);
 98+ C c = m.get(0);
10099 disambig.put(t, c);
101100
102101 double pop = popularityMeasure.measure(c);
@@ -108,7 +107,7 @@
109108
110109 if (disambig.size()>0) score = score / sequence.size(); //NOTE: treat unknown terms as having pop = 0
111110
112 - Disambiguation<X, LocalConcept> r = new Disambiguation<X, LocalConcept>(disambig, sequence, score, "score="+score+"; pop="+totalPop);
 111+ Disambiguation<X, C> r = new Disambiguation<X, C>(disambig, sequence, score, "score="+score+"; pop="+totalPop);
113112 return r;
114113 }
115114
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/CachingMeaningFetcher.java
@@ -15,18 +15,18 @@
1616 public class CachingMeaningFetcher<C extends WikiWordConcept> implements MeaningFetcher<C> {
1717
1818 protected MeaningFetcher<? extends C> fetcher;
19 - protected MRUHashMap<String, List<? extends C>> cache;
 19+ protected MRUHashMap<String, List<C>> cache;
2020
2121 public CachingMeaningFetcher(MeaningFetcher<? extends C> fetcher, int capacity) {
2222 this.fetcher = fetcher;
23 - this.cache = new MRUHashMap<String, List<? extends C>>(capacity);
 23+ this.cache = new MRUHashMap<String, List<C>>(capacity);
2424 }
2525
26 - public List<? extends C> getMeanings(String term) throws PersistenceException {
27 - List<? extends C> meanings = cache.get(term);
 26+ public List<C> getMeanings(String term) throws PersistenceException {
 27+ List<C> meanings = cache.get(term);
2828
2929 if (meanings==null) {
30 - meanings = fetcher.getMeanings(term);
 30+ meanings = (List<C>)fetcher.getMeanings(term); //XXX: ugly cast :(
3131 cache.put(term, meanings);
3232 }
3333
@@ -34,12 +34,12 @@
3535 }
3636
3737
38 - public <X extends TermReference> Map<X, List<? extends C>> getMeanings(Collection<X> terms) throws PersistenceException {
39 - Map<X, List<? extends C>> meanings= new HashMap<X, List<? extends C>>();
 38+ public <X extends TermReference> Map<X, List<C>> getMeanings(Collection<X> terms) throws PersistenceException {
 39+ Map<X, List<C>> meanings= new HashMap<X, List<C>>();
4040 List<X> todo = new ArrayList<X>(terms.size());
4141
4242 for (X t: terms) {
43 - List<? extends C> m = cache.get(t.getTerm());
 43+ List<C> m = cache.get(t.getTerm());
4444 if (m!=null) {
4545 meanings.put(t, m);
4646 cache.put(t.getTerm(), m);
@@ -50,11 +50,11 @@
5151 }
5252
5353 if (!todo.isEmpty()) {
54 - Map<X, List<? extends C>> parentMeanings = (Map<X, List<? extends C>>)(Object)fetcher.getMeanings(todo); //XXX: ugly cast, generics are a pain
 54+ Map<X, List<C>> parentMeanings = (Map<X, List<C>>)(Object)fetcher.getMeanings(todo); //XXX: ugly cast, generics are a pain
5555 meanings.putAll(parentMeanings);
5656
5757 for (X t: todo) {
58 - List<? extends C> m = parentMeanings.get(t);
 58+ List<C> m = parentMeanings.get(t);
5959 if (m==null) m = Collections.emptyList();
6060 cache.put(t.getTerm(), m);
6161 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/LocalConceptStore.java
@@ -12,8 +12,6 @@
1313 */
1414 public interface LocalConceptStore extends WikiWordConceptStore<LocalConcept>, WikiWordLocalStore {
1515
16 - public abstract DataSet<LocalConcept> getMeanings(String term, ConceptQuerySpec spec) throws PersistenceException;
17 -
1816 public int getNumberOfTerms() throws PersistenceException;
1917
2018 public abstract DataSet<TermMeaning> getAllTerms() throws PersistenceException;
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java
@@ -3,13 +3,14 @@
44 import de.brightbyte.data.cursor.DataSet;
55 import de.brightbyte.util.PersistenceException;
66 import de.brightbyte.wikiword.ConceptType;
7 -import de.brightbyte.wikiword.model.LocalConcept;
87 import de.brightbyte.wikiword.model.WikiWordConcept;
98
109
1110 public interface WikiWordConceptStore<T extends WikiWordConcept> extends WikiWordConceptStoreBase {
1211
1312 public static class ConceptQuerySpec {
 13+ //TODO: relevance limit, order, proper name types & preferred language
 14+
1415 private boolean includeRelations;
1516 private boolean includeStatistics;
1617 private boolean includeResource;
@@ -76,6 +77,8 @@
7778
7879 public DataSet<? extends T> getAllConcepts(ConceptQuerySpec spec) throws PersistenceException;
7980
 81+ public abstract DataSet<? extends WikiWordConcept> getMeanings(String term, ConceptQuerySpec spec) throws PersistenceException;
 82+
8083 public ConceptType getConceptType(int type) throws PersistenceException;
8184
8285 public StatisticsStore getStatisticsStore() throws PersistenceException;
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/GlobalConceptStore.java
@@ -7,7 +7,6 @@
88 import de.brightbyte.wikiword.Corpus;
99 import de.brightbyte.wikiword.model.GlobalConcept;
1010 import de.brightbyte.wikiword.model.LocalConcept;
11 -import de.brightbyte.wikiword.store.WikiWordConceptStore.ConceptQuerySpec;
1211
1312
1413 /**
@@ -15,10 +14,7 @@
1615 */
1716 public interface GlobalConceptStore extends WikiWordConceptStore<GlobalConcept> {
1817
19 - //TODO: relevance limit? order?
2018 public DataSet<GlobalConcept> getMeanings(String lang, String term, ConceptQuerySpec spec) throws PersistenceException;
21 -
22 - public DataSet<GlobalConcept> getMeanings(String term, ConceptQuerySpec spec) throws PersistenceException;
2319
2420 //public abstract ResultSet queryTermRefersTo() throws PersistenceException;
2521
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/WikiWordConcept.java
@@ -11,7 +11,7 @@
1212 import de.brightbyte.wikiword.ConceptType;
1313 import de.brightbyte.wikiword.DatasetIdentifier;
1414
15 -public abstract class WikiWordConcept {
 15+public class WikiWordConcept {
1616 public static class ByName implements Comparator<WikiWordConcept> {
1717 protected Collator collator;
1818
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java
@@ -480,7 +480,7 @@
481481 }
482482
483483 public void listMeaningsLocal(String term, ConsoleOutput out) throws PersistenceException {
484 - DataSet<LocalConcept> meanings = getLocalConceptStore().getMeanings(term, resolvedConceptSpec);
 484+ DataSet<? extends WikiWordConcept> meanings = getLocalConceptStore().getMeanings(term, resolvedConceptSpec);
485485 out.writeConcepts(meanings);
486486 }
487487

Status & tagging log