Esempio n. 1
0
def main0(ResFP,SolFP,Strict=True,NoAmb=False):
    if not mecabtools.files_corresponding_p(ResFP,SolFP,Strict=True):
        sys.exit('result and solutions do not seem aligned')

    ResSentsRaw=mecabtools.extract_sentences(ResFP)
    SolSentsRaw=mecabtools.extract_sentences(SolFP)

    CumScores=([0,0,0],[0,0,0],[0,0])
    #Cntr=0
    for Cntr,ResSentRaw in enumerate(ResSentsRaw):
        if Debug:
            print('Sent '+str(Cntr+1)+': '+''.join([Line.split('\t')[0] for Line in ResSentRaw]))
        SolSentRaw=SolSentsRaw.__next__()
        if Debug>=2:
            print(ResSentRaw)
            print(SolSentRaw)
        MkdSentSol=mecabtools.mark_sentlines(SolSentRaw,[7,9])
        #for SentPair in SentPairs:
        if all(MkdLine[1] for MkdLine in MkdSentSol):
            if not all(MkdLine[2]=='original' for MkdLine in MkdSentSol):
                SolSentRaw=[ MkdLine[1] for MkdLine in MkdSentSol ]
            #print(SolSentRaw)
                
            ResSent=process_chunk(ResSentRaw)
            SolSent=process_chunk(SolSentRaw,NoAmb)
            Scores=score_sent(ResSent,SolSent)
            if Debug:
                print(Scores)
            CumScores=cumulate_scores(CumScores,Scores)
            
    return calculate_fscore(CumScores)
Esempio n. 2
0
def main0(ResFP,SolFP):
    Strict=False
    if not mecabtools.files_corresponding_p(ResFP,SolFP,Strict=Strict):
        sys.exit('result and solutions do not seem aligned')

    if not Strict:
        ResFPRed=ResFP+'.reduced'; SolFPRed=SolFP+'.reduced'
        exist_and_new_p=lambda FP: os.path.isfile(FP) and (datetime.datetime.fromtimestamp(os.path.getctime(FP))-datetime.datetime.now()).seconds<180
        if exist_and_new_p(ResFP) and exist_and_new_p(SolFP):
            FPR=ResFP+'.reduced'; FPS=SolFP+'.reduced'

    ResSentsRaw=mecabtools.extract_sentences(ResFP)
    SolSentsRaw=mecabtools.extract_sentences(SolFP)

    process_sentsraw=lambda SentsRaw: [process_chunk(SentRaw) for SentRaw in SentsRaw]
    SentPairs=zip(process_sentsraw(ResSentsRaw),process_sentsraw(SolSentsRaw))
    Scores=score_sents(SentPairs)

    return calculate_fscore(Scores)