Ejemplo n.º 1
0
def demo():
    """
    Demonstration program to handle command line parameters and then run what they want.
    """
    from USFMBible import USFMBible
    if BibleOrgSysGlobals.verbosityLevel > 0: print( "{} Demo".format( ProgNameVersion ) )

    # Load a USFM Bible and BT
    if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nLoading USFM Bible…" )
    name1, encoding1, testFolder1 = "MBTV", 'utf-8', "../../../../../Data/Work/Matigsalug/Bible/MBTV/" # You can put your test folder here
    name2, encoding2, testFolder2 = "MS-BT", 'utf-8', "../../../../../Data/Work/Matigsalug/Bible/MBTBT/" # You can put your test folder here
    MS_ILLEGAL_STRINGS_1 = ( 'c','f','j','o','q','v','x','z', ) + DEFAULT_ILLEGAL_STRINGS_1
    MS_ILLEGAL_STRINGS_2 = ( 'We ',' we ',' us ',' us.',' us,',' us:',' us;',' us!',' us?',' us–',' us—',
                             'Our ',' our ','You ','you ','you.','you,','you:','you;','you!','you?','you–','you—',
                             'Your ','your ','yours ',' the the ', ) + DEFAULT_ILLEGAL_STRINGS_2

    if os.access( testFolder1, os.R_OK ):
        UB1 = USFMBible( testFolder1, name1, encoding1 )
        UB1.load()
        if BibleOrgSysGlobals.verbosityLevel > 0: print( UB1 )
        if BibleOrgSysGlobals.strictCheckingFlag:
            UB1.check()
        #UB1.doAllExports( "OutputFiles", wantPhotoBible=False, wantODFs=False, wantPDFs=False )
    else: print( "Sorry, test folder {!r} is not readable on this computer.".format( testFolder1 ) )

    if os.access( testFolder2, os.R_OK ):
        UB2 = USFMBible( testFolder2, name2, encoding2 )
        UB2.load()
        if BibleOrgSysGlobals.verbosityLevel > 0: print( UB2 )
        if BibleOrgSysGlobals.strictCheckingFlag:
            UB2.check()
        #UB2.doAllExports( "OutputFiles", wantPhotoBible=False, wantODFs=False, wantPDFs=False )
    else: print( "Sorry, test folder {!r} is not readable on this computer.".format( testFolder2 ) )

    if 0: # Test one book
        if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nTesting one book only…" )
        BBB = 'JDE'
        result = compareBooksPedantic( UB1[BBB], UB2[BBB], illegalStrings1=MS_ILLEGAL_STRINGS_1, illegalStrings2=MS_ILLEGAL_STRINGS_2 )
        if BibleOrgSysGlobals.verbosityLevel > 0:
            print( "Comparing {} gave:".format( BBB ) )
            print( ' ', result )

    if 1: # Test the whole Bibles
        if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nTesting for whole Bible…" )
        results = compareBibles( UB1, UB2, illegalStrings1=MS_ILLEGAL_STRINGS_1, illegalStrings2=MS_ILLEGAL_STRINGS_2 )
        totalCount = resultsBooksCount = 0
        if BibleOrgSysGlobals.verbosityLevel > 0:
            print( "\nComparing the entire Bibles gave:" )
            for BBB,bookResults in results.items():
                if bookResults:
                    resultsBooksCount += 1
                    totalCount += len( bookResults )
                    print( '\n{} ({} vs {}):'.format( BBB, name1, name2 ) )
                    for (C,V,marker),resultString in bookResults:
                        resultString = resultString.replace( 'Bible1', name1 ).replace( 'Bible2', name2 )
                        print( '  {} {}:{} {} {}'.format( BBB, C, V, marker, resultString ) )
            print( "{} total results in {} books (out of {})".format( totalCount, resultsBooksCount, len(UB1) ) )

    if 0: # Compare one book
        if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nAnalyzing one book only…" )
        BBB = 'JDE'
        segmentResult, otherResult = segmentizeBooks( UB1[BBB], UB2[BBB] )
        if BibleOrgSysGlobals.verbosityLevel > 0:
            print( "Comparing {} gave:".format( BBB ) )
            #print( ' 1s', len(segmentResult), segmentResult )
            print( ' 2o', len(otherResult), otherResult )
        dict12, dict21 = loadWordCompares( 'Tests/DataFilesForTests', 'MSBTCheckWords.txt' )
        awResult = analyzeWords( segmentResult, dict12, dict21 )
        if BibleOrgSysGlobals.verbosityLevel > 0:
            print( "Comparing {} gave:".format( BBB ) )
            print( '\n{} ({} vs {}):'.format( BBB, name1, name2 ) )
            for (C,V,marker),resultString in awResult:
                resultString = resultString.replace( 'Bible1', name1 ).replace( 'Bible2', name2 )
                print( '  {} {}:{} {} {}'.format( BBB, C, V, marker, resultString ) )
            print( "{:,} results in {}".format( len(awResult), BBB ) )

    if 0: # Compare the whole Bibles
        if BibleOrgSysGlobals.verbosityLevel > 0: print( "\nAnalyzing whole Bible…" )
        totalSegments = totalCount = 0
        for BBB in UB1.getBookList():
            segmentResult, otherResult = segmentizeBooks( UB1[BBB], UB2[BBB] )
            totalSegments += len( segmentResult )
            if BibleOrgSysGlobals.verbosityLevel > 0:
                print( "Comparing {} gave:".format( BBB ) )
                #print( ' 1s', len(segmentResult), segmentResult )
                print( ' 2o', len(otherResult), otherResult )
            dict12, dict21 = loadWordCompares( 'Tests/DataFilesForTests', 'MSBTCheckWords.txt' )
            awResult = analyzeWords( segmentResult, dict12, dict21 )
            totalCount += len( awResult )
            if BibleOrgSysGlobals.verbosityLevel > 0:
                print( '\n{} ({} vs {}):'.format( BBB, name1, name2 ) )
                for (C,V,marker),resultString in awResult:
                    resultString = resultString.replace( 'Bible1', name1 ).replace( 'Bible2', name2 )
                    print( '  {} {}:{} {} {}'.format( BBB, C, V, marker, resultString ) )
                print( "  {:,} results in {}".format( len(awResult), BBB ) )
        if BibleOrgSysGlobals.verbosityLevel > 0:
            print( "{:,} total results in {} books ({:,} segments)".format( totalCount, len(UB1), totalSegments ) )