I don't have much experience with rdf sparql, only on occasion I do something very simple. Here are 2 samples of my data:
1 Sample:
@prefix ew: <http://ew.com/content/> .
@prefix sesame: <http://www.openrdf.org/schema/sesame#> .
ew:50467332 ew:name "He resigns, citing PTSD"^^xsd:token ;
ew:section "health"^^xsd:token ;
dc:isPartOf <http://ew.go.com/Health> ;
dc:created "2018-01-08T13:54:14.340-08:00"^^xsd:dateTime ;
dc:date "2018-01-08T18:23:47.000-05:00"^^xsd:dateTime ;
dc:identifier "50467332"^^xsd:int ;
dc:modified "2018-01-08T15:24:01.547-08:00"^^xsd:dateTime .
2 Sample:
@prefix ew: <http://ew.com/content/> .
@prefix sesame: <http://www.openrdf.org/schema/sesame#> .
ew:50477535 ew:name "Having a Baby in Your 40s"^^xsd:token ;
ew:section "agm"^^xsd:token ;
dc:isPartOf <http://ew.go.com/agm/Wellness> ;
dc:created "2018-01-09T08:32:57.047-08:00"^^xsd:dateTime ;
dc:date "2016-08-18T09:52:00.000-04:00"^^xsd:dateTime ;
dc:identifier "50477535"^^xsd:int ;
dc:modified "2018-01-09T08:32:57.047-08:00"^^xsd:dateTime .
I have rdf triples where ew:section can be of many variations, but I'm interested in finding only these 2 variations, namely:
ew:section "health"^^xsd:token ;
and
ew:section "agm"^^xsd:token ;
The query I'm testing right now has them both in OPTIONAL blocks, but the result I get back is a mixture of all sorts of "section", and the ones I'm interested in. How can I look for only those 2 section? I understand that I'm getting unwanted data because I have my sections in "OPTIONAL", but I'm not sure how to make both of them equally "important". I'm attempting to use UNION at the moment, but without positive results. Much appreciate your time. Here is my query:
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX mrss: <http://search.yahoo.com/mrss/>
PREFIX search: <http://www.openrdf.org/contrib/lucenesail#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX ew: <http://ew.com/content/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?id
WHERE{
?sub dc:identifier ?id;
dc:date ?date;
search:matches ?match.
?match dc:date ?dateSearch;
search:max "50";
search:sort search:order.
OPTIONAL {?sub news:section "agm"^^xsd:token;
dc:isPartOf <http://ew.go.com/agm/Wellness>.}
OPTIONAL {?sub $sectionClause.}
}
ORDER BY DESC(?date)