本文整理汇总了Python中Datum.Datum类的典型用法代码示例。如果您正苦于以下问题:Python Datum类的具体用法?Python Datum怎么用?Python Datum使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Datum类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setFeaturesTrain
def setFeaturesTrain(self, data):
newData = []
words = []
for datum in data:
words.append(datum.word)
## This is so that the feature factory code doesn't
## accidentally use the true label info
previousLabel = "O"
for i in range(0, len(data)):
datum = data[i]
newDatum = Datum(datum.word, datum.label)
newDatum.features = self.computeFeatures(words, previousLabel, i)
newDatum.previousLabel = previousLabel
newData.append(newDatum)
previousLabel = datum.label
return newData
示例2: setFeaturesTest
def setFeaturesTest(self, data):
newData = []
words = []
labels = []
labelIndex = {}
for datum in data:
words.append(datum.word)
if not labelIndex.has_key(datum.label):
labelIndex[datum.label] = len(labels)
labels.append(datum.label)
## This is so that the feature factory code doesn't
## accidentally use the true label info
for i in range(0, len(data)):
datum = data[i]
if i == 0:
previousLabel = "O"
datum.features = self.computeFeatures(words, previousLabel, i)
newDatum = Datum(datum.word, datum.label)
newDatum.features = self.computeFeatures(words, previousLabel, i)
newDatum.previousLabel = previousLabel
newData.append(newDatum)
else:
for previousLabel in labels:
datum.features = self.computeFeatures(words, previousLabel, i)
newDatum = Datum(datum.word, datum.label)
newDatum.features = self.computeFeatures(words, previousLabel, i)
newDatum.previousLabel = previousLabel
newData.append(newDatum)
return newData