Exemplo n.º 1
0
 def __expand_predicate(pred_head):
     predicate = Predicate()
     dep_list = [
         self._dependencies['aux'],
         self._dependencies['auxpass'],
         self._dependencies['neg'],
         self._dependencies['prt'],
         self._dependencies['cop']
     ]
     for dep in dep_list:
         dep_wn = self._get_dependents(dep, pred_head)
         if dep_wn:
             for d in dep_wn:
                 predicate.add_word_unit(d)
                 self._print_expansion_debug_info(pred_head, dep, d)
                 if dep == self._dependencies['neg']:
                     predicate.negation.append(d)
                 if dep == self._dependencies['aux']:
                     predicate.auxiliary.append(d)
     return predicate
Exemplo n.º 2
0
    def _expand_predicate(self, head):

        def __expand_predicate(pred_head):
            predicate = Predicate()
            dep_list = [
                self._dependencies['aux'],
                self._dependencies['auxpass'],
                self._dependencies['neg'],
                self._dependencies['prt'],
                self._dependencies['cop']
            ]
            for dep in dep_list:
                dep_wn = self._get_dependents(dep, pred_head)
                if dep_wn:
                    for d in dep_wn:
                        predicate.add_word_unit(d)
                        self._print_expansion_debug_info(pred_head, dep, d)
                        if dep == self._dependencies['neg']:
                            predicate.negation.append(d)
                        if dep == self._dependencies['aux']:
                            predicate.auxiliary.append(d)
            return predicate

        predicates = []
        predicate = Predicate(head, head)
        # Find out if there is any aux, auxpass, and neg
        expanded_pred = __expand_predicate(head)
        predicate.extend(expanded_pred)
        predicate.negation = expanded_pred.negation
        predicate.auxiliary = expanded_pred.auxiliary
        # Find out if there is any xcomp
        xcomp_list = self._get_dependents(self._dependencies['xcomp'], head)
        if xcomp_list:
            # Get xcomp conjunction first
            xcomp_list_len = len(xcomp_list)
            for i in xrange(xcomp_list_len):
                xcomp_list.extend(self._get_conjunction(xcomp_list[i]))
            for xcomp in xcomp_list:
                if xcomp.pos.startswith(self._pos_tags['vb']):
                    # If the xcomp doesn't immediately follow its head, separate them
                    if xcomp.index - predicate.head.index > 3:
                        pred = Predicate(xcomp, xcomp)
                        pred.extend(__expand_predicate(xcomp))
                        # Remove "to" preceding the comp
                        for wn in pred.sequence:
                            if wn.index < xcomp.index and wn.word == 'to':
                                pred.remove_word_unit(wn)
                        # Also add the head to predicates
                        predicates.append(predicate)
                    else:
                        pred = deepcopy(predicate)
                        pred.add_word_unit(xcomp)
                        pred.extend(__expand_predicate(xcomp))
                    self._print_expansion_debug_info(head, 'xcomp', xcomp)
                    predicates.append(pred)
                elif xcomp.pos.startswith(self._pos_tags['nn']):
                    pred = deepcopy(predicate)
                    pred.add_word_unit(xcomp)
                    pred.extend(__expand_predicate(xcomp))
                    self._print_expansion_debug_info(head, 'xcomp', xcomp)
                    predicates.append(pred)
        else:
            predicates.append(predicate)
        return predicates