use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class StrongDictionary method doImport.
@Override
public Bible doImport(File inputFile) throws Exception {
Bible result = new Bible("Strong's dictionary");
MetadataBook mb = new MetadataBook();
mb.setValue(MetadataBookKey.description, "Strong's dictionary compiled by BibleMultiConverter from public sources.");
mb.setValue(MetadataBookKey.source, "https://github.com/openscriptures/HebrewLexicon/ and https://github.com/morphgnt/strongs-dictionary-xml/");
mb.setValue(MetadataBookKey.rights, "Strong's Greek Dictionary is in the public domain. Strong's Hebrew Dictionary is provided as XML files by the Open Scriptures Hebrew Bible Project, which are licensed CC-BY-4.0.");
mb.finished();
result.getBooks().add(mb.getBook());
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc;
try (InputStream in = new URL("https://raw.githubusercontent.com/morphgnt/strongs-dictionary-xml/master/strongsgreek.xml").openStream()) {
doc = db.parse(in);
}
for (Node entryNode = doc.getDocumentElement().getLastChild().getFirstChild(); entryNode != null; entryNode = entryNode.getNextSibling()) {
Element entry = (Element) entryNode;
int number = Integer.parseInt(entry.getAttribute("strongs"));
System.out.println("G" + number);
Book bk = new Book("G" + number, BookID.DICTIONARY_ENTRY, "G" + number, "G" + number);
FormattedText prolog = new FormattedText();
bk.getChapters().add(new Chapter());
bk.getChapters().get(0).setProlog(prolog);
result.getBooks().add(bk);
Visitor<RuntimeException> v = prolog.getAppendVisitor();
for (Node childNode = entry.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
if (childNode instanceof Text) {
if (childNode.getTextContent().replaceAll("[ \r\n\t]+", " ").equals(" or ") && childNode.getNextSibling().getNodeName().equals("greek")) {
v.visitFormattingInstruction(FormattingInstructionKind.ITALIC).visitText("-or-");
v.visitLineBreak(LineBreakKind.PARAGRAPH);
} else if (childNode.getTextContent().trim().length() > 0) {
visitAttribute(v, "Remark", childNode.getTextContent());
}
continue;
}
Element elem = (Element) childNode;
switch(elem.getNodeName()) {
case "strongs":
int compNumber = Integer.parseInt(elem.getTextContent());
if (compNumber != number)
throw new IOException(compNumber + " != " + number);
break;
case "greek":
v.visitHeadline(1).visitText(elem.getAttribute("unicode"));
visitAttribute(v, "Transliteration", elem.getAttribute("translit"));
break;
case "pronunciation":
visitAttribute(v, "Pronunciation", elem.getAttribute("strongs"));
break;
case "strongs_derivation":
visitAttribute(v, "Strongs Derivation", parseGreekContent(elem));
break;
case "strongs_def":
visitAttribute(v, "Strongs Definition", parseGreekContent(elem));
break;
case "kjv_def":
visitAttribute(v, "KJV Definition", parseGreekContent(elem));
if (elem.getNextSibling() != null && !elem.getNextSibling().getNodeName().equals("see")) {
Element moreInfo = doc.createElement("more_info");
elem.getParentNode().insertBefore(moreInfo, elem.getNextSibling());
while (moreInfo.getNextSibling() != null) {
if (moreInfo.getNextSibling().getNodeName().equals("see"))
break;
moreInfo.appendChild(moreInfo.getNextSibling());
}
if (moreInfo.getTextContent().trim().isEmpty())
moreInfo.getParentNode().removeChild(moreInfo);
}
break;
case "strongsref":
visitAttribute(v, "Reference", "[" + elem.getAttribute("language").substring(0, 1) + Integer.parseInt(elem.getAttribute("strongs")) + "]");
case "more_info":
visitAttribute(v, "More Information", parseGreekContent(elem));
break;
case "see":
visitAttribute(v, "See Also", "[" + elem.getAttribute("language").substring(0, 1) + Integer.parseInt(elem.getAttribute("strongs")) + "]");
break;
default:
throw new IOException(elem.getNodeName());
}
}
prolog.trimWhitespace();
prolog.finished();
}
try (InputStream in = new URL("https://raw.githubusercontent.com/openscriptures/HebrewLexicon/master/HebrewStrong.xml").openStream()) {
doc = db.parse(in);
}
for (Node entryNode = doc.getDocumentElement().getFirstChild(); entryNode != null; entryNode = entryNode.getNextSibling()) {
if (entryNode instanceof Text) {
if (!entryNode.getTextContent().trim().isEmpty()) {
throw new IOException(entryNode.getTextContent());
}
continue;
}
Element entry = (Element) entryNode;
String id = entry.getAttribute("id");
System.out.println(id);
Book bk = new Book(id, BookID.DICTIONARY_ENTRY, id, id);
FormattedText prolog = new FormattedText();
bk.getChapters().add(new Chapter());
bk.getChapters().get(0).setProlog(prolog);
result.getBooks().add(bk);
Visitor<RuntimeException> v = prolog.getAppendVisitor();
for (Node childNode = entry.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
if (childNode instanceof Text) {
if (!childNode.getTextContent().trim().isEmpty()) {
throw new IOException(childNode.getTextContent());
}
continue;
}
Element elem = (Element) childNode;
switch(elem.getNodeName()) {
case "w":
v.visitHeadline(1).visitText(elem.getTextContent());
visitAttribute(v, "Transliteration", elem.getAttribute("xlit"));
visitAttribute(v, "Pronunciation", elem.getAttribute("pron"));
if (elem.getAttribute("xml:lang").equals("heb")) {
visitAttribute(v, "Language", "Hebrew");
} else if (elem.getAttribute("xml:lang").equals("arc")) {
visitAttribute(v, "Language", "Aramaic");
} else if (elem.getAttribute("xml:lang").equals("x-pn")) {
visitAttribute(v, "Language", "Proper Noun");
} else {
throw new IOException(elem.getAttribute("xml:lang"));
}
visitAttribute(v, "Part of speech", elem.getAttribute("pos"));
break;
case "source":
visitAttribute(v, "Source", parseHebrewContent(elem));
break;
case "meaning":
visitAttribute(v, "Meaning", parseHebrewContent(elem));
break;
case "usage":
visitAttribute(v, "Usage", parseHebrewContent(elem));
break;
case "note":
// skip
break;
default:
throw new IOException(elem.getNodeName());
}
}
prolog.trimWhitespace();
prolog.finished();
}
return result;
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class TheWord method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
boolean hasOT = false, hasNT = false;
Map<BookID, Book> foundBooks = new EnumMap<>(BookID.class);
for (Book bk : bible.getBooks()) {
if (!COVERED_BOOKS.contains(bk.getId()))
continue;
foundBooks.put(bk.getId(), bk);
if (bk.getId().isNT())
hasNT = true;
else
hasOT = true;
}
if (!hasOT && !hasNT) {
System.out.println("WARNING: Unable to export, no supported book is covered!");
return;
}
File file = new File(exportArgs[0] + "." + (hasOT && hasNT ? "ont" : hasOT ? "ot" : "nt"));
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"))) {
bw.write("\uFEFF");
TheWordVisitor twvo = hasOT ? new TheWordVisitor(bw, false) : null;
TheWordVisitor twvn = hasNT ? new TheWordVisitor(bw, true) : null;
for (BookID bid : BOOK_ORDER) {
if ((bid.isNT() && !hasNT) || (!bid.isNT() && !hasOT))
continue;
TheWordVisitor twv = bid.isNT() ? twvn : twvo;
Book bk = foundBooks.get(bid);
int[] verseCount = StandardVersification.KJV.getVerseCount(bid);
for (int cnumber = 1; cnumber <= verseCount.length; cnumber++) {
Chapter ch = bk != null && cnumber <= bk.getChapters().size() ? bk.getChapters().get(cnumber - 1) : null;
int maxVerse = verseCount[cnumber - 1];
int nextVerse = 1;
if (ch != null) {
BitSet allowedNumbers = new BitSet(maxVerse + 1);
allowedNumbers.set(1, maxVerse + 1);
for (VirtualVerse vv : ch.createVirtualVerses(allowedNumbers)) {
while (vv.getNumber() > nextVerse) {
bw.write("- - -\r\n");
nextVerse++;
}
if (vv.getNumber() != nextVerse)
throw new RuntimeException("Verse to write :" + vv.getNumber() + ", but next verse slot in file: " + nextVerse);
for (Headline h : vv.getHeadlines()) {
bw.write("<TS" + (h.getDepth() < 3 ? h.getDepth() : 3) + ">");
h.accept(twv);
twv.reset();
bw.write("<Ts>");
}
for (Verse v : vv.getVerses()) {
if (!v.getNumber().equals("" + vv.getNumber())) {
bw.write(" (" + v.getNumber() + ")");
}
v.accept(twv);
twv.reset();
}
bw.write("\r\n");
nextVerse++;
}
}
if (nextVerse > maxVerse + 1)
throw new RuntimeException(nextVerse + "/" + (maxVerse + 1));
for (int i = 0; i <= maxVerse - nextVerse; i++) {
bw.write("- - -\r\n");
}
}
}
bw.write("\r\nabout=Converted by BibleMultiConverter\r\n");
}
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class UnboundBible method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
MetadataBook mb = bible.getMetadataBook();
if (mb == null)
mb = new MetadataBook();
String fileTypeName = mb.getValue("filetype@unbound");
UnboundBibleFileType fileType = fileTypeName != null ? UnboundBibleFileType.valueOf(fileTypeName) : UnboundBibleFileType.Unmapped_BCVS;
Map<String, List<String[]>> mapping = new HashMap<>();
Map<BookID, List<String>> extraEmptyVerses = new EnumMap<>(BookID.class);
List<Book> allBooks = new ArrayList<>(bible.getBooks());
if (exportArgs.length == 2) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(exportArgs[1]), StandardCharsets.UTF_8))) {
String line;
List<Book> nonexistingExtraEmptyVersesBooks = new ArrayList<>();
while ((line = br.readLine()) != null) {
if (line.isEmpty() || line.startsWith("#"))
continue;
String[] fields = line.split("\t", -1);
if (fields.length != 8)
throw new IOException(line);
int isNull = Integer.parseInt(fields[7]);
if (isNull == 0) {
String key = fields[3] + " " + fields[4] + ":" + fields[5] + " " + fields[6];
String[] value = Arrays.copyOf(fields, 3);
if (!mapping.containsKey(key))
mapping.put(key, new ArrayList<String[]>());
mapping.get(key).add(value);
} else if (isNull == 1) {
BookID id = BOOK_INFO_BY_CODE.get(fields[3]).id;
if (!extraEmptyVerses.containsKey(id))
extraEmptyVerses.put(id, new ArrayList<String>());
extraEmptyVerses.get(id).add(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + fields[3] + "\t" + fields[4] + "\t" + fields[5] + "\t" + fields[6] + "\t0\t");
Book existingBook = null;
for (Book bk : allBooks) {
if (bk.getId() == id)
existingBook = bk;
}
if (existingBook == null) {
if (nonexistingExtraEmptyVersesBooks.isEmpty() || nonexistingExtraEmptyVersesBooks.get(nonexistingExtraEmptyVersesBooks.size() - 1).getId() != id)
nonexistingExtraEmptyVersesBooks.add(new Book(id.getOsisID(), id, id.getOsisID(), id.getOsisID()));
} else if (!nonexistingExtraEmptyVersesBooks.isEmpty()) {
int pos = allBooks.indexOf(existingBook);
allBooks.addAll(pos, nonexistingExtraEmptyVersesBooks);
nonexistingExtraEmptyVersesBooks.clear();
}
} else {
throw new IOException(line);
}
}
}
fileType = UnboundBibleFileType.Mapped_BCVS;
}
boolean useRoundtrip = Boolean.getBoolean("unbound.roundtrip");
boolean useParsedFormat = Boolean.getBoolean("unbound.parsed");
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportArgs[0]), StandardCharsets.UTF_8))) {
if (exportArgs.length == 2 && useRoundtrip)
bw.write("\r\n");
bw.write("#THE UNBOUND BIBLE (www.unboundbible.org)\r\n");
bw.write("#name\t" + bible.getName() + "\r\n");
bw.write("#filetype\t" + fileType.name().replace('_', '-') + "\r\n");
writeMetadata(bw, "copyright", mb.getValue(MetadataBookKey.rights));
writeMetadata(bw, "abbreviation", mb.getValue("abbreviation@unbound"));
writeMetadata(bw, "language", mb.getValue(MetadataBookKey.language));
writeMetadata(bw, "note", mb.getValue(MetadataBookKey.description));
bw.write("#columns\t" + fileType.getColumnHeader() + "\r\n");
int[] sorting = { 0 };
for (Book bk : allBooks) {
if (bk.getId() == BookID.METADATA)
continue;
UnboundBibleBookInfo bi = BOOK_INFO_BY_ID.get(bk.getId());
if (bi == null) {
System.out.println("WARNING: Skipping unsupported book: " + bk.getAbbr());
continue;
}
if (extraEmptyVerses.containsKey(bk.getId())) {
for (String emptyVerse : extraEmptyVerses.get(bk.getId())) {
bw.write(emptyVerse + "\r\n");
}
}
for (int cc = 0; cc < bk.getChapters().size(); cc++) {
Chapter ch = bk.getChapters().get(cc);
int chapter = cc + 1;
for (Verse vv : ch.getVerses()) {
String vn = vv.getNumber(), svn = "";
int c = chapter;
if (vn.matches("[0-9]+,.*")) {
int pos = vn.indexOf(',');
c = Integer.parseInt(vn.substring(0, pos));
vn = vn.substring(pos + 1);
}
if (vn.equals("1-/") || vn.equals("1-//")) {
vn = "0";
} else if (c == 1 && vn.endsWith("//")) {
c = 0;
vn = vn.substring(0, vn.length() - 2);
} else if (vn.endsWith("/a")) {
vn = vn.substring(0, vn.length() - 2);
svn = "EndA";
} else if (vn.endsWith("/b")) {
vn = vn.substring(0, vn.length() - 2);
svn = "EndB";
} else if (vn.endsWith("/")) {
vn = vn.substring(0, vn.length() - 1);
} else if (vn.matches("[0-9]+[.][a-z]")) {
svn = vn.substring(vn.length() - 1) + vn.substring(vn.length() - 1);
vn = vn.substring(0, vn.length() - 2);
} else if (!vn.matches("[0-9]+")) {
Matcher m = Pattern.compile("([0-9]+)([-,/.a-zG][-0-9,/.a-zG]*)").matcher(vn);
if (!m.matches())
throw new IOException(vn);
vn = m.group(1);
svn = m.group(2);
}
int v = Integer.parseInt(vn);
sorting[0] += 10;
StringBuilder sb = new StringBuilder();
vv.accept(new UnboundBibleVisitor(sb, sorting, useParsedFormat));
String text = sb.toString();
if (useRoundtrip && text.contains("\uFEFF")) {
if (text.equals("\uFEFF-\uFEFF"))
text = "";
text = text.replace("\uFEFF ", " ").replace(" \uFEFF", " ");
}
for (String[] nrsva_fields : lookup(mapping, bi.code, c, v, svn)) {
String[] fields = new String[] { nrsva_fields[0], nrsva_fields[1], nrsva_fields[2], bi.code, "" + c, "" + v, svn, "" + sorting[0], text };
fileType.writeFields(bw, fields, "nrsva_book_index", "nrsva_chapter", "nrsva_verse", "orig_book_index", "orig_chapter", "orig_verse", "orig_subverse", "order_by", "text");
}
}
}
}
}
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class UnboundBible method doImport.
@Override
public Bible doImport(File inputFile) throws Exception {
boolean useRoundtrip = Boolean.getBoolean("unbound.roundtrip");
boolean useParsedFormat = Boolean.getBoolean("unbound.parsed");
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), StandardCharsets.UTF_8))) {
String line = br.readLine();
if (line.isEmpty())
// mapped ones have an extra empty line...
line = br.readLine();
if (!line.equals("#THE UNBOUND BIBLE (www.unboundbible.org)"))
throw new IOException(line);
line = br.readLine();
if (!line.startsWith("#name\t"))
throw new IOException(line);
Bible result = new Bible(line.substring(6));
MetadataBook mb = new MetadataBook();
result.getBooks().add(mb.getBook());
line = br.readLine();
if (!line.startsWith("#filetype\t"))
throw new IOException(line);
UnboundBibleFileType filetype = UnboundBibleFileType.valueOf(line.substring(10).replace('-', '_'));
if (filetype == UnboundBibleFileType.Unmapped_BCV && useRoundtrip) {
mb.setValue("filetype@unbound", filetype.toString());
}
readMetadata(br, mb, "copyright", MetadataBookKey.rights.toString());
readMetadata(br, mb, "abbreviation", "abbreviation@unbound");
readMetadata(br, mb, "language", MetadataBookKey.language.toString());
readMetadata(br, mb, "note", MetadataBookKey.description.toString());
mb.finished();
line = br.readLine();
if (!line.equals("#columns\t" + filetype.getColumnHeader()))
throw new IOException(line);
Map<BookID, Book> books = new HashMap<>();
int sorting = -1, lastChapter = 0;
String[] lastFields = new String[0];
while ((line = br.readLine()) != null) {
if (line.startsWith("#"))
throw new IOException(line);
if (line.trim().isEmpty())
continue;
String[] fields = filetype.parseFields(line, "orig_book_index", "orig_chapter", "orig_verse", "orig_subverse", "order_by", "text");
if (fields[4] != null && Arrays.equals(fields, lastFields))
continue;
if (fields[2].isEmpty() && fields[4].equals("0") && fields[5].isEmpty())
continue;
UnboundBibleBookInfo bi = BOOK_INFO_BY_CODE.get(fields[0]);
if (bi == null)
throw new IOException("Invalid book code: " + fields[0] + " in " + line);
Book bk = books.get(bi.id);
if (bk == null) {
bk = new Book(bi.id.getOsisID(), bi.id, bi.name, bi.name);
result.getBooks().add(bk);
books.put(bi.id, bk);
lastChapter = 0;
}
int chapter = Integer.parseInt(fields[1]);
String verse = "" + Integer.parseInt(fields[2]);
if (chapter == 0) {
chapter = 1;
verse += "//";
} else if (verse.equals("0")) {
verse = "1-/";
}
String subverse = fields[3];
if (subverse != null && !subverse.isEmpty()) {
if (subverse.length() == 1 && subverse.charAt(0) >= 'a' && subverse.charAt(0) <= 'z') {
verse += subverse;
} else if (subverse.length() == 2 && subverse.charAt(0) == subverse.charAt(1) && subverse.charAt(0) >= 'a' && subverse.charAt(0) <= 'z') {
verse += "." + subverse.charAt(0);
} else if (subverse.matches("[.-][0-9]+")) {
verse += subverse;
} else if (subverse.equals("EndA")) {
verse += "/a";
} else if (subverse.equals("EndB")) {
verse += "/b";
} else {
throw new IOException(subverse);
}
}
if (chapter < lastChapter) {
System.out.println("WARNING: Verses reordered across chapters detected");
verse = chapter + "," + verse;
chapter = lastChapter;
}
lastChapter = chapter;
int sortingDiff = 0;
if (fields[4] == null) {
if (sorting != -1)
throw new IOException("Inconsistent sorting: " + line);
} else {
int s = Integer.parseInt(fields[4]);
if (s <= sorting && lastFields[2].equals(fields[2]))
throw new IOException("Inconsistent sorting: " + s + " <= last " + sorting + " in " + line);
if (s != (sorting == -1 ? 10 : sorting + 10)) {
sortingDiff = s - (sorting == -1 ? 10 : sorting + 10);
}
sorting = s;
if (lastFields.length > 5 && lastFields[5].equals(fields[5]) && lastFields[2].equals(fields[2]))
System.out.println("WARNING: Same verse text as previous: " + line);
}
lastFields = fields;
String text = fields[5];
if (useRoundtrip) {
String last;
do {
last = text;
text = text.replace(" ", " \uFEFF ");
} while (!last.equals(text));
if (text.endsWith(" "))
text += "\uFEFF";
if (text.startsWith(" "))
text = "\uFEFF" + text;
if (text.length() == 0)
text = "\uFEFF-\uFEFF";
} else {
text = text.replaceAll(" +", " ").trim();
if (text.length() == 0) {
if (bk.getChapters().size() == 0) {
books.remove(bk.getId());
result.getBooks().remove(bk);
}
continue;
}
}
while (bk.getChapters().size() < chapter) bk.getChapters().add(new Chapter());
if (bk.getChapters().size() != chapter && useRoundtrip)
throw new RuntimeException("Invalid chapter order: " + bk.getId() + chapter + "/" + verse + " " + text);
Chapter ch = bk.getChapters().get(chapter - 1);
if (!ch.getVerses().isEmpty() && ch.getVerses().get(ch.getVerses().size() - 1).getNumber().equals(verse))
verse += "/";
Verse vv = new Verse(verse);
Visitor<RuntimeException> vvv = vv.getAppendVisitor();
if (useParsedFormat) {
String[] words = text.split(" ");
int[] strongs = new int[10];
String[] rmacs = new String[10];
int strongCount = 0, rmacCount = 0;
String word = words[0];
for (int i = 1; i < words.length; i++) {
if (words[i].matches("[GH][0-9]+")) {
strongs[strongCount++] = Integer.parseInt(words[i].substring(1));
} else if (words[i].matches(Utils.RMAC_REGEX)) {
rmacs[rmacCount++] = words[i];
} else {
if (strongCount > 0 || rmacCount > 0) {
vvv.visitGrammarInformation(strongCount > 0 ? Arrays.copyOf(strongs, strongCount) : null, rmacCount > 0 ? Arrays.copyOf(rmacs, rmacCount) : null, null).visitText(word);
strongCount = rmacCount = 0;
} else {
vvv.visitText(word);
}
vvv.visitText(" ");
word = words[i];
}
}
if (strongCount > 0 || rmacCount > 0) {
vvv.visitGrammarInformation(strongCount > 0 ? Arrays.copyOf(strongs, strongCount) : null, rmacCount > 0 ? Arrays.copyOf(rmacs, rmacCount) : null, null).visitText(word);
strongCount = rmacCount = 0;
} else {
vvv.visitText(word);
}
} else {
vvv.visitText(text);
}
if (useRoundtrip && sortingDiff != 0) {
vvv.visitExtraAttribute(ExtraAttributePriority.SKIP, "unbound", "sorting-diff", "" + sortingDiff);
}
vv.finished();
ch.getVerses().add(vv);
}
return result;
}
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class Volksbibel2000 method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
// update chapter splitting for Bibles that use a different one
for (Book bk : bible.getBooks()) {
if (bk.getId() == BookID.BOOK_Joel && bk.getChapters().size() == 3) {
System.out.println("INFO: Splitting Joel chapters...");
Chapter ch2 = bk.getChapters().get(1);
Chapter ch3 = new Chapter();
for (int i = 0; i < ch2.getVerses().size(); i++) {
Verse v = ch2.getVerses().get(i);
try {
int vnum = Integer.parseInt(v.getNumber());
if (vnum >= 28) {
ch2.getVerses().remove(i);
Verse vv = new Verse("2," + v.getNumber());
v.accept(vv.getAppendVisitor());
vv.finished();
ch3.getVerses().add(vv);
i--;
}
} catch (NumberFormatException ex) {
// ignore non-numeric verses
}
}
if (!ch3.getVerses().isEmpty()) {
bk.getChapters().add(2, ch3);
}
} else if (bk.getId() == BookID.BOOK_Mal && bk.getChapters().size() == 4) {
System.out.println("INFO: merging Maleachi chapters...");
Chapter ch3 = bk.getChapters().get(2);
Chapter ch4 = bk.getChapters().remove(3);
for (Verse v : ch4.getVerses()) {
Verse vv = new Verse("4," + v.getNumber());
v.accept(vv.getAppendVisitor());
vv.finished();
ch3.getVerses().add(vv);
}
}
}
String escapeChar = exportArgs.length == 1 ? "" : exportArgs[1];
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(exportArgs[0])), StandardCharsets.ISO_8859_1))) {
bw.write("Importdatei für Volksbibel 2000");
bw.newLine();
bw.write("Klicken Sie im Hauptfenster bei gedrückter STRG-Taste auf den Button");
bw.newLine();
bw.write("\"Integration\", wählen Sie diese Datei aus und folgen Sie den Anweisungen");
bw.newLine();
bw.write("auf dem Bildschirm.");
bw.newLine();
bw.newLine();
if (!escapeChar.isEmpty()) {
bw.write("Nach dem erfolgreichen Import öffnen Sie die .mc-Datei in LiveCode und");
bw.newLine();
bw.write("lassen folgendes Script laufen:");
bw.newLine();
bw.newLine();
bw.write(" local myData, escapeChar");
bw.newLine();
bw.write(" put \"" + escapeChar + "\" into escapeChar");
bw.newLine();
bw.write(" repeat with i = 2 to the number of cards");
bw.newLine();
bw.write(" put the htmltext of field 2 of card i into myData");
bw.newLine();
bw.write(" replace escapeChar & \"<\" with \"<\" in myData");
bw.newLine();
bw.write(" replace escapeChar & \">\" with \">\" in myData");
bw.newLine();
bw.write(" replace escapeChar & \" \" with \"\" in myData");
bw.newLine();
bw.write(" replace escapeChar & \"&\" with \"&\" in myData");
bw.newLine();
bw.write(" set the htmltext of field 2 of card i to myData");
bw.newLine();
bw.write(" end repeat //");
bw.newLine();
bw.write(" answer \"Fertig.\" //");
bw.newLine();
bw.newLine();
}
for (Book book : bible.getBooks()) {
String bookAbbr = BOOK_NAMES.get(book.getId());
if (bookAbbr == null) {
System.out.println("WARNING: Skipping book " + book.getAbbr());
continue;
}
int cnumber = 0;
for (Chapter chapter : book.getChapters()) {
StringBuilder content = new StringBuilder();
cnumber++;
bw.write(bookAbbr + " " + cnumber);
bw.newLine();
for (Verse v : chapter.getVerses()) {
v.accept(new Vb2000Visitor(content, v, "", escapeChar));
content.append('\n');
}
for (String line : content.toString().split("\n")) {
line = BOOK_HEADERS.matcher(line).replaceAll("$1 " + escapeChar + " $2");
line = MISDETECTED_WORDS.matcher(line).replaceAll("$1 " + escapeChar + " $2");
line = line.replace("Lied der Lieder", "Lied " + escapeChar + " der Lieder");
while (!line.isEmpty() && line.split(" ").length < 3) {
if (escapeChar.isEmpty())
line += " *";
else
line = escapeChar + " " + line;
}
bw.write(line);
bw.newLine();
}
}
}
}
}
Aggregations