What happens if we put a variable in the head of a GenericRuleReasoner, which does not appear in the body of the rule?
For instance if we have the following rule :
rule1: (?x rdf:type :Person) -> (?y :father ?x)
The rule says that every person has a father.
Suppose we have a triple :a rdf:type :Person
How does the reasoner behaves here? Will it create a new triple with blank node like _x :father :a ?
I think it will complain about that. It is, after all, ambiguous: do you mean 'there is a ?y such that...' or 'for any ?y ....'?
From what you say it's clear that you expect former, the existential version, because that's what introducing a bNode does. So try:
rule1: makeTemp(?y), (?x rdf:type ex:Person) -> (?y ex:fatherOf ?x)
or
rule1: makeInstance(?y, ex:father, ?x), (?x rdf:type ex:Person) -> (?y ex:fatherOf ?x)
the latter of which will give you a consistent father node, whereas the former simply introduces a bNode.
Related
I am trying to create my own property rules in Jena Fuseki. To do so I am using the Generic Rule Reasoning that allows me to use my own rules. When I use this strategy with my rules from a file everything works fine:
:model_inf a ja:InfModel ;
ja:baseModel :tdbGraph ;
ja:reasoner [
ja:reasonerURL <http://jena.hpl.hp.com/2003/GenericRuleReasoner> ;
ja:rulesFrom <file://...> ;
] .
However, I would not want to use a file but add the rules directly as a string. I tried just to copy the content of the rule files that worked in the example above, for instance (a small slice of the file):
#-*-mode: conf-unix-*-
#prefix time: <http://www.w3.org/2006/time#>
#include <owlmicro>
-> table(owl:sameAs).
#---------------------------------------------------------------------------
# Equality
#---------------------------------------------------------------------------
sameAs_symmetry:
(?x owl:sameAs ?y)
-> (?y owl:sameAs ?x).
sameAs_transitivity:
(?x owl:sameAs ?y)
(?y owl:sameAs ?z)
-> (?x owl:sameAs ?x).
sameAs_Thing1:
-> [(?x rdf:type owl:Thing) <- (?x owl:sameAs ?y)].
sameAs_Thing2:
-> [(?x owl:sameAs ?x) <- (?x rdf:type owl:Thing)].
and put this in a variable string_rules_variable (with proper escaping):
:model_inf a ja:InfModel ;
ja:baseModel :tdbGraph ;
ja:reasoner [
ja:reasonerURL <http://jena.hpl.hp.com/2003/GenericRuleReasoner> ;
ja:rules [
${string_rules_variable}
] ;
] .
where ${string_rules_variable} (javascript string interpolation) contains the rules read from the file.
In the end, the repository was created with no error, but the rules doesn't worked nor the owlmicro statements appeared in the repository.
So, am I doing anything wrong, or is it a Jena Fuseki issue?
P.S. I am using nodejs to send this in the body of a post request with text/turtle content-type in headers.
I have a grammar for parsing diverse SQL code.
Problem :
- sometimes, I want it to handle nested comments (ex: Microsoft SQL):
COMMENT: '/*' (COMMENT|.)*? ('*/' | EOF) -> channel(HIDDEN);
- sometimes, I want it to not handle them (ex: Oracle):
COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
I don't want to :
make two different grammars
compile my grammar twice to get two different lexers and two different parsers.
Best solution would be to have an argument, passed to the lexer/parser, to choose which "COMMENT implementation" to use.
Can I do this ? If yes, how, if not, is there a satisfying solution to my problem ?
Thanks !
You can achieve this using a semantic predicate in your lexer. You will need to (1) split the lexer and parser from each other. (2) Create a base class for the lexer with a boolean field, property, or method that you can set true if you want the lexer to allow nested comments, or false to disallow. For sake of below code, assume you add "bool nested = false;" to the lexer base class. (3) Within your lexer grammar, create one COMMENT rule as shown below. (4) After creating you lexer, assign the "nested" field to true if you want nested comments to be recognized.
COMMENT
: (
{nested}? '/*' (COMMENT|.)*? ('*/' | EOF)
| '/*' .*? '*/') -> channel(HIDDEN)
;
I have had an issue with my Xtext grammar in that the parser cannot recover upon reaching a misspelled keyword. Here is a minimal grammar which reproduces the issue and resembles my actual grammar structure:
Model:
'NS' name=ID
(
a+=TypeA |
b+=TypeB |
c+=TypeC
)*
'EndNS'
;
TypeA:
'TypeA' name=ID ';'
;
TypeB:
'TypeB' name=ID
'EndTypeB'
;
TypeC:
'TypeC' name=ID
'EndTypeC'
;
So if I created a file with the following text:
NS myNamespace
TypeA myA;
TypeB myB
EndTypeB
TypeC myC
EndTypeC
EndNS
And then I misspelled the TypeA keyword, then both the TypeB and TypeC entries would also fail to parse despite having a keyword centric grammar. (This problem will still occur if you remove the namespace concept, or if you make the type entries ordered) My expectation is that the TypeA entry would be null, but upon reaching the TypeB keyword, the parser would recover and add them to the AST.
My question then is, is there an issue I am missing in my current grammar and how can I structure this grammar to provide the best parser recovery ability?
I'm starting to find xText and I found something that I don't know how to solve.
I have 2 grammars
A.xtext
Domain:
'domain' name=ID
'{'
(instances+=Instance)*
'}'
Instance:
'instance' name=ID
B.xText
import "http://somewhere/languages/A" as A
MyCommand:
DomainCommand | InstanceCommand
;
DomainCommand:
'domain'
domain=[A::Domain]
;
InstanceCommand:
'instance'
instance=[A::Instance]
;
SomeFile.A
domain A {
instance X
instance Y
}
SomeFile.B
domain A
instance A.X
When I'm writting my text file in my B Grammar I can access the Domain values defined in some file.A but I don't know what's the best way to access the Instance X and to make sure is from the domain A.
I built a simple ontology to test how SWRL rules infer new relations between individuals in an ontology, but it didn't work. My rule is:
(hasFather(?x, ?y) ∧ hasMother(?x, ?z) → spouseOf(?y, ?z)
and may be read as
x has a father y, x has mother z → y is spouse of z).
There are three individuals in my ontology: Husband, Wife, and Son. I set child has mother is Wife, has father is Husband. And then my rule is employed in order to set Husband is spouseOf Wife. I used the Jess plugin to test my rule but no result. Why doesn't the rule isn't work? Is there something wrong with my rule, or something wrong with Jess on Protege 3.3?
What you wrote in your ontology is not the rule you wrote in this question. Your ontology contains the following rule:
hasFather(?y, ?x) ∧ hasMother(?z, ?x) → spouseOf(?y, ?z)
In the RDF/XML file, swap swrl:argument1 with swrl:argument2 and it'll work.
Sonvx, Pellet reasoner can be used to test SWRL rules. Pellet reasoner provides Java APIs to test SWRL rules. download pellet here
let me know if you need something else.