r64485 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64484‎ | r64485 | r64486 >
Date:12:20, 1 April 2010
Author:daniel
Status:deferred
Tags:
Comment:
disambiguator tweaks: meaning overrides, etc
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/PopularityDisambiguator.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/SlidingCoherenceDisambiguator.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/SlidingCoherenceDisambiguator.java
@@ -22,6 +22,7 @@
2323 public class SlidingCoherenceDisambiguator extends CoherenceDisambiguator {
2424
2525 protected int window ;
 26+ protected boolean runningStart = false;
2627
2728 public SlidingCoherenceDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, FeatureFetcher<LocalConcept, Integer> featureFetcher, boolean featuresAreNormalized) {
2829 this(meaningFetcher, featureFetcher, WikiWordConcept.theCardinality,
@@ -64,7 +65,9 @@
6566 LabeledMatrix<LocalConcept, LocalConcept> similarities = new MapLabeledMatrix<LocalConcept, LocalConcept>(true);
6667 FeatureFetcher<LocalConcept, Integer> features = getFeatureCache(meanings, context);
6768
68 - for (int i= window; ; i++) {
 69+ int start = runningStart ? 0 : window;
 70+
 71+ for (int i= start; ; i++) {
6972 int from = i-window;
7073 int to = i+1;
7174
@@ -122,5 +125,14 @@
123126 }
124127
125128 return getInterpretations(terms.subList(from, to), mset);
126 - }
 129+ }
 130+
 131+ public boolean getRunningStart() {
 132+ return runningStart;
 133+ }
 134+
 135+ public void setRunningStart(boolean runningStart) {
 136+ this.runningStart = runningStart;
 137+ }
 138+
127139 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/PopularityDisambiguator.java
@@ -45,7 +45,7 @@
4646 List<? extends LocalConcept> m = meanings.get(t);
4747 if (m==null || m.size()==0) continue;
4848
49 - if (m.size()>0) Collections.sort(m, popularityComparator);
 49+ if (m.size()>1) Collections.sort(m, popularityComparator);
5050
5151 LocalConcept c = m.get(0);
5252 disambig.put(t, c);
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/AbstractDisambiguator.java
@@ -1,6 +1,8 @@
22 package de.brightbyte.wikiword.disambig;
33
 4+import java.util.ArrayList;
45 import java.util.Collection;
 6+import java.util.Collections;
57 import java.util.List;
68 import java.util.Map;
79
@@ -11,18 +13,46 @@
1214
1315 public abstract class AbstractDisambiguator<T extends TermReference, C extends WikiWordConcept> implements Disambiguator<T, C> {
1416
15 - protected MeaningCache.Manager<C> meaningCacheManager;
 17+ private MeaningCache.Manager<C> meaningCacheManager;
1618
17 - protected Output trace;
 19+ private Output trace;
 20+
 21+ private Map<? extends T, C> meaningOverrides;
1822
1923 public AbstractDisambiguator(MeaningFetcher<? extends C> meaningFetcher) {
2024 if (meaningFetcher==null) throw new NullPointerException();
2125 this.meaningCacheManager = new MeaningCache.Manager<C>(meaningFetcher, 10);
2226 }
2327
 28+ public void setMeaningOverrides(Map<? extends T, C> overrideMap) {
 29+ this.meaningOverrides = overrideMap;
 30+ }
 31+
 32+ protected <X extends T>Map<X, List<? extends C>> getMeanings(List<X> terms) throws PersistenceException {
 33+ List<X> todo = terms;
 34+
 35+ if (meaningOverrides!=null) {
 36+ todo = new ArrayList<X>();
 37+ for (X t: terms) {
 38+ if (!meaningOverrides.containsKey(t)) todo.add(t);
 39+ }
 40+ }
 41+
 42+ MeaningCache<C> mcache = meaningCacheManager.newCache();
 43+ Map<X, List<? extends C>> meanings = mcache.getMeanings(todo);
 44+
 45+ if (meaningOverrides!=null && todo.size()!=terms.size()) {
 46+ for (X t: terms) {
 47+ C c = meaningOverrides.get(t);
 48+ if (c!=null) meanings.put(t, Collections.singletonList(c));
 49+ }
 50+ }
 51+
 52+ return meanings;
 53+ }
 54+
2455 public <X extends T>Result<X, C> disambiguate(List<X> terms, Collection<C> context) throws PersistenceException {
25 - MeaningCache<C> mcache = meaningCacheManager.newCache();
26 - Map<X, List<? extends C>> meanings = mcache.getMeanings(terms);
 56+ Map<X, List<? extends C>> meanings = getMeanings(terms);
2757 return disambiguate(terms, meanings, context);
2858 }
2959

Status & tagging log