Ejemplo n.º 1
0
    def test_rules(self, train_auxs):
        f = lambda x: 1 if x else 0

        predictions = []
        for i in range(len(train_auxs)):
            aux = train_auxs[i]
            sendict = self.sentences[aux.sentnum]
            tree = sendict.get_nltk_tree()
            word_subtree_positions = nt.get_smallest_subtree_positions(tree)

            if aux.type == 'modal':
                predictions.append(
                    f(wc.modal_rule(sendict, aux, tree,
                                    word_subtree_positions)))
            elif aux.type == 'be':
                predictions.append(f(wc.be_rule(sendict, aux)))
            elif aux.type == 'have':
                predictions.append(f(wc.have_rule(sendict, aux)))
            elif aux.type == 'do':
                predictions.append(
                    f(wc.do_rule(sendict, aux, tree, word_subtree_positions)))
            elif aux.type == 'so':
                predictions.append(f(wc.so_rule(sendict, aux)))
            elif aux.type == 'to':
                predictions.append(f(wc.to_rule(sendict, aux)))

        return predictions
Ejemplo n.º 2
0
def my_rules_vector(sentdict, aux, tree, subtree_positions):
    aux_type = aux.type
    vector = [bool_to_int(aux_type == 'modal' and wc.modal_rule(sentdict, aux, tree, subtree_positions)),
              bool_to_int(aux_type == 'be' and wc.be_rule(sentdict, aux)),
              bool_to_int(aux_type == 'have' and wc.have_rule(sentdict, aux)),
              bool_to_int(aux_type == 'do' and wc.do_rule(sentdict, aux, tree, subtree_positions)),
              bool_to_int(aux_type == 'to' and wc.to_rule(sentdict, aux)),
              bool_to_int(aux_type == 'so' and wc.so_rule(sentdict, aux))]
    return vector
Ejemplo n.º 3
0
    def test_my_rules(self, original_rules=False, idxs=None):
        self.predictions = []
        print "Length of test set: %d, length of All_auxs-training vectors: %d" % (
            len(self.test_classes),
            len(self.all_auxiliaries) - len(self.train_vectors),
        )
        for i in range(self.pre_oversample_length, len(self.all_auxiliaries)):
            if idxs == None or i in idxs:
                aux = self.all_auxiliaries.get_aux(i)
                sendict = self.sentences.get_sentence(aux.sentnum)
                tree = sendict.get_nltk_tree()
                word_subtree_positions = nt.get_smallest_subtree_positions(tree)

                if not original_rules:
                    if aux.type == "modal":
                        self.predictions.append(
                            vc.bool_to_int(wc.modal_rule(sendict, aux, tree, word_subtree_positions))
                        )
                    elif aux.type == "be":
                        self.predictions.append(vc.bool_to_int(wc.be_rule(sendict, aux)))
                    elif aux.type == "have":
                        self.predictions.append(vc.bool_to_int(wc.have_rule(sendict, aux)))
                    elif aux.type == "do":
                        self.predictions.append(vc.bool_to_int(wc.do_rule(sendict, aux, tree, word_subtree_positions)))
                    elif aux.type == "so":
                        self.predictions.append(vc.bool_to_int(wc.so_rule(sendict, aux)))
                    elif aux.type == "to":
                        self.predictions.append(vc.bool_to_int(wc.to_rule(sendict, aux)))
                else:
                    auxidx = aux.wordnum
                    if aux.type == "modal":
                        self.predictions.append(
                            vc.bool_to_int(dv.modalcheck(sendict, auxidx, tree, word_subtree_positions))
                        )
                    elif aux.type == "be":
                        self.predictions.append(
                            vc.bool_to_int(dv.becheck(sendict, auxidx, tree, word_subtree_positions))
                        )
                    elif aux.type == "have":
                        self.predictions.append(
                            vc.bool_to_int(dv.havecheck(sendict, auxidx, tree, word_subtree_positions))
                        )
                    elif aux.type == "do":
                        self.predictions.append(
                            vc.bool_to_int(dv.docheck(sendict, auxidx, tree, word_subtree_positions))
                        )
                    elif aux.type == "so":
                        self.predictions.append(
                            vc.bool_to_int(dv.socheck(sendict, auxidx, tree, word_subtree_positions))
                        )
                    elif aux.type == "to":
                        self.predictions.append(
                            vc.bool_to_int(dv.tocheck(sendict, auxidx, tree, word_subtree_positions))
                        )
