private void saveGender(String np, Gender gender) { final String key = np.replaceAll("!", "").trim(); if (np.startsWith("!")) { endsWithGender.put(reverse(key), gender); } else if (np.endsWith("!")) { startsWithGender.put(key, gender); } else { exactGender.put(key, gender); } }
private void saveMultiplicity(String np, Multiplicity multiplicity) { final String key = np.replaceAll("!", "").trim(); if (np.startsWith("!")) { endsWithMultiplicity.put(reverse(key), multiplicity); } else if (np.endsWith("!")) { startsWithMultiplicity.put(key, multiplicity); } else { exactMultiplicity.put(key, multiplicity); } }
private void saveGender(String np, Gender gender) { final String key = np.replaceAll("!", "").trim(); if (np.startsWith("!")) { endsWithGender.put(reverse(key), gender); } else if (np.endsWith("!")) { startsWithGender.put(key, gender); } else { exactGender.put(key, gender); } }
private void saveMultiplicity(String np, Multiplicity multiplicity) { final String key = np.replaceAll("!", "").trim(); if (np.startsWith("!")) { endsWithMultiplicity.put(reverse(key), multiplicity); } else if (np.endsWith("!")) { startsWithMultiplicity.put(key, multiplicity); } else { exactMultiplicity.put(key, multiplicity); } }
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; }