简体   繁体   中英

Get all data with specific property SPARQL

I have simple RDF data set with following values: user, url, time and ip. I can list all the data using:

SELECT DISTINCT * WHERE { ?s ?p ?o }

But now I need to list all the data with specific user. I would very much appreciate if the data from the query would be in the same format as the data from above query but it is not necessary.
I tried this and some modifications to this but none of it seems to work:

SELECT DISTINCT * WHERE { ?s ?p ?o. ?u foaf:user username. }

I am just starting to work with Jena and SPARQL and any help will be much appreciated. Thanks in advance.

EDIT: @AKSW foaf:user works because foaf is my own prefix I defined. I struggled with getting the queries working and had no clue what I was doing. This is something I hadn't clean up yet.
I ended up using query SELECT DISTINCT * WHERE {?u foaf:name USER_NAME_LITERAL . ?u ?p ?o . } SELECT DISTINCT * WHERE {?u foaf:name USER_NAME_LITERAL . ?u ?p ?o . } SELECT DISTINCT * WHERE {?u foaf:name USER_NAME_LITERAL . ?u ?p ?o . } which was the one you suggested, so thank you. If you post it as answer I will mark it as accepted.

Assuming your data set consists of records of class :Record with fields :user , :url , :time and :ip :

SELECT * { ?r   ?p      ?o;
                 a      :Record;
                :user   ?u.
           ?u   :name "your user name".
          }

Or, assuming that you know that the URI of the user is :user123:

SELECT * { ?r   ?p      ?o;
                 a      :Record;
                :user   :user123.
          }

Notes: This is a summarization of the comments of AKSW. I use the default prefix : instead of foaf: , as this could lead to others assuming it was part of the already existing foaf "friend of a friend" vocabulary. The WHERE keyword can always be left out and the DISTINCT keyword should not be necessary in this case, barring unusual circumstances such as the same triple being contained in multiple graphs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM