use of biblemulticonverter.data.FormattedText 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.FormattedText 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.FormattedText in project BibleMultiConverter by schierlm.
the class StrippedDiffable method extractFootnotes.
private FormattedText extractFootnotes(FormattedText text) {
String types = text.getElementTypes(1);
if (!types.contains("f"))
return null;
final FormattedText result = new FormattedText();
if (types.matches("[^f]+f")) {
List<FormattedText> parts = text.splitContent(false, true);
parts.get(parts.size() - 1).accept(result.getAppendVisitor());
} else {
text.accept(new FormattedText.VisitorAdapter<RuntimeException>(null) {
Visitor<RuntimeException> outerVisitor = result.getAppendVisitor();
Visitor<RuntimeException> innerVisitor = null;
@Override
protected void beforeVisit() throws RuntimeException {
if (innerVisitor == null) {
innerVisitor = outerVisitor.visitFormattingInstruction(FormattingInstructionKind.ITALIC);
innerVisitor.visitText("[");
}
}
@Override
protected Visitor<RuntimeException> getVisitor() throws RuntimeException {
return innerVisitor;
}
@Override
public Visitor<RuntimeException> visitHeadline(int depth) throws RuntimeException {
return null;
}
@Override
public Visitor<RuntimeException> visitFootnote() throws RuntimeException {
if (innerVisitor != null) {
innerVisitor.visitText("]");
innerVisitor = null;
}
return outerVisitor;
}
@Override
public boolean visitEnd() throws RuntimeException {
if (innerVisitor != null) {
innerVisitor.visitText("]");
innerVisitor = null;
}
return false;
}
});
}
return result;
}
use of biblemulticonverter.data.FormattedText 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.FormattedText 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