Search in sources :

Example 36 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class StrongAugmentationServiceImpl method augment.

@Override
public AugmentedStrongs augment(final String version, final String reference, final String[] keys) {
    final Map<String, String> augmentedStrongs = new HashMap<>((keys.length + 4) * 2);
    if (StringUtils.isBlank(version) || StringUtils.isBlank(reference)) {
        // won't be able to resolve so just return the keys as is
        for (String k : keys) {
            augmentedStrongs.put(k, k);
        }
        return new AugmentedStrongs(keys, new EntityDoc[0]);
    }
    // for each key, we see if there is an augment strong number
    final StringBuilder query = new StringBuilder(keys.length * 10 + 16);
    query.append("(");
    for (int i = 0; i < keys.length; i++) {
        // if Hebrew and not augmented
        if (isNonAugmentedHebrew(keys[i])) {
            // then we're looking at Hebrew, so look up the augmentedStrongs data
            // and we're looking for the first of any strong number
            // build the lucene query...
            query.append(StringConversionUtils.getStrongPaddedKey(keys[i]));
            query.append("? ");
        } else {
            // add directly to the augmented list
            augmentedStrongs.put(keys[i], keys[i]);
        }
    }
    final EntityDoc[] docs;
    if (query.length() > 1) {
        // add the reference in the query. We may have several due to versifications mapping, so we're going to look for documents where at least 1 of the verses is in the doc
        query.append(") AND (");
        String[] individualVerses;
        boolean foundDigit = false;
        for (int i = reference.length() - 1; i > 1; i--) {
            // Check to see if there are chapter or verse number
            if (Character.isDigit(reference.charAt(i))) {
                foundDigit = true;
                break;
            }
        }
        if (foundDigit) {
            individualVerses = StringUtils.split(this.versificationService.convertReference(reference, version, JSwordPassageService.OT_BOOK).getKey().getOsisID());
        } else {
            // If there are no chapter or verse number, the query does not need to list all the verses in the book.
            individualVerses = new String[1];
            individualVerses[0] = reference;
        }
        // a single chapter can be optimized, also JSword returns the key as Gen.1 rather than expanded
        boolean queryAppended = false;
        if (individualVerses.length == 1) {
            int countSeparators = 0;
            for (int ii = 0; ii < individualVerses[0].length() && countSeparators < 2; ii++) {
                if (individualVerses[0].charAt(ii) == '.') {
                    countSeparators++;
                }
            }
            if (countSeparators < 2) {
                query.append("references:");
                query.append(individualVerses[0]);
                query.append(".*");
                query.append(' ');
                queryAppended = true;
            }
        }
        if (!queryAppended) {
            for (String v : individualVerses) {
                query.append("references:");
                query.append(v);
                query.append(' ');
            }
        }
        query.append(")");
        // run the query for the hebrew words and add them to the list
        docs = this.augmentedStrongs.search("augmentedStrong", query.toString());
        for (EntityDoc d : docs) {
            final String augmentedStrong = d.get("augmentedStrong");
            augmentedStrongs.put(augmentedStrong.substring(0, augmentedStrong.length() - 1).toLowerCase(), augmentedStrong);
        }
        // check which strongs didn't make it
        for (String k : keys) {
            final String keyingStrong = StringConversionUtils.getStrongPaddedKey(k).toLowerCase();
            if (!augmentedStrongs.containsKey(keyingStrong)) {
                augmentedStrongs.put(keyingStrong, k);
            }
        }
    } else {
        docs = new EntityDoc[0];
    }
    final String[] augmented = new String[augmentedStrongs.size()];
    return new AugmentedStrongs(augmentedStrongs.values().toArray(augmented), docs);
}
Also used : HashMap(java.util.HashMap) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc)

Example 37 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class AlternativeTranslationsServiceImpl method get.

