Ejemplo n.º 1
0
 def get_active(self):
     if self.state.visualization_settings["chapter_mode"]:
         chapter_tree = self.state.build_chapter_trees()[1]
         return node_ancestry(
             chapter_tree[self.state.chapter(self.selected_node)['id']],
             chapter_tree)
     else:
         return node_ancestry(self.selected_node, self.state.tree_node_dict)
Ejemplo n.º 2
0
 def calc_canonical_set(self):
     canonical_set = set()
     for node_id in self.canonical:
         for node in node_ancestry(self.tree_node_dict[node_id],
                                   self.tree_node_dict):
             canonical_set.add(node["id"])
     return canonical_set
Ejemplo n.º 3
0
 def node_ancestry_text(self, node=None):
     node = node if node else self.selected_node
     text = []
     end_indices = []
     index = 0
     for node in node_ancestry(node, self.tree_node_dict):
         text.append(node["text"])
         index += len(node["text"])
         end_indices.append(index)
     return text, end_indices
Ejemplo n.º 4
0
 def expand_node(self, node, change_selection=True, center_selection=True):
     ancestry = node_ancestry(node, self.state.tree_node_dict)
     for ancestor in ancestry:
         ancestor['open'] = True
     if change_selection or not self.selected_node['open']:
         #self.controller.nav_select(node)
         self.select_node(node)
     self.draw(self.root,
               self.selected_node,
               center_on_selection=center_selection)
Ejemplo n.º 5
0
 def construct_memory(self, node):
     ancestry = node_ancestry(node, self.tree_node_dict)
     memories = []
     for i, ancestor in enumerate(ancestry):
         if 'memories' in ancestor:
             for memory_id in ancestor['memories']:
                 memory = self.memories[memory_id]
                 if (memory['inheritability'] == 'none' and memory['root_id'] == node['id']) \
                         or memory['inheritability'] == 'subtree' \
                         or (memory['inheritability'] == 'delayed' and i < self.context_window_index()):
                     memories.append(memory)
     return memories
Ejemplo n.º 6
0
    def semantic_search_memory(self,
                               node,
                               document_limit=100,
                               max_length=1000):
        documents = []

        # join nodes that are too small
        for ancestor in node_ancestry(node, self.tree_node_dict)[:-1]:
            text = ancestor['text']
            while len(text) > max_length:
                documents.append(text[:max_length])
                text = text[max_length:]
            documents.append(text)
        #documents.reverse()
        query = node['text']
        return search(query, documents)
Ejemplo n.º 7
0
    def select_node(self, node_id, fire_callbacks=True):
        if self.selected_node_id != node_id and self.tree_node_dict and node_id in self.tree_node_dict:
            self.pre_selection_updated()

            self.selected_node_id = node_id
            self.selected_node["visited"] = True
            self.tree_raw_data["selected_node_id"] = self.selected_node_id

            # Open all parents but not the node itself
            ancestors = node_ancestry(self.selected_node, self.tree_node_dict)
            for ancestor in ancestors[:-1]:
                ancestor["open"] = True
            # Always open the root
            self.tree_raw_data["root"]["open"] = True

            if fire_callbacks:
                self.selection_updated()
            return self.selected_node