Search in sources :

Example 1 with JSwordPassageServiceImpl

use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.

the class LoaderTest method getLoader.

/**
 * Gets a loader to be tested
 *
 * @param key the key to the properties
 * @param file where the file that should be tested is
 * @return the loader
 */
private Loader getLoader(final String key, final String file) {
    final Properties coreProperties = new Properties();
    coreProperties.put(key, file);
    final JSwordVersificationService versificationService = TestUtils.mockVersificationService();
    return new Loader(new JSwordPassageServiceImpl(versificationService, null, null, null, mock(VersionResolver.class), null), null, coreProperties, this.entityManager, this.clientSessionProvider, mock(AppManagerService.class));
}
Also used : JSwordPassageServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl) JSwordVersificationService(com.tyndalehouse.step.core.service.jsword.JSwordVersificationService) Properties(java.util.Properties) AppManagerService(com.tyndalehouse.step.core.service.AppManagerService)

Example 2 with JSwordPassageServiceImpl

use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.

the class SearchServiceImplTest method getSearchServiceUnderTest.

/**
 * @return the search service to test
 */
private SearchServiceImpl getSearchServiceUnderTest() {
    final JSwordMetadataService meta = mock(JSwordMetadataService.class);
    final JSwordModuleService module = mock(JSwordModuleService.class);
    final JSwordVersificationService versificationService = TestUtils.mockVersificationService();
    final PassageOptionsValidationService optionsValidationService = mock(PassageOptionsValidationService.class);
    final JSwordPassageServiceImpl jsword = new JSwordPassageServiceImpl(versificationService, null, null, null, TestUtils.mockVersionResolver(), optionsValidationService);
    when(optionsValidationService.getAvailableFeaturesForVersion(any(String.class), any(List.class), any(String.class), any(InterlinearMode.class))).thenReturn(new AvailableFeatures());
    when(module.isInstalled("ESV_th")).thenReturn(true);
    when(module.isIndexed(any(String.class))).thenReturn(true);
    when(meta.supportsFeature(any(String.class), any(LookupOption.class))).thenReturn(true);
    final JSwordSearchServiceImpl jswordSearch = new JSwordSearchServiceImpl(versificationService, null, jsword);
    subjects = new SubjectSearchServiceImpl(entityManager, jswordSearch, meta, module, versificationService);
    return new SearchServiceImpl(jswordSearch, meta, versificationService, subjects, new TimelineServiceImpl(entityManager, jsword), null, entityManager, TestUtils.mockVersionResolver(), mock(LexiconDefinitionServiceImpl.class), null, null);
}
Also used : JSwordPassageServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl) LexiconDefinitionServiceImpl(com.tyndalehouse.step.core.service.impl.LexiconDefinitionServiceImpl) LookupOption(com.tyndalehouse.step.core.models.LookupOption) JSwordVersificationService(com.tyndalehouse.step.core.service.jsword.JSwordVersificationService) TimelineServiceImpl(com.tyndalehouse.step.core.service.impl.TimelineServiceImpl) PassageOptionsValidationService(com.tyndalehouse.step.core.service.PassageOptionsValidationService) JSwordModuleService(com.tyndalehouse.step.core.service.jsword.JSwordModuleService) JSwordMetadataService(com.tyndalehouse.step.core.service.jsword.JSwordMetadataService) AvailableFeatures(com.tyndalehouse.step.core.models.AvailableFeatures) List(java.util.List) InterlinearMode(com.tyndalehouse.step.core.models.InterlinearMode) JSwordSearchServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordSearchServiceImpl) JSwordSearchServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordSearchServiceImpl)

Example 3 with JSwordPassageServiceImpl

use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.

the class PerformancePassageRetrieval method testConcurrencyIssueThroughStep.

/**
 * tries to replicate the issue with bookdata not being able to be read in a concurrent fashion
 *
 * @throws NoSuchKeyException a no such key exception
 * @throws BookException a book exception
 * @throws InterruptedException when the thread is interrupted
 */
