Search in sources :

Example 16 with VirtualVerse

use of biblemulticonverter.data.VirtualVerse in project BibleMultiConverter by schierlm.

the class AbstractVersificationDetector method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    VersificationScheme[] schemes = loadSchemes();
    Set<String> totalVerses = new HashSet<String>();
    boolean includeXref = exportArgs.length > 0 && exportArgs[0].equals("-xref");
    XrefCountVisitor xcv = includeXref ? new XrefCountVisitor(schemes, totalVerses) : null;
    // fill missing verses
    for (Book book : bible.getBooks()) {
        for (int cc = 0; cc < book.getChapters().size(); cc++) {
            Chapter chapter = book.getChapters().get(cc);
            if (includeXref && chapter.getProlog() != null) {
                chapter.getProlog().accept(xcv);
            }
            if (useVerseRanges()) {
                for (VerseRange vr : chapter.createVerseRanges()) {
                    int cnumber = vr.getChapter() == 0 ? cc + 1 : vr.getChapter();
                    countVerse(schemes, totalVerses, book.getAbbr(), book.getId(), cnumber, vr.getMinVerse());
                    countVerse(schemes, totalVerses, book.getAbbr(), book.getId(), cnumber, vr.getMaxVerse());
                }
            } else {
                for (VirtualVerse v : chapter.createVirtualVerses()) {
                    countVerse(schemes, totalVerses, book.getAbbr(), book.getId(), cc + 1, v.getNumber());
                }
            }
            if (includeXref) {
                for (Verse vv : chapter.getVerses()) {
                    vv.accept(xcv);
                }
            }
        }
    }
    // sort them
    Arrays.sort(schemes);
    // print them
    System.out.print("Best match:  ");
    int totalVerseCount = totalVerses.size();
    printScheme(schemes[0], totalVerseCount);
    System.out.println();
    System.out.println("Other options:");
    for (int i = 1; i < Math.min(11, schemes.length); i++) {
        printScheme(schemes[i], totalVerseCount);
        if (schemes[i].missingChapters.size() > schemes[0].missingChapters.size() + 2 || schemes[i].missingVerses.size() > schemes[0].missingVerses.size() + 5)
            break;
    }
    // print selected schemes
    if (exportArgs.length > (includeXref ? 1 : 0)) {
        System.out.println();
        System.out.println("Selected schemes:");
        for (int i = includeXref ? 1 : 0; i < exportArgs.length; i++) {
            boolean found = false;
            for (VersificationScheme scheme : schemes) {
                if (scheme.getName().equals(exportArgs[i])) {
                    printScheme(scheme, totalVerseCount);
                    found = true;
                    break;
                }
            }
            if (!found)
                System.out.println(exportArgs[i] + " (Unknown scheme)");
        }
    }
}
Also used : VerseRange(biblemulticonverter.data.VerseRange) VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) Book(biblemulticonverter.data.Book) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse) HashSet(java.util.HashSet)

Example 17 with VirtualVerse

use of biblemulticonverter.data.VirtualVerse in project BibleMultiConverter by schierlm.

the class Accordance method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    boolean paraMarker = false;
    for (Book book : bible.getBooks()) {
        if (!BOOK_NAME_MAP.containsKey(book.getId())) {
            continue;
        }
        for (Chapter chapter : book.getChapters()) {
            for (Verse v : chapter.getVerses()) {
                if (v.getElementTypes(Integer.MAX_VALUE).contains("b")) {
                    paraMarker = true;
                    break;
                }
            }
            if (paraMarker)
                break;
        }
        if (paraMarker)
            break;
    }
    File mainFile = new File(exportArgs[0] + ".txt");
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mainFile), StandardCharsets.UTF_8));
        BufferedWriter bnw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportArgs[0] + "-booknames.txt"), StandardCharsets.UTF_8))) {
        for (Book book : bible.getBooks()) {
            String bookName = BOOK_NAME_MAP.get(book.getId());
            if (bookName == null) {
                System.out.println("WARNING: Skipping book " + book.getAbbr());
                continue;
            }
            bnw.write(bookName + "\t" + book.getAbbr() + "\n");
            bw.write(bookName + " ");
            int cnumber = 0;
            for (Chapter chapter : book.getChapters()) {
                cnumber++;
                bw.write(cnumber + ":");
                List<VirtualVerse> vvs = chapter.createVirtualVerses();
                if (vvs.isEmpty()) {
                    bw.write("1 " + (paraMarker ? "¶" : "") + "\n");
                    paraMarker = false;
                }
                for (VirtualVerse vv : vvs) {
                    bw.write(vv.getNumber() + " " + (paraMarker ? "¶ " : ""));
                    paraMarker = false;
                    StringBuilder sb = new StringBuilder();
                    for (Verse v : vv.getVerses()) {
                        if (!v.getNumber().equals("" + vv.getNumber())) {
                            sb.append(" <b>(" + v.getNumber() + ")</b> ");
                        }
                        v.accept(new AccordanceVisitor(sb));
                    }
                    String verseText = sb.toString().replaceAll("  +", " ").trim();
                    if (verseText.endsWith(" ¶")) {
                        verseText = verseText.substring(0, verseText.length() - 2);
                        paraMarker = true;
                    }
                    bw.write(verseText + "\n");
                }
            }
        }
    }
    if (mainFile.length() > 0) {
        try (RandomAccessFile raf = new RandomAccessFile(mainFile, "rw")) {
            raf.setLength(mainFile.length() - 1);
        }
    }
}
Also used : VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) BufferedWriter(java.io.BufferedWriter) RandomAccessFile(java.io.RandomAccessFile) Book(biblemulticonverter.data.Book) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Aggregations

Chapter (biblemulticonverter.data.Chapter)17 Verse (biblemulticonverter.data.Verse)17 VirtualVerse (biblemulticonverter.data.VirtualVerse)17 Book (biblemulticonverter.data.Book)16 Headline (biblemulticonverter.data.FormattedText.Headline)12 BufferedWriter (java.io.BufferedWriter)9 MetadataBook (biblemulticonverter.data.MetadataBook)8 FileOutputStream (java.io.FileOutputStream)8 OutputStreamWriter (java.io.OutputStreamWriter)8 File (java.io.File)6 BookID (biblemulticonverter.data.BookID)5 BigInteger (java.math.BigInteger)4 QName (javax.xml.namespace.QName)4 FormattedText (biblemulticonverter.data.FormattedText)3 BIBLEBOOK (biblemulticonverter.schema.zef2005.BIBLEBOOK)3 CAPTION (biblemulticonverter.schema.zef2005.CAPTION)3 CHAPTER (biblemulticonverter.schema.zef2005.CHAPTER)3 EnumCaptionType (biblemulticonverter.schema.zef2005.EnumCaptionType)3 ObjectFactory (biblemulticonverter.schema.zef2005.ObjectFactory)3 STYLE (biblemulticonverter.schema.zef2005.STYLE)3