Rule isn't working

I have the following rule in a file called 3\ Rules.ttl

@prefix rule: <tag:stardog:api:rule:> .
@prefix carnot: <http://Carnot.org/> .

[] a rule:SPARQLRule;
rule:content """
	IF {
	  ?e a carnot:Employee .
	  ?e carnot:employeeDepartment  ?d .
	  ?a carnot:assignmentEmployees ?e .
	  ?a carnot:assignmentPairs     ?p
	}
	THEN {
		?p carnot:pairDepartment ?d 
	}
""".

I load the file using: stardog data add testDB 3\ Rules.ttl

But it doesn’t seem to work.

However, if I do the same thing as a query, i.e.,

prefix rule: <tag:stardog:api:rule:>
prefix carnot: <http://Carnot.org/>

insert { ?p carnot:pairDepartment ?d }
where{
  ?e a carnot:Employee .
  ?e carnot:employeeDepartment  ?d .
  ?a carnot:assignmentEmployees ?e .
  ?a carnot:assignmentPairs     ?p
}

it works.

Am I doing something wrong w.r.t loading the Rules file?

Hi Phil,

The first thing to check is always your stardog.log file.

It’s also a bit simpler to use our “inline rules” syntax by writing your rule directly in the TTL file, not as a string. You can find an example in the docs.

Jess

When I put this in the Rules file,

@prefix rule: <tag:stardog:api:rule:> .
@prefix carnot: <http://Carnot.org/> .

IF {
	  ?e a carnot:Employee .
	  ?e carnot:employeeDepartment  ?d .
	  ?a carnot:assignmentEmployees ?e .
	  ?a carnot:assignmentPairs     ?p
	}
THEN {
		?p carnot:pairDepartment ?d 
	}
.

I get the following error,
Expected ':', found ' ' [line 4]

I guess I don’t understand the inline syntax.
thanks
phil

The inline rules syntax was introduced in Stardog 5.1.0. Are you using an older version of Stardog?

Also, the . at the end of your file is invalid. The rules aren’t terminated as triples are.

Jess

I’m using 5.0.1, I’ll try to upgrade.
I had submitted a request for 5.2 but never received an email. I’ll try again.
thanks
phil

Let us know if you have an issue downloading. The upgrade should be seamless if you placed your Stardog home directory outside the binary distribution.

Jess

I'm still waiting for the email.

However if I insert the rule the old way, no problem appears in the stardog.log, and I do see the rule in the Browser,

You said “it doesn’t seem to work” in your original post. Can you further explain how you came to that conclusion? Rules are evaluated at query time when reasoning is enabled for the query. Did you see any messages in your stardog.log file?

Jess

edit: Sorry just noticed you said no messages in the log file.

I just ran a query to use the rule and I got the following in the log file,
WARN 2018-02-25 10:20:19,552 [XNIO-1 task-17] com.complexible.stardog.reasoning.rule.RuleExtractor:parseRule(157): Ignoring invalid rule:

    IF {
      ?e a carnot:Employee .
      ?e carnot:employeeDepartment  ?d .
      ?a carnot:assignmentEmployees ?e .
      ?a carnot:assignmentPairs     ?p
    }
    THEN {
            ?p carnot:pairDepartment ?d
    }

Parse error was: com.complexible.common.rdf.query.parser.sparql.ast.VisitorException: QName ‘carnot:Employee’ uses an undefined prefix

So I added the carnot namespace to the database, and now it works.

Why wasn’t the carnot prefix that I used to define the rule used? Why did I need to add carnot to the database?

Thanks
phil

I’ve tried to reply 3 times and my reply doesn’t show up.

Are you trying to post an image? Our anti-spam measures are a little aggressive for new users. I will have to check into it. Are you able to describe the problem with text?

I was pasting something from the stardog.log, maybe that was the problem.

Anyway, I tried running a query, and saw an error in the log “carnot:Employee’ uses an undefined prefix”

So, I added the carnot prefix to the database as carnot=http://Carnot.org/ and then the query worked. This is good grogress.

Why wasn’t the carnot prefix I used to define the rule saved with the rule?

Also, now the Browser doesn’t seem to be working and there’s no error in the log.

For a prefix to be recognized in a rule string, it must be in the rule string itself, or defined in the database. The prefixes in the containing TTL file are not used. The inline rules syntax simplifies this. Here’s the relevant section from the docs:

However, the namespace URIs used by the literal embedded rules can be defined in two places: the string that contains the rule—​in the example above, you can see the default namespace is urn:test:–or in the Stardog database in which the rules are stored. Either place will work; if there are conflicts, the “closest definition wins”, that is, if foo:Example is defined in both the rule content and in the Stardog database, the definition in the rule content is the one that Stardog will use.

What is not working with the browser? Can you explain it in more detail please?

Jess

With the carnot namespace not in the database, I see the following for pairing1"
image

With the carnot namespace in the database. I see the following for paring1:
image

I.e., the References are lost.
phil

I’m not sure exactly what’s going on here. Are you able to reproduce the issue with a SPARQL query?

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