Search in sources :

Example 1 with Book

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

the class LogosRenumberedDiffable method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    String outputFile = exportArgs[0];
    VersificationScheme scheme = null;
    if (exportArgs.length == 2) {
        if (!exportArgs[1].matches("Bible[A-Z0-9]*")) {
            System.out.println("Invalid versification: " + exportArgs[1]);
            return;
        }
        scheme = new LogosVersificationDetector().loadScheme(exportArgs[1]);
        if (scheme == null) {
            System.out.println("Invalid versification: " + exportArgs[1]);
            return;
        }
    }
    for (Book book : bible.getBooks()) {
        int cnumber = 0;
        for (Chapter chap : book.getChapters()) {
            cnumber++;
            if (chap.getProlog() != null) {
                FormattedText newProlog = new FormattedText();
                chap.getProlog().accept(new MapXrefVisitor(newProlog.getAppendVisitor(), scheme));
                newProlog.finished();
                chap.setProlog(newProlog);
            }
            for (int j = 0; j < chap.getVerses().size(); j++) {
                Verse v = chap.getVerses().get(j);
                Verse nv = new Verse(mapVerse(book.getAbbr(), book.getId(), cnumber, v.getNumber(), scheme, ""));
                v.accept(new MapXrefVisitor(nv.getAppendVisitor(), scheme));
                nv.finished();
                chap.getVerses().set(j, nv);
            }
        }
    }
    new Diffable().doExport(bible, new String[] { outputFile });
}
Also used : Book(biblemulticonverter.data.Book) Chapter(biblemulticonverter.data.Chapter) Diffable(biblemulticonverter.format.Diffable) VersificationScheme(biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme) FormattedText(biblemulticonverter.data.FormattedText) Verse(biblemulticonverter.data.Verse) LogosVersificationDetector(biblemulticonverter.logos.tools.LogosVersificationDetector)

Example 2 with Book

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

the class StrippedDiffable method extractPrologs.

private void extractPrologs(Bible bible) {
    for (Book book : bible.getBooks()) {
        for (Chapter chapter : book.getChapters()) {
            chapter.getVerses().clear();
            if (chapter.getProlog() != null) {
                Verse prologVerse = new Verse("1");
                chapter.getProlog().accept(prologVerse.getAppendVisitor());
                chapter.getVerses().add(prologVerse);
                chapter.setProlog(null);
            }
        }
    }
}
Also used : Book(biblemulticonverter.data.Book) Chapter(biblemulticonverter.data.Chapter) Verse(biblemulticonverter.data.Verse)

Example 3 with Book

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

the class StrippedDiffable method extractFootnotes.

private void extractFootnotes(Bible bible) {
    for (Book book : bible.getBooks()) {
        for (Chapter chapter : book.getChapters()) {
            chapter.getVerses().clear();
            if (chapter.getProlog() != null) {
                chapter.setProlog(extractFootnotes(chapter.getProlog()));
            }
            List<Verse> verses = chapter.getVerses();
            for (int i = 0; i < verses.size(); i++) {
                Verse v = verses.get(i);
                FormattedText extracted = extractFootnotes(v);
                if (extracted == null) {
                    verses.remove(i);
                    i--;
                } else {
                    Verse vv = new Verse(v.getNumber());
                    extracted.accept(vv.getAppendVisitor());
                    verses.set(i, vv);
                }
            }
        }
    }
}
Also used : Book(biblemulticonverter.data.Book) Chapter(biblemulticonverter.data.Chapter) FormattedText(biblemulticonverter.data.FormattedText) Verse(biblemulticonverter.data.Verse)

Example 4 with Book

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

the class StrippedDiffable method renameBookInXref.

protected void renameBookInXref(Bible bible, String oldName, String newName, boolean setFinished) {
    for (Book book : bible.getBooks()) {
        for (Chapter chap : book.getChapters()) {
            if (chap.getProlog() != null) {
                FormattedText newProlog = new FormattedText();
                chap.getProlog().accept(new RenameXrefVisitor(newProlog.getAppendVisitor(), oldName, newName));
                if (setFinished)
                    newProlog.finished();
                chap.setProlog(newProlog);
            }
            for (int j = 0; j < chap.getVerses().size(); j++) {
                Verse v = chap.getVerses().get(j);
                Verse nv = new Verse(v.getNumber());
                v.accept(new RenameXrefVisitor(nv.getAppendVisitor(), oldName, newName));
                if (setFinished)
                    nv.finished();
                chap.getVerses().set(j, nv);
            }
        }
    }
}
Also used : Book(biblemulticonverter.data.Book) Chapter(biblemulticonverter.data.Chapter) FormattedText(biblemulticonverter.data.FormattedText) Verse(biblemulticonverter.data.Verse)

Example 5 with Book

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

