Search in sources :

Example 6 with LexiconSuggestion

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;
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion) ArrayList(java.util.ArrayList) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc)

Example 7 with LexiconSuggestion

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;
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc)

Example 8 with LexiconSuggestion

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);
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion) HashMap(java.util.HashMap) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) ArrayList(java.util.ArrayList) BookAndBibleCount(com.tyndalehouse.step.core.models.search.BookAndBibleCount)

Example 9 with LexiconSuggestion

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);
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc)

Aggregations

LexiconSuggestion (com.tyndalehouse.step.core.models.LexiconSuggestion)9 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)5 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SearchToken (com.tyndalehouse.step.core.models.SearchToken)1 BookAndBibleCount (com.tyndalehouse.step.core.models.search.BookAndBibleCount)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1