/** Return the multiplicity for a given string, if it is known, or UNKNOWN otherwise */ public Multiplicity lookupMultiplicity(String text) { return lookup( exactMultiplicity, startsWithMultiplicity, endsWithMultiplicity, text, Multiplicity.UNKNOWN); }
/** Return the multiplicity for a given string, if it is known, or UNKNOWN otherwise */ public Multiplicity lookupMultiplicity(String text) { return lookup( exactMultiplicity, startsWithMultiplicity, endsWithMultiplicity, text, Multiplicity.UNKNOWN); }
/** Return the gender for a given string, if it is known, or UNKNOWN otherwise */ public Gender lookupGender(String text) { return lookup(exactGender, startsWithGender, endsWithGender, text, Gender.UNKNOWN); }
/** Return the gender for a given string, if it is known, or UNKNOWN otherwise */ public Gender lookupGender(String text) { return lookup(exactGender, startsWithGender, endsWithGender, text, Gender.UNKNOWN); }
private <T> T lookup( Map<String, T> exact, Map<String, T> startsWith, Map<String, T> endsWith, String inputText, T defaultValue) { String text = inputText.toLowerCase(); // Try an exact match T t = exact.get(text); if (t != null) { return t; } final List<String> words = WORD_SPLITTER.splitToList(text); // Try start t = lookup(startsWith, words); if (t != null) { return t; } // Try endWith final List<String> reversed = new ArrayList<>(words.size()); for (int i = words.size() - 1; i > 0; i--) { final String word = reverse(words.get(i)); reversed.add(word); } t = lookup(endsWith, reversed); if (t != null) { return t; } return defaultValue; }
private <T> T lookup( Map<String, T> exact, Map<String, T> startsWith, Map<String, T> endsWith, String inputText, T defaultValue) { String text = inputText.toLowerCase(); // Try an exact match T t = exact.get(text); if (t != null) { return t; } final List<String> words = WORD_SPLITTER.splitToList(text); // Try start t = lookup(startsWith, words); if (t != null) { return t; } // Try endWith final List<String> reversed = new ArrayList<>(words.size()); for (int i = words.size() - 1; i > 0; i--) { final String word = reverse(words.get(i)); reversed.add(word); } t = lookup(endsWith, reversed); if (t != null) { return t; } return defaultValue; }