Question

I am trying to get instances that contains keywords using bif:contains, but I want to get only one label for each ?s (instance) and I don't care which one. I can't filter it with something like regex because it's for a general query. This is my query but it gets all labels from each instance (?s):

SELECT DISTINCT ?s,?o1,?sc,?l WHERE {
  ?s ?s1textp ?o1 .
  ?o1 bif:contains ' (madrid AND embargo) ' OPTION ( score ?sc ) . 
  ?s <http://www.w3.org/2000/01/rdf-schema#label> ?l      
}
ORDER BY DESC ( ?sc )
LIMIT 30
OFFSET 0

I tried out with nested queries, but when I add a LIMIT I get no results.

SELECT DISTINCT ?s,?o1,?sc,?l WHERE {
  ?s ?s1textp ?o1 .   
  ?o1 bif:contains ' (madrid AND embargo) ' OPTION ( score ?sc ) .                 
  {
    SELECT DISTINCT ?s,?l WHERE {
      ?s <http://www.w3.org/2000/01/rdf-schema#label> ?l
    }
    LIMIT 1
  }      
}
ORDER BY DESC ( ?sc )
LIMIT 30
OFFSET 0

I saw also the SAMPLE aggregate function; it takes exactly what I want in DBpedia endpoint, but it's not working on my own Virtuoso! (I'm using the open source version.)

SELECT DISTINCT ?s,?o1,?sc,?l WHERE {
  ?s ?s1textp ?o1 .
  ?o1 bif:contains ' (madrid AND embargo) ' OPTION ( score ?sc ) . 
  {
    SELECT DISTINCT ?s,(SAMPLE(?l) AS ?l) WHERE {
      ?s <http://www.w3.org/2000/01/rdf-schema#label> ?l
    }
    GROUP BY ?s
  }
}
ORDER BY desc ( ?sc )
LIMIT 30
OFFSET 0
Was it helpful?

Solution

The official DBpedia endpoint is running on Virtuoso, so if that's doing the right thing, you probably just need to update your own Virtuoso instance. VOS is currently at 7.2.2 (or 6.1.8, if you must stay on v6) 6.1.6, and the Virtuoso Github space (instructions) holds the latest code cuts in stable/7 and develop/7 (and stable/6 and develop/6), each of which delivers what the path suggests.

For the future -- questions specifically regarding Virtuoso are generally best raised on the public OpenLink Discussion Forums, the Virtuoso Users mailing list, or a confidential Support Case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top