ExecutionException: Invalid BIND on dates SWRL rule honored by Protege

I created an A-box that describes a person named Yves going to a healthcare appointment (or 'encounter') and having his blood pressure measured. I also added SWRL rules to my model, which should conclude that his blood pressure was elevated, because he was over 18 years old at the time of the appointment and because the value of his systolic blood pressure was > 120.

I have omitted the T-box in the interest of simplicity, but at the expense of uninformative OBO Foundry terms. Let me know if that's a problem.

  • over-18 encounters, year granularity
    obo:OGMS_0000097(?enc) ^ obo:OMRSE_00000011(?role) ^ obo:BFO_0000055(?enc, ?role) ^ obo:NCBITaxon_9606(?pers) ^ obo:RO_0000052(?role, ?pers) ^ ontologies:TURBO_0000303(?pers, ?sns) ^ obo:UBERON_0035946(?sns) ^ obo:RO_0002223(?encStart, ?enc) ^ obo:BFO_0000035(?encStart) ^ obo:IAO_0000416(?encStartDate) ^ obo:IAO_0000136(?encStartDate, ?encStart) ^ efo:EFO_0004950(?dob) ^ obo:IAO_0000136(?dob, ?sns) ^ obo:IAO_0000004(?dob, ?dobVal) ^ obo:IAO_0000004(?encStartDate, ?encStartDateVal) ^ swrlb:date(?encStartDateVal, ?ey, ?em, ?ed, ?ez) ^ swrlb:date(?dobVal, ?by, ?bm, ?bd, ?bz) ^ swrlb:subtract(?yeardiff, ?ey, ?by) -> ontologies:TURBO_0010335(?enc) ^ ontologies:TURBO_0010336(?enc, ?yeardiff)
  • SBPMDs with valspecs > 120 from over-18 encounters are over-18/over-120 SBPMDs
    ontologies:TURBO_0010335(?enc) ^ obo:HTN_00000001(?sbpmd) ^ obo:OBI_0000299(?enc, ?sbpmd) ^ obo:OBI_0001933(?valspec) ^ obo:OBI_0001938(?sbpmd, ?valspec) ^ obo:OBI_0002135(?valspec, ?bpval) ^ swrlb:greaterThan(?bpval, 120) -> ontologies:TURBO_0010334(?sbpmd)

Protege honors the rules

I get an error when I submit the following query to Stardog 7.0.0, via Stardog Studio 1.1.0

