Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/analyzer/mangler/SpellingAlternator.java |
— | — | @@ -5,7 +5,6 @@ |
6 | 6 | import java.util.Collections; |
7 | 7 | import java.util.HashSet; |
8 | 8 | import java.util.List; |
9 | | -import java.util.Set; |
10 | 9 | |
11 | 10 | import de.brightbyte.wikiword.disambig.Term; |
12 | 11 | |
— | — | @@ -21,16 +20,19 @@ |
22 | 21 | this.weightFactor = weightFactor; |
23 | 22 | } |
24 | 23 | |
25 | | - public Collection<Term> getAlternatives(String term) { |
26 | | - if (manglers.isEmpty()) return Collections.singleton(new Term(term)); |
| 24 | + public Collection<Term> getAlternatives(String term, Collection<Term> into) { |
| 25 | + if (manglers.isEmpty() && into==null) { |
| 26 | + return Collections.singleton(new Term(term)); |
| 27 | + } |
27 | 28 | |
28 | | - Set<Term> alternatives = new HashSet<Term>(); |
| 29 | + if (into==null) into = new HashSet<Term>(); |
| 30 | + into.add(new Term(term)); |
29 | 31 | |
30 | | - collectAlternatives(term, 0, 1, alternatives); |
31 | | - return alternatives; |
| 32 | + if (!manglers.isEmpty()) collectAlternatives(term, 0, 1, into); |
| 33 | + return into; |
32 | 34 | } |
33 | 35 | |
34 | | - private void collectAlternatives(String term, int index, double weight, Set<Term> alternatives) { |
| 36 | + private void collectAlternatives(String term, int index, double weight, Collection<Term> alternatives) { |
35 | 37 | if (index>=manglers.size()) return; |
36 | 38 | if (!alternatives.add(new Term(term, weight))) return; |
37 | 39 | |
— | — | @@ -44,14 +46,14 @@ |
45 | 47 | collectAlternatives(term, index+1, weight, alternatives); //primitive recursion |
46 | 48 | } |
47 | 49 | |
48 | | - public List<Collection<Term>> getAlternatives(List<String> terms) { |
49 | | - List<Collection<Term>> alternatives = new ArrayList<Collection<Term>>(terms.size()); |
| 50 | + public List<Collection<Term>> getAlternatives(List<String> terms, List<Collection<Term>> into) { |
| 51 | + if (into == null) into = new ArrayList<Collection<Term>>(terms.size()); |
50 | 52 | |
51 | 53 | for (String t: terms) { |
52 | | - Collection<Term> alt = getAlternatives(t); |
53 | | - alternatives.add(alt); |
| 54 | + Collection<Term> alt = getAlternatives(t, null); |
| 55 | + into.add(alt); |
54 | 56 | } |
55 | 57 | |
56 | | - return alternatives; |
| 58 | + return into; |
57 | 59 | } |
58 | 60 | } |