public static void testConcurrencyIssueThroughStep() throws NoSuchKeyException, BookException, InterruptedException {
    final String[] names = { "KJV", "ESV_th" };
    final String[] ref = { "Rom.2", "John 7", "2Ki.2", "Rom.1;John 4;2Ki.2", "Acts 3:4-6" };
    final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
    thbean.setThreadContentionMonitoringEnabled(true);
    final JSwordPassageServiceImpl jsi = new JSwordPassageServiceImpl(TestUtils.mockVersificationService(), null, null, null, TestUtils.mockVersionResolver(), null);
    final Queue<Long> times = new ConcurrentLinkedQueue<Long>();
    final AtomicLong iterations = new AtomicLong();
    final Runnable r1 = new Runnable() {

        @Override
        public void run() {
            for (int ii = 0; ii < 1000; ii++) {
                final long l = System.currentTimeMillis();
                jsi.getOsisText(names[ii % 2], ref[ii % 5]);
                times.add(System.currentTimeMillis() - l);
                iterations.incrementAndGet();
            }
            final ThreadInfo threadInfo = thbean.getThreadInfo(new long[] { Thread.currentThread().getId() }, true, true)[0];
            System.err.println("Waited a total of " + threadInfo.getBlockedCount() + " times, resulting in " + threadInfo.getBlockedTime() + "ms wasted time");
        }
    };
    int ii = 0;
    final long start = System.currentTimeMillis();
    final List<Thread> threads = new ArrayList<Thread>();
    while (ii++ < 16) {
        final Thread t1 = new Thread(r1);
        t1.start();
        threads.add(t1);
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(10000);
                } catch (final InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(iterations.get() + " iterations so far");
            }
        }
    }).start();
    for (final Thread t : threads) {
        t.join();
    }
    final long total = System.currentTimeMillis() - start;
    System.err.println(String.format("Executed: %d in %d ms, %f ms / iteration", iterations.get(), total, (double) total / (double) iterations.get()));
}
Also used : JSwordPassageServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl) ThreadMXBean(java.lang.management.ThreadMXBean) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) ThreadInfo(java.lang.management.ThreadInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 4 with JSwordPassageServiceImpl

use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.

the class InterleavedOsisReader method main.

/**
 * Just shows XML on the stdout
 *
 * @param args not used
 * @throws Exception any kind of exception
 */
public static void main(final String[] args) throws Exception {
    final String[] versions = new String[] { "OSMHB", "ESV_th" };
    final String ref = "Mic.5";
    final boolean unicodeBreakDown = false;
    final boolean compare = true;
    final InterlinearMode interlinearMode = InterlinearMode.INTERLEAVED;
    boolean format = false;
    final Format prettyFormat = format ? Format.getPrettyFormat() : Format.getRawFormat();
    final Book currentBook = Books.installed().getBook(versions[0]);
    final Book[] books = new Book[versions.length];
    for (int ii = 0; ii < versions.length; ii++) {
        books[ii] = Books.installed().getBook(versions[ii]);
    }
    final BookData bookData = new BookData(books, currentBook.getKey(ref), compare);
    final Element osisFragment = bookData.getOsisFragment();
    final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
    final String inputString = xmlOutputter.outputString(osisFragment);
    LOGGER.debug(inputString);
    if (unicodeBreakDown) {
        outputUnicode(inputString);
    }
    // do the test
    final JSwordPassageServiceImpl jsi = new JSwordPassageServiceImpl(TestUtils.mockVersificationService(), null, null, null, TestUtils.mockVersionResolver(), null);
    final List<LookupOption> options = new ArrayList<LookupOption>();
    options.add(LookupOption.CHAPTER_BOOK_VERSE_NUMBER);
    // options.add(LookupOption.HEADINGS_ONLY);
    // options.add(LookupOption.HEADINGS);
    // options.add(LookupOption.CHAPTER_BOOK_VERSE_NUMBER);
    final String osisText = jsi.getInterleavedVersions(versions, ref, options, interlinearMode, "en").getValue();
    LOGGER.debug(osisText);
    final SAXBuilder sb = new SAXBuilder();
    if (unicodeBreakDown) {
        outputUnicode(osisText);
    }
}
Also used : JSwordPassageServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl) XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Format(org.jdom2.output.Format) Book(org.crosswire.jsword.book.Book) InterlinearMode(com.tyndalehouse.step.core.models.InterlinearMode) BookData(org.crosswire.jsword.book.BookData)

