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


Python idd3.Relation类代码示例

本文整理汇总了Python中idd3.Relation的典型用法代码示例。如果您正苦于以下问题:Python Relation类的具体用法?Python Relation怎么用?Python Relation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: process_pp_when_be_is_root

    def process_pp_when_be_is_root(relations, index, context, engine, info,
                                   subjs):

        """TODO: Docstring for process_pp_when_be_is_root."""

        prep_indices = Relation.get_children_with_dep('prep', relations,
                                                      index)
        if not prep_indices:
            return []

        if subjs['return_list'][0].lower() == 'it':
            prep_index = prep_indices[0]
            pobj_children = Relation.get_children_with_dep('pobj', relations, prep_index)
            if pobj_children:
                pobj_index = pobj_children[0]
            else:
                return []

            pobj_return_value = engine.analyze(relations, pobj_index, context +
                                               [index, prep_index])

            return_list = []
            for noun in pobj_return_value['return_list']:
                return_list.append(relations[prep_index].word + ' ' + noun)

            engine.mark_processed(relations, prep_index)

            return return_list
        else:
            for prep_index in prep_indices:
                engine.analyze(relations, prep_index, context + [index])
            return []
开发者ID:dmhowcroft,项目名称:idd3,代码行数:32,代码来源:vp_rulesets.py

示例2: extract

    def extract(self, relations, index, context, engine, info={}):
        """extract(relations, index, context, engine, info) -> str | list(str)

        An nn can be a single word or multiple words connected by cc/conj.

        Examples:

            * Oil prices
                nn(prices, Oil)
                -> return "Oil"
            * East and West Germany
                nn(Germany, East)
                cc(East, and)
                conj(East, West)
                -> return ["East", "West"]
        """
        conj_indices = Relation.get_children_with_dep('conj', relations,
                                                      index)

        if conj_indices != []:
            # Consume the conjunction.
            cc_indices = Relation.get_children_with_dep('cc', relations, index)
            for i in cc_indices:
                engine.analyze(relations, cc_indices[0], context + [index])

            conjs = [engine.analyze(relations, i, context + [index],
                                    info={'class': 'NP'})
                     for i in conj_indices]
            conjs = [c[0] for c in conjs]  # TODO: check if this makes sense.

            return [relations[index].word] + conjs
        else:
            return relations[index].word
开发者ID:dmhowcroft,项目名称:idd3,代码行数:33,代码来源:misc_rulesets.py

示例3: process_pp_when_be_is_root

    def process_pp_when_be_is_root(relations, index, context, engine, info,
                                   subjs):
        # TODO: Maybe unnecessary.

        """Process prepositional phrases when be is root."""

        prep_indices = Relation.get_children_with_dep('adpmod', relations,
                                                      index)
        if prep_indices == []:
            return []

        if subjs['return_list'][0].lower() == 'it':
            prep_index = prep_indices[0]
            pobj_index = Relation.get_children_with_dep('adpobj', relations,
                                                        prep_index)[0]

            pobj_return_value = engine.analyze(relations, pobj_index, context +
                                               [index, prep_index])

            return_list = []
            for noun in pobj_return_value['return_list']:
                return_list.append(relations[prep_index].word + ' ' + noun)

            engine.mark_processed(relations, prep_index)

            return return_list
        else:
            for prep_index in prep_indices:
                engine.analyze(relations, prep_index, context + [index])
            return []
开发者ID:andrecunha,项目名称:idd3,代码行数:30,代码来源:vp_rulesets.py

示例4: process_conjs

    def process_conjs(relations, index, context, engine, info, subjs, auxs,
                      prop_ids):

        """Process cc/conj."""

        conj_indices = Relation.get_children_with_dep('conj', relations,
                                                      index)

        if conj_indices != []:
            cc_indices = Relation.get_children_with_dep('cc', relations, index)

            if cc_indices:
                conjunction = engine.analyze(relations, cc_indices[0],
                                             context + [index])
            else:
                conjunction = None

            preconj_indices = Relation.get_children_with_dep('preconj',
                                                             relations, index)
            if preconj_indices != []:
                preconj = engine.analyze(relations, preconj_indices[0],
                                         context + [index])
                conjunction = preconj + '_' + conjunction

            for i in conj_indices:
                ret = engine.analyze(relations, i, context + [index],
                                     info={'class': 'VP',
                                           'subj': subjs,
                                           'aux': auxs})
                prop_ids.extend(ret['prop_ids'])

            if conjunction:
                conj_prop = tuple([conjunction] + prop_ids)
                engine.emit(conj_prop, 'C')
