def _on_moved(event):
     node = self.nodes.match(name=note_name(event.src_path)).first()
     new_name = note_name(event.dest_path)
     # TODO: What if this name already exists in the vault?
     node.name = new_name
     node.obsidian_url = obsidian_url(new_name, self.vault_name)
     self.graph.push(node)
 def _on_moved(event):
     if smdc.DEBUG:
         print("On moved", event.src_path, event.dest_path, flush=True)
     old_name = note_name(event.src_path)
     node = self.nodes.match(name=old_name).first()
     new_name = note_name(event.dest_path)
     # TODO: What if this name already exists in the vault?
     node['name'] = new_name
     node['obsidian_url'] = obsidian_url(new_name, self.vault_name)
     node[PROP_PATH] = event.dest_path
     self.graph.push(node)
     print(f"onSMDMovedEvent/{old_name}/{new_name}", flush=True)
 def _on_deleted(event):
     name = note_name(event.src_path)
     node = self.nodes.match(name=name).first()
     in_rels = self.relationships.match([None, node])
     if len(in_rels) > 0:
         # If there are still active incoming links, keep the node as a reference
         node.clear()
         node.clear_labels()
         node.add_label(CAT_DANGLING)
         node.name = escape_cypher(name)
         node.obsidian_url = escape_cypher(obsidian_url(name, self.vault_name))
         self._clear_outgoing(node)
     else:
         self.graph.delete(node)
    def _process_node_on_graph(self, note: Note):
        in_graph = self.nodes.match(name=note.name)
        if len(in_graph) == 0:
            # Create new node
            node = node_from_note(note)
            self.graph.create(node)
            return
        # Update
        node = in_graph.first()
        # Update labels
        node.clear_labels()
        note_tags = map(escape_cypher, note.tags)
        node.update_labels(note_tags)
        for tag in note_tags:
            if tag not in self.tags:
                properties = ['name', 'aliases']
                # TODO: Is this too slow?
                if True:
                    properties.append("content")
                create_index(self.graph, tag, properties)
                self.tags.add(tag)
        # Update properties
        node.clear()
        escaped_properties = {}
        for key, value in note.properties.items():
            escaped_properties[key] = escape_cypher(str(value))
        node.update(escaped_properties)
        self.graph.push(node)

        # Delete active relations
        self._clear_outgoing(node)

        # Insert up-to-date relations
        subgraph = None
        for trgt, rels in note.out_rels.items():
            trgt_node = self.nodes.match(name=trgt)
            if len(trgt_node) == 0:
                trgt_node = Node(CAT_DANGLING, name=escape_cypher(trgt),
                                 obsidian_url=escape_cypher(obsidian_url(trgt, self.vault_name)))
                if subgraph is None:
                    subgraph = trgt_node
                else:
                    subgraph = subgraph | trgt_node
            else:
                trgt_node = trgt_node.first()
            # Possibly refactor this with
            subgraph = add_rels_between_nodes(rels, node, trgt_node, subgraph)
        if subgraph is not None:
            self.graph.create(subgraph)
 def _on_deleted(event):
     if smdc.DEBUG:
         print("On deleted", event.src_path, flush=True)
     name = note_name(event.src_path)
     node = self.nodes.match(name=name).first()
     node_id = node.identity
     in_rels = self.relationships.match([None, node])
     if len(in_rels) > 0:
         # If there are still active incoming links, keep the node as a reference
         node.clear()
         node.clear_labels()
         node.add_label(CAT_DANGLING)
         node.name = escape_cypher(name)
         node.obsidian_url = escape_cypher(
             obsidian_url(name, self.vault_name))
         self._clear_outgoing(node)
     else:
         self.graph.delete(node)
     print(f"onSMDDeletedEvent/{node_id}", flush=True)