use of org.puimula.libvoikko.Analysis in project sukija by ahomansikka.
the class StartSuggestion method suggest.
@Override
public boolean suggest(String word, VoikkoAttribute voikkoAtt) {
if (!hyphen && (word.indexOf("-") >= 0)) {
//System.out.println ("DING " + word);
return false;
}
//System.out.println ("HUUHAA " + hyphen + " " + word + " " + word.indexOf ("-"));
List<Analysis> analysisList = new ArrayList<Analysis>();
//
for (int i = Math.min(maxLength, word.length() - 1); i >= minLength; i--) {
final String startOfWord = word.substring(0, i);
List<Analysis> analysis = voikko.analyze(startOfWord);
if (baseFormOnly) {
for (Analysis a : analysis) {
if (startOfWord.equals(a.get("BASEFORM").toLowerCase())) {
analysisList.add(a);
}
}
if (!tryAll && analysisList.size() > 0) {
voikkoAtt.addAnalysis(analysisList);
return true;
}
} else {
if (analysis.size() > 0) {
analysisList.addAll(analysis);
if (!tryAll) {
voikkoAtt.addAnalysis(analysisList);
return true;
}
}
}
}
voikkoAtt.addAnalysis(analysisList);
return (analysisList.size() > 0);
}
use of org.puimula.libvoikko.Analysis in project sukija by ahomansikka.
the class SuggestionTester method analyze.
public static void analyze(Reader reader, Writer writer, Voikko voikko, String suggestionFile, boolean stopOnSuccess, boolean useHyphenFilter, TokenStream t) throws IOException {
List<Analysis> analysis = null;
((Tokenizer) t).setReader(reader);
// t = new VoikkoFilter (t, voikko);
t = new SuggestionFilter(t, voikko, suggestionFile, false);
CharTermAttribute termAtt = t.addAttribute(CharTermAttribute.class);
BaseFormAttribute baseFormAtt = t.addAttribute(BaseFormAttribute.class);
FlagsAttribute flagsAtt = t.addAttribute(FlagsAttribute.class);
OriginalWordAttribute originalWordAtt = t.addAttribute(OriginalWordAttribute.class);
try {
t.reset();
while (t.incrementToken()) {
writer.write("Sana: " + originalWordAtt.getOriginalWord() + " | " + termAtt.toString() + " | ");
writer.write(Constants.toString(flagsAtt));
writer.write("\n");
writer.flush();
}
t.end();
} finally {
t.close();
}
}
use of org.puimula.libvoikko.Analysis in project sukija by ahomansikka.
the class VoikkoAttributeImpl method copyTo.
/** Tämä kopioi myös kentät eli on deep copy. */
@Override
public void copyTo(AttributeImpl target) {
// Deep copy.
List<Analysis> cloned = null;
if (analysis != null) {
cloned = new ArrayList<Analysis>(analysis.size());
for (int i = 0; i < analysis.size(); i++) {
Analysis a = new Analysis();
a.putAll(analysis.get(i));
cloned.add(a);
}
}
((VoikkoAttributeImpl) target).setAnalysis(cloned);
}
use of org.puimula.libvoikko.Analysis in project sukija by ahomansikka.
the class VoikkoUtils method newBaseForm.
public static final Analysis newBaseForm(String baseForm) {
Analysis analysis = new Analysis();
analysis.put("BASEFORM", baseForm);
return analysis;
}
use of org.puimula.libvoikko.Analysis in project sukija by ahomansikka.
the class AhoCorasickCorrector method getCorrections.
public Set<String> getCorrections(List<Analysis> analysis) {
Set<String> set = new HashSet<String>();
for (Analysis a : analysis) {
final String wb = a.get("WORDBASES");
final String baseForm = a.get("BASEFORM");
set.add(baseForm.toLowerCase());
if (wb != null) {
//System.out.println ("Base0 " + wb + " " + baseForm);
for (Token token : trie.tokenize(wb)) {
//System.out.println ("Base2 " + token.getFragment());
if (token.isMatch()) {
//System.out.println ("Base3 " + token.getFragment());
String[] s = MapClass.map.get(token.getFragment());
//System.out.println ("Base4 " + java.util.Arrays.asList(s).toString());
for (int i = 1; i < s.length; i++) {
//System.out.println ("Base5 " + s[i]);
if (baseForm.indexOf(s[i]) >= 0) {
String bf = baseForm.replace(s[i], s[0]);
//System.out.println ("Base8 " + baseForm.indexOf(s[i]));
//System.out.println ("Base9 " + baseForm + " " + bf + " § " + wb);
set.add(bf.toLowerCase());
}
}
}
}
}
}
return set;
}
Aggregations