Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/SlidingCoherenceDisambiguator.java |
— | — | @@ -22,6 +22,7 @@ |
23 | 23 | public class SlidingCoherenceDisambiguator extends CoherenceDisambiguator { |
24 | 24 | |
25 | 25 | protected int window ; |
| 26 | + protected boolean runningStart = false; |
26 | 27 | |
27 | 28 | public SlidingCoherenceDisambiguator(MeaningFetcher<LocalConcept> meaningFetcher, FeatureFetcher<LocalConcept, Integer> featureFetcher, boolean featuresAreNormalized) { |
28 | 29 | this(meaningFetcher, featureFetcher, WikiWordConcept.theCardinality, |
— | — | @@ -64,7 +65,9 @@ |
65 | 66 | LabeledMatrix<LocalConcept, LocalConcept> similarities = new MapLabeledMatrix<LocalConcept, LocalConcept>(true); |
66 | 67 | FeatureFetcher<LocalConcept, Integer> features = getFeatureCache(meanings, context); |
67 | 68 | |
68 | | - for (int i= window; ; i++) { |
| 69 | + int start = runningStart ? 0 : window; |
| 70 | + |
| 71 | + for (int i= start; ; i++) { |
69 | 72 | int from = i-window; |
70 | 73 | int to = i+1; |
71 | 74 | |
— | — | @@ -122,5 +125,14 @@ |
123 | 126 | } |
124 | 127 | |
125 | 128 | 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 | + |
127 | 139 | } |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/PopularityDisambiguator.java |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | List<? extends LocalConcept> m = meanings.get(t); |
47 | 47 | if (m==null || m.size()==0) continue; |
48 | 48 | |
49 | | - if (m.size()>0) Collections.sort(m, popularityComparator); |
| 49 | + if (m.size()>1) Collections.sort(m, popularityComparator); |
50 | 50 | |
51 | 51 | LocalConcept c = m.get(0); |
52 | 52 | disambig.put(t, c); |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/AbstractDisambiguator.java |
— | — | @@ -1,6 +1,8 @@ |
2 | 2 | package de.brightbyte.wikiword.disambig; |
3 | 3 | |
| 4 | +import java.util.ArrayList; |
4 | 5 | import java.util.Collection; |
| 6 | +import java.util.Collections; |
5 | 7 | import java.util.List; |
6 | 8 | import java.util.Map; |
7 | 9 | |
— | — | @@ -11,18 +13,46 @@ |
12 | 14 | |
13 | 15 | public abstract class AbstractDisambiguator<T extends TermReference, C extends WikiWordConcept> implements Disambiguator<T, C> { |
14 | 16 | |
15 | | - protected MeaningCache.Manager<C> meaningCacheManager; |
| 17 | + private MeaningCache.Manager<C> meaningCacheManager; |
16 | 18 | |
17 | | - protected Output trace; |
| 19 | + private Output trace; |
| 20 | + |
| 21 | + private Map<? extends T, C> meaningOverrides; |
18 | 22 | |
19 | 23 | public AbstractDisambiguator(MeaningFetcher<? extends C> meaningFetcher) { |
20 | 24 | if (meaningFetcher==null) throw new NullPointerException(); |
21 | 25 | this.meaningCacheManager = new MeaningCache.Manager<C>(meaningFetcher, 10); |
22 | 26 | } |
23 | 27 | |
| 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 | + |
24 | 55 | 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); |
27 | 57 | return disambiguate(terms, meanings, context); |
28 | 58 | } |
29 | 59 | |