def evalObj(self,subj, queue, bindings, proof, query): from query import applySparqlQueries ns = self.store.newSymbol(SPARQL_NS) assert isinstance(subj, List) subj = [a for a in subj] assert len(subj) == 2 source, query = subj F = self.store.newFormula() applySparqlQueries(source, query, F) if query.contains(obj=ns['ConstructQuery']): return F if query.contains(obj=ns['SelectQuery']) or query.contains(obj=ns['AskQuery']): return self.store.newLiteral(sparql_output(query, F))
def sparql_queryString(source, queryString): from query import applySparqlQueries store = source.store ns = store.newSymbol(SPARQL_NS) from sparql import sparql_parser import sparql2cwm convertor = sparql2cwm.FromSparql(store) import StringIO p = sparql_parser.N3Parser(StringIO.StringIO(queryString), sparql_parser.branches, convertor) q = p.parse(sparql_parser.start).close() F = store.newFormula() applySparqlQueries(source, q, F) F = F.close() ## print 'result is ', F ## print 'query is ', q.n3String() return outputString(q, F)