def _get_union_of_graphs(graph_list): g = Graph(directed=True) db = GraphDatabase(g) query = "" for g in graph_list: query += f" CREATE {convert_graph_to_string(g)}" db.query(query) return db.get_graph()
def visit(self, g): if not isinstance(g, Graph): raise TypeError( "DrsRule.visit_to_graph() needs an igraph.Graph as an argument" ) db = GraphDatabase(g) lst = db.query(self._rules, repeat_n_times=1) return lst
def visit(self, g): if not isinstance(g, Graph): raise TypeError( "DrsRule.visit_to_graph() needs an igraph.Graph as an argument" ) db = GraphDatabase(g, node_matcher=VectorNodeMatcher(self.metric)) rule = 'MATCH ' + str(self.small_drs) + ' RETURN __RESULT__;' lst = db.query(rule) return lst
def visit(self, g): if not isinstance(g, Graph): raise TypeError("DrsRule.visit_to_graph() needs an igraph.Graph as an argument") db = GraphDatabase(g, node_matcher=VectorNodeMatcher(self.metric), code_container_factory=DummyCodeContainerFactory()) lst = db.query(str(self.text), repeat_n_times=5) if lst: return True return False
def __get_relations_and_entities_from_graph(self, g): if not isinstance(g, Graph): raise TypeError("The writer needs an igraph.Graph as an argument") db = GraphDatabase(g) lst = db.query( "MATCH {}(a), {'type': 'relation', 'name': 'r'}(a,b), {}(b) RETURN a, b, r", repeat_n_times=5) triplets = [(self.__get_correct_name(item['a'], g), item['r']['text'], self.__get_correct_name(item['b'], g)) for item in lst] return list(unique_everseen(triplets, key=tuple))
def _create_graph_from_natural_language(sentence): g = Graph(directed=True) db = GraphDatabase(g) parser = Parser(db) parsed_dict = parser.execute(sentence) db = parsed_dict['graph'] n = 10 db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/verbs.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/names.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/various.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/prepositions.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/punctuation.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/compound1.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/compound2.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/adjectives.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/delete.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/subordinates.parvus')).read(), n) db = repeat_db_rules_n_times( db, open(os.path.join(_path, '../rules/parsing/recursive.parvus')).read(), n) return { 'graph': db.get_graph(), 'word_nodes': parsed_dict['word_nodes'], }
def visit(self, g): prior_names = [] db = GraphDatabase(g) for v in g.vs: refers_to = v['refers_to'] if refers_to: prior_names_string = '[' + ' '.join( ['"' + item + '"' for item in prior_names]) + ']' db.query(self._rules % (str(refers_to), v['name'], str(refers_to), prior_names_string), repeat_n_times=1) prior_names.append(v['name']) return True