@Test public void shouldRecognizeAbbreviations() { assertRecognizedCorrectly("TR'", "TR", SecondaryPos.Abbreviation, Sets.immutableEnumSet(FirstLetterConsonant, LastLetterVowel, LastVowelFrontal, LastVowelUnrounded, LastLetterNotVoiceless)); assertRecognizedCorrectly("MB'", "MB", SecondaryPos.Abbreviation, Sets.immutableEnumSet(FirstLetterConsonant, LastLetterVowel, LastVowelFrontal, LastVowelUnrounded, LastLetterNotVoiceless)); assertRecognizedCorrectly("POL'", "POL", SecondaryPos.Abbreviation, Sets.immutableEnumSet(FirstLetterConsonant, LastLetterVowel, LastVowelFrontal, LastVowelUnrounded, LastLetterNotVoiceless)); assertRecognizedCorrectly("İŞÇĞÜÖ'", "İŞÇĞÜÖ", SecondaryPos.Abbreviation, Sets.immutableEnumSet(FirstLetterVowel, LastLetterVowel, LastVowelFrontal, LastVowelRounded, LastLetterNotVoiceless)); assertThat(findRootsForPartialInput("123'", "123'e"), hasSize(0)); }
@Override public List<? extends Root> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence input) { final TurkishSequence properNounCandidate = partialInput.subsequence(0, partialInput.length() - 1); final String properNounCandidateUnderlyingString = properNounCandidate.getUnderlyingString(); if (StringUtils.isAllUpperCase(properNounCandidateUnderlyingString)) { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.Abbreviation, null); if (!properNounCandidate.getLastChar().getLetter().isVowel()) { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate.append(TURKISH_CHAR_E_UPPERCASE), null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } else { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } } else { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.ProperNoun, null); final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } }
ProperNounFromApostropheRootFinder implements RootFinder { @Override public List<? extends Root> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence input) { final TurkishSequence properNounCandidate = partialInput.subsequence(0, partialInput.length() - 1); final String properNounCandidateUnderlyingString = properNounCandidate.getUnderlyingString(); if (StringUtils.isAllUpperCase(properNounCandidateUnderlyingString)) { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.Abbreviation, null); if (!properNounCandidate.getLastChar().getLetter().isVowel()) { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate.append(TURKISH_CHAR_E_UPPERCASE), null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } else { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } } else { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.ProperNoun, null); final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } } }
ProperNounFromApostropheRootFinder implements RootFinder { @Override public List<? extends Root> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence input) { final TurkishSequence properNounCandidate = partialInput.subsequence(0, partialInput.length() - 1); final String properNounCandidateUnderlyingString = properNounCandidate.getUnderlyingString(); if (StringUtils.isAllUpperCase(properNounCandidateUnderlyingString)) { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.Abbreviation, null); if (!properNounCandidate.getLastChar().getLetter().isVowel()) { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate.append(TURKISH_CHAR_E_UPPERCASE), null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } else { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } } else { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.ProperNoun, null); final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } }  }
ProperNounFromApostropheRootFinder implements RootFinder { @Override public List<? extends Root> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence input) { final TurkishSequence properNounCandidate = partialInput.subsequence(0, partialInput.length() - 1); final String properNounCandidateUnderlyingString = properNounCandidate.getUnderlyingString(); if (StringUtils.isAllUpperCase(properNounCandidateUnderlyingString)) { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.Abbreviation, null); if (!properNounCandidate.getLastChar().getLetter().isVowel()) { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate.append(TURKISH_CHAR_E_UPPERCASE), null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } else { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } } else { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.ProperNoun, null); final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } }  @Override boolean handles(TurkishSequence partialInput, TurkishSequence input); @Override List<? extends Root> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence input); }
ProperNounFromApostropheRootFinder implements RootFinder { @Override public List<? extends Root> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence input) { final TurkishSequence properNounCandidate = partialInput.subsequence(0, partialInput.length() - 1); final String properNounCandidateUnderlyingString = properNounCandidate.getUnderlyingString(); if (StringUtils.isAllUpperCase(properNounCandidateUnderlyingString)) { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.Abbreviation, null); if (!properNounCandidate.getLastChar().getLetter().isVowel()) { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate.append(TURKISH_CHAR_E_UPPERCASE), null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } else { final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } } else { final Lexeme lexeme = new ImmutableLexeme(properNounCandidateUnderlyingString, properNounCandidateUnderlyingString, PrimaryPos.Noun, SecondaryPos.ProperNoun, null); final ImmutableSet<PhoneticAttribute> phoneticAttributes = Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(properNounCandidate, null)); return Arrays.asList(new ImmutableRoot(properNounCandidate, lexeme, phoneticAttributes, null)); } }  @Override boolean handles(TurkishSequence partialInput, TurkishSequence input); @Override List<? extends Root> findRootsForPartialInput(TurkishSequence partialInput, TurkishSequence input);  }