def computeStats(self, absList, statOut=None, errorOut=None): """ compute RPF stats for detected quantities in a list of abstracts. write results to output stream. write final RPF stats to statOut write TP/FP/FN to errorOut """ stats = EntityStats(self.entityTypes) for abs in absList: errorOut.write('---'+abs.id+'---\n') for sentence in abs.sentences: # decide if should output sentence printedSentence = False # count correct and incorrect labelings for eType in self.entityTypes: for token in sentence: if self.isImportantNumber(token) == True: if token.hasLabel(eType) and token.hasAnnotation(eType): stats.irstats[eType].incTP() errorOut.write('+TP: ' + token.text + ' ('+eType+')\n') elif token.hasLabel(eType) == True: stats.irstats[eType].incFP() errorOut.write('-FP: ' + token.text + ' ('+eType+')\n') elif token.hasAnnotation(eType) == True: stats.irstats[eType].incFN() errorOut.write('-FN: ' + token.text + ' ('+eType+')\n') stats.printStats() # stats.writeStats(statOut) if statOut != None: stats.saveStats(statOut, keyPrefix='NF - ') return stats
def computeStats(self, absList, statOut=None, errorOut=None, typeList=[], keyPrefix=''): """ compute RPF stats for associated mentions and quantities in a list of abstracts. write final RPF stats to statOut write TP/FP/FN to errorOut """ if len(keyPrefix) == 0: keyPrefix = 'Assoc - ' if len(typeList) > 0: statDescription = '-'.join(typeList) else: statDescription = self.entityTypesString stats = EntityStats([statDescription]) totalFalsePairs = 0 for abs in absList: errorOut.write('---%s (%s)\n'%(abs.id, statDescription)) for s in abs.sentences: [tp, fp, fn, falsePairs] = self.checkAssociations(s, errorOut, typeList) errorOut.write('tp: %d, fp: %d, fn: %d, falsePairs: %d\n'%(tp, fp, fn, falsePairs)) totalFalsePairs += falsePairs stats.irstats[statDescription].addTP(tp) stats.irstats[statDescription].addFP(fp) stats.irstats[statDescription].addFN(fn) stats.printStats() print 'Total false pairs: ', totalFalsePairs # stats.writeStats(statOut) stats.saveStats(statOut, keyPrefix=keyPrefix) return stats
def computeStats(self, absList, statOut=None, errorOut=None, typeList=[], keyPrefix=''): """ compute RPF stats for associated mentions and quantities in a list of abstracts. write final RPF stats to statOut write TP/FP/FN to errorOut """ if len(keyPrefix) == 0: keyPrefix = 'Assoc - ' if len(typeList) > 0: statDescription = '-'.join(typeList) else: statDescription = self.entityTypesString stats = EntityStats([statDescription]) totalFalsePairs = 0 for abs in absList: errorOut.write('---%s (%s)\n' % (abs.id, statDescription)) for s in abs.sentences: [tp, fp, fn, falsePairs] = self.checkAssociations(s, errorOut, typeList) errorOut.write('tp: %d, fp: %d, fn: %d, falsePairs: %d\n' % (tp, fp, fn, falsePairs)) totalFalsePairs += falsePairs stats.irstats[statDescription].addTP(tp) stats.irstats[statDescription].addFP(fp) stats.irstats[statDescription].addFN(fn) stats.printStats() print 'Total false pairs: ', totalFalsePairs # stats.writeStats(statOut) stats.saveStats(statOut, keyPrefix=keyPrefix) return stats
def computeStats(self, absList, statOut=None, errorOut=None): """ compute RPF stats for detected mentions in a list of abstracts. write results to output stream. write final RPF stats to statOut write TP/FP/FN to errorOut """ stats = EntityStats(self.entityTypes) for abs in absList: errorOut.write('---'+abs.id+'---\n') # identify ALL annotated mentions, even in sentences we are not focused on # for sentence in abs.allSentences(): # for mType in self.entityTypes: # aList = sentence.getAnnotatedMentions(mType, recomputeMentions=True) # # for sentence in abs.sentences: # for mType in self.entityTypes: # self.compareAnnotatedAndDetected(sentence, mType, \ # stats.irstats[mType], errorOut) for sentence in abs.allSentences(): for mType in self.entityTypes: if sentence in abs.sentences: self.compareAnnotatedAndDetected(sentence, mType, \ stats.irstats[mType], errorOut) else: aList = sentence.getAnnotatedMentions(mType, recomputeMentions=True) stats.printStats() if statOut != None: stats.saveStats(statOut, keyPrefix='MF - ') return stats