use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.
the class OriginalWordSuggestionServiceImpl method getMatchingAllForms.
/**
* retrieves forms from the lexicon
*
* @param greek true to indicate greek, false to indicate hebrew
* @param form form in lower case, containing a % if appropriate
* @return the list of suggestions
*/
private List<LexiconSuggestion> getMatchingAllForms(final boolean greek, final String form) {
final List<LexiconSuggestion> suggestions = new ArrayList<LexiconSuggestion>();
final EntityDoc[] results;
// search by unicode or translit?
if (isHebrewText(form) || GreekUtils.isGreekText(form)) {
results = this.specificForms.search(new String[] { "accentedUnicode" }, QueryParser.escape(form) + '*', getFilter(greek), TRANSLITERATION_SORT, true, SearchService.MAX_SUGGESTIONS);
} else {
// assume transliteration - at this point suggestionType is not going to be MEANING
final String simplifiedTransliteration = getSimplifiedTransliterationClause(greek, form, true);
results = this.specificForms.search(new String[] { "simplifiedStepTransliteration" }, simplifiedTransliteration, getFilter(greek), TRANSLITERATION_SORT, true, simplifiedTransliteration, SearchService.MAX_SUGGESTIONS);
}
for (final EntityDoc f : results) {
final LexiconSuggestion suggestion = convertToSuggestionFromSpecificForm(f);
if (suggestion != null) {
suggestions.add(suggestion);
}
}
return suggestions;
}
use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.
the class OriginalWordSuggestionServiceImpl method convertToSuggestionFromSpecificForm.
/**
* @param specificForm the specific form to be converted
* @return the suggestion
*/
private LexiconSuggestion convertToSuggestionFromSpecificForm(final EntityDoc specificForm) {
final String strongNumber = specificForm.get(STRONG_NUMBER_FIELD);
final EntityDoc[] results = this.definitions.searchExactTermBySingleField(STRONG_NUMBER_FIELD, 1, strongNumber);
if (results.length > 0) {
final LexiconSuggestion suggestion = new LexiconSuggestion();
suggestion.setStrongNumber(strongNumber);
suggestion.setGloss(results[0].get("stepGloss"));
suggestion.setMatchingForm(specificForm.get("accentedUnicode"));
suggestion.setStepTransliteration(specificForm.get("stepTransliteration"));
return suggestion;
}
return null;
}
use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.
the class JSwordStrongNumberHelper method readDataFromLexicon.
/**
* Read data from lexicon.
*
* @param reader the reader
* @param verseRef the verse ref
* @param augmentedStrongNumbers the strong numbers
*/
private void readDataFromLexicon(final EntityIndexReader reader, final String verseRef, final String augmentedStrongNumbers, final String userLanguage) {
final EntityDoc[] docs = reader.search("strongNumber", augmentedStrongNumbers);
final List<LexiconSuggestion> verseSuggestions = new ArrayList<>();
Map<String, LexiconSuggestion> suggestionsFromSearch = new HashMap<>(docs.length * 2);
for (final EntityDoc d : docs) {
final LexiconSuggestion ls = new LexiconSuggestion();
ls.setStrongNumber(d.get("strongNumber"));
ls.setGloss(d.get("stepGloss"));
if (userLanguage.equalsIgnoreCase("es")) {
ls.set_es_Gloss(d.get("es_Gloss"));
} else if (userLanguage.equalsIgnoreCase("zh")) {
ls.set_zh_Gloss(d.get("zh_Gloss"));
} else if (userLanguage.equalsIgnoreCase("zh_tw")) {
ls.set_zh_tw_Gloss(d.get("zh_tw_Gloss"));
}
ls.setMatchingForm(d.get("accentedUnicode"));
ls.setStepTransliteration(d.get("stepTransliteration"));
suggestionsFromSearch.put(ls.getStrongNumber(), ls);
this.allStrongs.put(ls.getStrongNumber(), new BookAndBibleCount());
}
String[] strongs = StringUtils.split(augmentedStrongNumbers);
for (String s : strongs) {
verseSuggestions.add(suggestionsFromSearch.get(s));
}
this.verseStrongs.put(verseRef, verseSuggestions);
}
use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.
the class VocabularyServiceImpl method readRelatedWords.
/**
* Read related words, i.e. all the words that are in the related numbers fields.
*
* @param defs the definitions that have been looked up.
* @return the map
*/
private Map<String, List<LexiconSuggestion>> readRelatedWords(final EntityDoc[] defs, final String userLanguage) {
// this map keys the original word strong number to all the related codes
final Map<String, SortedSet<LexiconSuggestion>> relatedWords = new HashMap<String, SortedSet<LexiconSuggestion>>(defs.length * 2);
// to avoid doing lookups twice, we key each short definition by its code as well
final Map<String, LexiconSuggestion> lookedUpWords = new HashMap<>(defs.length * 2);
for (final EntityDoc doc : defs) {
final String sourceNumber = doc.get("strongNumber");
final String relatedWordNumbers = doc.get("relatedNumbers");
final String[] allRelatedWords = split(relatedWordNumbers, "[ ,]+");
for (final String relatedWord : allRelatedWords) {
LexiconSuggestion shortLexiconDefinition = lookedUpWords.get(relatedWord);
// look up related word from index
if (shortLexiconDefinition == null) {
final EntityDoc[] relatedDoc = this.definitions.searchUniqueBySingleField("strongNumber", userLanguage, relatedWord);
// assume first doc
if (relatedDoc.length > 0) {
shortLexiconDefinition = OriginalWordUtils.convertToSuggestion(relatedDoc[0], userLanguage);
lookedUpWords.put(relatedWord, shortLexiconDefinition);
}
}
// store as a link to its source number
if (shortLexiconDefinition != null) {
SortedSet<LexiconSuggestion> associatedNumbersSoFar = relatedWords.get(sourceNumber);
if (associatedNumbersSoFar == null) {
associatedNumbersSoFar = new TreeSet<>(SortingUtils.LEXICON_SUGGESTION_COMPARATOR);
relatedWords.put(sourceNumber, associatedNumbersSoFar);
}
associatedNumbersSoFar.add(shortLexiconDefinition);
}
}
}
return convertToListMap(relatedWords);
}
Aggregations