开发者ID:andrecunha,项目名称:idd3,代码行数:34,代码来源:vp_rulesets.py

示例5: process_conjs

    def process_conjs(relations, index, context, engine):

        """TODO: Docstring for process_conjs."""

        # Composite NP with conjunction

        conj_indices = Relation.get_children_with_dep('conj', relations, index)

        if conj_indices != []:
            # Consume the cc.
            cc_indices = Relation.get_children_with_dep('cc', relations, index)
            for i in cc_indices:
                engine.analyze(relations, i, context + [index])

            # Get the conjs.
            conjs = [engine.analyze(relations, i, context + [index],
                                    info={'class': 'NP'})
                     for i in conj_indices]
            # TODO: check if this makes sense.
            conjs = [c[0] for c in conjs]
        else:
            conjs = []

        conjs = [relations[index].word] + conjs

        return conjs
开发者ID:dmhowcroft,项目名称:idd3,代码行数:26,代码来源:np_rulesets.py

示例6: transform

    def transform(self, relations):
        for index, relation in enumerate(relations):
            if relation.rel in ('null', 'root', 'xcomp', 'rcmod')\
                    and relation.tag in ('VBZ', 'VBD', 'VBP', 'VB')\
                    and relation.word in self.verb_forms:
                xcomp_indices = Relation.get_children_with_dep('xcomp', relations, index)
                if not xcomp_indices:
                    continue
                else:
                    xcomp_index = xcomp_indices[0]

                if relations[xcomp_index].tag == 'VB':
                    aux_indices = Relation.get_children_with_dep('aux', relations, xcomp_index)

                    aux_indices_with_to = [index for index in aux_indices if relations[index].tag == 'TO']
                    if aux_indices_with_to:
                        to_index = aux_indices_with_to[0]
                    else:
                        continue

                    # Append 'to' and the xcomp head to main verb.
                    relations[index].word += ' to ' + \
                        relations[xcomp_index].word

                    # Remove 'aux' and 'xcomp' relations.
                    delete_indices(relations, [to_index, xcomp_index])

                    # Change head of relations pointing to xcomp to point to
                    #   the main verb.
                    for i, rel in enumerate(relations):
                        if rel.head == xcomp_index - 2:
                            rel.head = index
                            relations[index].deps.append(i)

                    relations[index].deps.sort()
开发者ID:dmhowcroft,项目名称:idd3,代码行数:35,代码来源:transform.py

示例7: transform

    def transform(self, relations):
        for i in range(len(relations)):
            cc_indices = Relation.get_children_with_dep('cc', relations, i)
            conj_indices = Relation.get_children_with_dep('conj', relations, i)

            if cc_indices and not conj_indices:
                relations[cc_indices[0]].rel = 'preconj'
开发者ID:andrecunha,项目名称:idd3,代码行数:7,代码来源:transform.py

示例8: process_comps

    def process_comps(relations, index, context, engine, info):

        """Process complements (direct objects, open clausal complements,
            adjectival complements, and subject predicates)."""

        dobj_index = Relation.get_children_with_dep('dobj', relations, index)
        xcomp_index = Relation.get_children_with_dep('xcomp', relations, index)
        acomp_index = Relation.get_children_with_dep('acomp', relations, index)
        attr_index = Relation.get_children_with_dep('attr', relations, index)

        comps_indices = sorted(dobj_index + xcomp_index + acomp_index +
                               attr_index)
        _comps = [engine.analyze(relations, i, context + [index], info)
                  for i in comps_indices]

        comps = []
        for comp in _comps:
            if isinstance(comp, dict):
                if 'return_value' in comp:  # xcomp
                    comp = comp['return_value']
                else:  # attr
                    comp = comp['return_list']

            if isinstance(comp, list):
                comps.extend(comp)
            else:
                if comp is not None:
                    comps.append(comp)

        return comps
开发者ID:andrecunha,项目名称:idd3,代码行数:30,代码来源:vp_rulesets.py

示例9: process_iobj

    def process_iobj(relations, index, context, engine, info):

        """TODO: Docstring for process_iobj."""

        # prep + pobj
        prep_indices = Relation.get_children_with_dep('prep', relations, index)
        for prep_index in prep_indices:
            engine.analyze(relations, prep_index, context + [index])

        # iobj
        iobj_index = Relation.get_children_with_dep('iobj', relations, index)
        if iobj_index != []:
            engine.analyze(relations, iobj_index[0], context + [index])
