Simple SPARQL Query not working

sparql semantic-web

199 просмотра

1 ответ

I'm new in SPARQL. I made a ontology in Protege and Have 2 classes:

Book
Page

So.. In "individual by class" I have this

Book1 startWith page1
Book1 endWith page2

Book2 startWith page2
Book2 endWith page5

Book3 startWith page1
Book3 endWith page2

Also page1 have a data-property with value 1

page2 with value 2
page5 with value 2

So.. I want to make a SPARQL query that returns all books with the that start in the same page and end in the same page.

Now this is my SPARQL query but not working.

PREFIX foaf: <http://xmlns.com/foaf/0.1/>  
SELECT ?book, ?book2
WHERE { ?book foaf:starWith ?f1 .  
        ?book foaf:endWith ?f2 .  
        ?book2 foaf:starWith ?f3 .
        ?book2 foaf:endWith ?f4 .    
        FILTER regex(?f1, ?f3)   
}  

Sorry I'm new with that

Автор: Federick Jons Источник Размещён: 08.11.2019 11:23

Ответы (1)


4 плюса

  1. You have a typo in the query, the property is called startWith.
  2. Don't use existing ontologies/namespaces for your own ontology, i.e. don't use RDF, RDFS, OWL, FOAF. Instead, use your own namespace.
  3. There is no comma allowed between the projection variables. At least not from the SPARQL specs. Some triple stores do support some extended syntax, but I would always stick to standard SPARQL.
  4. The REGEX is totally wrong. Not sure what you want to do with it, but this is used for String matching. A FILTER(?book != book2 && ?f1 = ?f3 && ?f2 = ?f4) is enough

The query:

PREFIX  myNs: <http://my-namespace.org/>
SELECT  ?book1 ?book2
WHERE
  { ?book1 myNs:startWith ?s1 .
    ?book1 myNs:endWith ?e1 .
    ?book2 myNs:startWith ?s2 .
    ?book2 myNs:endWith ?e2
    FILTER (?book1 != ?book2 && ?s1 = ?s2 && ?e1 = ?e2)
  }
Автор: AKSW Размещён: 20.08.2016 01:58
Вопросы из категории :
32x32