def remove_actor_bad_uris(self): self.__sparql = SPARQLWrapper( 'http://localhost:5820/BestLinkedMovieDatabase/update') self.__sparql.setMethod(POST) self.__sparql.setReturnFormat(JSON) self.__sparql.setQuery(Queries.remove_bad_actor_dbp_refs()) self.__sparql.query()
def match_actors(self, uri_chunks: Tuple): response = None with open('Data/DBPediaActors.ttl', 'wb') as output: for uri_chunk in uri_chunks: uri_string = "(" + "".join(uri + "," for uri in uri_chunk)[:-1] + ")" self.__sparql.setQuery( Queries.dbpedia_uris_to_resources(uri_string, 'Person')) response = self.__sparql.query().convert() output.write(response) output.flush() return response
def clean_actor_uris(self, uris) -> Graph or None: cleaned_graph = Graph() self.__sparql.setQuery( Queries.lmdb_actors_to_dbpedia_movie_uri_pairs()) response = self.__sparql.query().convert() pairs = list( map(Stardog.__to_movie_clean_uri_pair, response["results"]["bindings"])) if len(pairs) == 0: return None for lmdb_resource, dbp_uri in pairs: lmdb_resource = URIRef(lmdb_resource) dbp_uri = URIRef( dbp_uri.replace('"', "").replace("'", "").replace("`", "")) cleaned_graph.add((lmdb_resource, namespace.OWL.sameAs, dbp_uri)) cleaned_graph.serialize('Data/CleanedLMDBActorSameAs.ttl', format='turtle') return cleaned_graph # It is now safe to import the cleaned data using stardog.
def get_actors(self) -> Tuple: self.__sparql.setQuery(Queries.lmdb_actors_to_dbpedia_uris()) response = self.__sparql.query().convert() uris = list(map(Stardog.__to_uri, response["results"]["bindings"])) return tuple(tuple(uris[i:i + 100]) for i in range(0, len(uris), 100))