@Test public void should_create_roots_without_orthographic_changes_and_no_lexeme_attributes() { { final List<DynamicRoot> roots = findRootsForPartialInput("al", "al"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("al")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("al")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("almak")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Verb)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.NoVoicing))); } { final List<DynamicRoot> roots = findRootsForPartialInput("sal", "sal"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("sal")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("sal")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("salmak")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Verb)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.NoVoicing))); } { final List<DynamicRoot> roots = findRootsForPartialInput("al", "aldı"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("al")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("al")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("almak")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Verb)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.NoVoicing))); } { final List<DynamicRoot> roots = findRootsForPartialInput("sal", "saldı"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("sal")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("sal")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("salmak")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Verb)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.NoVoicing))); } }
@Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishChar lastVowel = partialInput.getLastVowel(); final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Verb; final SecondaryPos secondaryPos = null; final EnumSet<LexemeAttribute> lexemeAttributes = EnumSet.noneOf(LexemeAttribute.class); final DynamicLexeme lexeme = new DynamicLexeme(lemmaSeq.getUnderlyingString(), lemmaRootSeq.getUnderlyingString(), primaryPos, secondaryPos, lexemeAttributes); final EnumSet<PhoneticExpectation> phoneticExpectations = EnumSet.noneOf(PhoneticExpectation.class); final EnumSet<PhoneticAttribute> phoneticAttributes = phoneticsAnalyzer.calculatePhoneticAttributes(partialInput, lexemeAttributes); final DynamicRoot noAttrRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); this.setLexemeAndPhoneticAttributes(Arrays.asList(noAttrRoot)); this.setLemma(Arrays.asList(noAttrRoot)); final TurkishChar lastChar = partialInput.getLastChar(); final TurkicLetter lastLetter = lastChar.getLetter(); final boolean partialSurfaceCanBeRootOfAVerb = this.seemsLikeAValidVerbRoot(partialInput); if (wholeSurface.equals(partialInput)) return partialSurfaceCanBeRootOfAVerb ? Arrays.asList(noAttrRoot) : Collections.<DynamicRoot>emptyList(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); final TurkicLetter firstLetterAfterPartialInput = firstCharAfterPartialInput.getLetter(); final String wholeSurfaceStr = wholeSurface.getUnderlyingString(); final String partialInputStr = partialInput.getUnderlyingString(); final boolean mightHaveProgressiveVowelDrop = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("iyor", "ıyor", "uyor", "üyor")); final boolean mightHaveAorist_A = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ar", "er")); final boolean mightHaveAorist_I = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ır", "ir")); final boolean voicingMightHaveHappened = lastLetter.equals(TurkishAlphabet.L_d) && firstLetterAfterPartialInput.isVowel(); final Set<DynamicRoot> possibleProgressiveVowelDropRoots = mightHaveProgressiveVowelDrop ? this.getProgressiveDropRoots(noAttrRoot, lastVowel) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_A_Roots = mightHaveAorist_A ? this.getAorist_A_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_I_Roots = mightHaveAorist_I ? this.getAorist_I_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleCausativeRoots = this.getPossibleCausativeRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); final Set<DynamicRoot> possiblePassiveRoots = this.getPossiblePassiveRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); if (voicingMightHaveHappened) { Function<DynamicRoot, DynamicRoot> voicingRootFunction = new Function<DynamicRoot, DynamicRoot>() { @Override public DynamicRoot apply(DynamicRoot input) { return getPossibleVoicingRoot(input); } }; final Collection<DynamicRoot> possibleProgressiveVowelDropRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleProgressiveVowelDropRoots), voicingRootFunction); possibleProgressiveVowelDropRoots.addAll(possibleProgressiveVowelDropRoots_voicing); final Collection<DynamicRoot> possibleAorist_A_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_A_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_A_Roots_voicing); final Collection<DynamicRoot> possibleAorist_I_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_I_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_I_Roots_voicing); final Collection<DynamicRoot> possibleCausativeRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleCausativeRoots), voicingRootFunction); possibleCausativeRoots.addAll(possibleCausativeRoots_voicing); final Collection<DynamicRoot> possiblePassiveRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possiblePassiveRoots), voicingRootFunction); possiblePassiveRoots.addAll(possiblePassiveRoots_voicing); } final HashSet<DynamicRoot> generatedRoots = new HashSet<DynamicRoot>(); generatedRoots.add(noAttrRoot); if (voicingMightHaveHappened) generatedRoots.add(this.getPossibleVoicingRoot(noAttrRoot)); generatedRoots.addAll(possibleProgressiveVowelDropRoots); generatedRoots.addAll(possibleAorist_A_Roots); generatedRoots.addAll(possibleAorist_I_Roots); generatedRoots.addAll(possibleCausativeRoots); generatedRoots.addAll(possiblePassiveRoots); this.setLexemeAndPhoneticAttributes(generatedRoots); this.setLemma(generatedRoots); return Collections2.filter(generatedRoots, new Predicate<DynamicRoot>() { @Override public boolean apply(DynamicRoot input) { return seemsLikeAValidVerbRoot(new TurkishSequence(input.getLexeme().getLemmaRoot())); } }); }
BruteForceVerbRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishChar lastVowel = partialInput.getLastVowel(); final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Verb; final SecondaryPos secondaryPos = null; final EnumSet<LexemeAttribute> lexemeAttributes = EnumSet.noneOf(LexemeAttribute.class); final DynamicLexeme lexeme = new DynamicLexeme(lemmaSeq.getUnderlyingString(), lemmaRootSeq.getUnderlyingString(), primaryPos, secondaryPos, lexemeAttributes); final EnumSet<PhoneticExpectation> phoneticExpectations = EnumSet.noneOf(PhoneticExpectation.class); final EnumSet<PhoneticAttribute> phoneticAttributes = phoneticsAnalyzer.calculatePhoneticAttributes(partialInput, lexemeAttributes); final DynamicRoot noAttrRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); this.setLexemeAndPhoneticAttributes(Arrays.asList(noAttrRoot)); this.setLemma(Arrays.asList(noAttrRoot)); final TurkishChar lastChar = partialInput.getLastChar(); final TurkicLetter lastLetter = lastChar.getLetter(); final boolean partialSurfaceCanBeRootOfAVerb = this.seemsLikeAValidVerbRoot(partialInput); if (wholeSurface.equals(partialInput)) return partialSurfaceCanBeRootOfAVerb ? Arrays.asList(noAttrRoot) : Collections.<DynamicRoot>emptyList(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); final TurkicLetter firstLetterAfterPartialInput = firstCharAfterPartialInput.getLetter(); final String wholeSurfaceStr = wholeSurface.getUnderlyingString(); final String partialInputStr = partialInput.getUnderlyingString(); final boolean mightHaveProgressiveVowelDrop = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("iyor", "ıyor", "uyor", "üyor")); final boolean mightHaveAorist_A = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ar", "er")); final boolean mightHaveAorist_I = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ır", "ir")); final boolean voicingMightHaveHappened = lastLetter.equals(TurkishAlphabet.L_d) && firstLetterAfterPartialInput.isVowel(); final Set<DynamicRoot> possibleProgressiveVowelDropRoots = mightHaveProgressiveVowelDrop ? this.getProgressiveDropRoots(noAttrRoot, lastVowel) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_A_Roots = mightHaveAorist_A ? this.getAorist_A_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_I_Roots = mightHaveAorist_I ? this.getAorist_I_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleCausativeRoots = this.getPossibleCausativeRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); final Set<DynamicRoot> possiblePassiveRoots = this.getPossiblePassiveRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); if (voicingMightHaveHappened) { Function<DynamicRoot, DynamicRoot> voicingRootFunction = new Function<DynamicRoot, DynamicRoot>() { @Override public DynamicRoot apply(DynamicRoot input) { return getPossibleVoicingRoot(input); } }; final Collection<DynamicRoot> possibleProgressiveVowelDropRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleProgressiveVowelDropRoots), voicingRootFunction); possibleProgressiveVowelDropRoots.addAll(possibleProgressiveVowelDropRoots_voicing); final Collection<DynamicRoot> possibleAorist_A_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_A_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_A_Roots_voicing); final Collection<DynamicRoot> possibleAorist_I_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_I_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_I_Roots_voicing); final Collection<DynamicRoot> possibleCausativeRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleCausativeRoots), voicingRootFunction); possibleCausativeRoots.addAll(possibleCausativeRoots_voicing); final Collection<DynamicRoot> possiblePassiveRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possiblePassiveRoots), voicingRootFunction); possiblePassiveRoots.addAll(possiblePassiveRoots_voicing); } final HashSet<DynamicRoot> generatedRoots = new HashSet<DynamicRoot>(); generatedRoots.add(noAttrRoot); if (voicingMightHaveHappened) generatedRoots.add(this.getPossibleVoicingRoot(noAttrRoot)); generatedRoots.addAll(possibleProgressiveVowelDropRoots); generatedRoots.addAll(possibleAorist_A_Roots); generatedRoots.addAll(possibleAorist_I_Roots); generatedRoots.addAll(possibleCausativeRoots); generatedRoots.addAll(possiblePassiveRoots); this.setLexemeAndPhoneticAttributes(generatedRoots); this.setLemma(generatedRoots); return Collections2.filter(generatedRoots, new Predicate<DynamicRoot>() { @Override public boolean apply(DynamicRoot input) { return seemsLikeAValidVerbRoot(new TurkishSequence(input.getLexeme().getLemmaRoot())); } }); } }
BruteForceVerbRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishChar lastVowel = partialInput.getLastVowel(); final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Verb; final SecondaryPos secondaryPos = null; final EnumSet<LexemeAttribute> lexemeAttributes = EnumSet.noneOf(LexemeAttribute.class); final DynamicLexeme lexeme = new DynamicLexeme(lemmaSeq.getUnderlyingString(), lemmaRootSeq.getUnderlyingString(), primaryPos, secondaryPos, lexemeAttributes); final EnumSet<PhoneticExpectation> phoneticExpectations = EnumSet.noneOf(PhoneticExpectation.class); final EnumSet<PhoneticAttribute> phoneticAttributes = phoneticsAnalyzer.calculatePhoneticAttributes(partialInput, lexemeAttributes); final DynamicRoot noAttrRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); this.setLexemeAndPhoneticAttributes(Arrays.asList(noAttrRoot)); this.setLemma(Arrays.asList(noAttrRoot)); final TurkishChar lastChar = partialInput.getLastChar(); final TurkicLetter lastLetter = lastChar.getLetter(); final boolean partialSurfaceCanBeRootOfAVerb = this.seemsLikeAValidVerbRoot(partialInput); if (wholeSurface.equals(partialInput)) return partialSurfaceCanBeRootOfAVerb ? Arrays.asList(noAttrRoot) : Collections.<DynamicRoot>emptyList(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); final TurkicLetter firstLetterAfterPartialInput = firstCharAfterPartialInput.getLetter(); final String wholeSurfaceStr = wholeSurface.getUnderlyingString(); final String partialInputStr = partialInput.getUnderlyingString(); final boolean mightHaveProgressiveVowelDrop = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("iyor", "ıyor", "uyor", "üyor")); final boolean mightHaveAorist_A = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ar", "er")); final boolean mightHaveAorist_I = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ır", "ir")); final boolean voicingMightHaveHappened = lastLetter.equals(TurkishAlphabet.L_d) && firstLetterAfterPartialInput.isVowel(); final Set<DynamicRoot> possibleProgressiveVowelDropRoots = mightHaveProgressiveVowelDrop ? this.getProgressiveDropRoots(noAttrRoot, lastVowel) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_A_Roots = mightHaveAorist_A ? this.getAorist_A_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_I_Roots = mightHaveAorist_I ? this.getAorist_I_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleCausativeRoots = this.getPossibleCausativeRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); final Set<DynamicRoot> possiblePassiveRoots = this.getPossiblePassiveRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); if (voicingMightHaveHappened) { Function<DynamicRoot, DynamicRoot> voicingRootFunction = new Function<DynamicRoot, DynamicRoot>() { @Override public DynamicRoot apply(DynamicRoot input) { return getPossibleVoicingRoot(input); } }; final Collection<DynamicRoot> possibleProgressiveVowelDropRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleProgressiveVowelDropRoots), voicingRootFunction); possibleProgressiveVowelDropRoots.addAll(possibleProgressiveVowelDropRoots_voicing); final Collection<DynamicRoot> possibleAorist_A_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_A_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_A_Roots_voicing); final Collection<DynamicRoot> possibleAorist_I_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_I_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_I_Roots_voicing); final Collection<DynamicRoot> possibleCausativeRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleCausativeRoots), voicingRootFunction); possibleCausativeRoots.addAll(possibleCausativeRoots_voicing); final Collection<DynamicRoot> possiblePassiveRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possiblePassiveRoots), voicingRootFunction); possiblePassiveRoots.addAll(possiblePassiveRoots_voicing); } final HashSet<DynamicRoot> generatedRoots = new HashSet<DynamicRoot>(); generatedRoots.add(noAttrRoot); if (voicingMightHaveHappened) generatedRoots.add(this.getPossibleVoicingRoot(noAttrRoot)); generatedRoots.addAll(possibleProgressiveVowelDropRoots); generatedRoots.addAll(possibleAorist_A_Roots); generatedRoots.addAll(possibleAorist_I_Roots); generatedRoots.addAll(possibleCausativeRoots); generatedRoots.addAll(possiblePassiveRoots); this.setLexemeAndPhoneticAttributes(generatedRoots); this.setLemma(generatedRoots); return Collections2.filter(generatedRoots, new Predicate<DynamicRoot>() { @Override public boolean apply(DynamicRoot input) { return seemsLikeAValidVerbRoot(new TurkishSequence(input.getLexeme().getLemmaRoot())); } }); }  }
BruteForceVerbRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishChar lastVowel = partialInput.getLastVowel(); final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Verb; final SecondaryPos secondaryPos = null; final EnumSet<LexemeAttribute> lexemeAttributes = EnumSet.noneOf(LexemeAttribute.class); final DynamicLexeme lexeme = new DynamicLexeme(lemmaSeq.getUnderlyingString(), lemmaRootSeq.getUnderlyingString(), primaryPos, secondaryPos, lexemeAttributes); final EnumSet<PhoneticExpectation> phoneticExpectations = EnumSet.noneOf(PhoneticExpectation.class); final EnumSet<PhoneticAttribute> phoneticAttributes = phoneticsAnalyzer.calculatePhoneticAttributes(partialInput, lexemeAttributes); final DynamicRoot noAttrRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); this.setLexemeAndPhoneticAttributes(Arrays.asList(noAttrRoot)); this.setLemma(Arrays.asList(noAttrRoot)); final TurkishChar lastChar = partialInput.getLastChar(); final TurkicLetter lastLetter = lastChar.getLetter(); final boolean partialSurfaceCanBeRootOfAVerb = this.seemsLikeAValidVerbRoot(partialInput); if (wholeSurface.equals(partialInput)) return partialSurfaceCanBeRootOfAVerb ? Arrays.asList(noAttrRoot) : Collections.<DynamicRoot>emptyList(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); final TurkicLetter firstLetterAfterPartialInput = firstCharAfterPartialInput.getLetter(); final String wholeSurfaceStr = wholeSurface.getUnderlyingString(); final String partialInputStr = partialInput.getUnderlyingString(); final boolean mightHaveProgressiveVowelDrop = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("iyor", "ıyor", "uyor", "üyor")); final boolean mightHaveAorist_A = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ar", "er")); final boolean mightHaveAorist_I = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ır", "ir")); final boolean voicingMightHaveHappened = lastLetter.equals(TurkishAlphabet.L_d) && firstLetterAfterPartialInput.isVowel(); final Set<DynamicRoot> possibleProgressiveVowelDropRoots = mightHaveProgressiveVowelDrop ? this.getProgressiveDropRoots(noAttrRoot, lastVowel) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_A_Roots = mightHaveAorist_A ? this.getAorist_A_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_I_Roots = mightHaveAorist_I ? this.getAorist_I_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleCausativeRoots = this.getPossibleCausativeRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); final Set<DynamicRoot> possiblePassiveRoots = this.getPossiblePassiveRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); if (voicingMightHaveHappened) { Function<DynamicRoot, DynamicRoot> voicingRootFunction = new Function<DynamicRoot, DynamicRoot>() { @Override public DynamicRoot apply(DynamicRoot input) { return getPossibleVoicingRoot(input); } }; final Collection<DynamicRoot> possibleProgressiveVowelDropRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleProgressiveVowelDropRoots), voicingRootFunction); possibleProgressiveVowelDropRoots.addAll(possibleProgressiveVowelDropRoots_voicing); final Collection<DynamicRoot> possibleAorist_A_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_A_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_A_Roots_voicing); final Collection<DynamicRoot> possibleAorist_I_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_I_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_I_Roots_voicing); final Collection<DynamicRoot> possibleCausativeRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleCausativeRoots), voicingRootFunction); possibleCausativeRoots.addAll(possibleCausativeRoots_voicing); final Collection<DynamicRoot> possiblePassiveRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possiblePassiveRoots), voicingRootFunction); possiblePassiveRoots.addAll(possiblePassiveRoots_voicing); } final HashSet<DynamicRoot> generatedRoots = new HashSet<DynamicRoot>(); generatedRoots.add(noAttrRoot); if (voicingMightHaveHappened) generatedRoots.add(this.getPossibleVoicingRoot(noAttrRoot)); generatedRoots.addAll(possibleProgressiveVowelDropRoots); generatedRoots.addAll(possibleAorist_A_Roots); generatedRoots.addAll(possibleAorist_I_Roots); generatedRoots.addAll(possibleCausativeRoots); generatedRoots.addAll(possiblePassiveRoots); this.setLexemeAndPhoneticAttributes(generatedRoots); this.setLemma(generatedRoots); return Collections2.filter(generatedRoots, new Predicate<DynamicRoot>() { @Override public boolean apply(DynamicRoot input) { return seemsLikeAValidVerbRoot(new TurkishSequence(input.getLexeme().getLemmaRoot())); } }); }  @Override boolean handles(TurkishSequence partialInput, TurkishSequence wholeSurface); @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface); }
BruteForceVerbRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishChar lastVowel = partialInput.getLastVowel(); final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Verb; final SecondaryPos secondaryPos = null; final EnumSet<LexemeAttribute> lexemeAttributes = EnumSet.noneOf(LexemeAttribute.class); final DynamicLexeme lexeme = new DynamicLexeme(lemmaSeq.getUnderlyingString(), lemmaRootSeq.getUnderlyingString(), primaryPos, secondaryPos, lexemeAttributes); final EnumSet<PhoneticExpectation> phoneticExpectations = EnumSet.noneOf(PhoneticExpectation.class); final EnumSet<PhoneticAttribute> phoneticAttributes = phoneticsAnalyzer.calculatePhoneticAttributes(partialInput, lexemeAttributes); final DynamicRoot noAttrRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); this.setLexemeAndPhoneticAttributes(Arrays.asList(noAttrRoot)); this.setLemma(Arrays.asList(noAttrRoot)); final TurkishChar lastChar = partialInput.getLastChar(); final TurkicLetter lastLetter = lastChar.getLetter(); final boolean partialSurfaceCanBeRootOfAVerb = this.seemsLikeAValidVerbRoot(partialInput); if (wholeSurface.equals(partialInput)) return partialSurfaceCanBeRootOfAVerb ? Arrays.asList(noAttrRoot) : Collections.<DynamicRoot>emptyList(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); final TurkicLetter firstLetterAfterPartialInput = firstCharAfterPartialInput.getLetter(); final String wholeSurfaceStr = wholeSurface.getUnderlyingString(); final String partialInputStr = partialInput.getUnderlyingString(); final boolean mightHaveProgressiveVowelDrop = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("iyor", "ıyor", "uyor", "üyor")); final boolean mightHaveAorist_A = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ar", "er")); final boolean mightHaveAorist_I = !lastLetter.isVowel() && strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ır", "ir")); final boolean voicingMightHaveHappened = lastLetter.equals(TurkishAlphabet.L_d) && firstLetterAfterPartialInput.isVowel(); final Set<DynamicRoot> possibleProgressiveVowelDropRoots = mightHaveProgressiveVowelDrop ? this.getProgressiveDropRoots(noAttrRoot, lastVowel) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_A_Roots = mightHaveAorist_A ? this.getAorist_A_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleAorist_I_Roots = mightHaveAorist_I ? this.getAorist_I_Roots(noAttrRoot) : new HashSet<DynamicRoot>(); final Set<DynamicRoot> possibleCausativeRoots = this.getPossibleCausativeRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); final Set<DynamicRoot> possiblePassiveRoots = this.getPossiblePassiveRoots(lastLetter, partialInput, wholeSurface, noAttrRoot); if (voicingMightHaveHappened) { Function<DynamicRoot, DynamicRoot> voicingRootFunction = new Function<DynamicRoot, DynamicRoot>() { @Override public DynamicRoot apply(DynamicRoot input) { return getPossibleVoicingRoot(input); } }; final Collection<DynamicRoot> possibleProgressiveVowelDropRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleProgressiveVowelDropRoots), voicingRootFunction); possibleProgressiveVowelDropRoots.addAll(possibleProgressiveVowelDropRoots_voicing); final Collection<DynamicRoot> possibleAorist_A_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_A_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_A_Roots_voicing); final Collection<DynamicRoot> possibleAorist_I_Roots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleAorist_I_Roots), voicingRootFunction); possibleAorist_A_Roots.addAll(possibleAorist_I_Roots_voicing); final Collection<DynamicRoot> possibleCausativeRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possibleCausativeRoots), voicingRootFunction); possibleCausativeRoots.addAll(possibleCausativeRoots_voicing); final Collection<DynamicRoot> possiblePassiveRoots_voicing = Collections2.transform(ImmutableSet.copyOf(possiblePassiveRoots), voicingRootFunction); possiblePassiveRoots.addAll(possiblePassiveRoots_voicing); } final HashSet<DynamicRoot> generatedRoots = new HashSet<DynamicRoot>(); generatedRoots.add(noAttrRoot); if (voicingMightHaveHappened) generatedRoots.add(this.getPossibleVoicingRoot(noAttrRoot)); generatedRoots.addAll(possibleProgressiveVowelDropRoots); generatedRoots.addAll(possibleAorist_A_Roots); generatedRoots.addAll(possibleAorist_I_Roots); generatedRoots.addAll(possibleCausativeRoots); generatedRoots.addAll(possiblePassiveRoots); this.setLexemeAndPhoneticAttributes(generatedRoots); this.setLemma(generatedRoots); return Collections2.filter(generatedRoots, new Predicate<DynamicRoot>() { @Override public boolean apply(DynamicRoot input) { return seemsLikeAValidVerbRoot(new TurkishSequence(input.getLexeme().getLemmaRoot())); } }); }  @Override boolean handles(TurkishSequence partialInput, TurkishSequence wholeSurface); @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface);  }