use of org.crosswire.jsword.book.BookException in project step by STEPBible.
the class JSwordAnalysisServiceImpl method getTextStats.
@Override
public PassageStat getTextStats(final String version, final Key reference, final ScopeType scopeType) {
try {
final Book book = this.versification.getBookFromVersion(version);
final Versification av11n = this.versification.getVersificationForVersion(book);
final BookData bookData = getExpandedBookData(reference, scopeType, av11n, book);
final String canonicalText = OSISUtil.getCanonicalText(bookData.getOsisFragment());
final String[] words = split(canonicalText, WORD_SPLIT);
Set<String> languageStopWords = getLanguageStopList(book);
final PassageStat stat = new PassageStat();
for (final String word : words) {
// only add word if not in STOP list
if (!languageStopWords.contains(StringConversionUtils.unAccent(word.toUpperCase(), true))) {
stat.addWord(word);
}
}
return stat;
} catch (final BookException e) {
throw new StepInternalException("Unable to read passage text", e);
}
}
use of org.crosswire.jsword.book.BookException in project step by STEPBible.
the class JSwordSearchServiceImpl method doSearch.
private void doSearch(final DefaultSearchModifier modifier, final Map<String, Key> resultsPerVersion, final IndividualSearch currentSearch, final Book bible) {
String version = bible.getInitials();
if (bible.getIndexStatus().equals(IndexStatus.DONE)) {
final Key luceneSearchResults;
try {
String query = currentSearch.getQuery();
// small optimization and cater for versions that don't support Gen-Rev as a range:
query = GEN_REV_RANGE.matcher(query).replaceAll("");
luceneSearchResults = bible.find(new DefaultSearchRequest(query, modifier));
} catch (final BookException e) {
throw new LuceneSearchException("Unable to search for " + currentSearch.getQuery() + " with Bible " + version, e);
}
resultsPerVersion.put(version, luceneSearchResults);
} else {
LOGGER.error("Module [{}] is not indexed.", version);
resultsPerVersion.put(version, PassageKeyFactory.instance().createEmptyKeyList(av11nService.getVersificationForVersion(bible)));
}
}
use of org.crosswire.jsword.book.BookException in project step by STEPBible.
the class JSwordSearchServiceImpl method getIndexSearcher.
/**
* Retrieves the index from JSword
* @param bookName the book name
* @return the index searcher responsible for carrying out operations on JSword data.
*/
public IndexSearcher getIndexSearcher(String bookName) {
final IndexManager indexManager = IndexManagerFactory.getIndexManager();
Index index;
try {
index = indexManager.getIndex(this.av11nService.getBookFromVersion(bookName));
} catch (BookException e) {
throw new StepInternalException(e.getMessage(), e);
}
if (!(index instanceof LuceneIndex)) {
LOGGER.warn("Unsupported Lucene Index type [{}]", index.getClass());
throw new StepInternalException("Unable to obtain index");
}
@SuppressWarnings("resource") final LuceneIndex li = (LuceneIndex) index;
return (IndexSearcher) li.getSearcher();
}
use of org.crosswire.jsword.book.BookException in project step by STEPBible.
the class JSwordPassageServiceImpl method doInterleavedVersionsLookup.
private OsisWrapper doInterleavedVersionsLookup(String[] versions, final BookData data, final Versification v11n, final List<LookupOption> options, final InterlinearMode displayMode, final String userLanguage) {
Book[] books = data.getBooks();
try {
setUnaccenter(data, displayMode);
final TransformingSAXEventProvider transformer = executeStyleSheet(v11n, options, null, data, data.getSAXEventProvider(), displayMode, userLanguage);
String[] languages = new String[books.length];
for (int ii = 0; ii < books.length; ii++) {
languages[ii] = books[ii].getLanguage().getCode();
}
final Key key = data.getKey();
return new OsisWrapper(writeToString(transformer), key, languages, v11n, resolver.getShortName(versions[0]), displayMode, StringUtils.join(versions, 1));
} catch (final TransformerException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final SAXException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final BookException e) {
throw new LocalisedException(e, e.getMessage());
}
}
use of org.crosswire.jsword.book.BookException in project step by STEPBible.
the class JSwordPassageServiceImpl method getTextForBookData.
/**
* Gets the osis text
*
* @param options the list of lookup options
* @param interlinearVersion the interlinear version if applicable
* @param bookData the bookdata to use to look up the required version/reference combo
* @param displayMode the mode to display the text with
* @return the html text
*/
private OsisWrapper getTextForBookData(final List<LookupOption> options, final String interlinearVersion, final BookData bookData, final InterlinearMode displayMode) {
// check we have a book in mind and a reference
notNull(bookData, "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
notNull(bookData.getFirstBook(), "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
Key key = bookData.getKey();
notNull(key, "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
// the original book
final Book book = bookData.getFirstBook();
final Versification versification = this.versificationService.getVersificationForVersion(book);
try {
// first check whether the key is contained in the book
key = normalize(key, versification);
final SAXEventProvider osissep = bookData.getSAXEventProvider();
final TransformingSAXEventProvider htmlsep = executeStyleSheet(versification, options, interlinearVersion, bookData, osissep, displayMode, "en");
final OsisWrapper osisWrapper = new OsisWrapper(writeToString(htmlsep), key, getLanguages(book, displayMode, htmlsep, options), versification, resolver.getShortName(bookData.getFirstBook().getInitials()), displayMode, interlinearVersion);
if (key instanceof Passage) {
final Passage p = (Passage) key;
final boolean hasMultipleRanges = p.hasRanges(RestrictionType.NONE);
osisWrapper.setMultipleRanges(hasMultipleRanges);
if (hasMultipleRanges) {
// get the first "range" and set up the start and ends
final VerseRange r = p.rangeIterator(RestrictionType.NONE).next();
osisWrapper.setStartRange(versification.getOrdinal(r.getStart()));
osisWrapper.setEndRange(versification.getOrdinal(r.getEnd()));
} else {
Iterator<Key> keys = p.iterator();
Verse start = null;
Verse end = null;
while (keys.hasNext()) {
if (start == null) {
start = (Verse) keys.next();
} else {
end = (Verse) keys.next();
}
}
if (start != null) {
osisWrapper.setStartRange(start.getOrdinal());
}
if (end != null) {
osisWrapper.setEndRange(end.getOrdinal());
} else if (start != null) {
osisWrapper.setEndRange(start.getOrdinal());
}
}
} else if (key instanceof VerseRange) {
final VerseRange vr = (VerseRange) key;
osisWrapper.setStartRange(versification.getOrdinal(vr.getStart()));
osisWrapper.setEndRange(versification.getOrdinal(vr.getEnd()));
osisWrapper.setMultipleRanges(false);
}
return osisWrapper;
} catch (final BookException e) {
throw new LocalisedException(e, e.getMessage());
} catch (final SAXException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final TransformerException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final NoSuchKeyException e) {
throw new TranslatedException(e, "invalid_reference_in_book", bookData.getKey().getName(), book.getInitials());
}
}
Aggregations