Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-LD and SPARQL #149

Closed
twistylittleworkshop opened this issue Mar 5, 2017 · 1 comment
Closed

JSON-LD and SPARQL #149

twistylittleworkshop opened this issue Mar 5, 2017 · 1 comment

Comments

@twistylittleworkshop
Copy link

twistylittleworkshop commented Mar 5, 2017

Hi,

My RDF/SPARQL/rdfstore-js knowledge may be at fault here, but I'm trying to SPARQL-query a store created from JSON-LD, using fragments of code from the doc (src below) and the latest (0.9.17) .min.js version. The higher level node() func returns the triples, the registeredGraphs() func returns the graph URI, which I have tried as default and named graphs to the query call. At best, a zero-length array is returned from the SPARQL query. Same results if I embed the global callback into the store callbacks.

What am I not getting correct here?

Many thanks.

==================


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/lib/rdfstore_min.js"></script>
<style>
</style>
<script type="text/javascript">
var global_store_ = null
var storeLoaded = function () {
	global_store_.node("ex:john_smith", "ex:test", function(err, graph) {
		console.log(graph)
	})
	global_store_.registeredGraphs(function(success, graphs){
		var graph_uris = graphs.map(function(namedNode){
			console.log(namedNode.nominalValue)
		});
	});
	// simple query execution
	global_store_.execute("SELECT * {?s ?p ?o }",
		function(err, results){
			console.log(results.length)
		}
	)
}
window.onload = function load (){
	rdfstore.create(function(err, store) {
		global_store_ = store
	        jsonld = {
	          "@context":
	          {
	             "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
	             "xsd": "http://www.w3.org/2001/XMLSchema#",
	             "name": "http://xmlns.com/foaf/0.1/name",
	             "age": {"@id": "http://xmlns.com/foaf/0.1/age", "@type": "xsd:integer" },
	             "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "xsd:anyURI" },
	             "ex": "http://www.example.org/people/"
	          },
	          "@id": "ex:john_smith",
	          "name": "John Smith",
	          "age": "41",
	          "homepage": "http://example.org/home/"
	        }
		store.setPrefix("ex", "http://www.example.org/people/")
		store.load("application/ld+json", jsonld, "ex:test", function(err,results) {console.log(results);storeLoaded()})
	});
}
</script>
</head>
<body>
</body>
</html>
@twistylittleworkshop
Copy link
Author

Okay, stand down. From a discussion in a resolved issue here, I must have not tried the exact combination of specifying default/named graphs. Smoothly running now, corrected code below:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/lib/rdfstore_min.js"></script>
<style>
</style>
<script type="text/javascript">
var global_store_ = null
var storeLoaded = function () {
	global_store_.node("ex:john_smith", "ex:test", function(err, graph) {
		console.log(graph)
	})
	global_store_.registeredGraphs(function(success, graphs){
		var graph_uris = graphs.map(function(namedNode){
			console.log(namedNode.nominalValue)
		});
	});
	// simple query execution
	global_store_.execute("SELECT * {?s ?p ?o }", ["http://www.example.org/people/test"],[],
		function(err, results){
			for (var i_ in results)
				console.log(results[i_])
		}
	)
}
window.onload = function load (){
	rdfstore.create(function(err, store) {
		global_store_ = store
	        jsonld = {
	          "@context":
	          {
	             "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
	             "xsd": "http://www.w3.org/2001/XMLSchema#",
	             "name": "http://xmlns.com/foaf/0.1/name",
	             "age": {"@id": "http://xmlns.com/foaf/0.1/age", "@type": "xsd:integer" },
	             "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "xsd:anyURI" },
	             "ex": "http://www.example.org/people/"
	          },
	          "@id": "ex:john_smith",
	          "name": "John Smith",
	          "age": "41",
	          "homepage": "http://example.org/home/"
	        }
		store.setPrefix("ex", "http://www.example.org/people/")
		store.load("application/ld+json", jsonld, "ex:test", function(err,results) {console.log(results);storeLoaded()})
	});
}
</script>
</head>
<body>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant