Beispiel #1
0
def old_rules_vector(sentdict, aux, tree, subtree_positions):
    aux_type = aux.type
    vector = [bool_to_int(aux_type == 'modal' and modalcheck(sentdict, aux.wordnum, tree, subtree_positions)),
              bool_to_int(aux_type == 'be' and becheck(sentdict, aux.wordnum, tree, subtree_positions)),
              bool_to_int(aux_type == 'have' and havecheck(sentdict, aux.wordnum, tree, subtree_positions)),
              bool_to_int(aux_type == 'do' and docheck(sentdict, aux.wordnum, tree, subtree_positions)),
              bool_to_int(aux_type == 'to' and tocheck(sentdict, aux.wordnum, tree, subtree_positions)),
              bool_to_int(aux_type == 'so' and socheck(sentdict, aux.wordnum, tree, subtree_positions))]
    return vector
Beispiel #2
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))
                        )
Beispiel #3
0
def old_rules_vector(sentdict, aux, tree, subtree_positions):
    aux_type = aux.type
    vector = [
        bool_to_int(
            aux_type == 'modal'
            and modalcheck(sentdict, aux.wordnum, tree, subtree_positions)),
        bool_to_int(
            aux_type == 'be'
            and becheck(sentdict, aux.wordnum, tree, subtree_positions)),
        bool_to_int(
            aux_type == 'have'
            and havecheck(sentdict, aux.wordnum, tree, subtree_positions)),
        bool_to_int(
            aux_type == 'do'
            and docheck(sentdict, aux.wordnum, tree, subtree_positions)),
        bool_to_int(
            aux_type == 'to'
            and tocheck(sentdict, aux.wordnum, tree, subtree_positions)),
        bool_to_int(
            aux_type == 'so'
            and socheck(sentdict, aux.wordnum, tree, subtree_positions))
    ]
    return vector
Beispiel #4
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)))