本文整理汇总了Python中Utils.ProgressCounter.ProgressCounter.endUpdate方法的典型用法代码示例。如果您正苦于以下问题:Python ProgressCounter.endUpdate方法的具体用法?Python ProgressCounter.endUpdate怎么用?Python ProgressCounter.endUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils.ProgressCounter.ProgressCounter
的用法示例。
在下文中一共展示了ProgressCounter.endUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compareExamples
# 需要导入模块: from Utils.ProgressCounter import ProgressCounter [as 别名]
# 或者: from Utils.ProgressCounter.ProgressCounter import endUpdate [as 别名]
def compareExamples(examples1, examples2, features1, features2=None):
ExampleUtils.readExamples(examples1)
exampleIter1 = ExampleUtils.readExamples(examples1)
exampleIter2 = ExampleUtils.readExamples(examples2)
features1 = IdSet(filename=features1)
if features2 != None:
features2 = IdSet(filename=features2)
else:
features2 = features1
# Compare feature sets
if set(features1.Ids.keys()) != set(features2.Ids.keys()):
print "Feature sets differ"
# Compare examples
counter = ProgressCounter(step=1)
for e1, e2 in itertools.izip(exampleIter1, exampleIter2):
counter.update()
assert e1[0] == e2[0], (removeFeatures(e1), removeFeatures(e2))
if e1[1] != e2[1]:
print "Class differs"
print " E1", removeFeatures(e1)
print " E2", removeFeatures(e2)
f1 = getFeatureNames(e1, features1)
f2 = getFeatureNames(e2, features2)
f1Set = set(f1)
f2Set = set(f2)
f1Only = f1Set.difference(f2Set)
f2Only = f2Set.difference(f1Set)
if len(f1Only) > 0 or len(f2Only) > 0:
print "Features differ"
print " E1", removeFeatures(e1)
print " E2", removeFeatures(e2)
if len(f1Only) > 0:
print " E1-only features:", f1Only
if len(f2Only) > 0:
print " E2-only features:", f2Only
else:
assert len(f1) == len(f2)
fCount = 0
differ = False
for feature1, feature2 in zip(f1, f2):
#f1Id = features1.getId(feature1, createIfNotExist=False)
#if f1Id == 454 or feature1 == "e1_strength_Positive_regulation":
# print "!!!!!!!!!!!", 454, feature1, e1[2][f1Id]
if feature1 != feature2:
if not differ:
print "Feature order differs for example", e1[0]
differ = True
print "[" + feature1 + "/" + feature2 + "](" + str(fCount) + ") ",
else:
f1Id = features1.getId(feature1, createIfNotExist=False)
f2Id = features2.getId(feature2, createIfNotExist=False)
f1Value = e1[2][f1Id]
f2Value = e2[2][f2Id]
if f1Value != f2Value:
if not differ:
print "Feature values differ", e1[0]
differ = True
print "[" + feature1 + "/" + str(f1Id) + "]" + "[" + str(f1Value) + "/" + str(f2Value) + "]" + "(" + str(fCount) + ") ",
fCount += 1
if differ:
print
counter.endUpdate()
示例2: ids
# 需要导入模块: from Utils.ProgressCounter import ProgressCounter [as 别名]
# 或者: from Utils.ProgressCounter.ProgressCounter import endUpdate [as 别名]
#.........这里部分代码省略.........
if output.endswith(".gz"):
outfile = gzip.open(output, openStyle)
else:
outfile = open(output, openStyle)
# Build examples
self.exampleCount = 0
if type(input) in types.StringTypes:
self.elementCounts = self.getElementCounts(input)
if self.elementCounts["sentences"] > 0:
self.progress = ProgressCounter(self.elementCounts["sentences"], "Build examples")
else:
self.elementCounts = None
self.progress = ProgressCounter(None, "Build examples")
else:
self.elementCounts = None
self.progress = ProgressCounter(None, "Build examples")
self.calculatePredictedRange(self.getSentences(input, self.parse, self.tokenization))
inputIterator = getCorpusIterator(input, None, self.parse, self.tokenization)
#goldIterator = []
if gold != None:
goldIterator = getCorpusIterator(gold, None, self.parse, self.tokenization)
for inputSentences, goldSentences in itertools.izip_longest(inputIterator, goldIterator, fillvalue=None):
assert inputSentences != None
assert goldSentences != None
self.processDocument(inputSentences, goldSentences, outfile)
else:
for inputSentences in inputIterator:
self.processDocument(inputSentences, None, outfile)
outfile.close()
self.progress.endUpdate()
# Show statistics
print >> sys.stderr, "Examples built:", self.exampleCount
print >> sys.stderr, "Features:", len(self.featureSet.getNames())
if self.exampleStats.getExampleCount() > 0:
self.exampleStats.printStats()
# Save Ids
if allowNewIds:
self.saveIds()
def processDocument(self, sentences, goldSentences, outfile):
#calculatePredictedRange(self, sentences)
for i in range(len(sentences)):
sentence = sentences[i]
goldSentence = None
if goldSentences != None:
goldSentence = goldSentences[i]
self.progress.update(1, "Building examples ("+sentence.sentence.get("id")+"): ")
self.processSentence(sentence, outfile, goldSentence)
def processSentence(self, sentence, outfile, goldSentence=None):
if sentence.sentenceGraph != None:
goldGraph = None
if goldSentence != None:
goldGraph = goldSentence.sentenceGraph
self.exampleCount += self.buildExamplesFromGraph(sentence.sentenceGraph, outfile, goldGraph)
@classmethod
def run(cls, input, output, parse, tokenization, style, classIds=None, featureIds=None, gold=None, append=False, allowNewIds=True):
print >> sys.stderr, "Running", cls.__name__
print >> sys.stderr, " input:", input