r68121 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68120‎ | r68121 | r68122 >
Date:13:37, 16 June 2010
Author:daniel
Status:deferred
Tags:
Comment:
changed interfacer of SpellingAlternator to avoid object instantiation
Modified paths:
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/analyzer/mangler/SpellingAlternator.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/analyzer/mangler/SpellingAlternator.java
@@ -5,7 +5,6 @@
66 import java.util.Collections;
77 import java.util.HashSet;
88 import java.util.List;
9 -import java.util.Set;
109
1110 import de.brightbyte.wikiword.disambig.Term;
1211
@@ -21,16 +20,19 @@
2221 this.weightFactor = weightFactor;
2322 }
2423
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+ }
2728
28 - Set<Term> alternatives = new HashSet<Term>();
 29+ if (into==null) into = new HashSet<Term>();
 30+ into.add(new Term(term));
2931
30 - collectAlternatives(term, 0, 1, alternatives);
31 - return alternatives;
 32+ if (!manglers.isEmpty()) collectAlternatives(term, 0, 1, into);
 33+ return into;
3234 }
3335
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) {
3537 if (index>=manglers.size()) return;
3638 if (!alternatives.add(new Term(term, weight))) return;
3739
@@ -44,14 +46,14 @@
4547 collectAlternatives(term, index+1, weight, alternatives); //primitive recursion
4648 }
4749
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());
5052
5153 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);
5456 }
5557
56 - return alternatives;
 58+ return into;
5759 }
5860 }

Status & tagging log