# User-defined rules not working as expected

**URL:** <https://community.stardog.com/t/user-defined-rules-not-working-as-expected/1952>\
**Category:** Support\
**Created:** [September 29, 2019, 11:10pm UTC](https://community.stardog.com/t/user-defined-rules-not-working-as-expected/1952 "2019-09-29T23:10:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sa-bpelakh](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/sa-bpelakh/32/610_2.png) [@sa-bpelakh](https://community.stardog.com/u/sa-bpelakh)\
**Post date:** [September 29, 2019, 11:10pm UTC](https://community.stardog.com/t/user-defined-rules-not-working-as-expected/1952/1 "2019-09-29T23:10:30Z")

</div>

I am trying to confirm the functionality for user-defined rules, using Stardog 7.0.1. I have this reduced data set

> :Control\_19 a :Control ;  
> rdfs:label "Control 19" ;  
> :hasOwnerOrg :Organization\_25 ;  
> :partOf\_c :BusinessProcessCategory\_20,  
> :BusinessProcessCategory\_56 .
> 
> IF {  
> ?control a :Control;   
> :hasOwnerOrg ?org ;  
> :partOf\_c ?category ;  
> .
> 
> ```
> BIND (URI(CONCAT('http://data.test.com/', 
> SHA1(CONCAT(STR(?control), STR(?org), STR(?category)))))
> as ?orgProcessInCategory)            
> 
> ```
> 
> }  
> THEN {  
> ?orgProcessInCategory a :OrgProcessInCategory ;  
> :hasRelSubject ?org ;  
> :hasRelObject ?category ;  
> .  
> }

When I do the basic ?s ?p ?o query, I expect to see the explicitly asserted triples plus the 6 inferred triples (reasoning is enabled and set to SL, which is supposed to run user-defined rules).

I validated my logic by inverting the rule into a construct query, i.e.

> construct  
> {  
> ?orgProcessInCategory a :OrgProcessInCategory ;  
> onto:hasRelSubject ?org ;  
> onto:hasRelObject ?category ;  
> .  
> }  
> where  
> {  
> ?control a :Control;   
> :hasOwnerOrg ?org ;  
> :partOf\_c ?category ;  
> .
> 
> ```
> BIND (URI(CONCAT('http://data.test.com/', 
> SHA1(CONCAT(STR(?control), STR(?org), STR(?category)))))
> as ?orgProcessInCategory)            
> 
> ```
> 
> }

And that produces the expected results. So, there must be something basic I am missing - any hints?

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [September 30, 2019, 12:15am UTC](https://community.stardog.com/t/user-defined-rules-not-working-as-expected/1952/2 "2019-09-30T00:15:29Z")

</div>

You've got two problems here. It looks like you're trying to create a new individual in a SWRL rule. Stardog has support for that but it needs to be done using the UUID() function. I'm not sure what happens when you do it this way. I suspect you'll see some warnings in the logs but I'm not positive.

The second problem is multiple atoms in the head portion of your rule. It will be executed as separate rules for each atom in the head.

See the documentation here for details [Home | Stardog Documentation Latest](https://www.stardog.com/docs/#_new_individuals_with_swrl)

---

<div class="post-metadata">

**Author:** ![sa-bpelakh](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/sa-bpelakh/32/610_2.png) [@sa-bpelakh](https://community.stardog.com/u/sa-bpelakh)\
**Post date:** [September 30, 2019, 1:54am UTC](https://community.stardog.com/t/user-defined-rules-not-working-as-expected/1952/3 "2019-09-30T01:54:04Z")

</div>

Thank you, I missed that portion of the documentation, and certainly using UUID() is not valid when multiple atoms are present in the rule head. I will utilize a different approach.

---

<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:** [October 14, 2019, 1:58am UTC](https://community.stardog.com/t/user-defined-rules-not-working-as-expected/1952/4 "2019-10-14T01:58:26Z")

</div>

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