开发者ID:dmhowcroft,项目名称:idd3,代码行数:13,代码来源:vp_rulesets.py

示例10: process_iobj

    def process_iobj(relations, index, context, engine, info):

        """Process the indirect object."""

        # adpmod + adpobj
        prep_indices = Relation.get_children_with_dep('adpmod', relations,
                                                      index)
        for prep_index in prep_indices:
            engine.analyze(relations, prep_index, context + [index])

        # iobj
        iobj_index = Relation.get_children_with_dep('iobj', relations, index)
        if iobj_index != []:
            engine.analyze(relations, iobj_index[0], context + [index])
开发者ID:andrecunha,项目名称:idd3,代码行数:14,代码来源:vp_rulesets.py

示例11: extract

    def extract(self, relations, index, context, engine, info={}):
        """extract(relations, index, context, engine, info) -> None

        Prepositional phrases always generate new propositions, according to
            Chand et al.'s manual.

        Examples:

            * to the city
                pobj(to, city)
                det(city, the)
                -> emit((to the city,))

            * to both East and West Germany
                pobj(to, Germany)
                preconj(Germany, both)
                nn(Germany, East)
                cc(East, and)
                conj(East, West)
                -> emit((to East Germany, )) # Proposition x
                -> emit((to West Germany, )) # Proposition y
                -> emit((both, x, y))

            * TODO: insert example with PCOMP.
        """
        # adpobj
        pobj_index = Relation.get_children_with_dep('adpobj', relations, index)
        if pobj_index != []:
            pobjs = engine.analyze(relations, pobj_index[0], context + [index])

            emitted_prop_ids = []
            for pobj in pobjs['return_list']:
                prop_id = engine.emit((relations[index].word + ' ' + pobj,),
                                      'M')
                emitted_prop_ids.append(prop_id)

            if pobjs['ids_for_preconj'] != []:
                indices = [j for i, j in enumerate(emitted_prop_ids)
                           if i in pobjs['ids_for_preconj']]
                proposition = tuple([pobjs['preconj']] + indices)
                engine.emit(proposition, 'C')

        # adpcomp
        pcomp_index = Relation.get_children_with_dep('adpcomp', relations,
                                                     index)
        if pcomp_index != []:
            pcomp = engine.analyze(relations, pcomp_index[0],
                                   context + [index])['return_value']
            if pcomp is not None:
                engine.emit((relations[index].word + ' ' + pcomp,), 'M')
开发者ID:andrecunha,项目名称:idd3,代码行数:50,代码来源:misc_rulesets.py

示例12: process_auxs

    def process_auxs(relations, index, context, engine, info):

        """Process auxiliaries and modals."""

        aux_index = Relation.get_children_with_dep('aux', relations, index)
        auxpass_index = Relation.get_children_with_dep('auxpass', relations,
                                                       index)
        auxs_index = sorted(aux_index + auxpass_index)
        auxs = [engine.analyze(relations, i, context + [index])
                for i in auxs_index]

        if auxs == [] and 'aux' in info:
            auxs = info['aux']

        return auxs
开发者ID:andrecunha,项目名称:idd3,代码行数:15,代码来源:vp_rulesets.py

示例13: process_ignorables

    def process_ignorables(relations, index, context, engine, info):

        """Process elements that can be ignored (complm - DEPRECATED,
            and mark)."""

        # complm
        complm_indices = Relation.get_children_with_dep('complm', relations,
                                                        index)
        for i in complm_indices:
            engine.analyze(relations, i, context + [index])

        # TODO: check if this makes sense.
        # mark
        mark_indices = Relation.get_children_with_dep('mark', relations, index)
        for i in mark_indices:
            engine.analyze(relations, i, context + [index])
开发者ID:andrecunha,项目名称:idd3,代码行数:16,代码来源:vp_rulesets.py

示例14: process_ccomp

    def process_ccomp(relations, index, context, engine, info):

        """Process clausal complements."""

        ccomp_index = Relation.get_children_with_dep('ccomp', relations, index)
        if ccomp_index != []:
            engine.analyze(relations, ccomp_index[0], context + [index], info)
开发者ID:andrecunha,项目名称:idd3,代码行数:7,代码来源:vp_rulesets.py

示例15: process_negs

    def process_negs(relations, index, context, engine, info):

        """Process negations."""

        neg_indices = Relation.get_children_with_dep('neg', relations, index)
        for i in neg_indices:
            engine.analyze(relations, i, context + [index])
开发者ID:andrecunha,项目名称:idd3,代码行数:7,代码来源:np_rulesets.py


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