use of biblemulticonverter.data.Book 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.Book 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