Search in sources :

Example 1 with Diffable

use of biblemulticonverter.format.Diffable 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 Diffable

use of biblemulticonverter.format.Diffable in project BibleMultiConverter by schierlm.

the class Validate method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    Map<String, Set<String>> dictionaryEntries = null;
    if (exportArgs.length > 0 && exportArgs[0].equals("IncludeExternalRefs")) {
        dictionaryEntries = new HashMap<String, Set<String>>();
        for (int i = 1; i < exportArgs.length; i++) {
            String ref = exportArgs[i];
            if (ref.startsWith("S"))
                ref = "Lstrongs=" + ref.substring(1);
            if (ref.startsWith("B")) {
                for (Book baseBook : new Diffable().doImport(new File(ref.substring(1))).getBooks()) {
                    if (baseBook.getId().getZefID() < 0)
                        continue;
                    Book book = null;
                    for (Book oldBook : bible.getBooks()) {
                        if (oldBook.getId().equals(baseBook.getId())) {
                            book = oldBook;
                            break;
                        }
                    }
                    if (book == null) {
                        book = new Book(baseBook.getAbbr(), baseBook.getId(), "$BBL$" + baseBook.getAbbr(), "$BBL$" + baseBook.getAbbr());
                        bible.getBooks().add(book);
                    }
                    for (int ch = 0; ch < baseBook.getChapters().size(); ch++) {
                        for (Verse v : baseBook.getChapters().get(ch).getVerses()) {
                            while (book.getChapters().size() <= ch) book.getChapters().add(new Chapter());
                            Chapter c = book.getChapters().get(ch);
                            boolean verseFound = false;
                            for (Verse vv : c.getVerses()) {
                                if (vv.getNumber().equals(v.getNumber())) {
                                    verseFound = true;
                                    break;
                                }
                            }
                            if (!verseFound) {
                                Verse vv = new Verse(v.getNumber());
                                vv.getAppendVisitor().visitText("X");
                                vv.finished();
                                c.getVerses().add(vv);
                            }
                        }
                    }
                }
            } else if (ref.startsWith("L")) {
                if (ref.contains("=")) {
                    int pos = ref.indexOf('=');
                    Set<String> entryList = new HashSet<>();
                    try (BufferedReader br = new BufferedReader(new FileReader(ref.substring(pos + 1)))) {
                        String line;
                        while ((line = br.readLine()) != null) {
                            entryList.add(line);
                        }
                    }
                    dictionaryEntries.put(ref.substring(1, pos), entryList);
                } else {
                    Set<String> entryList = new HashSet<>();
                    for (Book bk : bible.getBooks()) {
                        if (bk.getId().equals(BookID.DICTIONARY_ENTRY)) {
                            entryList.add(bk.getAbbr());
                        }
                    }
                    dictionaryEntries.put(ref.substring(1), entryList);
                }
            } else if (ref.startsWith("X")) {
                try (BufferedWriter bw = new BufferedWriter(new FileWriter(ref.substring(1)))) {
                    for (Book bk : bible.getBooks()) {
                        if (bk.getId().equals(BookID.DICTIONARY_ENTRY)) {
                            bw.write(bk.getAbbr());
                            bw.newLine();
                        }
                    }
                }
            } else {
                System.out.println("WARNING: external reference: " + ref);
            }
        }
        exportArgs = new String[0];
    }
    List<String> danglingReferences = new ArrayList<>();
    bible.validate(danglingReferences, dictionaryEntries);
    if (danglingReferences.size() > 0) {
        System.out.println("Dangling references: ");
        for (String reference : danglingReferences) {
            System.out.println("\t" + reference);
        }
        System.out.println();
    }
    if (exportArgs.length == 1 && exportArgs[0].equals("PrintSpecialVerseSummary")) {
        System.out.println("Special verse numbers:");
        printSpecialVerseNumbers(bible);
    } else if (exportArgs.length == 1 && exportArgs[0].equals("PrintHeadlines")) {
        System.out.println("Headlines:");
        printHeadlines(bible);
    } else if (exportArgs.length > 0) {
        System.out.println("WARNING: Unsupported arguments: " + Arrays.toString(exportArgs));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) FileWriter(java.io.FileWriter) Diffable(biblemulticonverter.format.Diffable) Chapter(biblemulticonverter.data.Chapter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) Book(biblemulticonverter.data.Book) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) Verse(biblemulticonverter.data.Verse)

Aggregations

Book (biblemulticonverter.data.Book)2 Chapter (biblemulticonverter.data.Chapter)2 Verse (biblemulticonverter.data.Verse)2 Diffable (biblemulticonverter.format.Diffable)2 FormattedText (biblemulticonverter.data.FormattedText)1 LogosVersificationDetector (biblemulticonverter.logos.tools.LogosVersificationDetector)1 VersificationScheme (biblemulticonverter.tools.AbstractVersificationDetector.VersificationScheme)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1