Search in sources :

Example 1 with BookAndBibleCount

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

the class JSwordStrongNumberHelper method calculateStrongArrayCounts.

/**
 * Calculate counts for an array of Strong number.
 */
public PassageStat calculateStrongArrayCounts(final String version, PassageStat stat, final String userLanguage) {
    Map<String, Integer[]> result = new HashMap<String, Integer[]>(128);
    this.isOT = DivisionName.OLD_TESTAMENT.contains(this.reference.getBook());
    final Versification targetVersification = isOT ? otV11n : ntV11n;
    final Key key = VersificationsMapper.instance().mapVerse(this.reference, targetVersification);
    this.allStrongs = new HashMap<>(256);
    Map<String, Integer[]> temp = stat.getStats();
    temp.forEach((strongNum, feq) -> this.allStrongs.put(strongNum, new BookAndBibleCount()));
    Map<String, EntityDoc> augmentedReferences = new HashMap<>(0);
    // now get counts in the relevant portion of text
    applySearchCounts(getBookFromKey(key), augmentedReferences);
    temp.forEach((strongNum, freq) -> {
        BookAndBibleCount bBCount = this.allStrongs.get(strongNum);
        result.put(strongNum, new Integer[] { freq[0], bBCount.getBook(), bBCount.getBible() });
    });
    stat.setStats(result);
    return stat;
}
Also used : HashMap(java.util.HashMap) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) Versification(org.crosswire.jsword.versification.Versification) BookAndBibleCount(com.tyndalehouse.step.core.models.search.BookAndBibleCount) Key(org.crosswire.jsword.passage.Key)

Example 2 with BookAndBibleCount

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

the class JSwordStrongNumberHelper method applySearchCounts.

/**
 * Applies the search counts for every strong number.
 *
 * @param bookName the book name
 * @param augmentedByStrong the augmented strongs found in the original augmentation querys
 */
private void applySearchCounts(final String bookName, final Map<String, EntityDoc> augmentedByStrong) {
    try {
        final IndexSearcher is = jSwordSearchService.getIndexSearcher(this.isOT ? STRONG_OT_VERSION_BOOK.getInitials() : STRONG_NT_VERSION_BOOK.getInitials());
        final TermDocs termDocs = is.getIndexReader().termDocs();
        for (final Entry<String, BookAndBibleCount> strong : this.allStrongs.entrySet()) {
            final String strongKey = strong.getKey();
            termDocs.seek(new Term(LuceneIndex.FIELD_STRONG, this.strongAugmentationService.reduce(strongKey)));
            final EntityDoc entityDoc = augmentedByStrong.get(strongKey);
            final String references = entityDoc != null ? entityDoc.get("references") : null;
            // we'll never need more than 200 documents as this is the cut off point
            int bible = 0;
            int book = 0;
            while (termDocs.next()) {
                final int freq = termDocs.freq();
                final Document doc = is.doc(termDocs.doc());
                final String docRef = doc.get(LuceneIndex.FIELD_KEY);
                if ((references == null || augmentedVersionInVerse(docRef, references))) {
                    if (docRef != null && docRef.startsWith(bookName)) {
                        book += freq;
                    }
                    bible += freq;
                }
            }
            final BookAndBibleCount value = strong.getValue();
            value.setBible(bible);
            value.setBook(book);
        }
    } catch (final IOException e) {
        throw new StepInternalException(e.getMessage(), e);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) TermDocs(org.apache.lucene.index.TermDocs) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) BookAndBibleCount(com.tyndalehouse.step.core.models.search.BookAndBibleCount) Term(org.apache.lucene.index.Term) IOException(java.io.IOException) Document(org.apache.lucene.document.Document)

Example 3 with BookAndBibleCount

use of com.tyndalehouse.step.core.models.search.BookAndBibleCount 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)

Aggregations

EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)3 BookAndBibleCount (com.tyndalehouse.step.core.models.search.BookAndBibleCount)3 HashMap (java.util.HashMap)2 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)1 LexiconSuggestion (com.tyndalehouse.step.core.models.LexiconSuggestion)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Document (org.apache.lucene.document.Document)1 Term (org.apache.lucene.index.Term)1 TermDocs (org.apache.lucene.index.TermDocs)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Key (org.crosswire.jsword.passage.Key)1 Versification (org.crosswire.jsword.versification.Versification)1