semantalytics / xsparql

14 stars 4 forks source link

how to use an OR path (disjunction)? #39

Closed VladimirAlexiev closed 7 months ago

VladimirAlexiev commented 8 months ago

@nunolopez All of these alternatives

let $geom := $class/(position|raeumlicherGeltungsbereich)
let $geom := $class/position | $class/raeumlicherGeltungsbereich
geo:asGML {$class/(position|raeumlicherGeltungsbereich)}^^geo:gmlLiteral.

cause the following error:

net/sf/xsparql/rewriter/XQuerySerializer.g: node from line 0:0 mismatched tree node: DOWN expecting <UP>
Parse error: java.lang.Exception: Errors for Serializer. Translation aborted.
java.lang.Exception: Errors for Serializer. Translation aborted.
        at net.sf.xsparql.rewriter.XSPARQLProcessor.process(XSPARQLProcessor.java:257)
        at net.sf.xsparql.Main.rewriteQuery(Main.java:197)
        at net.sf.xsparql.Main.main(Main.java:111)

Disjunction (given eg as book/(chapter|appendix)/section) is allowed in both XPath 2.0 and 3.1:

VladimirAlexiev commented 8 months ago

I tried this

let $geom1 := $class/position
let $geom2 := $class/raeumlicherGeltungsbereich
let $geometry := xsparql2:_serialize($geom1 or $geom2)

but that's evaluated as false because it checks the boolean value of those XML nodes, not their existence.

Then tried:

let $geom := $class/position union $class/raeumlicherGeltungsbereich
let $geometry := xsparql2:_serialize($geom)

net/sf/xsparql/rewriter/XQuerySerializer.g: node from line 29:29 required (...)+ loop did not match anything at input 'union'
Parse error: java.lang.Exception: Errors for Serializer. Translation aborted.
java.lang.Exception: Errors for Serializer. Translation aborted.

Then tried:

let $geom1 := $class/position
let $geom2 := $class/raeumlicherGeltungsbereich
let $geometry := xsparql2:_serialize($geom1 union $geom2)

net/sf/xsparql/rewriter/XQuerySerializer.g: node from line 31:44 mismatched tree node: union expecting <UP>
Parse error: java.lang.Exception: Errors for Serializer. Translation aborted.
VladimirAlexiev commented 8 months ago

I worked around it this way:

let $geom      := ($class/X:raeumlicherGeltungsbereich, $class/X:position) # alternatives
let $geo       := if (fn:empty($geom)) then () else fn:concat($id,"/geo")
let $geometry  := if (fn:empty($geom)) then () else XSPARQL:_serialize($geom/*)