Example 5 with JSwordPassageServiceImpl

use of com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl in project step by STEPBible.

the class OsisReader method main.

/**
 * Just shows XML on the stdout
 *
 * @param args not used
 * @throws Exception any kind of exception
 */
public static void main(final String[] args) throws Exception {
    final String version = "ESV_th";
    final String ref = "Gen.2";
    boolean format = true;
    final Book currentBook = Books.installed().getBook(version);
    final BookData bookData = new BookData(currentBook, currentBook.getKey(ref));
    final Element osisFragment = bookData.getOsisFragment();
    final XMLOutputter xmlOutputter = new XMLOutputter(format ? Format.getPrettyFormat() : Format.getRawFormat());
    LOGGER.debug(xmlOutputter.outputString(osisFragment));
    // do the test
    final JSwordPassageServiceImpl jsi = new JSwordPassageServiceImpl(TestUtils.mockVersificationService(), null, null, null, TestUtils.mockVersionResolver(), null);
    final List<LookupOption> options = new ArrayList<LookupOption>();
    // options.add(LookupOption.DIVIDE_HEBREW);
    options.add(LookupOption.NOTES);
    options.add(LookupOption.HEADINGS);
    options.add(LookupOption.GREEK_ACCENTS);
    final String osisText = jsi.getOsisText(version, ref, options, "ESV_th", InterlinearMode.NONE).getValue();
    final SAXBuilder sb = new SAXBuilder();
    try {
        final Document d = sb.build(new StringReader(osisText));
        LOGGER.debug("Transformed is:\n {}", xmlOutputter.outputString(d));
        xmlOutputter.outputString(d);
    } catch (final JDOMParseException e) {
        LOGGER.debug("Transformed is:\n [{}]", osisText);
    }
    // InterleavedOsisReader.outputUnicode(osisText);
    LOGGER.debug("Double whitespace: {}", osisText.contains("  "));
}
Also used : JSwordPassageServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl) JDOMParseException(org.jdom2.input.JDOMParseException) XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) Book(org.crosswire.jsword.book.Book) AbstractPassageBook(org.crosswire.jsword.book.basic.AbstractPassageBook) StringReader(java.io.StringReader) BookData(org.crosswire.jsword.book.BookData)

Aggregations

JSwordPassageServiceImpl (com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl)5 LookupOption (com.tyndalehouse.step.core.models.LookupOption)3 ArrayList (java.util.ArrayList)3 InterlinearMode (com.tyndalehouse.step.core.models.InterlinearMode)2 JSwordVersificationService (com.tyndalehouse.step.core.service.jsword.JSwordVersificationService)2 Book (org.crosswire.jsword.book.Book)2 BookData (org.crosswire.jsword.book.BookData)2 Element (org.jdom2.Element)2 SAXBuilder (org.jdom2.input.SAXBuilder)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 AvailableFeatures (com.tyndalehouse.step.core.models.AvailableFeatures)1 AppManagerService (com.tyndalehouse.step.core.service.AppManagerService)1 PassageOptionsValidationService (com.tyndalehouse.step.core.service.PassageOptionsValidationService)1 LexiconDefinitionServiceImpl (com.tyndalehouse.step.core.service.impl.LexiconDefinitionServiceImpl)1 TimelineServiceImpl (com.tyndalehouse.step.core.service.impl.TimelineServiceImpl)1 JSwordMetadataService (com.tyndalehouse.step.core.service.jsword.JSwordMetadataService)1 JSwordModuleService (com.tyndalehouse.step.core.service.jsword.JSwordModuleService)1 JSwordSearchServiceImpl (com.tyndalehouse.step.core.service.jsword.impl.JSwordSearchServiceImpl)1 StringReader (java.io.StringReader)1 ThreadInfo (java.lang.management.ThreadInfo)1