Re: SPARQL puzzle

Dan,

Have you considered this the SPARQl 1.1 features:

FILTER(NOT EXISTS{pattern})


There is a related MINUS { pattern } but OPTIONAL/!bound is like the 
former without duplicates.

http://www.w3.org/2009/sparql/docs/query-1.1/rq25.xml#negation

sparql.org is useful for formatting queries.


SELECT ?c ?l where { ?x <http://schema.org/range>
<http://schema.org/Text> . ?x
<http://www.w3.org/2000/01/rdf-schema#label> ?l . ?x
<http://schema.org/domain> ?c . OPTIONAL { ?x
<http://schema.org/range> ?r2  } . FILTER (  !bound(?r2) )  }
==>
SELECT  ?c ?l
WHERE
   { ?x <http://schema.org/range> <http://schema.org/Text> .
     ?x <http://www.w3.org/2000/01/rdf-schema#label> ?l .
     ?x <http://schema.org/domain> ?c
     OPTIONAL
       { ?x <http://schema.org/range> ?r2 }
     FILTER ( ! bound(?r2) )
   }


 Andy


On 07/05/12 13:37, Dan Brickley wrote:
> I'm stuck with a query, and #swig didn't know so I'm trying here!
>
> I'm using this dataset,
>
> https://dvcs.w3.org/hg/webschema/raw-file/feb8d27d0757/schema.org/drafts/alpha/_schema.nt
>
> ...which is from an experimental rdfa.html export of the Schema.org schema.
>
> My query goal, is to find all the properties (and the rdfs:domain
> type(s) they're associated with, ultimately) which have an expected
> value of "Text", but which do not also have any other expected types.
>
> Note that this 'expected type' notion is expressed using a repeatable
> property, schema:range, which is a more relaxed cousin of rdfs:range
> (i.e. it's a hint for expected properties, but doesn't have the strong
> semantics of rdfs:range).
>
> So for example, there is a  class<http://schema.org/JobPosting>
>           that defines a property "responsibilities" whose schema:range
> expected value is text. The result set ought to contain this, only if
> we don't have another schema:range pointing to a type like (the
> fictional) ResponsibilityInfo. Use case is that I want to find
> properties that are candidates for having their controlled values
> externally enumerated, but which don't yet have a relevant schema.org
> type defined. See
> http://www.w3.org/wiki/WebSchemas/ExternalEnumerations if you're
> interested.
>
> I've been trying this using Jena on the commandline, with variations
> on things like
>
>   SELECT ?c ?l  where { ?x<http://schema.org/range>
> <http://schema.org/Text>  . ?x
> <http://www.w3.org/2000/01/rdf-schema#label>  ?l . ?x
> <http://schema.org/domain>  ?c . OPTIONAL { ?x
> <http://schema.org/range>  ?r2  } . FILTER ( ! (?r2 !=
> <http://schema.org/Text>  &&   bound(?r2)) )  }
>
> SELECT ?c ?l where { ?x<http://schema.org/range>
> <http://schema.org/Text>  . ?x
> <http://www.w3.org/2000/01/rdf-schema#label>  ?l . ?x
> <http://schema.org/domain>  ?c . OPTIONAL { ?x
> <http://schema.org/range>  ?r2  } . FILTER (  !bound(?r2) )  }
>
> sparql --data _schema.nt 'SELECT ?x ?c ?l ?r1 ?r2  where { ?x
> <http://schema.org/range>  ?r1 . ?x
> <http://www.w3.org/2000/01/rdf-schema#label>  ?l . ?x
> <http://schema.org/domain>  ?c . OPTIONAL { ?x
> <http://schema.org/range>  ?r2  } .  FILTER (?r1 =
> <http://schema.org/Text>  &&  ?r2 !=<http://schema.org/Text>   ) } '
>
> (these aren't right, but give some indication of what I was trying)
>
> I find !bound pretty hard to think about. Is this something that needs
> SPARQL 1.1 maybe?
>
> cheers,
>
> Dan
>

Received on Monday, 7 May 2012 13:46:18 UTC