Ejemplo n.º 4
0
def my_rules_vector(sentdict, aux, tree, subtree_positions):
    aux_type = aux.type
    vector = [
        bool_to_int(aux_type == 'modal'
                    and wc.modal_rule(sentdict, aux, tree, subtree_positions)),
        bool_to_int(aux_type == 'be' and wc.be_rule(sentdict, aux)),
        bool_to_int(aux_type == 'have' and wc.have_rule(sentdict, aux)),
        bool_to_int(aux_type == 'do'
                    and wc.do_rule(sentdict, aux, tree, subtree_positions)),
        bool_to_int(aux_type == 'to' and wc.to_rule(sentdict, aux)),
        bool_to_int(aux_type == 'so' and wc.so_rule(sentdict, aux))
    ]
    return vector
Ejemplo n.º 5
0
    def test_rules(self, train_auxs):
        f = lambda x: 1 if x else 0

        predictions = []
        for i in range(len(train_auxs)):
            aux = train_auxs[i]
            sendict = self.sentences[aux.sentnum]
            tree = sendict.get_nltk_tree()
            word_subtree_positions = nt.get_smallest_subtree_positions(tree)

            if aux.type == 'modal': predictions.append(f(wc.modal_rule(sendict, aux, tree, word_subtree_positions)))
            elif aux.type == 'be': predictions.append(f(wc.be_rule(sendict, aux)))
            elif aux.type == 'have': predictions.append(f(wc.have_rule(sendict, aux)))
            elif aux.type == 'do': predictions.append(f(wc.do_rule(sendict, aux, tree, word_subtree_positions)))
            elif aux.type == 'so': predictions.append(f(wc.so_rule(sendict, aux)))
            elif aux.type == 'to': predictions.append(f(wc.to_rule(sendict, aux)))

        return predictions
Ejemplo n.º 6
0
    def test_my_rules(self, original_rules=False, idxs=None):
        self.predictions = []
        print 'Length of test set: %d, length of All_auxs-training vectors: %d' % (
            len(self.test_classes),
            len(self.all_auxiliaries) - len(self.train_vectors))
        for i in range(self.pre_oversample_length, len(self.all_auxiliaries)):
            if idxs == None or i in idxs:
                aux = self.all_auxiliaries.get_aux(i)
                sendict = self.sentences.get_sentence(aux.sentnum)
                tree = sendict.get_nltk_tree()
                word_subtree_positions = nt.get_smallest_subtree_positions(
                    tree)

                if not original_rules:
                    if aux.type == 'modal':
                        self.predictions.append(
                            vc.bool_to_int(
                                wc.modal_rule(sendict, aux, tree,
                                              word_subtree_positions)))
                    elif aux.type == 'be':
                        self.predictions.append(
                            vc.bool_to_int(wc.be_rule(sendict, aux)))
                    elif aux.type == 'have':
                        self.predictions.append(
                            vc.bool_to_int(wc.have_rule(sendict, aux)))
                    elif aux.type == 'do':
                        self.predictions.append(
                            vc.bool_to_int(
                                wc.do_rule(sendict, aux, tree,
                                           word_subtree_positions)))
                    elif aux.type == 'so':
                        self.predictions.append(
                            vc.bool_to_int(wc.so_rule(sendict, aux)))
                    elif aux.type == 'to':
                        self.predictions.append(
                            vc.bool_to_int(wc.to_rule(sendict, aux)))
                else:
                    auxidx = aux.wordnum
                    if aux.type == 'modal':
                        self.predictions.append(
                            vc.bool_to_int(
                                dv.modalcheck(sendict, auxidx, tree,
                                              word_subtree_positions)))
                    elif aux.type == 'be':
                        self.predictions.append(
                            vc.bool_to_int(
                                dv.becheck(sendict, auxidx, tree,
                                           word_subtree_positions)))
                    elif aux.type == 'have':
                        self.predictions.append(
                            vc.bool_to_int(
                                dv.havecheck(sendict, auxidx, tree,
                                             word_subtree_positions)))
                    elif aux.type == 'do':
                        self.predictions.append(
                            vc.bool_to_int(
                                dv.docheck(sendict, auxidx, tree,
                                           word_subtree_positions)))
                    elif aux.type == 'so':
                        self.predictions.append(
                            vc.bool_to_int(
                                dv.socheck(sendict, auxidx, tree,
                                           word_subtree_positions)))
                    elif aux.type == 'to':
                        self.predictions.append(
                            vc.bool_to_int(
                                dv.tocheck(sendict, auxidx, tree,
                                           word_subtree_positions)))