use of biblemulticonverter.data.BookID in project BibleMultiConverter by schierlm.
the class MyBibleZone method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
String outfile = exportArgs[0];
if (!outfile.endsWith(".SQLite3"))
outfile += ".SQLite3";
boolean hasFootnotes = false, hasStrongs = false;
for (Book bk : bible.getBooks()) {
for (Chapter ch : bk.getChapters()) {
for (Verse vv : ch.getVerses()) {
String elementTypes = vv.getElementTypes(Integer.MAX_VALUE);
if (elementTypes.contains("f")) {
hasFootnotes = true;
}
if (elementTypes.contains("g")) {
hasStrongs = true;
}
}
}
}
new File(outfile).delete();
SqlJetDb db = SqlJetDb.open(new File(outfile), true);
db.getOptions().setAutovacuum(true);
db.beginTransaction(SqlJetTransactionMode.WRITE);
db.getOptions().setUserVersion(0);
db.createTable("CREATE TABLE info (name TEXT, value TEXT)");
db.createTable("CREATE TABLE books (book_number NUMERIC, book_color TEXT, short_name TEXT, long_name TEXT)");
db.createTable("CREATE TABLE introductions (book_number NUMERIC, introduction TEXT)");
db.createIndex("CREATE UNIQUE INDEX introductions_index on introductions(book_number)");
db.createTable("CREATE TABLE verses (book_number INTEGER, chapter INTEGER, verse INTEGER, text TEXT)");
db.createIndex("CREATE UNIQUE INDEX verses_index on verses (book_number, chapter, verse)");
db.createTable("CREATE TABLE stories (book_number NUMERIC, chapter NUMERIC, verse NUMERIC, order_if_several NUMERIC, title TEXT)");
db.createIndex("CREATE UNIQUE INDEX stories_index on stories(book_number, chapter, verse, order_if_several)");
Map<String, String> infoValues = new LinkedHashMap<>();
MetadataBook mb = bible.getMetadataBook();
if (mb == null)
mb = new MetadataBook();
infoValues.put("language", "xx");
infoValues.put("description", bible.getName());
infoValues.put("detailed_info", "");
infoValues.put("russian_numbering", "false");
infoValues.put("chapter_string", "Chapter");
infoValues.put("introduction_string", "Introduction");
infoValues.put("strong_numbers", hasStrongs ? "true" : "false");
infoValues.put("right_to_left", "false");
infoValues.put("digits0-9", "0123456789");
infoValues.put("swaps_non_localized_words_in_mixed_language_line", "false");
infoValues.put("localized_book_abbreviations", "false");
infoValues.put("font_scale", "1.0");
infoValues.put("contains_accents", "true");
for (String mbkey : mb.getKeys()) {
if (mbkey.startsWith("MyBible.zone@")) {
infoValues.put(mbkey.substring(13).replace('.', '_'), mb.getValue(mbkey));
} else {
infoValues.put("detailed_info", infoValues.get("detailed_info") + "\r\n<br><b>" + mbkey + ":</b>" + mb.getValue(mbkey));
}
}
String bibleIntro = null, singleFootnoteMarker = null, singleXrefMarker = null;
if (exportArgs.length > 1) {
Properties props = new Properties();
FileInputStream in = new FileInputStream(exportArgs[1]);
props.load(in);
in.close();
bibleIntro = (String) props.remove("__INTRODUCTION__");
singleFootnoteMarker = (String) props.remove("__FOOTNOTE_MARKER__");
singleXrefMarker = (String) props.remove("__XREF_MARKER__");
for (Object key : props.keySet()) {
String template = props.getProperty(key.toString());
template = template.replace("${name}", bible.getName());
for (String mbkey : mb.getKeys()) template = template.replace("${" + mbkey + "}", mb.getValue(mbkey));
infoValues.put(key.toString(), template);
}
}
ISqlJetTable infoTable = db.getTable("info");
ISqlJetTable booksTable = db.getTable("books");
ISqlJetTable introductionsTable = db.getTable("introductions");
ISqlJetTable versesTable = db.getTable("verses");
ISqlJetTable storiesTable = db.getTable("stories");
for (Map.Entry<String, String> entry : infoValues.entrySet()) {
infoTable.insert(entry.getKey(), entry.getValue());
}
SqlJetDb cdb = null;
ISqlJetTable footnotesTable = null;
if (hasFootnotes) {
String commentaryfile = outfile.replace(".SQLite3", ".commentaries.SQLite3");
new File(commentaryfile).delete();
cdb = SqlJetDb.open(new File(commentaryfile), true);
cdb.getOptions().setAutovacuum(true);
cdb.beginTransaction(SqlJetTransactionMode.WRITE);
cdb.getOptions().setUserVersion(0);
cdb.createTable("CREATE TABLE info (name TEXT, value TEXT)");
cdb.createTable("CREATE TABLE commentaries (book_number NUMERIC, chapter_number_from NUMERIC, verse_number_from NUMERIC, chapter_number_to NUMERIC, verse_number_to NUMERIC, marker TEXT, text TEXT )");
cdb.createIndex("CREATE INDEX commentaries_index on commentaries(book_number, chapter_number_from, verse_number_from)");
ISqlJetTable cInfoTable = cdb.getTable("info");
for (String key : Arrays.asList("language", "description", "russian_numbering")) {
cInfoTable.insert(key, infoValues.get(key));
}
cInfoTable.insert("is_footnotes", "true");
footnotesTable = cdb.getTable("commentaries");
}
final Set<String> unsupportedFeatures = new HashSet<>();
FormattedText introProlog = null;
for (Book bk : bible.getBooks()) {
if (bk.getId() == BookID.INTRODUCTION || bk.getId() == BookID.INTRODUCTION_OT || bk.getId() == BookID.INTRODUCTION_NT || bk.getId() == BookID.APPENDIX) {
if (introProlog == null)
introProlog = new FormattedText();
introProlog.getAppendVisitor().visitHeadline(1).visitText(bk.getLongName());
bk.getChapters().get(0).getProlog().accept(introProlog.getAppendVisitor());
continue;
}
MyBibleZoneBook info = null;
for (MyBibleZoneBook bi : BOOK_INFO) {
if (bi.bookID == bk.getId())
info = bi;
}
if (info == null) {
System.out.println("WARNING: Skipping unsupported book " + bk.getId());
continue;
}
booksTable.insert(info.bookNumber, info.bookColor, bk.getAbbr(), bk.getShortName());
FormattedText prologs = null;
for (int cn = 1; cn <= bk.getChapters().size(); cn++) {
Chapter ch = bk.getChapters().get(cn - 1);
if (ch.getProlog() != null) {
if (prologs == null)
prologs = new FormattedText();
prologs.getAppendVisitor().visitHeadline(1).visitText(cn == 1 ? bk.getLongName() : "" + cn);
ch.getProlog().accept(prologs.getAppendVisitor());
}
int vn = 0;
for (VirtualVerse vv : ch.createVirtualVerses()) {
vn++;
while (vn < vv.getNumber()) versesTable.insert(info.bookNumber, cn, vn++, "");
if (vn != vv.getNumber())
throw new RuntimeException(vn + " != " + vv.getNumber());
for (int hl = 0; hl < vv.getHeadlines().size(); hl++) {
final StringBuilder sb = new StringBuilder();
final Map<StringBuilder, String> xrefTags = new HashMap<>();
vv.getHeadlines().get(hl).accept(new VisitorAdapter<RuntimeException>(null) {
@Override
protected Visitor<RuntimeException> wrapChildVisitor(Visitor<RuntimeException> childVisitor) throws RuntimeException {
return this;
}
@Override
protected void beforeVisit() throws RuntimeException {
unsupportedFeatures.add("markup in headline");
}
@Override
public void visitText(String text) throws RuntimeException {
sb.append(text.replace('<', '〈').replace('>', '〉'));
}
@Override
public Visitor<RuntimeException> visitFootnote() throws RuntimeException {
// handle this separately; we do not like
// footnote text inside the headline!
unsupportedFeatures.add("footnote in headline");
return new VisitorAdapter<RuntimeException>(null) {
@Override
protected Visitor<RuntimeException> wrapChildVisitor(Visitor<RuntimeException> childVisitor) throws RuntimeException {
return this;
}
@Override
public Visitor<RuntimeException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws RuntimeException {
if (!BOOK_NUMBERS.containsKey(book))
return null;
final StringBuilder innerBuilder = new StringBuilder();
String endVerse = firstChapter != lastChapter ? "-" + lastChapter + ":" + lastVerse : !firstVerse.equals(lastVerse) ? "-" + lastVerse : "";
xrefTags.put(innerBuilder, "<x>" + BOOK_NUMBERS.get(book) + " " + firstChapter + ":" + firstVerse + endVerse + "</x>");
return new VisitorAdapter<RuntimeException>(null) {
@Override
protected void beforeVisit() throws RuntimeException {
throw new RuntimeException("Unsupported content inside headline xref");
}
@Override
public void visitText(String text) throws RuntimeException {
innerBuilder.append(text.replace('<', '〈').replace('>', '〉'));
}
};
}
};
}
@Override
public Visitor<RuntimeException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws RuntimeException {
unsupportedFeatures.add("extra atrribute in headline");
return prio.handleVisitor(category, this);
}
});
String headline = sb.toString();
for (Map.Entry<StringBuilder, String> xrefTag : xrefTags.entrySet()) {
headline = headline.replace(xrefTag.getKey().toString(), xrefTag.getValue());
}
storiesTable.insert(info.bookNumber, cn, vn, hl, headline);
}
StringBuilder vb = new StringBuilder();
Map<String, MyBibleHTMLVisitor> footnotes = new HashMap<>();
MyBibleVerseVisitor mbvv = new MyBibleVerseVisitor(vb, footnotes, unsupportedFeatures);
for (Verse v : vv.getVerses()) {
if (!v.getNumber().equals("" + vv.getNumber())) {
vb.append(" <e>(" + v.getNumber() + ")</e> ");
}
mbvv.reset();
v.accept(mbvv);
}
if (singleXrefMarker != null || singleFootnoteMarker != null) {
String singleXref = null, singleFootnote = null;
for (Map.Entry<String, MyBibleHTMLVisitor> fn : footnotes.entrySet()) {
if (!fn.getKey().matches("\\[[0-9]+\\]"))
continue;
if (fn.getValue().getResult().startsWith(FormattedText.XREF_MARKER) && singleXrefMarker != null) {
if (singleXref == null) {
singleXref = fn.getKey();
} else {
System.out.println("WARNING: More than one XREF footnote in verse " + info.bookID + " " + cn + ":" + vn);
singleXref = "-";
}
} else if (singleFootnoteMarker != null) {
if (singleFootnote == null) {
singleFootnote = fn.getKey();
} else {
System.out.println("WARNING: More than one normal footnote in verse " + info.bookID + " " + cn + ":" + vn);
singleFootnote = "-";
}
}
}
if (singleXref != null && !singleXref.equals("-")) {
MyBibleHTMLVisitor xfn = footnotes.remove(singleXref);
if (xfn == null)
throw new RuntimeException();
footnotes.put(singleXrefMarker, xfn);
String verse = vb.toString();
vb.setLength(0);
vb.append(verse.replace("<f>" + singleXref + "</f>", "<f>" + singleXrefMarker + "</f>"));
}
if (singleFootnote != null && !singleFootnote.equals("-")) {
MyBibleHTMLVisitor sfn = footnotes.remove(singleFootnote);
if (sfn == null)
throw new RuntimeException();
footnotes.put(singleFootnoteMarker, sfn);
String verse = vb.toString();
vb.setLength(0);
vb.append(verse.replace("<f>" + singleFootnote + "</f>", "<f>" + singleFootnoteMarker + "</f>"));
}
}
for (Map.Entry<String, MyBibleHTMLVisitor> fn : footnotes.entrySet()) {
footnotesTable.insert(info.bookNumber, cn, vn, cn, vn, fn.getKey(), fn.getValue().getResult());
}
versesTable.insert(info.bookNumber, cn, vn, vb.toString().trim());
}
}
if (prologs != null) {
MyBibleHTMLVisitor v = new MyBibleHTMLVisitor(unsupportedFeatures, "in introduction");
prologs.accept(v);
introductionsTable.insert(info.bookNumber, v.getResult());
}
}
if (bibleIntro != null) {
introductionsTable.insert(0, bibleIntro);
} else if (introProlog != null) {
MyBibleHTMLVisitor v = new MyBibleHTMLVisitor(unsupportedFeatures, "in introduction");
introProlog.accept(v);
introductionsTable.insert(0, v.getResult());
}
if (!unsupportedFeatures.isEmpty()) {
System.out.println("WARNING: Skipped unsupported features: " + unsupportedFeatures);
}
db.commit();
db.close();
if (cdb != null) {
cdb.commit();
cdb.close();
}
}
use of biblemulticonverter.data.BookID in project BibleMultiConverter by schierlm.
the class SWORDVersificationDetector method loadSchemes.
@Override
protected VersificationScheme[] loadSchemes() throws IOException {
// parse header
VersificationScheme[] result = new VersificationScheme[ALL_V11N_NAMES.length];
for (int i = 0; i < result.length; i++) {
EnumMap<BookID, BitSet[]> coveredBooks = new EnumMap<BookID, BitSet[]>(BookID.class);
Versification v11n = Versifications.instance().getVersification(ALL_V11N_NAMES[i]);
for (Iterator<BibleBook> it = v11n.getBookIterator(); it.hasNext(); ) {
BibleBook bb = (BibleBook) it.next();
BitSet[] chapters = new BitSet[v11n.getLastChapter(bb)];
coveredBooks.put(BookMapping.MAPPING.get(bb), chapters);
for (int j = 1; j <= v11n.getLastChapter(bb); j++) {
chapters[j - 1] = new BitSet();
chapters[j - 1].set(1, v11n.getLastVerse(bb, j) + 1);
}
}
result[i] = new VersificationScheme(ALL_V11N_NAMES[i], coveredBooks);
}
return result;
}
use of biblemulticonverter.data.BookID in project BibleMultiConverter by schierlm.
the class ZefaniaXMLRoundtrip method parseContent.
private boolean parseContent(Visitor<RuntimeException> visitor, List<Object> contentList, Map<BookID, String> abbrMap) throws IOException {
boolean contentFound = false;
for (Object n : contentList) {
if (n instanceof String) {
String value = normalize((String) n, false);
visitor.visitText(value);
contentFound |= value.trim().length() > 0;
} else if (n instanceof DIV || n instanceof NOTE) {
NOTE note;
Visitor<RuntimeException> v;
if (n instanceof DIV) {
note = ((DIV) n).getNOTE();
if (note.getContent().size() == 0)
continue;
v = visitor.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefania", "footnote-source", "div").visitFootnote();
} else {
note = (NOTE) n;
if (note.getContent().size() == 0)
continue;
v = visitor.visitFootnote();
}
boolean subContentFound = parseContent(v, note.getContent(), abbrMap);
if (!subContentFound)
visitEmptyMarker(v);
contentFound = true;
} else if (n instanceof BR) {
BR br = (BR) n;
Visitor<RuntimeException> v = visitor;
int count = 1;
if (br.getCount() != null) {
count = br.getCount().intValue();
v = visitor.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefania", "newline-group", br.getCount() + "--" + br.getArt().value());
}
if (count < 1 || count > 10)
throw new RuntimeException();
for (int ii = 0; ii < count; ii++) {
switch(br.getArt()) {
case X_NL:
v.visitLineBreak(LineBreakKind.NEWLINE);
break;
case X_P:
v.visitLineBreak(LineBreakKind.PARAGRAPH);
break;
default:
throw new RuntimeException(br.getArt().toString());
}
}
contentFound = true;
} else if (n instanceof XREF) {
XREF xref = (XREF) n;
Visitor<RuntimeException> footnoteVisitor = visitor.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefania", "footnote-source", "inner-xref").visitFootnote();
boolean first = true;
for (String mscope : xref.getMscope().split(" ")) {
Matcher m = Utils.compilePattern("([0-9]+);([0-9]+)(-[0-9]+)?;([0-9]+)(-[0-9]+)?").matcher(mscope);
if (!m.matches())
throw new IOException(mscope);
BookID bookID = BookID.fromZefId(Integer.parseInt(m.group(1)));
int chapter = Integer.parseInt(m.group(2)), endChapter = chapter;
if (m.group(3) != null)
endChapter = Integer.parseInt(m.group(3).substring(1));
String verse = m.group(4);
if (verse.equals("0"))
verse = "1//G";
String endVerse = m.group(5);
if (endVerse == null)
endVerse = verse;
else
endVerse = endVerse.substring(1);
if (endVerse.equals("0"))
endVerse = "1//G";
String abbr = abbrMap.get(bookID);
if (abbr == null)
abbr = bookID.getOsisID();
if (first)
first = false;
else
footnoteVisitor.visitText(" ");
if (chapter == endChapter && !verse.equals("1//G") && !endVerse.equals("1//G") && Integer.parseInt(verse) > Integer.parseInt(endVerse)) {
String tmp = verse;
verse = endVerse;
endVerse = tmp;
}
footnoteVisitor.visitCrossReference(abbr, bookID, chapter, verse, endChapter, endVerse).visitText(abbr + " " + chapter + ":" + verse);
}
contentFound = true;
} else if (n instanceof JAXBElement<?>) {
String name = ((JAXBElement<?>) n).getName().toString();
Object nn = ((JAXBElement<?>) n).getValue();
if (name.equals("STYLE") && nn instanceof STYLE) {
String css = ((STYLE) nn).getCss();
String id = ((STYLE) nn).getId();
if (id != null && css != null)
throw new IOException(id + "/" + css);
if (css != null && css.startsWith("display:block;")) {
// not really a formatting instruction, but more some
// clever way of indentation
List<Object> content = ((STYLE) nn).getContent();
Visitor<RuntimeException> contentVisitor = visitor.visitCSSFormatting(css);
boolean subContentFound = parseContent(contentVisitor, content, abbrMap);
if (!subContentFound)
visitEmptyMarker(contentVisitor);
} else {
FormattingInstructionKind kind;
if (id != null && id.equals("cl:divineName")) {
kind = FormattingInstructionKind.DIVINE_NAME;
} else if (css == null) {
throw new IOException(id);
} else if (css.contains("italic")) {
kind = FormattingInstructionKind.ITALIC;
} else if (css.contains("bold")) {
kind = FormattingInstructionKind.BOLD;
} else if (css.equalsIgnoreCase("color:#FF0000")) {
kind = FormattingInstructionKind.WORDS_OF_JESUS;
} else if (css.equals("color:blue")) {
kind = FormattingInstructionKind.LINK;
} else if (css.equals("color:#00CC33;font-size:8pt;vertical-align:super") || css.equals("font-size:small")) {
kind = FormattingInstructionKind.SUPERSCRIPT;
} else {
throw new IOException(css);
}
List<Object> content = ((STYLE) nn).getContent();
Visitor<RuntimeException> contentVisitor = visitor.visitFormattingInstruction(kind);
if (css != null && !kind.getCss().equals(css)) {
contentVisitor = contentVisitor.visitCSSFormatting(css);
}
if (content.size() == 0) {
visitEmptyMarker(contentVisitor);
} else {
boolean subContentFound = parseContent(contentVisitor, content, abbrMap);
if (!subContentFound)
visitEmptyMarker(contentVisitor);
}
}
} else if ((name.equals("gr") || name.equals("GRAM")) && nn instanceof GRAM) {
GRAM gram = (GRAM) nn;
Visitor<RuntimeException> strongVisitor = visitor;
if (!name.equals("GRAM")) {
strongVisitor = strongVisitor.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefania", "gram-tag", name);
}
if (gram.getStr() == null && gram.getRmac() == null)
throw new IOException();
int[] strongs = null;
if (gram.getStr() != null) {
String strong = gram.getStr().trim().replaceAll(" ++", " ");
if (strong.length() == 0)
strong = "0";
if (strong.equals("?"))
strong = "99111";
if (strong.startsWith("G")) {
strongVisitor = strongVisitor.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefania", "strong-prefix", "G");
strong = strong.replace("G", "");
} else if (strong.startsWith("H")) {
strongVisitor = strongVisitor.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefania", "strong-prefix", "H");
strong = strong.replace("H", "");
}
if (!strong.matches("[0-9]+( [0-9]+)*"))
throw new IOException(strong);
String[] tmpStrongs = strong.split(" ");
strongs = new int[tmpStrongs.length];
for (int i = 0; i < tmpStrongs.length; i++) {
strongs[i] = Integer.parseInt(tmpStrongs[i]);
}
}
String[] rmacs = null;
if (gram.getRmac() != null) {
String rmac = gram.getRmac();
rmacs = rmac.split(" ");
}
strongVisitor = strongVisitor.visitGrammarInformation(strongs, rmacs, null);
if (!parseContent(strongVisitor, gram.getContent(), abbrMap)) {
visitEmptyMarker(strongVisitor);
}
} else {
throw new IOException(name + "/" + nn.getClass().toString());
}
contentFound = true;
} else {
throw new IOException(n.getClass().toString());
}
}
return contentFound;
}
use of biblemulticonverter.data.BookID in project BibleMultiConverter by schierlm.
the class LogosVersificationDetector method loadSchemes.
@Override
protected VersificationScheme[] loadSchemes() throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(LogosVersificationDetector.class.getResourceAsStream("/logos-versemap.dat"), StandardCharsets.ISO_8859_1))) {
// parse header
String line = br.readLine();
String[] fields = line.split(" ");
VersificationScheme[] result = new VersificationScheme[fields.length];
for (int i = 0; i < result.length; i++) {
result[i] = new VersificationScheme(fields[i], new EnumMap<BookID, BitSet[]>(BookID.class));
}
// parse content
BookID book = null;
while ((line = br.readLine()) != null) {
fields = line.split(" ");
int idx = 0;
if (!fields[0].matches("[0-9,-]+")) {
book = BookID.fromOsisId(fields[0]);
idx++;
}
BitSet affected = readBits(fields[idx]);
idx++;
BitSet[] chapters = new BitSet[fields.length - idx];
for (int i = 0; i < chapters.length; i++) {
chapters[i] = readBits(fields[i + idx]);
}
for (int i = affected.nextSetBit(0); i >= 0; i = affected.nextSetBit(i + 1)) {
result[i].getCoveredBooks().put(book, chapters);
}
}
// refresh metadata
for (int i = 0; i < result.length; i++) {
result[i] = new VersificationScheme(result[i].getName(), result[i].getCoveredBooks());
}
return result;
}
}
use of biblemulticonverter.data.BookID in project BibleMultiConverter by schierlm.
the class LogosVerseMapDownloader method parseVerseMap.
private static void parseVerseMap(Document doc, Writer w) throws Exception {
Map<String, BookID> bookMap = new HashMap<String, BookID>();
for (String bookName : ALL_BOOK_NAMES) {
String[] parts = bookName.split("=");
bookMap.put(parts[0], parts[1].equals("-") ? BookID.DICTIONARY_ENTRY : BookID.fromOsisId(parts[1]));
}
Map<String, Integer> versificationMap = new HashMap<String, Integer>();
for (int i = 0; i < ALL_VERSIFICATIONS.length; i++) {
String v11n = ALL_VERSIFICATIONS[i];
if (i != 0)
w.write(' ');
w.write(v11n);
versificationMap.put(v11n.equals("Bible") ? "bible" : v11n.substring(5).toLowerCase(), i);
}
w.write('\n');
Map<String, Integer> namedVerseMap = new HashMap<>();
for (int i = 0; i < LogosHTML.NAMED_VERSES.length; i++) {
namedVerseMap.put(LogosHTML.NAMED_VERSES[i], i);
}
XPath xp = javax.xml.xpath.XPathFactory.newInstance().newXPath();
NodeList nl = (NodeList) xp.evaluate("//div[@class='Level2']/table", doc, XPathConstants.NODESET);
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
String book = xp.evaluate("../h2/text()", n).trim();
BookID bookID = bookMap.get(book);
if (bookID == null)
throw new IOException("Unknown book name: " + book);
if (// skip this book
bookID == BookID.DICTIONARY_ENTRY)
continue;
w.write(bookID.getOsisID() + " ");
List<List<String>> table = new ArrayList<List<String>>();
Node tr = n.getFirstChild();
while (true) {
while (tr instanceof Text && tr.getTextContent().trim().length() == 0) tr = tr.getNextSibling();
if (tr == null)
break;
List<String> row = new ArrayList<String>();
table.add(row);
Node td = tr.getFirstChild();
while (true) {
while (td instanceof Text && td.getTextContent().trim().length() == 0) td = td.getNextSibling();
if (td == null)
break;
row.add(td.getTextContent());
td = td.getNextSibling();
}
tr = tr.getNextSibling();
}
for (int j = 1; j < table.get(0).size(); j++) {
BitSet v11ns = new BitSet();
for (String v11n : table.get(0).get(j).split(", ")) {
if (!versificationMap.containsKey(v11n))
System.out.println("SKIPPING VERSEMAP " + v11n);
else
v11ns.set(versificationMap.get(v11n));
}
List<BitSet> chapters = new ArrayList<>();
for (int k = 1; k < table.size(); k++) {
if (table.get(k).get(0).isEmpty())
table.get(k).set(0, "1");
if (!table.get(k).get(0).matches("[0-9]+"))
continue;
int chapterNumber = Integer.parseInt(table.get(k).get(0));
String ranges = table.get(k).get(j);
if (ranges.length() > 0) {
while (chapters.size() < chapterNumber) chapters.add(new BitSet());
BitSet chapter = chapters.get(chapterNumber - 1);
for (String range : ranges.split(", ")) {
if (!range.matches("[0-9-]+")) {
Integer idx = namedVerseMap.get(range);
if (idx == null) {
System.out.println("SKIPPING VERSE " + range);
continue;
}
range = String.valueOf(idx + 1000);
}
String[] parts = range.split("-");
if (parts.length == 1) {
chapter.set(Integer.parseInt(parts[0]));
} else if (parts.length == 2) {
chapter.set(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]) + 1);
} else {
throw new IOException("Unsupported verse ranges: " + ranges);
}
}
}
}
writeBits(v11ns, w);
for (BitSet chapter : chapters) {
w.write(' ');
writeBits(chapter, w);
}
w.write('\n');
}
}
}
Aggregations