Reputation: 1198
I'm practicing some SPARQL queries and features, my problem is that whenever I get new RDF data, I go to protoge, build classes and relationships and instances that accompany to these RDF, then explore these data, then import it to a dataset in Fuseki, then I query it. and if I make any mistake in my data, I'd need to repeat the whole process.
It's becoming tedious and time consuming, that's why I badly need to ask you if there's a place (tool or a fuseki support plugin ... or anything ..) where I can write my simple rdf data directly and then query it from my fuseki.
that data I want to write for example is really simple, it's like this:
@prefix dei: <http://www.warsaw.pl/ > .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
dei:~rcardish/
rdf:type foaf:Person ;
foaf:name “Rafa Cardish" ;
foaf:member <http://www.warsaw.pl> ;
rdfs:SeeAlso <http://www.linkedin.com/in/rafacardish>
but even that simple and small rdf takes me time in my current way.
Your help is appreciated.
Now I can do this to load my data into fuseki
./fuseki-server --file=/Users/bla bla bla/rdfData.rdf /testdataset
and this is the data
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix : <http://example.org/book/> .
@prefix ns: <http://example.org/ns#> .
:book1 dc:title "SPARQL Tutorial" .
:book1 ns:price 42 .
:book1 ns:discount 0.2 .
:book2 dc:title "The Semantic Web" .
:book2 ns:price 23 .
:book2 ns:discount 0.25 .
but I don't know how to query it because when i run Fuseki, i go to query and I have to select a dataset but here there is no dataset shown in the drop down
Now it's working, my mistake is that the file extension was .ttl.rdf, when I make it .ttl alone it works
Upvotes: 1
Views: 854
Reputation: 1801
You can use command line tools (e.g. Redland tools) or write a simple script to load RDF and run SPARQL queries over it (e.g. using RDFlib):
1) Using Redland: roqet query.rq -D data.ttl -r json
Runnit it with a query for ?s dc:title ?title
using your example data returns:
"bindings" : [
{
"s" : { "type": "uri", "value": "http://example.org/book/book1" },
"title" : { "type": "literal", "value": "SPARQL Tutorial" }
},
{
"s" : { "type": "uri", "value": "http://example.org/book/book2" },
"title" : { "type": "literal", "value": "The Semantic Web" }
}
]
JSON is one of result formats but you can also get CSV, etc.
See also: Command line Semantic Web with Redland
2) Using RDFlib to run SPARQL queries is also quite a compact way to do this (in Python):
import rdflib
g = rdflib.Graph()
g.parse("data.ttl", format="n3")
qres = g.query(
"""SELECT DISTINCT *
WHERE {
?s dc:title ?title .
}""")
for row in qres:
print("%s : %s" % row)
Results:
http://example.org/book/book1 : SPARQL Tutorial
http://example.org/book/book2 : The Semantic Web
Upvotes: 1
Reputation: 85913
You can use Jena's command line tools to run SPARQL queries easily. In the Jena distribution, there's a sparql executable with --query and --data flags. Once you have your RDF file (if you're writing by hand, I'd suggest using the Turtle/N3 serialization and giving your file the .ttl or .n3 suffix), and then it's easy to run a query. For instance, when I have a data.n3 file like this:
@prefix : <http://stackoverflow.com/a/35854800/1281433/>
<http://stackoverflow.com/users/1281433/> :hasUserName "Joshua Taylor" .
and a query.rq like this:
prefix : <http://stackoverflow.com/a/35854800/1281433/>
select ?user where {
?user :hasUserName "Joshua Taylor"
}
Then I can get output like this:
$ sparql --query query.rq --data data.n3
---------------------------------------------
| user |
=============================================
| <http://stackoverflow.com/users/1281433/> |
---------------------------------------------
Upvotes: 0