Search in sources :

Example 1 with LexiconSuggestion

use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.

the class LexiconDefinitionServiceImpl method lookup.

@Override
public Map<String, LexiconSuggestion> lookup(final Set<String> strongNumbers, final String userLanguage) {
    final Map<String, LexiconSuggestion> results = new HashMap<String, LexiconSuggestion>(strongNumbers.size() * 2);
    // exit early if no strong numbers
    if (strongNumbers.size() == 0) {
        return results;
    }
    final StringBuilder query = new StringBuilder(strongNumbers.size() * 7);
    for (final String strong : strongNumbers) {
        query.append(strong);
        query.append(' ');
    }
    final EntityDoc[] lexiconDefitions = this.definitions.searchSingleColumn("strongNumber", query.toString());
    for (final EntityDoc lexiconDefinition : lexiconDefitions) {
        final String strongNumber = lexiconDefinition.get("strongNumber");
        final LexiconSuggestion suggestion = getLexiconSuggestion(lexiconDefinition, strongNumber, userLanguage);
        results.put(strongNumber, suggestion);
    }
    return results;
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion) HashMap(java.util.HashMap) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc)

Example 2 with LexiconSuggestion

use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.

the class LexiconDefinitionServiceImpl method getLexiconSuggestion.

/**
 * Converts the entity documents to its lexicon suggestion
 * @param lexiconDefinition the lexicon definition
 * @param strongNumber the strong number
 * @return the lexicon suggestion with transliteration, gloss, etc.
 */
private LexiconSuggestion getLexiconSuggestion(final EntityDoc lexiconDefinition, final String strongNumber, final String userLanguage) {
    final LexiconSuggestion suggestion = new LexiconSuggestion();
    if (userLanguage.equalsIgnoreCase("es"))
        suggestion.setGloss(lexiconDefinition.get("es_Gloss"));
    else if (userLanguage.equalsIgnoreCase("zh"))
        suggestion.setGloss(lexiconDefinition.get("zh_Gloss"));
    else if (userLanguage.equalsIgnoreCase("zh_tw"))
        suggestion.setGloss(lexiconDefinition.get("zh_tw_Gloss"));
    else
        suggestion.setGloss(lexiconDefinition.get("stepGloss"));
    suggestion.setMatchingForm(lexiconDefinition.get("accentedUnicode"));
    suggestion.setStepTransliteration(lexiconDefinition.get("stepTransliteration"));
    suggestion.setStrongNumber(strongNumber);
    return suggestion;
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion)

Example 3 with LexiconSuggestion

use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.

the class OriginalWordUtils method convertToSuggestion.

/**
 * converts a definition to a suggested form
 *
 * @param def the definition
 * @return the suggestion
 */
public static LexiconSuggestion convertToSuggestion(final EntityDoc def, final String userLanguage) {
    final LexiconSuggestion suggestion = new LexiconSuggestion();
    suggestion.setGloss(def.get("stepGloss"));
    suggestion.setMatchingForm(def.get("accentedUnicode"));
    suggestion.setStepTransliteration(def.get("stepTransliteration"));
    suggestion.setStrongNumber(def.get(STRONG_NUMBER_FIELD));
    if ((userLanguage == null) || (userLanguage == "")) {
        suggestion.set_es_Gloss(def.get("es_Gloss"));
        suggestion.set_zh_tw_Gloss(def.get("zh_tw_Gloss"));
        suggestion.set_zh_Gloss(def.get("zh_Gloss"));
    } else if (userLanguage.equalsIgnoreCase("es"))
        suggestion.set_es_Gloss(def.get("es_Gloss"));
    else if (userLanguage.equalsIgnoreCase("zh_tw"))
        suggestion.set_zh_tw_Gloss(def.get("zh_tw_Gloss"));
    else if (userLanguage.equalsIgnoreCase("zh"))
        suggestion.set_zh_Gloss(def.get("zh_Gloss"));
    return suggestion;
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion)

Example 4 with LexiconSuggestion

use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.

the class MeaningSuggestionServiceImpl method convertTermsToSuggestions.

private void convertTermsToSuggestions(final String[] meaningTerms, final List<LexiconSuggestion> suggestions) {
    if (meaningTerms != null) {
        for (String term : meaningTerms) {
            final LexiconSuggestion suggestion = new LexiconSuggestion();
            suggestion.setGloss(term);
            suggestions.add(suggestion);
        }
    }
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion)

Example 5 with LexiconSuggestion

use of com.tyndalehouse.step.core.models.LexiconSuggestion in project step by STEPBible.

the class SearchPageController method populateMetaSearch.

/**
 * Populates the meta data for a search
 *
 * @param req     the request
 * @param results the results
 */
