def __init__(self): super().__init__() self.Constituent = classes.get("Constituent") self.Feature = classes.get("Feature") self.trees = [] self.constituents = {} self.features = {} self.lexicon = {} self.rules = {} self.sentence = "" for key, value in self.options.items(): self.rules[key] = value.get("default")
def __init__(self): super().__init__() self.Constituent = classes.get('Constituent') self.Feature = classes.get('Feature') self.trees = [] self.constituents = {} self.features = {} self.lexicon = {} self.rules = {} self.sentence = '' for key, value in self.options.items(): self.rules[key] = value.get('default')
def __init__(self): SavedObject.__init__(self) self.Constituent = classes.get('Constituent') self.Feature = classes.get('Feature') self.trees = [] self.constituents = {} self.features = {} self.lexicon = {} self.rules = {} self.sentence = '' self.parser = None self.syntax_display_mode = 2 for key, value in self.options.items(): self.rules[key] = value.get('default')
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()
def init_forest_keepers(self): """ Put empty forest keepers (Kataja documents) in place -- you want to do this after plugins have changed the classes that implement these. :return: """ self.forest_keepers = [classes.get('KatajaDocument')()] self.forest_keeper = self.forest_keepers[0] ctrl.call_watchers(self.forest_keeper, 'document_changed')
def __init__(self, gloss_text='', comments=None, syntax=None): """ Create an empty forest. Gloss_text and comments are metadata about trees that doesn't belong to syntax implementation, so its kept here. Syntax implementations may still use it. By default, a new Forest doesn't create its nodes -- it doesn't do the derivation yet. This is to save speed and memory with large structures. If the is_parsed -flag is False when created, but once Forest is displayed, the derivation has to run and after that is_parsed is True. """ super().__init__() self.nodes_from_synobs = {} self.main = ctrl.main self.main.forest = self # assign self to be the active forest while # creating the managers. self.in_display = False self.visualization = None self.gloss = None self.is_parsed = False self.syntax = syntax or classes.get('SyntaxConnection')() self.parser = INodeToKatajaConstituent(self) self.undo_manager = UndoManager(self) self.chain_manager = ChainManager(self) self.tree_manager = TreeManager(self) self.free_drawing = FreeDrawing(self) self.projection_manager = ProjectionManager(self) self.derivation_steps = DerivationStepManager(self) self.old_label_mode = 0 self.trees = [] self.nodes = {} self.edges = {} self.groups = {} self.others = {} self.vis_data = {} self.width_map = {} self.traces_to_draw = {} self.comments = [] self.gloss_text = '' self.ongoing_animations = set() self.halt_drawing = False self.gloss_text = gloss_text self.comments = comments # Update request flags self._do_edge_visibility_check = False
def __init__(self, gloss_text='', comments=None, syntax=None): """ Create an empty forest. Gloss_text and comments are metadata about trees that doesn't belong to syntax implementation, so its kept here. Syntax implementations may still use it. By default, a new Forest doesn't create its nodes -- it doesn't do the derivation yet. This is to save speed and memory with large structures. If the is_parsed -flag is False when created, but once Forest is displayed, the derivation has to run and after that is_parsed is True. """ super().__init__() self.nodes_from_synobs = {} self.main = ctrl.main self.main.forest = self # assign self to be the active forest while # creating the managers. self.in_display = False self.visualization = None self.gloss = None self.is_parsed = False self.syntax = syntax or classes.get('SyntaxConnection')() self.parser = INodeToKatajaConstituent(self) self.undo_manager = UndoManager(self) self.chain_manager = ChainManager(self) self.tree_manager = TreeManager(self) self.free_drawing = FreeDrawing(self) self.projection_manager = ProjectionManager(self) self.derivation_steps = DerivationStepManager(self) self.trees = [] self.nodes = {} self.edges = {} self.groups = {} self.others = {} self.vis_data = {} self.width_map = {} self.traces_to_draw = {} self.comments = [] self.gloss_text = '' self.ongoing_animations = set() self.halt_drawing = False self.gloss_text = gloss_text self.comments = comments # Update request flags self._do_edge_visibility_check = False
def create_forests(self, filename=None, clear=False): """ This will read list of strings where each line defines a trees or an element of trees. This can be used to reset the KatajaDocument if no treeset or an empty treeset is given. It is common to override this method in plugins to provide custom commands for e.g. running parsers. Example of tree this can read: [.AspP [.Asp\\Ininom] [.vP [.KP [.K\\ng ] [.DP [.D´ [.D ] [.NP\\lola ]] [.KP [.K\\ng] [.DP [.D´ [.D ] [.NP\\alila ] ] [.KP\\{ni Maria} ]]]]] [.v´ [.v ] [.VP [.V ] [.KP\\{ang tubig}]]]]] Ininom = drank ng = NG ng = NG lola = grandma alila = servant ni Maria = NG Maria ang tubig = ANG water 'Maria's grandmother's servant drank the water' :param filename: (optional) file to load from :param clear: (optional) if True, start with an empty treeset and don't attempt to load examples """ print('************* create forests ****************') if clear: treelist = [] else: treelist = self.load_treelist_from_text_file( self.__class__.default_treeset_file) or [] # 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 = [] # buildstring is the bracket trees or trees. buildstring = [] # definitions includes given definitions for constituents of this trees definitions = {} # gloss_text is the gloss for whole trees gloss_text = '' # comments are internal notes about the trees, displayed as help text or something comments = [] started_forest = False syntax_class = classes.get('SyntaxConnection') for line in treelist: line = line.strip() #line.split('=', 1) parts = line.split('=', 1) # comment line if line.startswith('#'): if started_forest: comments.append(line[1:]) # Definition line elif len(parts) > 1 and not line.startswith('['): started_forest = True word = parts[0].strip() values = parts[1] definitions[word] = values # Gloss text: elif line.startswith("'"): if started_forest: if line.endswith("'"): line = line[:-1] gloss_text = line[1:] # empty line: finalize this forest elif started_forest and not line: syn = syntax_class() syn.sentence = buildstring syn.lexicon = definitions forest = Forest(gloss_text=gloss_text, comments=comments, syntax=syn) self.forests.append(forest) started_forest = False # trees definition starts a new forest elif line and not started_forest: started_forest = True buildstring = line definitions = {} gloss_text = '' comments = [] # another trees definition, append to previous elif line: buildstring += '\n' + line if started_forest: # make sure that the last forest is also added syn = syntax_class() syn.sentence = buildstring syn.lexicon = definitions forest = Forest(gloss_text=gloss_text, comments=comments, syntax=syn) self.forests.append(forest) if not self.forests: syn = syntax_class() forest = Forest(gloss_text='', comments=[], syntax=syn) self.forests.append(forest) self.current_index = 0 self.forest = self.forests[0] # allow change tracking (undo) again ctrl.resume_undo()
def create_forests(self, filename=None, clear=False): """ This will read list of strings where each line defines a trees or an element of trees. This can be used to reset the KatajaDocument if no treeset or an empty treeset is given. It is common to override this method in plugins to provide custom commands for e.g. running parsers. Example of tree this can read: [.AspP [.Asp\\Ininom] [.vP [.KP [.K\\ng ] [.DP [.D´ [.D ] [.NP\\lola ]] [.KP [.K\\ng] [.DP [.D´ [.D ] [.NP\\alila ] ] [.KP\\{ni Maria} ]]]]] [.v´ [.v ] [.VP [.V ] [.KP\\{ang tubig}]]]]] Ininom = drank ng = NG ng = NG lola = grandma alila = servant ni Maria = NG Maria ang tubig = ANG water 'Maria's grandmother's servant drank the water' :param filename: (optional) file to load from :param clear: (optional) if True, start with an empty treeset and don't attempt to load examples """ print("************* create forests ****************") if clear: treelist = [] else: treelist = self.load_treelist_from_text_file(self.__class__.default_treeset_file) or [] # 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 = [] # buildstring is the bracket trees or trees. buildstring = [] # definitions includes given definitions for constituents of this trees definitions = {} # gloss_text is the gloss for whole trees gloss_text = "" # comments are internal notes about the trees, displayed as help text or something comments = [] started_forest = False syntax_class = classes.get("SyntaxConnection") for line in treelist: line = line.strip() # line.split('=', 1) parts = line.split("=", 1) # comment line if line.startswith("#"): if started_forest: comments.append(line[1:]) # Definition line elif len(parts) > 1 and not line.startswith("["): started_forest = True word = parts[0].strip() values = parts[1] definitions[word] = values # Gloss text: elif line.startswith("'"): if started_forest: if line.endswith("'"): line = line[:-1] gloss_text = line[1:] # empty line: finalize this forest elif started_forest and not line: syn = syntax_class() syn.sentence = buildstring syn.lexicon = definitions forest = Forest(gloss_text=gloss_text, comments=comments, syntax=syn) self.forests.append(forest) started_forest = False # trees definition starts a new forest elif line and not started_forest: started_forest = True buildstring = line definitions = {} gloss_text = "" comments = [] # another trees definition, append to previous elif line: buildstring += "\n" + line if started_forest: # make sure that the last forest is also added syn = syntax_class() syn.sentence = buildstring syn.lexicon = definitions forest = Forest(gloss_text=gloss_text, comments=comments, syntax=syn) self.forests.append(forest) if not self.forests: syn = syntax_class() forest = Forest(gloss_text="", comments=[], syntax=syn) self.forests.append(forest) self.current_index = 0 self.forest = self.forests[0] # allow change tracking (undo) again ctrl.resume_undo()