the class StrongConcordance method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    if (exportArgs.length != 2)
        throw new IOException("Two parameters needed!");
    Map<String, List<OccurrenceInfo>> occurrences = new HashMap<String, List<OccurrenceInfo>>();
    int bookIndex = 0;
    for (Book bk : bible.getBooks()) {
        int cnumber = 0;
        for (Chapter ch : bk.getChapters()) {
            cnumber++;
            for (Verse v : ch.getVerses()) {
                Map<String, List<StringBuilder>> strongInfo = new HashMap<>();
                v.accept(new StrongInfoVisitor(strongInfo, bk.getId().isNT() ? 'G' : 'H'));
                for (Map.Entry<String, List<StringBuilder>> e : strongInfo.entrySet()) {
                    String[] strongs = e.getKey().split("\\+");
                    String suffix = "";
                    if (strongs.length > 1)
                        suffix = " [" + e.getKey() + "]";
                    for (StringBuilder val : e.getValue()) {
                        OccurrenceInfo info = new OccurrenceInfo(val.toString().trim() + suffix, bookIndex, cnumber, v.getNumber());
                        for (String strong : strongs) {
                            List<OccurrenceInfo> occInfo = occurrences.get(strong);
                            if (occInfo == null) {
                                occInfo = new ArrayList<OccurrenceInfo>();
                                occurrences.put(strong, occInfo);
                            }
                            occInfo.add(info);
                        }
                    }
                }
            }
        }
        // save memory for the dictionary
        bk.getChapters().clear();
        bookIndex++;
    }
    Diffable diffable = new Diffable();
    Bible dict = diffable.doImport(new File(exportArgs[0]));
    for (Book bk : dict.getBooks()) {
        if (bk.getId() != BookID.DICTIONARY_ENTRY || occurrences.get(bk.getAbbr()) == null)
            continue;
        List<OccurrenceInfo> occ = occurrences.remove(bk.getAbbr());
        FormattedText old = bk.getChapters().get(0).getProlog();
        FormattedText changed = new FormattedText();
        Visitor<RuntimeException> v = changed.getAppendVisitor();
        old.accept(v);
        v.visitHeadline(1).visitText("Occurrences in " + bible.getName());
        Collections.sort(occ);
        List<OccurrenceInfo> part = new ArrayList<>();
        while (occ.size() > 0) {
            OccurrenceInfo first = occ.remove(0);
            part.add(first);
            while (occ.size() > 0 && occ.get(0).phrase.equals(first.phrase)) {
                part.add(occ.remove(0));
            }
            v.visitFormattingInstruction(FormattingInstructionKind.BOLD).visitText(first.phrase + " (" + part.size() + "):");
            for (int i = 0; i < part.size(); i++) {
                v.visitText(i == 0 ? " " : ", ");
                int cnt = 1;
                OccurrenceInfo curr = part.get(i);
                while (i + 1 < part.size() && part.get(i + 1).equals(curr)) {
                    cnt++;
                    i++;
                }
                Book book = bible.getBooks().get(curr.bookIndex);
                v.visitCrossReference(book.getAbbr(), book.getId(), curr.chapter, curr.verse, curr.chapter, curr.verse).visitText(book.getAbbr() + " " + curr.chapter + ":" + curr.verse);
                if (cnt > 1)
                    v.visitText(" (" + cnt + ")");
            }
            v.visitLineBreak(LineBreakKind.PARAGRAPH);
            part.clear();
        }
        changed.finished();
        bk.getChapters().get(0).setProlog(changed);
    }
    if (!occurrences.isEmpty())
        System.out.println("Missing Strong references in dictionary: " + occurrences.keySet());
    diffable.doExport(dict, new String[] { exportArgs[1] });
}
Also used : HashMap(java.util.HashMap) Bible(biblemulticonverter.data.Bible) ArrayList(java.util.ArrayList) Book(biblemulticonverter.data.Book) ArrayList(java.util.ArrayList) List(java.util.List) Chapter(biblemulticonverter.data.Chapter) IOException(java.io.IOException) FormattedText(biblemulticonverter.data.FormattedText) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) Verse(biblemulticonverter.data.Verse)

Aggregations

Book (biblemulticonverter.data.Book)67 Chapter (biblemulticonverter.data.Chapter)60 Verse (biblemulticonverter.data.Verse)57 FormattedText (biblemulticonverter.data.FormattedText)27 MetadataBook (biblemulticonverter.data.MetadataBook)25 VirtualVerse (biblemulticonverter.data.VirtualVerse)24 BookID (biblemulticonverter.data.BookID)22 ArrayList (java.util.ArrayList)22 File (java.io.File)20 Bible (biblemulticonverter.data.Bible)19 Headline (biblemulticonverter.data.FormattedText.Headline)18 BufferedWriter (java.io.BufferedWriter)16 FileOutputStream (java.io.FileOutputStream)15 IOException (java.io.IOException)14 OutputStreamWriter (java.io.OutputStreamWriter)13 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 Visitor (biblemulticonverter.data.FormattedText.Visitor)9 FileInputStream (java.io.FileInputStream)9 EnumMap (java.util.EnumMap)9