0

Given the graph http://example.org/ as:

@prefix foaf:<http://xmlns.com/foaf/0.1/purl>.
<uri:alice> foaf:name "Alice".
<uri:bob> foaf:name "Bob".
<uri:carl> foaf:name "Carl".

Why this SPARQL query works:

PREFIX foaf:<http://xmlns.com/foaf/0.1/purl>
SELECT *
WHERE { 
    GRAPH <http://example.org/> {
        ?model_ic foaf:name ?name.
        FILTER (?name = "Bob")
    }
}

Whereas this one don't (well, technically it works but returns 0 matches)

PREFIX foaf:<http://xmlns.com/foaf/0.1/purl>
SELECT *
WHERE { 
    GRAPH <http://example.org/> {
        ?model_ic foaf:name "Bob".
    }
}
ffa
  • 747
  • 1
  • 6
  • 14

1 Answers1

1

If there is any other attachment to the name rather only the string you might have issues. For example, foaf:name normally has a language attached. Try:

PREFIX foaf:<http://xmlns.com/foaf/0.1/purl>
SELECT *
WHERE { 
GRAPH <http://example.org/> {
    ?model_ic foaf:name "Bob"@en.
}
}
Artemis
  • 3,271
  • 2
  • 20
  • 33
  • 1
    Thanks, I've manually used the command `INSERT {GRAPH { foaf:name "Bob"}}` to manually add a recognizable triple and now it works as expected. – ffa May 06 '15 at 10:28
  • I've tried to run a query like `SELECT ?b ?c WHERE { foaf:name ?name. ?name ?b ?c} ` to highligh any possible @ tag but again seems to not work. How can I do it? – ffa May 06 '15 at 10:32
  • Did you try he query I provided? And when you have `namespace:bob` you do not need the `<>`. You need to find the URI of the element and then find all the information about that element. – Artemis May 06 '15 at 10:36
  • Yes, it worked. However the example I have provided was intended to be as general as possible. I'm interested in the answer in general, not for the specific case, because in this context is pretty straightforward that the attribute should be a language, but in a broader context could not be so easy. I believe that the same argument could be applied for the ^^xsd:integer or ^^xsd:float and so on as example. – ffa May 06 '15 at 12:47
  • I don't think there is a way to extract string without knowing it's annotation. That is why using a filter ` filter ( str(?name)= "bob")) is a preferred way, because it only looks at the string. – Artemis May 06 '15 at 13:20