def __retrieve_property_values(self, uri, new_property_labels): if uri is None: return None query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " query += "SELECT ?p ?o WHERE { <%s> ?p_tmp ?o. ?p_tmp rdfs:label ?p }" % uri self.__sparql.setQuery(query) results = self.__sparql.query().convert() result_dict = {} for row in results["results"]["bindings"]: property_label = clean_with_unders(row["p"]["value"]) if property_label in new_property_labels: result_dict[property_label] = row["o"]["value"] return result_dict
def __get_properties_query(self): query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbo: <http://dbpedia.org/ontology/> " query += "SELECT DISTINCT ?property_label WHERE { " query += "{ " query += "?property rdfs:domain ?class. " query += "dbo:%s rdfs:subClassOf+ ?class. " % self.__entity_type query += "} UNION {" query += "?property rdfs:domain dbo:%s" % self.__entity_type query += "} " query += "?property rdfs:label ?property_label. " query += "FILTER (langMatches(lang(?property_label), \"EN\")). }" self.__sparql.setQuery(query) results = self.__sparql.query().convert() if len(results["results"]["bindings"]) == 0: return None property_labels = [clean_with_unders(row["property_label"]["value"]) for row in results["results"]["bindings"]] return property_labels
def test_clean_with_unders(self): string = "ahdsf. a?" string_with_unders = clean_with_unders(string) self.assertEqual(string_with_unders, "ahdsf_a")