当前位置: 首页>>代码示例>>Python>>正文


Python Document.setNESet方法代码示例

本文整理汇总了Python中document.Document.setNESet方法的典型用法代码示例。如果您正苦于以下问题:Python Document.setNESet方法的具体用法?Python Document.setNESet怎么用?Python Document.setNESet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在document.Document的用法示例。


在下文中一共展示了Document.setNESet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import setNESet [as 别名]
class Reader:
    """Returns object to read files stored on specified path"""
    
    def __init__(self, path):
        self.__document = Document()
        self.__path = path
        self.__parser = Parser()

    def read(self, textFile, mentionsFile):
        """Read files containing the text and mentions, returning an object of them having 'text' and 'cluster list' as attributes"""
 
        ls = []
        text = ""
        mentions = ""
        tuples = []
        mentionClustersList = []
        clusterCount = 0
        mentionToClusterMap = {}
        with open(self.__path + textFile) as f_text:
            text = f_text.read()
        temp = text.splitlines()

        if len(temp[-1]) == 0:
            temp.pop()

        text = " ".join(temp)
        self.__parser.process(text)
        dependenciesList = self.__parser.getDependencies()
        
        print "Index Map to be used when creating mentions file:"
        for i, j in enumerate(text):
            print i, j
        raw_input("\nPlease enter the indices of the mentions in the mentions file: <Press enter to continue process>")

        with open(self.__path + mentionsFile) as f_mention:
            mentions = f_mention.read()
        ls = mentions.splitlines()

        if len(ls[-1]) == 0:
            ls.pop()
        
        for line in ls:
            line = line.split()
            new_tuple = int(line[0]), int(line[1])
            tuples.append(new_tuple)

        for element in tuples:
            left = element[0]
            right = element[1]
            mentions = text[left:right]
            mentionClustersList.append(Cluster(mentions, element))
            mentionToClusterMap[element] = mentionClustersList[-1]
            clusterCount = clusterCount + 1
        
        n = NER()
        print"\nThis may take some time. Please wait...\n"
        n.process(self.__path + textFile)
        NERMap = n.getNERRelations()
        NESet = set(NERMap.keys())
        feature = Features(dependenciesList)
        self.__document.setText(text)
        self.__document.setTextPath(self.__path + textFile)
        self.__document.setMentionClustersList(mentionClustersList)
        self.__document.setFeatures(feature.getAppositiveRelations(), feature.getCopulativeRelations())
        self.__document.setMentionToClusterMap(mentionToClusterMap)
        self.__document.setParserObject(self.__parser)
        self.__document.setNERMap(NERMap)
        self.__document.setNESet(NESet)
        return self.__document
开发者ID:GomesNayagam,项目名称:multipass-for-coreference,代码行数:71,代码来源:reader.py


注:本文中的document.Document.setNESet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。