class Engine: def __init__(self): self.sparql = QueryExecution() self.entityLinker = EntityLinkers('sparqllinker') self.typeLinker = SynsetLinker() self.query_processor = Query() self.config = Configuration() self.gpcs = ['gpc1','gpc2'] self.split_n = 5 self.qgp = QueryGraphPattern() @staticmethod def chunks(l, n): """ Yield successive n-sized chunks from l. """ for i in xrange(0, len(l), n): yield l[i:i+n] @staticmethod def remove_list_duplicates(lst): return list(set(lst)) def type_entity_query_construction(self, query): type_links = self.types(query) entity_links = self.entities(query) queries = [] for e in entity_links: for gpc in self.gpcs: for t in Engine.chunks(type_links, self.split_n): queries.append(self.qgp.type_entity_query(gpc,t,e)) return queries def entity_literal_query_construction(self, e, p): pass def search_types(self, query, sim, th): return self.typeLinker.searching(query, sim, th) def sparql_execution(self, name, queries): results_dic = {} for q in queries: results = self.sparql.execute(name, q) for key in results.keys(): if key not in results_dic: results_dic[key] = results[key] return [results_dic[key] for key in results_dic.keys()] def types(self, query): return self.typeLinker.linking(query) def entities(self, query): return self.entityLinker.linking(query) def search(self, query): queries = self.type_entity_query_construction(query) return self.sparql_execution('teq', queries)
def __init__(self): self.sparql = QueryExecution() self.entityLinker = EntityLinkers('sparqllinker') self.typeLinker = SynsetLinker() self.query_processor = Query() self.config = Configuration() self.gpcs = ['gpc1','gpc2'] self.split_n = 5 self.qgp = QueryGraphPattern()