use of biblemulticonverter.data.Chapter 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)");
}
}
}
use of biblemulticonverter.data.Chapter 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 /> ";
} else if (exportArgs.length > 3 && exportArgs[3].equals("-nochapter")) {
verseSeparator = " ";
lineSeparator = "<br /> ";
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("&", "&").replace("<", "<").replace(">", ">") + "</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>");
}
}
use of biblemulticonverter.data.Chapter in project BibleMultiConverter by schierlm.
the class Validate method printSpecialVerseNumbers.
private void printSpecialVerseNumbers(Bible bible) throws IOException {
boolean lastPrinted = false;
for (Book b : bible.getBooks()) {
int chapter = 0;
for (Chapter c : b.getChapters()) {
chapter++;
Verse lastVerse = null;
for (Verse v : c.getVerses()) {
boolean print;
if (lastVerse == null) {
print = !v.getNumber().equals("1");
} else {
try {
int last = Integer.parseInt(lastVerse.getNumber());
print = !v.getNumber().equals("" + (last + 1));
} catch (NumberFormatException ex) {
print = true;
}
}
if (print) {
if (!lastPrinted && lastVerse != null) {
printShortVerse(b, chapter, lastVerse);
}
printShortVerse(b, chapter, v);
} else if (lastPrinted) {
System.out.println("\t====");
}
lastPrinted = print;
lastVerse = v;
}
}
}
}
use of biblemulticonverter.data.Chapter 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);
}
}
}
Aggregations