use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SearchServiceImpl method adaptQueryForRelatedStrongSearch.
/**
* Adapts the search query to be used in a strong search
*
* @param sq the search query object
* @return a list of strong numbers
*/
private Set<String> adaptQueryForRelatedStrongSearch(final SearchQuery sq) {
final Set<String> strongsFromQuery = getStrongsFromTextCriteria(sq);
// look up the related strong numbers
final Set<String> filteredStrongs = new HashSet<>(strongsFromQuery.size());
final StringBuilder fullQuery = new StringBuilder(64);
final QueryParser p = new QueryParser(Version.LUCENE_30, STRONG_NUMBER_FIELD, this.definitions.getAnalyzer());
// get all words suggested in query
final String query = retrieveStrongs(strongsFromQuery);
final EntityDoc[] results = retrieveStrongDefinitions(sq, filteredStrongs, p, query, fullQuery);
// now get all related words:
final String relatedQuery = getRelatedStrongQuery(results);
final EntityDoc[] relatedResults = retrieveStrongDefinitions(sq, filteredStrongs, p, relatedQuery, fullQuery);
setUniqueConsideredDefinitions(sq, results, relatedResults);
// append range to query
sq.getCurrentSearch().setQuery(fullQuery.toString().toLowerCase(), true);
return filteredStrongs;
}
use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SearchServiceImpl method setDefinitionForResults.
/**
* Sets the definitions onto the result object
*
* @param result the result object
* @param lexiconDefinitions the definitions that have been included in the search
*/
private void setDefinitionForResults(final SearchResult result, final List<EntityDoc> lexiconDefinitions, SuggestionType suggestionType) {
Collections.sort(lexiconDefinitions, new GlossComparator());
List<LexiconSuggestion> suggestions = new ArrayList(lexiconDefinitions.size());
for (final EntityDoc def : lexiconDefinitions) {
suggestions.add(convertToSuggestion(def, null));
}
result.setDefinitions(suggestions);
}
use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SearchServiceImpl method searchTextFieldsForDefinition.
/**
* Searches the underlying DB for the relevant entry
*
* @param searchQuery the query that is being passed in
* @return the list of strongs matched
*/
private Set<String> searchTextFieldsForDefinition(final String searchQuery) {
// first look through the text forms
final EntityDoc[] results = this.specificForms.search(new String[] { "accentedUnicode" }, searchQuery, null, null, false);
if (results.length == 0) {
return lookupFromLexicon(searchQuery);
}
// if we matched more than one, then we don't have our assumed uniqueness... log warning and
// continue with first matched strong
final Set<String> listOfStrongs = new HashSet<String>();
for (final EntityDoc f : results) {
listOfStrongs.add(f.get(STRONG_NUMBER_FIELD));
}
return listOfStrongs;
}
use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class SearchServiceImpl method lookupFromLexicon.
/**
* Looks up the search criteria from the lexicon
*
* @param query the query
* @return a list of strong numbers
*/
private Set<String> lookupFromLexicon(final String query) {
// if we still have nothing, then look through the definitions
final QueryParser parser = new QueryParser(Version.LUCENE_30, "accentedUnicode", this.definitions.getAnalyzer());
Query parsed;
try {
parsed = parser.parse(QueryParser.escape(query));
} catch (final ParseException e) {
throw new TranslatedException(e, "search_invalid");
}
final EntityDoc[] results = this.definitions.search(parsed);
final Set<String> matchedStrongs = new HashSet<String>();
for (final EntityDoc d : results) {
matchedStrongs.add(d.get(STRONG_NUMBER_FIELD));
}
return matchedStrongs;
}
use of com.tyndalehouse.step.core.data.EntityDoc in project step by STEPBible.
the class LoaderTest method testRobinsonMorphology.
/**
* tests loading of robinson's morphology codes
*/
@Test
public void testRobinsonMorphology() {
getLoader("test.data.path.morphology.robinson", "robinson_morphology.csv").loadRobinsonMorphology();
// check verb columns
EntityDoc[] entities = getEntities(1, "morphology", "code", "V-2AAP-DSM");
EntityDoc e = entities[0];
assertEquals("Verb", e.get("function"));
assertEquals("2nd Aorist", e.get("tense"));
assertEquals("Active", e.get("voice"));
assertEquals("Participle", e.get("mood"));
assertEquals("Dative", e.get("case"));
assertEquals("Singular", e.get("number"));
assertEquals("Masculine", e.get("gender"));
// check person and function
entities = getEntities(1, "morphology", "code", "F-1ASM");
e = entities[0];
assertEquals("1st", e.get("person"));
assertEquals("Reflexive pronoun", e.get("function"));
// check person and function
entities = getEntities(1, "morphology", "code", "F-1ASM");
e = entities[0];
assertEquals("1st", e.get("person"));
assertEquals("Reflexive pronoun", e.get("function"));
entities = getEntities(1, "morphology", "code", "D-NPM-C");
e = entities[0];
assertEquals("Contracted", e.get("suffix"));
}
Aggregations