-
Notifications
You must be signed in to change notification settings - Fork 146
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
Documentation examples how to use the library #656
Comments
Hi, I agree the documentation is very bad. You can read in a turtle (ttl) file and use the parse method to get the data into an rdflib store: I am not sure how to do a SPARQL query right now. Perhaps @jeff-zucker can help out with that, otherwise I need to look it up myself. |
From what I read from the API docs you could use SPARQLToQuery to convert textual SPARQL to a query object that can than be passed to querySync but I did not try this |
If you are not familiar with either RDF (turtle) or SPARQL, you may be better off starting with rdflib's built in querying functions like match() and any(). These work by matching a triple pattern. So if you want to find out everyone who is 21 years old let statements = store.match( null, SCHEMA('age'), 21);
for( let statement of statements){
console.log(statement.subject.value)
} This boils down to - find all statements, regardless of subject, that have an age (as defined in the SCHEMA vocabulary) equal to the literal value '21' and then cycle through the statements printing the value of the subject. All of this is documented in https://linkeddata.github.io/rdflib.js/Documentation/webapp-intro.html. But if that's not enough explanation, drop into the matrix chatroom for rdflib and ask as many questions as it takes. If you want to use SPARQL instead, you can do something like this : const preparedQuery = await $rdf.SPARQLToQuery( queryString, false, store );
store.query(preparedQuery, (results)=>{
// process results
} But if SPARQL is your goal, you may be better off with comunica which has a more robust SPARQL engine than rdflib does. |
@angelo-v @jeff-zucker thanks for the reply. I already contact comunica as well...main goal is to be able to retrieve data from turtle in a more "practical"...for example now after reading "manually" I end up on a situation where I actually need everything based on Thanks again |
@angelo-v from your example, it requires a |
The last piece of puzzy I need to figure is this error I am having now: |
You can parse a turtle string with So if the URI does not matter to you, you can basically pass in any URI you like, it does not need to resolve (since it won't be resolved), you just need to make sure you use the correct URIs in your query afterwards, since the relative ones will be based on that URI. |
If that URL is in a prefix declaration, it is missing a |
@jeff-zucker that's was one of the trials I made...I finally got it working! thanks for the support!!! |
Im am happy you could solve it. Documentation should nevertheless improve on that regard |
Hi,
I was suggested to use this library in order to read a
TTL
and apply a SPARQL on it. This is basically the first time I ever heard of SPARQL /TTL
files so, maybe for that reason I can't read the available documentation, I mean...the docs talks a lot about RDF, about turtles and so but I could not find a single example of library usage.Is there anyone who has an example showing use cases of reading a
ttl
or using thequery
function for example? Apparently it would be way more easier to get information out of aTTL
file by using this method. Right now my only option is to use N3 library and read the parsed data, one by one and extract the information I need based onIF/ELSE
...it can be done but not ideal if there is an alternative where I could just use a SPARQL which would give me what I need fro aTTL
file.Thanks in advance,
The text was updated successfully, but these errors were encountered: