Search code examples
sparqlrdfsemantic-webontologyrdfs

Matching two words together in sparql


How to List the laureate awards (given by their label) for which the description of the contribution (given by nobel:motivation) contains the word "human" together with the word "peace" (i.e., both words must be there).

I have use the bds:search namespace from the the full-text search feature of Blazegraph. After visiting this link i have composed this query Free text search in sparql when you have multiword and scaping character

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bds: <http://www.bigdata.com/rdf/search#>
PREFIX nobel: <http://data.nobelprize.org/terms/>

SELECT ?awards  ?description  
WHERE { 
  ?entity rdfs:label   ?awards  .
  ?entity nobel:motivation ?description  .
   FILTER ( bds:search ( ?description, '"human" AND "peace"' ) ) 
}

This query is returning me the following error on execution shown in image. Error Image How to correct this query and get the desired result? You may take a look at the specification of this dataset or download an RDF dump of the dataset enter image description here


Solution

  • Use bds:search to search for "human" category.Then apply filter and contain function to "peace".

    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX bds: <http://www.bigdata.com/rdf/search#>
    PREFIX nobel: <http://data.nobelprize.org/terms/>
    PREFIX bif: <http://www.openlinksw.com/schemas/bif#>
    
    SELECT ?awards  ?description  
    WHERE { 
      ?entity rdfs:label   ?awards  .
      ?entity nobel:motivation ?description  .
      ?description bds:search "human" .
      FILTER (CONTAINS(?description, "peace"))
    }