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


Python nltk.util方法代码示例

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


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

示例1: closure

# 需要导入模块: import nltk [as 别名]
# 或者: from nltk import util [as 别名]
def closure(self, rel, depth=-1):
        """Return the transitive closure of source under the rel
        relationship, breadth-first

            >>> from nltk.corpus import wordnet as wn
            >>> dog = wn.synset('dog.n.01')
            >>> hyp = lambda s:s.hypernyms()
            >>> list(dog.closure(hyp))
            [Synset('canine.n.02'), Synset('domestic_animal.n.01'),
            Synset('carnivore.n.01'), Synset('animal.n.01'),
            Synset('placental.n.01'), Synset('organism.n.01'),
            Synset('mammal.n.01'), Synset('living_thing.n.01'),
            Synset('vertebrate.n.01'), Synset('whole.n.02'),
            Synset('chordate.n.01'), Synset('object.n.01'),
            Synset('physical_entity.n.01'), Synset('entity.n.01')]

        """
        from nltk.util import breadth_first
        synset_offsets = []
        for synset in breadth_first(self, rel, depth):
            if synset._offset != self._offset:
                if synset._offset not in synset_offsets:
                    synset_offsets.append(synset._offset)
                    yield synset 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:26,代码来源:wordnet.py

示例2: closure

# 需要导入模块: import nltk [as 别名]
# 或者: from nltk import util [as 别名]
def closure(self, rel, depth=-1):
        """Return the transitive closure of source under the rel
        relationship, breadth-first

            >>> from nltk.corpus import wordnet as wn
            >>> dog = wn.synset('dog.n.01')
            >>> hyp = lambda s:s.hypernyms()
            >>> list(dog.closure(hyp))
            [Synset('domestic_animal.n.01'), Synset('canine.n.02'), Synset('animal.n.01'), Synset('carnivore.n.01'), Synset('organism.n.01'), Synset('placental.n.01'), Synset('living_thing.n.01'), Synset('mammal.n.01'), Synset('whole.n.02'), Synset('vertebrate.n.01'), Synset('object.n.01'), Synset('chordate.n.01'), Synset('physical_entity.n.01'), Synset('entity.n.01')]

        """
        from nltk.util import breadth_first
        synset_offsets = []
        for synset in breadth_first(self, rel, depth):
            if synset.offset != self.offset:
                if synset.offset not in synset_offsets:
                    synset_offsets.append(synset.offset)
                    yield synset 
开发者ID:blackye,项目名称:luscan-devel,代码行数:20,代码来源:wordnet.py

示例3: _generate_trees

# 需要导入模块: import nltk [as 别名]
# 或者: from nltk import util [as 别名]
def _generate_trees(self):
        # trees = util.load_obj(self.filename + '_gold_len10')
        trees = None

        if trees is None:
            print("Parsing treebank...")

            f = lambda t: len(t.leaves()) <= self.n
            m = lambda t: self._prepare(t)
            # f = lambda t: t
            # m = lambda t: t
            trees = [t for t in filter(f, map(m, self.parsed()))]

            # util.save_obj(trees, self.filename + '_gold_len10')

            # w/o filtering
            # trees = [t for t in self.parsed()]



        # add hmm induced tags
        if self.extra_tags is not None:
            # new_trees = util.load_obj(self.filename + '_35_len10')
            new_trees = None
            if new_trees is None:
                new_trees = []
                # cnt = 0
                for t, tags in zip(self.parsed(), self.extra_tags):
                    # if cnt % 100 == 0:
                    #     print cnt
                    # cnt += 1
                    for st, tag in zip(t.subtrees(lambda x: x.height() == 2), tags):
                        st.insert(0, tag)
                    t = self._prepare(t)
                    if len(t.leaves()) / 2 <= self.n:
                        new_trees += [t]
                # util.save_obj(new_trees, self.filename + '_35_len10')


        self.gold_tag_sents = [[(sub.label(), sub.leaves()[0]) \
                              for sub in t.subtrees(lambda x: x.height() == 2)] \
                              for t in trees]

        if self.extra_tags is not None:
            self.induce_tag_sents = [[(sub.leaves()[0], sub.leaves()[1]) \
                                  for sub in t.subtrees(lambda x: x.height() == 2)] \
                                  for t in new_trees]
        else:
            self.induce_tag_sents = None


        return trees 
开发者ID:jxhe,项目名称:struct-learning-with-flow,代码行数:54,代码来源:wsj10.py


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