# ExecutionException: Invalid BIND on dates SWRL rule honored by Protege

**URL:** <https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876>\
**Category:** Support\
**Created:** [September 4, 2019, 3:42pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876 "2019-09-04T15:42:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamillerpa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/mamillerpa/32/515_2.png) [@mamillerpa](https://community.stardog.com/u/mamillerpa)\
**Post date:** [September 4, 2019, 3:42pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/1 "2019-09-04T15:42:48Z")

</div>

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](https://github.com/PennTURBO/EhrGraphCollab/blob/master/hypertension_experimentation.ttl), 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._

![Abox](https://raw.githubusercontent.com/PennTURBO/EhrGraphCollab/master/Yves_cropped.png)

- 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

 ![protege_honors_date_based_swrl](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/5264cf94cf92d84f92375fceb9fcbe8587ec6486.png)

 ![over-18-encounter_explanation](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/7d27157caa72205dcf0f493d54eed1f90530906c.png)

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_0000035(x1)) ^ [Ontology Lookup Service (OLS)](http://purl.obolibrary.org/obo/BFO_0000055)(x2, x3) ^ [http://purl.obolibrary.org/obo/HTN\_00000001(x0)](http://purl.obolibrary.org/obo/HTN_00000001(x0)) ^ [http://purl.obolibrary.org/obo/IAO\_0000004](http://purl.obolibrary.org/obo/IAO_0000004)(x4, x5) ^ [http://purl.obolibrary.org/obo/IAO\_0000004](http://purl.obolibrary.org/obo/IAO_0000004)(x6, x7) ^ [http://purl.obolibrary.org/obo/IAO\_0000136](http://purl.obolibrary.org/obo/IAO_0000136)(x4, x1) ^ [http://purl.obolibrary.org/obo/IAO\_0000136](http://purl.obolibrary.org/obo/IAO_0000136)(x6, x8) ^ [http://purl.obolibrary.org/obo/IAO\_0000416(x4)](http://purl.obolibrary.org/obo/IAO_0000416(x4)) ^ [http://purl.obolibrary.org/obo/NCBITaxon\_9606(x9)](http://purl.obolibrary.org/obo/NCBITaxon_9606(x9)) ^ [http://purl.obolibrary.org/obo/OBI\_0000299](http://purl.obolibrary.org/obo/OBI_0000299)(x2, x0) ^ [http://purl.obolibrary.org/obo/OBI\_0001933(x10)](http://purl.obolibrary.org/obo/OBI_0001933(x10)) ^ [http://purl.obolibrary.org/obo/OBI\_0001938](http://purl.obolibrary.org/obo/OBI_0001938)(x0, x10) ^ [http://purl.obolibrary.org/obo/OBI\_0002135](http://purl.obolibrary.org/obo/OBI_0002135)(x10, x11) ^ [http://purl.obolibrary.org/obo/OGMS\_0000097(x2)](http://purl.obolibrary.org/obo/OGMS_0000097(x2)) ^ [http://purl.obolibrary.org/obo/OMRSE\_00000011(x3)](http://purl.obolibrary.org/obo/OMRSE_00000011(x3)) ^ [Ontology Lookup Service (OLS)](http://purl.obolibrary.org/obo/RO_0000052)(x3, x9) ^ [Ontology Lookup Service (OLS)](http://purl.obolibrary.org/obo/RO_0002223)(x1, x2) ^ [http://purl.obolibrary.org/obo/UBERON\_0035946(x8)](http://purl.obolibrary.org/obo/UBERON_0035946(x8)) ^ [http://transformunify.org/ontologies/TURBO\_0000303](http://transformunify.org/ontologies/TURBO_0000303)(x9, x8) ^ [http://www.ebi.ac.uk/efo/EFO\_0004950(x6)](http://www.ebi.ac.uk/efo/EFO_0004950(x6)) ^ BIND([A SWRL Namespace](http://www.w3.org/2003/11/swrlb#date)(x12, x13, x14, x15) AS x5) ^ BIND([A SWRL Namespace](http://www.w3.org/2003/11/swrlb#date)(x16, x17, x18, x19) AS x7) ^ [A SWRL Namespace](http://www.w3.org/2003/11/swrlb#greaterThan)(x11, "120"^^[http://www.w3.org/2001/XMLSchema#integer](http://www.w3.org/2001/XMLSchema#integer)) ^ BIND([A SWRL Namespace](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._

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [September 4, 2019, 3:52pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/2 "2019-09-04T15:52:17Z")

</div>

> [@mamillerpa](#):
>
> ?ey, ?em, ?ed

Where are these variables bound?

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [September 4, 2019, 3:58pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/4 "2019-09-04T15:58:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mamillerpa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/mamillerpa/32/515_2.png) [@mamillerpa](https://community.stardog.com/u/mamillerpa)\
**Post date:** [September 4, 2019, 4:01pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/5 "2019-09-04T16:01:03Z")

</div>

Thanks.

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?

---

<div class="post-metadata">

**Author:** ![mamillerpa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/mamillerpa/32/515_2.png) [@mamillerpa](https://community.stardog.com/u/mamillerpa)\
**Post date:** [September 4, 2019, 4:39pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/6 "2019-09-04T16:39:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lorenz\_b](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@lorenz\_b](https://community.stardog.com/u/lorenz_b)\
**Post date:** [September 6, 2019, 8:40am UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/7 "2019-09-06T08:40:12Z")

</div>

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

From the docs:

> `swrlb:date`  
> 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.

---

<div class="post-metadata">

**Author:** ![mamillerpa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/mamillerpa/32/515_2.png) [@mamillerpa](https://community.stardog.com/u/mamillerpa)\
**Post date:** [September 6, 2019, 4:48pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/8 "2019-09-06T16:48:08Z")

</div>

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](https://stackoverflow.com/questions/21702093/assigning-a-value-to-a-property-based-on-a-swrl-rule-protege-4-3-with-pellet-as) 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?

---

<div class="post-metadata">

**Author:** ![lorenz\_b](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@lorenz\_b](https://community.stardog.com/u/lorenz_b)\
**Post date:** [September 7, 2019, 7:29am UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/9 "2019-09-07T07:29:44Z")

</div>

I guess the post refers to the [SWRL API](https://github.com/protegeproject/swrlapi/wiki) built by Martin O'Connor. He created some [temporal extension](https://github.com/protegeproject/swrlapi/wiki/SWRLAPITemporal) 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](https://github.com/protegeproject/swrlapi/wiki/ModellingTime), [2](https://github.com/protegeproject/swrlapi/wiki/SWRLTemporalOntology) 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 😃

---

<div class="post-metadata">

**Author:** ![evren](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/evren/32/1515_2.png) [@evren](https://community.stardog.com/u/evren)\
**Post date:** [September 7, 2019, 12:38pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/10 "2019-09-07T12:38:24Z")

</div>

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:

```auto
SELECT * {
    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](https://www.stardog.com/docs/#_sparql_query_functions) for a complete list of functions Stardog supports and the namespaces recognized by Stardog.

Best,  
Evren

---

<div class="post-metadata">

**Author:** ![mamillerpa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/mamillerpa/32/515_2.png) [@mamillerpa](https://community.stardog.com/u/mamillerpa)\
**Post date:** [September 9, 2019, 12:58pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/11 "2019-09-09T12:58:08Z")

</div>

@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.**

---

<div class="post-metadata">

**Author:** ![evren](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/evren/32/1515_2.png) [@evren](https://community.stardog.com/u/evren)\
**Post date:** [September 9, 2019, 2:59pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/12 "2019-09-09T14:59:22Z")

</div>

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.

Best,

Evren

[1] [https://www.stardog.com/docs/#\_stardog\_rules\_syntax](https://www.stardog.com/docs/#_stardog_rules_syntax)

---

<div class="post-metadata">

**Author:** ![mamillerpa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/mamillerpa/32/515_2.png) [@mamillerpa](https://community.stardog.com/u/mamillerpa)\
**Post date:** [September 10, 2019, 2:22pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/13 "2019-09-10T14:22:13Z")

</div>

@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](https://community.stardog.com/t/same-individual-filter-in-toy-dataset-5-seconds-5-minutes/1886)

thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [September 24, 2019, 2:22pm UTC](https://community.stardog.com/t/executionexception-invalid-bind-on-dates-swrl-rule-honored-by-protege/1876/14 "2019-09-24T14:22:14Z")

</div>

Closed on September 24, 2019, 2:22pm UTC

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