use of biblemulticonverter.data.VirtualVerse in project BibleMultiConverter by schierlm.
the class AbstractVersificationDetector method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
VersificationScheme[] schemes = loadSchemes();
Set<String> totalVerses = new HashSet<String>();
boolean includeXref = exportArgs.length > 0 && exportArgs[0].equals("-xref");
XrefCountVisitor xcv = includeXref ? new XrefCountVisitor(schemes, totalVerses) : null;
// fill missing verses
for (Book book : bible.getBooks()) {
for (int cc = 0; cc < book.getChapters().size(); cc++) {
Chapter chapter = book.getChapters().get(cc);
if (includeXref && chapter.getProlog() != null) {
chapter.getProlog().accept(xcv);
}
if (useVerseRanges()) {
for (VerseRange vr : chapter.createVerseRanges()) {
int cnumber = vr.getChapter() == 0 ? cc + 1 : vr.getChapter();
countVerse(schemes, totalVerses, book.getAbbr(), book.getId(), cnumber, vr.getMinVerse());
countVerse(schemes, totalVerses, book.getAbbr(), book.getId(), cnumber, vr.getMaxVerse());
}
} else {
for (VirtualVerse v : chapter.createVirtualVerses()) {
countVerse(schemes, totalVerses, book.getAbbr(), book.getId(), cc + 1, v.getNumber());
}
}
if (includeXref) {
for (Verse vv : chapter.getVerses()) {
vv.accept(xcv);
}
}
}
}
// sort them
Arrays.sort(schemes);
// print them
System.out.print("Best match: ");
int totalVerseCount = totalVerses.size();
printScheme(schemes[0], totalVerseCount);
System.out.println();
System.out.println("Other options:");
for (int i = 1; i < Math.min(11, schemes.length); i++) {
printScheme(schemes[i], totalVerseCount);
if (schemes[i].missingChapters.size() > schemes[0].missingChapters.size() + 2 || schemes[i].missingVerses.size() > schemes[0].missingVerses.size() + 5)
break;
}
// print selected schemes
if (exportArgs.length > (includeXref ? 1 : 0)) {
System.out.println();
System.out.println("Selected schemes:");
for (int i = includeXref ? 1 : 0; i < exportArgs.length; i++) {
boolean found = false;
for (VersificationScheme scheme : schemes) {
if (scheme.getName().equals(exportArgs[i])) {
printScheme(scheme, totalVerseCount);
found = true;
break;
}
}
if (!found)
System.out.println(exportArgs[i] + " (Unknown scheme)");
}
}
}
use of biblemulticonverter.data.VirtualVerse 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