use of biblemulticonverter.data.Book 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 });
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class StrippedDiffable method extractPrologs.
private void extractPrologs(Bible bible) {
for (Book book : bible.getBooks()) {
for (Chapter chapter : book.getChapters()) {
chapter.getVerses().clear();
if (chapter.getProlog() != null) {
Verse prologVerse = new Verse("1");
chapter.getProlog().accept(prologVerse.getAppendVisitor());
chapter.getVerses().add(prologVerse);
chapter.setProlog(null);
}
}
}
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class StrippedDiffable method extractFootnotes.
private void extractFootnotes(Bible bible) {
for (Book book : bible.getBooks()) {
for (Chapter chapter : book.getChapters()) {
chapter.getVerses().clear();
if (chapter.getProlog() != null) {
chapter.setProlog(extractFootnotes(chapter.getProlog()));
}
List<Verse> verses = chapter.getVerses();
for (int i = 0; i < verses.size(); i++) {
Verse v = verses.get(i);
FormattedText extracted = extractFootnotes(v);
if (extracted == null) {
verses.remove(i);
i--;
} else {
Verse vv = new Verse(v.getNumber());
extracted.accept(vv.getAppendVisitor());
verses.set(i, vv);
}
}
}
}
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class StrippedDiffable method renameBookInXref.
protected void renameBookInXref(Bible bible, String oldName, String newName, boolean setFinished) {
for (Book book : bible.getBooks()) {
for (Chapter chap : book.getChapters()) {
if (chap.getProlog() != null) {
FormattedText newProlog = new FormattedText();
chap.getProlog().accept(new RenameXrefVisitor(newProlog.getAppendVisitor(), oldName, newName));
if (setFinished)
newProlog.finished();
chap.setProlog(newProlog);
}
for (int j = 0; j < chap.getVerses().size(); j++) {
Verse v = chap.getVerses().get(j);
Verse nv = new Verse(v.getNumber());
v.accept(new RenameXrefVisitor(nv.getAppendVisitor(), oldName, newName));
if (setFinished)
nv.finished();
chap.getVerses().set(j, nv);
}
}
}
}
use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.
the class StrongConcordance method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
if (exportArgs.length != 2)
throw new IOException("Two parameters needed!");
Map<String, List<OccurrenceInfo>> occurrences = new HashMap<String, List<OccurrenceInfo>>();
int bookIndex = 0;
for (Book bk : bible.getBooks()) {
int cnumber = 0;
for (Chapter ch : bk.getChapters()) {
cnumber++;
for (Verse v : ch.getVerses()) {
Map<String, List<StringBuilder>> strongInfo = new HashMap<>();
v.accept(new StrongInfoVisitor(strongInfo, bk.getId().isNT() ? 'G' : 'H'));
for (Map.Entry<String, List<StringBuilder>> e : strongInfo.entrySet()) {
String[] strongs = e.getKey().split("\\+");
String suffix = "";
if (strongs.length > 1)
suffix = " [" + e.getKey() + "]";
for (StringBuilder val : e.getValue()) {
OccurrenceInfo info = new OccurrenceInfo(val.toString().trim() + suffix, bookIndex, cnumber, v.getNumber());
for (String strong : strongs) {
List<OccurrenceInfo> occInfo = occurrences.get(strong);
if (occInfo == null) {
occInfo = new ArrayList<OccurrenceInfo>();
occurrences.put(strong, occInfo);
}
occInfo.add(info);
}
}
}
}
}
// save memory for the dictionary
bk.getChapters().clear();
bookIndex++;
}
Diffable diffable = new Diffable();
Bible dict = diffable.doImport(new File(exportArgs[0]));
for (Book bk : dict.getBooks()) {
if (bk.getId() != BookID.DICTIONARY_ENTRY || occurrences.get(bk.getAbbr()) == null)
continue;
List<OccurrenceInfo> occ = occurrences.remove(bk.getAbbr());
FormattedText old = bk.getChapters().get(0).getProlog();
FormattedText changed = new FormattedText();
Visitor<RuntimeException> v = changed.getAppendVisitor();
old.accept(v);
v.visitHeadline(1).visitText("Occurrences in " + bible.getName());
Collections.sort(occ);
List<OccurrenceInfo> part = new ArrayList<>();
while (occ.size() > 0) {
OccurrenceInfo first = occ.remove(0);
part.add(first);
while (occ.size() > 0 && occ.get(0).phrase.equals(first.phrase)) {
part.add(occ.remove(0));
}
v.visitFormattingInstruction(FormattingInstructionKind.BOLD).visitText(first.phrase + " (" + part.size() + "):");
for (int i = 0; i < part.size(); i++) {
v.visitText(i == 0 ? " " : ", ");
int cnt = 1;
OccurrenceInfo curr = part.get(i);
while (i + 1 < part.size() && part.get(i + 1).equals(curr)) {
cnt++;
i++;
}
Book book = bible.getBooks().get(curr.bookIndex);
v.visitCrossReference(book.getAbbr(), book.getId(), curr.chapter, curr.verse, curr.chapter, curr.verse).visitText(book.getAbbr() + " " + curr.chapter + ":" + curr.verse);
if (cnt > 1)
v.visitText(" (" + cnt + ")");
}
v.visitLineBreak(LineBreakKind.PARAGRAPH);
part.clear();
}
changed.finished();
bk.getChapters().get(0).setProlog(changed);
}
if (!occurrences.isEmpty())
System.out.println("Missing Strong references in dictionary: " + occurrences.keySet());
diffable.doExport(dict, new String[] { exportArgs[1] });
}
Aggregations