本文整理汇总了Python中document.Document.read_document方法的典型用法代码示例。如果您正苦于以下问题:Python Document.read_document方法的具体用法?Python Document.read_document怎么用?Python Document.read_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类document.Document
的用法示例。
在下文中一共展示了Document.read_document方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Probability
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import read_document [as 别名]
def Probability(self, doc, dclass = ""):
"""Calculates the probability for a class dclass given a document doc"""
if dclass:
sum_dclass = self.sum_words_in_class(dclass)
prob = 0
d = Document(self.__vocabulary)
d.read_document(doc)
for j in self.__document_classes:
sum_j = self.sum_words_in_class(j)
prod = 1
for i in d.Words():
wf_dclass = 1 + self.__document_classes[dclass].WordFreq(i)
wf = 1 + self.__document_classes[j].WordFreq(i)
r = wf * sum_dclass / (wf_dclass * sum_j)
prod *= r
prob += prod * self.__document_classes[j].NumberOfDocuments() / self.__document_classes[dclass].NumberOfDocuments()
if prob != 0:
return 1 / prob
else:
return -1
else:
prob_list = []
for dclass in self.__document_classes:
prob = self.Probability(doc, dclass)
prob_list.append([dclass,prob])
prob_list.sort(key = lambda x: x[1], reverse = True)
return prob_list
示例2: DocumentIntersectionWithClasses
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import read_document [as 别名]
def DocumentIntersectionWithClasses(self, doc_name):
res = [doc_name]
for dc in self.__document_classes:
d = Document(self.__vocabulary)
d.read_document(doc_name, learn=False)
o = self.__document_classes[dc] & d
intersection_ratio = len(o) / len(d.Words())
res += (dc, intersection_ratio)
return res
示例3: learn
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import read_document [as 别名]
def learn(self, directory, dclass_name):
""" directory is a path, where the files of the class with the name dclass_name can be found """
x = DocumentClass(self.__vocabulary)
dir = os.listdir(directory)
for file in dir:
d = Document(self.__vocabulary)
print(directory + "/" + file)
d.read_document(directory + "/" + file, learn = True)
x = x + d
self.__document_classes[dclass_name] = x
x.SetNumberOfDocs(len(dir))
示例4: learn
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import read_document [as 别名]
def learn(self,directory,classname):
x = DocumentClass()
dir = os.listdir(directory)
for file in dir:
d = Document()
print(directory + "/" + file)
d.read_document(directory + "/" + file)
x = x + d
self.__document_classes[classname] = x
#print(len(dir))
x.setNumberOfDocs(len(dir))