private void populateMetaSearch(final HttpServletRequest req, final SearchResult results) {
    try {
        final List<SearchToken> searchTokens = results.getSearchTokens();
        String scope = null;
        StringBuilder keyInfo = new StringBuilder(128);
        StringBuilder versions = new StringBuilder(32);
        StringBuilder shortSearchWord = new StringBuilder(32);
        StringBuilder longSearchWord = new StringBuilder(48);
        boolean strongSearch = false;
        for (SearchToken t : searchTokens) {
            final String tokenType = t.getTokenType();
            final String token = t.getToken();
            final String infoSeparator = " | ";
            if (SearchToken.VERSION.equals(tokenType)) {
                versions.append(token);
                versions.append(infoSeparator);
            } else if (SearchToken.REFERENCE.equals(tokenType)) {
                scope = token;
            } else if (SearchToken.SUBJECT_SEARCH.equals(tokenType)) {
                keyInfo.append(token);
                versions.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.NAVE_SEARCH.equals(tokenType)) {
                keyInfo.append(token);
                versions.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.NAVE_SEARCH_EXTENDED.equals(tokenType)) {
                keyInfo.append(token);
                versions.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.TEXT_SEARCH.equals(tokenType)) {
                keyInfo.append(token);
                versions.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.STRONG_NUMBER.equals(tokenType)) {
                strongSearch = true;
                final LexiconSuggestion enhancedTokenInfo = (LexiconSuggestion) t.getEnhancedTokenInfo();
                keyInfo.append(enhancedTokenInfo.getMatchingForm());
                keyInfo.append(" - ");
                keyInfo.append(enhancedTokenInfo.getGloss());
                keyInfo.append(" - ");
                keyInfo.append(enhancedTokenInfo.getStepTransliteration());
                keyInfo.append(" - ");
                keyInfo.append(enhancedTokenInfo.getStrongNumber());
                keyInfo.append(infoSeparator);
                shortSearchWord.append(enhancedTokenInfo.getStepTransliteration());
                longSearchWord.append(enhancedTokenInfo.getStepTransliteration());
                longSearchWord.append(", ");
                longSearchWord.append(enhancedTokenInfo.getGloss());
                longSearchWord.append(", ");
                longSearchWord.append(enhancedTokenInfo.getStrongNumber());
            } else if (SearchToken.MEANINGS.equals(tokenType)) {
                keyInfo.append(token);
                keyInfo.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.TOPIC_BY_REF.equals(tokenType)) {
                keyInfo.append(token);
                keyInfo.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.RELATED_VERSES.equals(tokenType)) {
                keyInfo.append(token);
                keyInfo.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.EXACT_FORM.equals(tokenType)) {
                keyInfo.append(token);
                keyInfo.append(infoSeparator);
                shortSearchWord.append(token);
            } else if (SearchToken.SYNTAX.equals(tokenType)) {
                keyInfo.append(token);
                keyInfo.append(infoSeparator);
                String tmpString = token;
                if (token.substring(0, 2).equals("t=")) {
                    tmpString = tmpString.substring(2);
                    tmpString = tmpString.replaceAll(" AND ", ", ");
                }
                shortSearchWord.append(tmpString);
            }
        }
        if (scope != null) {
            keyInfo.append(scope);
            keyInfo.append(" | ");
        }
        final String trimmedInfo = keyInfo.toString().trim();
        final String relevantInfo = (keyInfo.length() > 2 ? trimmedInfo.substring(0, trimmedInfo.length() - 2) : trimmedInfo).replaceAll("\\|", ",");
        req.setAttribute("description", ResourceBundle.getBundle("ErrorBundle").getString("search_results_for") + " " + relevantInfo);
        try {
            keyInfo.append(ResourceBundle.getBundle("ErrorBundle", clientSessionProvider.get().getLocale()).getString(results.getSearchType().getLanguageSearchKey()));
        } catch (MissingResourceException ex) {
            // swallow
            LOGGER.warn("Missing resource for {}", results.getSearchType().getLanguageSearchKey(), ex);
            keyInfo.append("Search");
        }
        String title = "";
        String description = "";
        if (strongSearch) {
            title = shortSearchWord.toString() + " in STEP Bible with Greek and Hebrew helps";
            description = "What the Bible says about " + longSearchWord.toString() + " in Bibles with Greek & Hebrew interlinear, search, study tools.  Recommended by schools, Free.";
        } else {
            title = shortSearchWord.toString() + " in STEP Bible, study tools, 280 languages";
            description = "What the Bible says about " + shortSearchWord.toString() + " in Bibles with original meaning, search, study helps, maps, topics, commentaries, meaning. Reliable, Free.";
        }
        // keyForTitle = "Bible verse about " + keyForTitle;
        req.setAttribute("title", wrapTitle(title, results.getMasterVersion(), null));
        req.setAttribute("canonicalUrl", req.getParameter("q"));
        req.setAttribute("description", description);
    } catch (Exception ex) {
        // a page with no title is better than no pages
        LOGGER.error("Unable to ascertain meta data", ex);
    }
}
Also used : LexiconSuggestion(com.tyndalehouse.step.core.models.LexiconSuggestion) SearchToken(com.tyndalehouse.step.core.models.SearchToken) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

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