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)
def process_sentsraw(SentsRaw): PSents=[] for SentRaw in SentsRaw: try: MkdLines=mecabtools.mark_sentlines(SentRaw,[7,9]) if any(Line[1] is None for Line in MkdLines): pass else: ProcessedSent=process_chunk(SentRaw) PSents.append(ProcessedSent) #yield ProcessedSent except: process_chunk(SentRaw) return PSents