def test_pure_sentence_2(self): node_type = "test_type" node_params = {'param1': 'param1_test', 'param2': 'param2_test'} node_id = 1 node = Node(node_type, node_params, node_id) assert node.node_params == node_params \ and node.node_type == node_type \ and node.node_id == node_id
def get_nodes_from_words(self, words: list, script_name: str, action: list, entity: list, context: list): nodes = [] for word in words: node_params = {'name': word, 'action': [], "entity": [], "context": []} if word in action: node_params['action'].append(script_name) if word in entity: node_params['entity'].append(script_name) if word in context: node_params['context'].append(script_name) node = Node(self.node_type, node_params) nodes.append(node) return nodes
def update_node(self, old_node: Node, new_node: Node): old_params = old_node.node_params new_params = new_node.node_params merged_type = new_node.node_type merged_params = {} for param in new_params: if param in old_params: if type(new_params[param]) == list: merged_params[ param] = old_params[param] + new_params[param] else: merged_params[param] = new_params[param] else: merged_params[param] = new_params[param] merged_node = Node(merged_type, merged_params, old_node.node_id) node_id = old_node.node_id for param in old_params: query_template = Template( "MATCH (n) WHERE id(n)=$node_id SET n.$param = NULL RETURN n") query = query_template.substitute(node_id=node_id, param=param) self.graph.run(query) for param in merged_params: value = merged_params[param] if type(value) == str: value = "'" + value + "'" query_template = Template( "MATCH (n) WHERE id(n)=$node_id SET n.$param = $value RETURN n" ) query = query_template.substitute(node_id=node_id, param=param, value=value) self.graph.run(query) return merged_node
def test_incorrect_node_params(self): node_type = "test_type" node_params = ["some_param1", "some_param2"] with pytest.raises(nodeError.CreateError): Node(node_type, node_params)
def test_incorrect_node_type(self): node_type = 1 node_params = {'param1': 'param1_test', 'param2': 'param2_test'} with pytest.raises(nodeError.CreateError): Node(node_type, node_params)