select * where { ?s a <http://transformunify.org/ontologies/TURBO_0010334> }

QueryEval: com.complexible.stardog.plan.eval.ExecutionException: Invalid BIND found in a clause: Q(x0) <- http://purl.obolibrary.org/obo/BFO_0000035(x1) ^ http://purl.obolibrary.org/obo/BFO_0000055(x2, x3) ^ http://purl.obolibrary.org/obo/HTN_00000001(x0) ^ http://purl.obolibrary.org/obo/IAO_0000004(x4, x5) ^ http://purl.obolibrary.org/obo/IAO_0000004(x6, x7) ^ http://purl.obolibrary.org/obo/IAO_0000136(x4, x1) ^ http://purl.obolibrary.org/obo/IAO_0000136(x6, x8) ^ http://purl.obolibrary.org/obo/IAO_0000416(x4) ^ http://purl.obolibrary.org/obo/NCBITaxon_9606(x9) ^ http://purl.obolibrary.org/obo/OBI_0000299(x2, x0) ^ http://purl.obolibrary.org/obo/OBI_0001933(x10) ^ http://purl.obolibrary.org/obo/OBI_0001938(x0, x10) ^ http://purl.obolibrary.org/obo/OBI_0002135(x10, x11) ^ http://purl.obolibrary.org/obo/OGMS_0000097(x2) ^ http://purl.obolibrary.org/obo/OMRSE_00000011(x3) ^ http://purl.obolibrary.org/obo/RO_0000052(x3, x9) ^ http://purl.obolibrary.org/obo/RO_0002223(x1, x2) ^ http://purl.obolibrary.org/obo/UBERON_0035946(x8) ^ http://transformunify.org/ontologies/TURBO_0000303(x9, x8) ^ http://www.ebi.ac.uk/efo/EFO_0004950(x6) ^ BIND(http://www.w3.org/2003/11/swrlb#date(x12, x13, x14, x15) AS x5) ^ BIND(http://www.w3.org/2003/11/swrlb#date(x16, x17, x18, x19) AS x7) ^ http://www.w3.org/2003/11/swrlb#greaterThan(x11, "120"^^http://www.w3.org/2001/XMLSchema#integer) ^ BIND(http://www.w3.org/2003/11/swrlb#subtract(x12, x16) AS x20)

Why doesn't Stardog like my rules and assertions? I can provide a simpler integer arithmetic SWRL rule that did work for me in Stardog is that's helpful.

Where are these variables bound?

The error you are seeing is because there is no way to determine components to construct the dates.


Sorry, I'm pretty new to SWRL. I thought I was using swrlb:date to extract the components like encounter year ?ey, month ?em, day ?ed and zone ?ez from a (previously bound) date like ?encStartDateVal, not to construct a date.

?ey and ?by are bound in a subtract operation, whose result is used in the consequent portion. But the other extracted date components don't appear anywhere else in the rule.

Do you have a sense of why it works in Protege, with Pellet? Is Stardog rewriting the rules as a SELECT statement?

I added Protege's explanation for the inference to my question.

@mamillerpa swrlb:date is a built-in predicate that needs all arguments to be bound.

From the docs:

Satisfied iff the first argument is the xsd:date representation consisting of the year the second argument, month the third argument, day the fourth argument, and timezone the fifth argument.

Not sure if this also means to bind parts if only the date argument was bound. From the specs it does not sound like this.

You could also try your rule or a smaller part in the SQWRL Tab of Protege:

obo:IAO_0000004(?encStartDate, ?encStartDateVal) ^ swrlb:date(?encStartDateVal, ?ey, ?em, ?ed, ?ez) -> sqwrl:select(?ey)

It should fail with an error I think.

1 Like

thanks @lorenz_b. you're right, SQWRL doesn't like my date parsing operation either. I started typing a simplified case into a StackOverflow post before I saw your response here. Do you think I should post it, or should I just accept the fact that there is no way to parse the year out of dates with Pellet and SWRL at this point in time?

This SO post from five years ago raises a similar question, and one response suggests importing a temporal ontology in order to get more functions. Do you think that's still relevant? Do you know where to find the temporal ontology they're talking about?

I guess the post refers to the SWRL API built by Martin O'Connor. He created some temporal extension for SWRL, and also piblished a paper about it

O'Connor, M.J. and Das, A. "A Method for Representing and Querying Temporal Information in OWL" Biomedical Engineering Systems and Technologies (Selected Papers), Springer-Verlag, CCIS 127, pp. 97-110, 2011.

but this only works with SWRL API in Protege and isn't in the standard in any sense. Indeed, you could use the temporal ontology, but the custom built-ins wouldn't be considered outside of the SWRL Tab, i.e. neither with Pellet, HermiT nor Stardog.

Seome more stuff about the SWRL API time apporach is spread in the Github Wiki, e.g. 1, 2 or of course in the paper.

That said, I'm still wondering why - as you stated - with standard Pellet your rule works. Had no time to test it. But the Pellet people are basically here :smiley:

1 Like

Hi Mark,

Before getting into SWRL semantics let me mention that with Stardog you can use subtraction with dates directly and compare two durations. In SPARQL (and Stardog rule syntax) this would look like this (or with a BIND if you want the actual difference value):

FILTER (?encStartDateVal - ?dobVal > "P18Y"^^xsd:duration)

In SWRL this will look like:

swrlb:subtract(?datediff, ?encStartDateVal, ?dobVal) ^ swrlb:greaterThan(?bpval, "P18Y"^^xsd:duration)

As you and Lorenz noted with standalone Pellet your rule would work as-is because the SWRL specification allows to bind arbitrary variables in the function arguments. However, functions in Stardog are based on SPARQL specification where there is a fixed return value. Therefore in a SWRL rule only the first variable will be bound to a value.

The other alternative here is to use the date component extraction functions from SPARQL (which were originally defined in XPath). In SPARQL these functions look like as follows:

    BIND("2019-09-07T07:43:56.540"^^xsd:dateTime as ?date)
    BIND(year(?date) AS ?year)
    BIND(month(?date) AS ?month)
    BIND(day(?date) AS ?day)
    BIND(hours(?date) AS ?hours)
    BIND(minutes(?date) AS ?minutes)
    BIND(seconds(?date) AS ?seconds)

In SWRL you can use these functions with the http://www.w3.org/ns/sparql# namespace or use the original IRIs from the XPath namespace, e.g. http://www.w3.org/2005/xpath-functions#year-from-dateTime. See the documentation for a complete list of functions Stardog supports and the namespaces recognized by Stardog.


1 Like

@lorenz_b and @evren, these recent posts are very helpful. Thanks.

I was hoping to write SWRL rules in Protege and then 'use' them at scale in Stardog. I understand that I may not be able to do that now, but that there are good alternatives.

Can you recommend a good tool or strategy for editing SWRL rules with something IDE-like [using the (,) ^ (,) -> (,)] notation and then getting them into RDF, for loading into Stardog?

PS, yes I have seen the documentation regarding Stardog Rule Syntax being strongly encouraged. I can see myself going that direction at some point in the future.

You can still write the rules in Protege and might even test them there if the reasoner you are using supports date arithmetic or the xpath functions I mentioned. If the reasoner does not support those functions then you'd be able to edit them but not run in Protege.

Stardog Studio provides native editing support for Stardog rule syntax [1] which can be written inline in Turtle files. There is no support for SWRL presentation syntax (,) ^ (,) -> (,) but it is possible to translate Stardog rule syntax to SWRL RDF syntax for interoperability.



[1] https://www.stardog.com/docs/#_stardog_rules_syntax

@evren OK, I'm on board with the Stardog rule syntax! But now I'm having a performance problem.

I started a new post: Same individual filter in toy dataset: 5 seconds -> 5 minutes


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.