Hi Mark,

I had a similar problem in the past: I wanted to have the possiblity to set an 
input variable via VALUES, and use some default derived from the data if the 
variable is not set. I solved it this way:

values ( ?input ) ( {undef} ) 
?x ?y ?default 
bind(coalesce(?input, $default) as ?actualVariableUsed )

For an example, see 
https://github.com/jneubert/skos-history/blob/master/sparql/added_concepts.rq, 
where it is possible to pass two version numbers to the query via VALUES. If 
not set, the latest and the version before are derived from the data. (The 
query is executable against Fuseki via a link on the readme page).

Hope that some of that could be helpful in your case - cheers, Joachim

-----Ursprüngliche Nachricht-----
Von: Mark Feblowitz [mailto:markfeblow...@comcast.net] 
Gesendet: Dienstag, 29. September 2015 01:54
An: users@jena.apache.org
Betreff: Need to bind a "default" type when no type matched in a VALUES set

I have need to identify 0 or more type resources from a given set  as having 
been asserted as types of a given subject entity;  if none matches, I’d like to 
bind some default resource to symbol a non-match.

So, I have a set of “whitelisted” types

        VALUES ?entType { ex:T1 ex:T2 ex:T3 }

and  I’m looking to match an entity against those types in this way:

        ?E a ?entType.

It’s fine to match more than one (although I’d rather not, but that’s a 
separate discussion).

In cases where there’s no match, I’d then like to force bind ?entType to, e.g., 
ex:T0 or owl:Thing.

To survive a non-match, the type match would likely need to be wrapped in an 
OPTIONAL block, likely with the VALUES statement in there too(?):

        OPTIONAL {
                VALUES ?entTypeS { ex:T1 ex:T2 ex:T3 }
                ?E a ?entTypeS.
                }

(Note the “S” in ?entTypeS - that’s for the next bit).

I’ve tried a conditional BIND
        BIND(IF(BOUND(?entType), ?entType, ex:T0) as ?entType) 

and also s COALESCE
        BIND(COALESCE(?entTypeS, ex:T0) as ?entType)


But it seems that neither works as I’d like.  I appears that, even though 
optional, the test against the VALUES set acts as a constraint.

I’ve also tried a FILTER, with 

        FILTER ( ?E1T in ( ex:T1, ex:T2, ex:T3 )) 
        BIND(COALESCE(?E1T, ex:T0) as ?E1Type)

That’s not even getting to executing (yet) - some non-parsing error on DBPedia 
Live. 

Have I stated the problem clearly enough? What might be other ways to address 
this?

Thanks,

Mark

Reply via email to