def _to_table(self, result): if not isinstance(result, dict): return result if "results" not in result: return result converted = [] for binding in result["results"]["bindings"]: rdf_item = {} for key, obj in list(binding.items()): try: rdf_item[key] = json_to_rdflib(obj) except ValueError: continue converted.append(rdf_item) return converted
def _to_table(self, result): if not isinstance(result, dict): return result if "results" not in result: return result converted = [] for binding in result["results"]["bindings"]: rdf_item = {} for key, obj in binding.items(): try: rdf_item[key] = json_to_rdflib(obj) except ValueError: continue converted.append(rdf_item) return converted
def _execute(self, query): q_string = unicode(query) result = self.execute_sparql(q_string) if type(result) == bool: return result converted = [] for binding in result["results"]["bindings"]: rdf_item = {} for key, obj in binding.items(): try: rdf_item[key] = json_to_rdflib(obj) except ValueError: continue converted.append(rdf_item) return converted
def _execute(self, query): q_string = unicode(query) result = self.execute_sparql(q_string) if 'boolean' in result: return result['boolean'] converted = [] for binding in result["results"]["bindings"]: rdf_item = {} for key, obj in binding.items(): try: rdf_item[key] = json_to_rdflib(obj) except ValueError: continue converted.append(rdf_item) return converted
def test_json_datatypes(self): """ Test that proper datatypes are returned. """ # Tests for a bug wrt datatype uri with AllegroGraph store, session = self._get_store_session(use_default_context=False) Person = session.get_class(surf.ns.FOAF + "Person") # Store datatype jake = session.get_resource("http://Jake", Person) jake.foaf_name = "Jake" jake.foaf_age = 62 jake.save() # Get birthday query = select('?age').where(('?s', a, Person.uri), ('?s', ns.FOAF.age, '?age')) result = store.execute_sparql(unicode(query)) assert len(result['results']['bindings']) == 1 entry = result['results']['bindings'][0] # Test that rdflib type is properly constructed age = json_to_rdflib(entry['age']) self.assertEquals(age.toPython(), 62)