2

If I run this query:

SELECT ?subject
WHERE { <http://dbpedia.org/resource/Oslo> dcterms:subject ?subject. }

I get this:

enter image description here

Which is correct. But I want all values in dbprop. So this part:

enter image description here

So a pseudo code that doesn't work would be:

SELECT ?properties
WHERE { <http://dbpedia.org/resource/Oslo> dbprop:* ?properties. }

Expected result would be then each property (like dbpprop:aprRecordHighC) and it's value (like 25.400000).

Is that possible?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Marius Lian
  • 523
  • 7
  • 15
  • 2
    Have a look at [Retrieve triples with properties restricted by namespace](http://stackoverflow.com/q/18831007/1281433) and [SPARQL - Restricting Result Resource to Certain Namespace(s)](http://stackoverflow.com/q/9597981/1281433). Just note that `dbpprop:` is a prefix for `http://dbpedia.org/property/`. – Joshua Taylor Oct 08 '14 at 01:32

1 Answers1

1

Yes, it is possible. If you want all the properties and values given the "Oslo" resource, you should issue the following query:

SELECT ?property ?value
WHERE { <http://dbpedia.org/resource/Oslo> ?property ?value. }

If you only want the dbprop properties, you can add a filter:

SELECT ?property ?value
WHERE { <http://dbpedia.org/resource/Oslo> ?property ?value 
FILTER regex(str(?property), "http://dbpedia\\.org/property/")}

I have tried both of these queries in the dbpedia endpoint and they worked.

You can find more information in the SPARQL specification: http://www.w3.org/TR/rdf-sparql-query/#func-str

Edit: apparently, from the comments I see that this question has been answered previously here

Community
  • 1
  • 1
Daniel Garijo
  • 959
  • 9
  • 15
  • 2
    This question is a duplicate of [SPARQL - Restricting Result Resource to Certain Namespace(s)](http://stackoverflow.com/q/9597981/1281433). This use of `regex` isn't great because you're not specifically matching the beginning of the URI string (the answer to the other question does). Additionally, in SPARQL 1.1, there's a `strstarts` function that's even better, as it doesn't do any regular expression testing. Do you know offhand whether the `.` in your regex match a literal `.` or are wildcards? – Joshua Taylor Oct 08 '14 at 01:35
  • oops I hadn't noticed the duplicate question, sorry. The sparql 1.1 suggestion is great, thanks! But I don't get your last question. Could you please elaborate? – Daniel Garijo Oct 08 '14 at 09:06
  • 1
    `.` is a meta-character in most regular expression dialects (including SPARQL) meaning *match any character* so your query as written would also match a property like `http://dbpediaXorg/property` (not that such a property would exist in DBPedia itself). To restrict it to literal `.` characters you need to use `"http://dbpedia\\.org/property/"` - backslash is the escape character for regular expressions but since it is also the escape character for SPARQL strings it needs double escaping in a SPARQL query – RobV Oct 08 '14 at 10:54
  • @JoshuaTaylor Good point about the `.` meta-character, I have gone back and updated my original answer to correct it to account for this. – RobV Oct 08 '14 at 11:00
  • I see. Thanks for clarifying it our, @RobV. I guess that I didn't realize because in this case they only have one property that matches the literal. I'll edit the response appropriately. – Daniel Garijo Oct 08 '14 at 11:08
  • Thanks Guys! So the following query is what I want then: SELECT ?property ?value WHERE { ?property ?value FILTER(STRSTARTS(STR(?property), "http://dbpedia.org/property"))} – Marius Lian Oct 08 '14 at 20:03
  • @MariusLian Code is not readable in comments, especially if you don't put it in backticks `\`like this\``. As written in your comment, that's not what you want for a query, because `STRSTARTS(STR(?property), "dbpedia.org/property")` won't work right, since the property URI string will actually start with a leading `http://`. – Joshua Taylor Oct 09 '14 at 15:06