/* * [CollectAndRepairBorns.java] * * Summary: Find Author/Birth/Death in blockquotes and Book Macros. * * Copyright: (c) 2011-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2011-10-18 initial version */ package com.mindprod.repair; import com.mindprod.commandline.CommandLine; import com.mindprod.common18.EIO; import com.mindprod.common18.Misc; import com.mindprod.filter.ExtensionListFilter; import com.mindprod.htmlmacros.macro.Global; import com.mindprod.htmlmacros.support.ConfigurationForMindprod; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import static java.lang.System.*; /** * Find Author/Birth/Death in blockquotes and Book Macros. *

* Fill in missing Birth/Death dates if known. * Export list of authors and dates in both csv and HTML format. * Exports does not include unknowns. Reports missing as as error. * FAILS TO BUILD JAR. So we leave out dynamically loaded classes and * run as a class. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-10-18 initial version * @since 2011-10-18 */ public class CollectAndRepairBorns { // declarations /** * should we actually change the files */ static boolean doCorrections; /** * collect birth/death dates for each author from Book Macros * * @param args command line args, list of files containing quotations , */ private static void collectBornsFromAllFiles( final String[] args ) { // get files to process from command line. out.println( "Gathering files to scan for authors/books..." ); CommandLine wantedFiles = new CommandLine( args, new NoSnippetsFilter(), new ExtensionListFilter( "html" ) ); for ( File fileBeingProcessed : wantedFiles ) { try { final String big = HunkIO.readEntireFile( fileBeingProcessed, HunkIO.UTF8 ); CollectBornsInBookMacros.collectBornsInBookMacroForPage( big, fileBeingProcessed ); CollectFamousBorns.collectBornsForPage( big, fileBeingProcessed ); } catch ( IOException e ) { e.printStackTrace( err ); err.println(); } } // end for to process each file }// /method /** * display statistics about what we found and did */ private static void displayStats() { out.println( "--- Statistics ---" ); out.println( AuthorBio.completeDates + " authors with complete dates" ); out.println( AuthorBio.completeDates / 365.25d + " average number of expected authors with a birthday today" ); out.println( AuthorBio.partialDates + " authors with partial dates" ); out.println( AuthorBio.unknowns + " authors marked unknown birthdate" ); out.println( RepairBornsInBookMacros.missing + " Book/DVD macros missing birth/death" ); final String dry = doCorrections ? "corrected" : "dry run corrected"; out.println( RepairBornsInBookMacros.corrected + " Book/DVD macro birth/deaths " + dry ); out.println( RepairFamousBorns.corrected + " quotation birth/deaths " + dry ); out.println( "done" ); }// /method /** * collect birth/death dates for each author from Book Macros * * @param args command line args, list of files containing quotations */ private static void repairBornsForAllFiles( final String[] args ) { // get files to process from command line. out.println( "Gathering files to repair for authors/books..." ); CommandLine wantedFiles = new CommandLine( args, new NoSnippetsFilter(), new ExtensionListFilter( "html" ) ); for ( File fileBeingProcessed : wantedFiles ) { try { final String originalPage = HunkIO.readEntireFile( fileBeingProcessed, HunkIO.UTF8 ); String modifiedPage = RepairBornsInBookMacros.repairBornsInBookMacrosForPage( originalPage, fileBeingProcessed ); modifiedPage = RepairFamousBorns.repairFamousBornsForPage( modifiedPage, fileBeingProcessed ); if ( !modifiedPage.equals( originalPage ) ) { if ( doCorrections ) { HunkIO.writeEntireFile( fileBeingProcessed, modifiedPage, HunkIO.UTF8 ); } else { // write corrections to *.bak file for examination. HunkIO.writeEntireFile( new File( EIO.getCanOrAbsPath( fileBeingProcessed ) + ".bak" ), modifiedPage, HunkIO.UTF8 ); } } } catch ( IOException e ) { e.printStackTrace( err ); err.println(); } } // end for to process each file }// /method // /declarations // methods @SuppressWarnings( { "ResultOfMethodCallIgnored" } ) /** * saves authors both as csv and html. Goes to E:\mindprod\jgloss\include\birthdatas.htmlfrag */ public static void main( String[] args ) throws IOException { Global.installConfiguration( new ConfigurationForMindprod() ); doCorrections = false; for ( int i = 0; i < args.length; i++ ) { if ( args[ i ].equals( "-c" ) ) { doCorrections = true; args[ i ] = null; } } out.println( "PASS 1: collect authors, birthdates and deathdates..." ); collectBornsFromAllFiles( args ); // both blockquotes and Book macros AuthorBio.sortAuthors(); AuthorWarning.displayWarnings(); // save list in E:/com/mindprod/repair/authors.csv AuthorBio.saveAuthorsAsCSV(); // generate HTML to be including in birthday.html AuthorBio.saveAuthorsAsHTML(); out.println( "PASS 2: repair missing authors, birthdates and deathdates..." ); repairBornsForAllFiles( args ); displayStats(); Misc.trackLastThread(); System.exit( 0 ); }// /method // /methods }