Esempio n. 1
0
    def create_forests(self, filename=None, clear=False):
        """ This will read sentences to parse. One sentence per line, no periods etc.

        :param filename: not used
        :param clear: start with empty
        """
        if clear:
            treelist = ['hello']
        else:
            treelist = self.load_treelist_from_text_file(self.__class__.default_treeset_file) or \
                       ['hello']

        # Clear this screen before we start creating a mess
        ctrl.disable_undo() # disable tracking of changes (e.g. undo)
        if self.forest:
            self.forest.retire_from_drawing()
        self.forests = []

        grammar = load_grammar(filename=running_environment.plugins_path + '/mgtdbpE/mg0.txt')

        for line in treelist:
            sentence = line.strip()
            if (not sentence) or sentence.startswith('#'):
                continue
            syn = classes.get('SyntaxConnection')()
            syn.sentence = sentence
            syn.lexicon = grammar
            forest = Forest(gloss_text=sentence, syntax=syn)
            self.forests.append(forest)
        self.current_index = 0
        self.forest = self.forests[0]
        # allow change tracking (undo) again
        ctrl.resume_undo()
Esempio n. 2
0
    def create_forests(self, filename=None, clear=False):
        """ This will read sentences to parse. One sentence per line, no periods etc.

        :param filename: not used
        :param clear: start with empty
        """
        if clear:
            treelist = ['hello']
        else:
            treelist = self.load_treelist_from_text_file(self.__class__.default_treeset_file) or \
                       ['hello']

        # Clear this screen before we start creating a mess
        ctrl.disable_undo()  # disable tracking of changes (e.g. undo)
        if self.forest:
            self.forest.retire_from_drawing()
        self.forests = []

        grammar = load_grammar(filename=running_environment.plugins_path +
                               '/mgtdbpE/mg0.txt')

        for line in treelist:
            sentence = line.strip()
            if (not sentence) or sentence.startswith('#'):
                continue
            syn = classes.get('SyntaxConnection')()
            syn.sentence = sentence
            syn.lexicon = grammar
            forest = Forest(gloss_text=sentence, syntax=syn)
            self.forests.append(forest)
        self.current_index = 0
        self.forest = self.forests[0]
        # allow change tracking (undo) again
        ctrl.resume_undo()
Esempio n. 3
0
 def derive_from_editable_lexicon(self, sentence, lexdata, semantics=''):
     """ Take edited version of get_editable_lexicon output and try derivation with it.
     """
     grammar = load_grammar(g=lexdata)
     self.lexicon = grammar
     ctrl.disable_undo()
     f = ctrl.forest
     f.clear()
     self.sentence = sentence
     self.parser = Parser(grammar, -0.0001, forest=f)
     # parser doesn't return anything, it pushes derivation steps to forest
     self.parser.parse(sentence=self.sentence, start='C')
     ds = f.derivation_steps
     ds.derivation_step_index = len(ds.derivation_steps) - 1
     ds.jump_to_derivation_step(ds.derivation_step_index)
     f.prepare_for_drawing()
     ctrl.resume_undo()
Esempio n. 4
0
 def derive_from_editable_lexicon(self, sentence, lexdata, semantics=''):
     """ Take edited version of get_editable_lexicon output and try derivation with it.
     """
     grammar = load_grammar(g=lexdata)
     self.lexicon = grammar
     ctrl.disable_undo()
     f = ctrl.forest
     f.clear()
     self.sentence = sentence
     self.parser = Parser(grammar, -0.0001, forest=f)
     # parser doesn't return anything, it pushes derivation steps to forest
     self.parser.parse(sentence=self.sentence, start='C')
     ds = f.derivation_steps
     ds.derivation_step_index = len(ds.derivation_steps) - 1
     ds.jump_to_derivation_step(ds.derivation_step_index)
     f.prepare_for_drawing()
     ctrl.resume_undo()