Search in sources :

Example 1 with VersificationScheme

use of biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme 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 VersificationScheme

use of biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme in project BibleMultiConverter by schierlm.

the class Versification method toNewVersificationScheme.

public VersificationScheme toNewVersificationScheme() {
    Map<BookID, BitSet[]> coveredBooks = new EnumMap<BookID, BitSet[]>(BookID.class);
    for (Map.Entry<BookID, VerseSet[]> entry : verseSets.entrySet()) {
        BitSet[] value = new BitSet[entry.getValue().length];
        for (int i = 0; i < value.length; i++) {
            value[i] = new BitSet();
            VerseSet vs = entry.getValue()[i];
            if (vs == null)
                continue;
            if (vs.verses != null)
                value[i].or(vs.verses);
            if (vs.lastRangeTo >= vs.lastRangeFrom)
                value[i].set(vs.lastRangeFrom, vs.lastRangeTo + 1);
        }
        coveredBooks.put(entry.getKey(), value);
    }
    return new VersificationScheme(name, coveredBooks);
}
Also used : BitSet(java.util.BitSet) VersificationScheme(biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with VersificationScheme

use of biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme in project BibleMultiConverter by schierlm.

the class LogosHTML method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    String versemap = exportArgs.length == 1 ? "Bible" : exportArgs[1];
    Properties bookDatatypeMap = null;
    VersificationScheme scheme;
    if (versemap.startsWith("author:")) {
        bookDatatypeMap = new Properties();
        try (InputStream in = new FileInputStream(versemap.substring(7))) {
            bookDatatypeMap.load(in);
        }
        versemap = null;
        scheme = new LogosVersificationDetector().loadScheme("Bible");
    } else {
        if (!versemap.matches("Bible[A-Z0-9]*")) {
            System.out.println("Invalid versification: " + versemap);
            return;
        }
        scheme = new LogosVersificationDetector().loadScheme(versemap);
        if (scheme == null) {
            System.out.println("Invalid versification: " + versemap);
            return;
        }
    }
    footnoteCounter = 0;
    grammarCounter = 0;
    String title = bible.getName();
    String verseSeparator = "<br />";
    lineSeparator = "<br />";
    boolean noChapterHeadings = false;
    if (exportArgs.length > 3 && exportArgs[3].equals("-inline")) {
        verseSeparator = " ";
        lineSeparator = "<br />&nbsp;&nbsp;&nbsp;&nbsp; ";
    } else if (exportArgs.length > 3 && exportArgs[3].equals("-nochapter")) {
        verseSeparator = " ";
        lineSeparator = "<br />&nbsp;&nbsp;&nbsp;&nbsp; ";
        noChapterHeadings = true;
    }
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(exportArgs[0])), StandardCharsets.UTF_8))) {
        bw.write("<html><head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n" + "<style>" + "body, h1, h2, h3, h4, h5, h6 { font-family: \"Times New Roman\";}\n" + "a { color: black; text-decoration: none;}\n" + "a.sdfootnotesym, a.sdendnotesym { font-style: italic;}\n" + "h1 {font-size: 24pt;}\n" + "h2 {font-size: 22pt;}\n" + "h3 {font-size: 20pt;}\n" + "h4 {font-size: 18pt;}\n" + "h5 {font-size: 16pt;}\n" + "h6 {font-size: 14pt;}\n" + "</style>\n" + "</head><body lang=\"de-DE\">\n");
        if (exportArgs.length > 2 && !exportArgs[2].equals("-")) {
            StringWriter sw = new StringWriter();
            try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(exportArgs[2]), StandardCharsets.UTF_8))) {
                char[] buffer = new char[4096];
                int len;
                while ((len = br.read(buffer)) != -1) sw.write(buffer, 0, len);
            }
            String template = sw.toString();
            template = template.replace("${name}", bible.getName());
            MetadataBook mb = bible.getMetadataBook();
            if (mb != null) {
                bible.getBooks().remove(0);
                for (String key : mb.getKeys()) template = template.replace("${" + key + "}", mb.getValue(key));
            }
            bw.write(template);
        } else {
            bw.write("<h1>" + title.replace("&", "&amp").replace("<", "&lt;").replace(">", "&gt;") + "</h1>\n");
        }
        StringWriter footnotes = new StringWriter();
        for (Book book : bible.getBooks()) {
            BitSet[] chapterVerses;
            String milestone;
            if (bookDatatypeMap != null) {
                milestone = bookDatatypeMap.getProperty(book.getId().getOsisID());
                chapterVerses = milestone == null ? null : ALL_CHAPTER_VERSES;
            } else {
                chapterVerses = scheme.getCoveredBooks().get(book.getId());
                String babbr = LOGOS_BOOKS.get(book.getId());
                milestone = babbr == null ? null : (versemap + ":" + babbr + " %c:%v");
            }
            if (milestone == null && book.getId().getZefID() < 0 && book.getChapters().size() == 1) {
                Chapter chapter = book.getChapters().get(0);
                if (chapter.getVerses().size() == 0 && chapter.getProlog() != null) {
                    // prolog only book
                    bw.write("<h2>");
                    if (book.getId() == BookID.DICTIONARY_ENTRY) {
                        if (bible.getName().toUpperCase().contains("STRONG") && book.getShortName().matches("[GH][1-9][0-9]*")) {
                            bw.write("[[@" + (book.getShortName().startsWith("G") ? "Greek" : "Hebrew") + "Strongs:" + book.getShortName() + "]]");
                        } else {
                            bw.write("[[@Headword:" + book.getAbbr() + "]]");
                            if (!book.getAbbr().equals(book.getShortName())) {
                                bw.write("[[@Headword:" + book.getShortName() + "]]");
                            }
                            if (!book.getLongName().equals(book.getShortName())) {
                                bw.write("[[@Headword:" + book.getLongName() + "]]");
                            }
                        }
                    }
                    bw.write(book.getLongName() + "</h2>\n");
                    footnoteNumber = 0;
                    chapter.getProlog().accept(new LogosVisitor(bw, "", footnotes, false, versemap, scheme, null, null, null, 2));
                    bw.write("\n<br/>\n");
                    continue;
                }
            }
            if (milestone == null) {
                System.out.println("WARNING: Skipping book " + book.getId());
                continue;
            }
            bw.write("<h2>[[@" + formatMilestone(milestone, "", "") + "]]" + book.getLongName() + " (" + book.getAbbr() + ")</h2>\n");
            int cnumber = 0;
            for (Chapter chapter : book.getChapters()) {
                cnumber++;
                if (!chapter.getVerses().isEmpty() && chapter.getVerses().get(0).getNumber().endsWith(".p")) {
                    Chapter prologue = new Chapter();
                    BitSet prologueVerses = new BitSet(100);
                    prologueVerses.set(1, 100);
                    while (!chapter.getVerses().isEmpty() && chapter.getVerses().get(0).getNumber().endsWith(".p")) {
                        Verse v = chapter.getVerses().remove(0);
                        Verse vv = new Verse(v.getNumber().replace(".p", ""));
                        v.accept(vv.getAppendVisitor());
                        vv.finished();
                        prologue.getVerses().add(vv);
                    }
                    exportChapter(milestone, "Prologue", prologue, versemap, scheme, verseSeparator, noChapterHeadings, bw, footnotes, book, chapterVerses, prologueVerses);
                }
                BitSet thisChapterVerses = chapterVerses != null && cnumber <= chapterVerses.length ? chapterVerses[cnumber - 1] : null;
                exportChapter(milestone, "" + cnumber, chapter, versemap, scheme, verseSeparator, noChapterHeadings, bw, footnotes, book, chapterVerses, thisChapterVerses);
            }
        }
        bw.write(footnotes.toString());
        bw.write("</body></html>");
    }
}
Also used : MetadataBook(biblemulticonverter.data.MetadataBook) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BitSet(java.util.BitSet) Chapter(biblemulticonverter.data.Chapter) VersificationScheme(biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) LogosVersificationDetector(biblemulticonverter.logos.tools.LogosVersificationDetector) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) MetadataBook(biblemulticonverter.data.MetadataBook) Book(biblemulticonverter.data.Book) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Verse(biblemulticonverter.data.Verse)

Aggregations

VersificationScheme (biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme)3 Book (biblemulticonverter.data.Book)2 Chapter (biblemulticonverter.data.Chapter)2 Verse (biblemulticonverter.data.Verse)2 LogosVersificationDetector (biblemulticonverter.logos.tools.LogosVersificationDetector)2 BitSet (java.util.BitSet)2 FormattedText (biblemulticonverter.data.FormattedText)1 MetadataBook (biblemulticonverter.data.MetadataBook)1 Diffable (biblemulticonverter.format.Diffable)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 EnumMap (java.util.EnumMap)1 LinkedHashMap (java.util.LinkedHashMap)1