@Override
public VersionsData get(final String passage) {
    final String allReferences = this.passageService.getAllReferences(passage, "ESV_th");
    final EntityDoc[] docs = this.alternativeTranslations.searchSingleColumn("reference", allReferences);
    final Map<String, VersionVerses> referenceToVV = new HashMap<String, VersionVerses>();
    final List<VersionVerses> versionVerses = new ArrayList<VersionVerses>(64);
    final VersionsData data = new VersionsData(versionVerses);
    // the same verse
    for (final EntityDoc d : docs) {
        // obtain the correct verse
        final VersionVerses vv = getCurrentRefVersionVerses(referenceToVV, versionVerses, d);
        // add an option
        final VersionVersePhraseOption phraseChangeOption = new VersionVersePhraseOption(d.get("matchingText"), d.get("fullText"), new ArrayList<VersionPhraseAlternative>(8));
        vv.getOptions().add(phraseChangeOption);
        for (int ii = 0; ii < this.fields.length; ii++) {
            if (d.get(this.fields[ii][0]) != null) {
                final VersionPhraseAlternative singlePhraseAlternative = new VersionPhraseAlternative(d.get(this.fields[ii][0]), d.get(this.fields[ii][1]), d.get(this.fields[ii][2]));
                phraseChangeOption.getPhraseAlternatives().add(singlePhraseAlternative);
            }
        }
    }
    return data;
}
Also used : VersionVerses(com.tyndalehouse.step.core.models.meanings.VersionVerses) VersionVersePhraseOption(com.tyndalehouse.step.core.models.meanings.VersionVersePhraseOption) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VersionsData(com.tyndalehouse.step.core.models.meanings.VersionsData) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) VersionPhraseAlternative(com.tyndalehouse.step.core.models.meanings.VersionPhraseAlternative)

Example 38 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class ModuleController method translateToVocabInfo.

/**
 * Copies over information.
 *
 * @param vocabResponse  the vocab response, including the definitions and the mappings to their related words
 * @param includeAllInfo true to include all information
 * @return a list of infos
 */
private List<VocabInfo> translateToVocabInfo(final VocabResponse vocabResponse, final boolean includeAllInfo, final String userLanguage) {
    final List<VocabInfo> morphologyInfos = new ArrayList<VocabInfo>(vocabResponse.getDefinitions().length);
    EntityDoc[] definitions = vocabResponse.getDefinitions();
    for (int i = 0; i < definitions.length; i++) {
        EntityDoc d = definitions[i];
        morphologyInfos.add(new VocabInfo(d, vocabResponse.getRelatedWords(), includeAllInfo, userLanguage));
    }
    return morphologyInfos;
}
Also used : ArrayList(java.util.ArrayList) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc) VocabInfo(com.tyndalehouse.step.models.info.VocabInfo)

Example 39 with EntityDoc

use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.

the class SimileTimelineTranslatorImpl method toDigestableForm.

@Override
public DigestableTimeline toDigestableForm(final EntityDoc[] events, final LocalDateTime suggestedDate) {
    final SimileTimelineImpl timeline = new SimileTimelineImpl();
    timeline.setLegend(getLegendItems());
    timeline.setDateTimeFormat(SIMILE_DEFAULT_TIME_FORMAT);
    final List<SimileEvent> eventList = new ArrayList<SimileEvent>();
    for (final EntityDoc te : events) {
        final SimileEvent e = translateEvent(te);
        eventList.add(e);
    }
    timeline.setEvents(eventList);
    if (suggestedDate != null) {
        timeline.setSuggestedDate(suggestedDate.toString());
    }
    return timeline;
}
Also used : ArrayList(java.util.ArrayList) EntityDoc(com.tyndalehouse.step.core.data.EntityDoc)

Aggregations

EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)39 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)5 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)5 LexiconSuggestion (com.tyndalehouse.step.core.models.LexiconSuggestion)5 ParseException (org.apache.lucene.queryParser.ParseException)5 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)4 IOException (java.io.IOException)4 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)4 Query (org.apache.lucene.search.Query)4 BookAndBibleCount (com.tyndalehouse.step.core.models.search.BookAndBibleCount)3 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)3 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)3 QueryParser (org.apache.lucene.queryParser.QueryParser)3 Key (org.crosswire.jsword.passage.Key)3 ExpandableSubjectHeadingEntry (com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)2 LexicalSearchEntry (com.tyndalehouse.step.core.models.search.LexicalSearchEntry)2 SubjectHeadingSearchEntry (com.tyndalehouse.step.core.models.search.SubjectHeadingSearchEntry)2