@Test public void should_create_roots_with_inverse_harmony_when_vowel_is_the_letter_after_next_letter() { { final List<DynamicRoot> roots = findRootsForPartialInput("ab", "abdeki"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("ab")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("ab")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("ab")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Noun)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.InverseHarmony))); } { final List<DynamicRoot> roots = findRootsForPartialInput("hal", "haldik"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("hal")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("hal")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("hal")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Noun)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.InverseHarmony))); } { final List<DynamicRoot> roots = findRootsForPartialInput("oy", "oypü"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("oy")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("oy")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("oy")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Noun)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.InverseHarmony))); } { final List<DynamicRoot> roots = findRootsForPartialInput("yup", "yupsö"); assertThat(roots, hasSize(1)); assertThat(roots.get(0).getSequence().getUnderlyingString(), equalTo("yup")); assertThat(roots.get(0).getLexeme().getLemmaRoot(), equalTo("yup")); assertThat(roots.get(0).getLexeme().getLemma(), equalTo("yup")); assertThat(roots.get(0).getLexeme().getPrimaryPos(), equalTo(PrimaryPos.Noun)); assertThat(roots.get(0).getLexeme().getAttributes(), equalTo((Set<LexemeAttribute>) ImmutableSet.of(LexemeAttribute.InverseHarmony))); } }
@Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Noun; 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 noOrtographicRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); if (wholeSurface.equals(partialInput) || partialInput.length() < 2) return Arrays.asList(noOrtographicRoot); final TurkishChar lastVowel = partialInput.getLastVowel(); if (lastVowel == null) return Arrays.asList(noOrtographicRoot); final TurkishChar lastChar = partialInput.getLastChar(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); if (Character.isUpperCase(lastChar.getCharValue()) || Character.isUpperCase(firstCharAfterPartialInput.getCharValue())) return Arrays.asList(noOrtographicRoot); final List<DynamicRoot> roots = this.getVoicingAndDoublingRoots(partialInput, lastChar, firstCharAfterPartialInput, noOrtographicRoot); final TurkishChar firstVowelAfterPartialInput = wholeSurface.subsequence(partialInput.length() - 1).getFirstVowel(); if (firstVowelAfterPartialInput != null) { if (lastVowel.getLetter().isFrontal() != firstVowelAfterPartialInput.getLetter().isFrontal()) { for (Root root : roots) { root.getLexeme().getAttributes().add(LexemeAttribute.InverseHarmony); } } } for (DynamicRoot root : roots) { final EnumSet<PhoneticAttribute> phoneticAttributesOfRoot = this.phoneticsAnalyzer.calculatePhoneticAttributes(root.getSequence(), root.getLexeme().getAttributes()); root.setPhoneticAttributes(phoneticAttributesOfRoot); } return roots; }
BruteForceNounRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Noun; 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 noOrtographicRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); if (wholeSurface.equals(partialInput) || partialInput.length() < 2) return Arrays.asList(noOrtographicRoot); final TurkishChar lastVowel = partialInput.getLastVowel(); if (lastVowel == null) return Arrays.asList(noOrtographicRoot); final TurkishChar lastChar = partialInput.getLastChar(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); if (Character.isUpperCase(lastChar.getCharValue()) || Character.isUpperCase(firstCharAfterPartialInput.getCharValue())) return Arrays.asList(noOrtographicRoot); final List<DynamicRoot> roots = this.getVoicingAndDoublingRoots(partialInput, lastChar, firstCharAfterPartialInput, noOrtographicRoot); final TurkishChar firstVowelAfterPartialInput = wholeSurface.subsequence(partialInput.length() - 1).getFirstVowel(); if (firstVowelAfterPartialInput != null) { if (lastVowel.getLetter().isFrontal() != firstVowelAfterPartialInput.getLetter().isFrontal()) { for (Root root : roots) { root.getLexeme().getAttributes().add(LexemeAttribute.InverseHarmony); } } } for (DynamicRoot root : roots) { final EnumSet<PhoneticAttribute> phoneticAttributesOfRoot = this.phoneticsAnalyzer.calculatePhoneticAttributes(root.getSequence(), root.getLexeme().getAttributes()); root.setPhoneticAttributes(phoneticAttributesOfRoot); } return roots; } }
BruteForceNounRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Noun; 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 noOrtographicRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); if (wholeSurface.equals(partialInput) || partialInput.length() < 2) return Arrays.asList(noOrtographicRoot); final TurkishChar lastVowel = partialInput.getLastVowel(); if (lastVowel == null) return Arrays.asList(noOrtographicRoot); final TurkishChar lastChar = partialInput.getLastChar(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); if (Character.isUpperCase(lastChar.getCharValue()) || Character.isUpperCase(firstCharAfterPartialInput.getCharValue())) return Arrays.asList(noOrtographicRoot); final List<DynamicRoot> roots = this.getVoicingAndDoublingRoots(partialInput, lastChar, firstCharAfterPartialInput, noOrtographicRoot); final TurkishChar firstVowelAfterPartialInput = wholeSurface.subsequence(partialInput.length() - 1).getFirstVowel(); if (firstVowelAfterPartialInput != null) { if (lastVowel.getLetter().isFrontal() != firstVowelAfterPartialInput.getLetter().isFrontal()) { for (Root root : roots) { root.getLexeme().getAttributes().add(LexemeAttribute.InverseHarmony); } } } for (DynamicRoot root : roots) { final EnumSet<PhoneticAttribute> phoneticAttributesOfRoot = this.phoneticsAnalyzer.calculatePhoneticAttributes(root.getSequence(), root.getLexeme().getAttributes()); root.setPhoneticAttributes(phoneticAttributesOfRoot); } return roots; }  }
BruteForceNounRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Noun; 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 noOrtographicRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); if (wholeSurface.equals(partialInput) || partialInput.length() < 2) return Arrays.asList(noOrtographicRoot); final TurkishChar lastVowel = partialInput.getLastVowel(); if (lastVowel == null) return Arrays.asList(noOrtographicRoot); final TurkishChar lastChar = partialInput.getLastChar(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); if (Character.isUpperCase(lastChar.getCharValue()) || Character.isUpperCase(firstCharAfterPartialInput.getCharValue())) return Arrays.asList(noOrtographicRoot); final List<DynamicRoot> roots = this.getVoicingAndDoublingRoots(partialInput, lastChar, firstCharAfterPartialInput, noOrtographicRoot); final TurkishChar firstVowelAfterPartialInput = wholeSurface.subsequence(partialInput.length() - 1).getFirstVowel(); if (firstVowelAfterPartialInput != null) { if (lastVowel.getLetter().isFrontal() != firstVowelAfterPartialInput.getLetter().isFrontal()) { for (Root root : roots) { root.getLexeme().getAttributes().add(LexemeAttribute.InverseHarmony); } } } for (DynamicRoot root : roots) { final EnumSet<PhoneticAttribute> phoneticAttributesOfRoot = this.phoneticsAnalyzer.calculatePhoneticAttributes(root.getSequence(), root.getLexeme().getAttributes()); root.setPhoneticAttributes(phoneticAttributesOfRoot); } return roots; }  @Override boolean handles(TurkishSequence partialInput, TurkishSequence wholeSurface); @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface); }
BruteForceNounRootFinder implements RootFinder { @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) public Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface) { final TurkishSequence rootSeq = partialInput; final TurkishSequence lemmaSeq = rootSeq; final TurkishSequence lemmaRootSeq = lemmaSeq; final PrimaryPos primaryPos = PrimaryPos.Noun; 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 noOrtographicRoot = new DynamicRoot(rootSeq, lexeme, phoneticAttributes, phoneticExpectations); if (wholeSurface.equals(partialInput) || partialInput.length() < 2) return Arrays.asList(noOrtographicRoot); final TurkishChar lastVowel = partialInput.getLastVowel(); if (lastVowel == null) return Arrays.asList(noOrtographicRoot); final TurkishChar lastChar = partialInput.getLastChar(); final TurkishChar firstCharAfterPartialInput = wholeSurface.charAt(partialInput.length()); if (Character.isUpperCase(lastChar.getCharValue()) || Character.isUpperCase(firstCharAfterPartialInput.getCharValue())) return Arrays.asList(noOrtographicRoot); final List<DynamicRoot> roots = this.getVoicingAndDoublingRoots(partialInput, lastChar, firstCharAfterPartialInput, noOrtographicRoot); final TurkishChar firstVowelAfterPartialInput = wholeSurface.subsequence(partialInput.length() - 1).getFirstVowel(); if (firstVowelAfterPartialInput != null) { if (lastVowel.getLetter().isFrontal() != firstVowelAfterPartialInput.getLetter().isFrontal()) { for (Root root : roots) { root.getLexeme().getAttributes().add(LexemeAttribute.InverseHarmony); } } } for (DynamicRoot root : roots) { final EnumSet<PhoneticAttribute> phoneticAttributesOfRoot = this.phoneticsAnalyzer.calculatePhoneticAttributes(root.getSequence(), root.getLexeme().getAttributes()); root.setPhoneticAttributes(phoneticAttributesOfRoot); } return roots; }  @Override boolean handles(TurkishSequence partialInput, TurkishSequence wholeSurface); @Override @SuppressWarnings({"UnnecessaryLocalVariable", "ConstantConditions"}) Collection<DynamicRoot> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence wholeSurface);  }