Apache Stanbol Rules
Rules tutorial
The rule pattern (modus ponens) used in Stanbol is the following
if conditioon then consequentFor example the statement "every person has a father", i.e. ∀x.∃y. Person(x) ⇒ hasFather(x, y), becomes
if X is a person then X has a fatherOr "the brother of the father is the uncle", i.e. ∀xyz. hasFather(x,y) ∧ hasBrother(y,z) ⇒ hasUncle(x,z), becomes
if Y is the father of X and Z the brother of Y then Z is the uncle of X
in Stanbol a rule is defined using the following syntax
ruleName[body -> head]where
- the ruleName identifies the rule
- the body is a set of atoms that must be satisfied by evaluating the rule
- the head or consequent is a set of atoms that must be true if the condition is evaluated to be true
- both body and head consist of a list of conjunctive atoms
- head = atom1 . atom2 . ... . atomM
- body = atom1 . atom2 . ... . atomN
- the conjunction ∧ in Stanbol Rules is expressed with the symbol " . "
An atom is the smallest unit of the interpretation of a rule, e.g. the following predicate calculus formula
Person(x) ⇒ hasFather(x, y)has two atoms
- Person(·)
- hasFather(·, ·)
- Class assertion atom
- Individual assertion atom
- Data value assertion atom
- Range assertion atom
- constants: they consist of URI (we are in Web context) or Literal (values), e.g. e.g. <http//dbpedia.org/resource/Bob_Marley> is a constant, but "Bob Marley"^^xsd:string is a constant too
- variables: any identifier preceded by ?, e.g. ?x is a variable, but also ?y is a variable
A class assertion atom is identified by the operator
is(classPredicate, argument)where
- classPredicate is a URI that identified a class
- argument is the resource that has to be proved as typed with the classPredicate. It can be both a constant (a URI) or a variable
is(http://xmlns.com/foaf/0.1/Person, ?x) is evaluated to be
true if the concrete value associated to ?x is typed as http://xmlns.com/foaf/0.1/Person
false otherwise
An individual assertion atom is useful to evaluate or assert facts between individuals and is identified by the operator
has(propertyPredicate, individualArgument1, individualArgument2)where
- propertyPredicate is the object property that has to be evaluated. It can be a constant (URI) or a variable (?x)
- individualArgument1 and individualArgument2 are the two arguments of the property. They can be either constants (URI) or variables (?x)
An datavalued assertion atom is useful to evaluate or assert facts between individuals and values and is identified by the operator
values(propertyPredicate, individualArgument, valueArgument)where
- propertyPredicate is the object property that has to be evaluated. It can be a constant (URI) or a variable (?x)
- individualArgumentis the subject of the statement. It can be either constants (i.e. URI) or variables (e.g. ?x)
- valueArgumentis the object of the statement. It can be either constants (i.e. a literal) or variables (e.g. ?x)
Hands-on about refactoring RDF graphs
Stanbol refactor coverts RDF graphs given a set of mapping rules i.e. transformation patterns. Stanbol rule syntax is described in detail in the Stanbol rules documentation page.
Below you can see an example of transformation patterns defined for the GRS patterns
RDF graph in input to which the refactoring should be applied.
Transformation patterns defined as Stanbol Rules
Example of access to Stanbol refactor from a Javascript application
Transformation patterns defined as Stanbol Rules
Click on the button below and view results!
See how to access the refactor service through cURL command as well as Javascript.
cURL command for refactorExample of access to Stanbol refactor from a Javascript application
Rules syntax in BNF
TOKEN
<DEFAULT> SKIP : { " " } |
<DEFAULT> SKIP : { "\r" | "\t" | "\n" } |
<DEFAULT> TOKEN : { <LARROW: "->"> | <COLON: ":"> | <EQUAL: "="> | <AND: "."> | <COMMA: ","> | <REFLEXIVE: "+"> | <SAME: "same"> | <DIFFERENT: "different"> | <LESSTHAN: "lt"> | <GREATERTHAN: "gt"> | <IS: "is"> | <NEW_NODE: "newNode"> | <LENGTH: "length"> | <SUBSTRING: "substring"> | <UPPERCASE: "upperCase"> | <LOWERCASE: "lowerCase"> | <STARTS_WITH: "startsWith"> | <ENDS_WITH: "endsWith"> | <LET: "let"> | <CONCAT: "concat"> | <HAS: "has"> | <VALUES: "values"> | <NOTEX: "notex"> | <PLUS: "sum"> | <MINUS: "sub"> | <NOT: "not"> | <NAMESPACE: "namespace"> | <LOCALNAME: "localname"> | <STR: "str"> | <APOX: "^"> | <UNION: "union"> | <CREATE_LABEL: "createLabel"> | <SPARQL_C: "sparql-c"> | <SPARQL_D: "sparql-d"> | <SPARQL_DD: "sparql-dd"> | <PROP: "prop"> | <IS_BLANK: "isBlank"> | <FORWARD_CHAIN: "!"> } |
<DEFAULT> TOKEN : { <LPAR: "("> | <RPAR: ")"> | <DQUOT: "\""> | <LQUAD: "["> | <RQUAD: "]"> } |
<DEFAULT> TOKEN : { <NUM: (["0"-"9"])+> | <VAR: (["0"-"9","a"-"z","A"-"Z","-","_","."])+> | <VARIABLE: "?" (["0"-"9","a"-"z","A"-"Z","-","_"])+> | <URI: "<" (["0"-"9","a"-"z","A"-"Z","-","_",".","#",":","/","(",")"])+ ">"> | <STRING: "\"" (["0"-"9","a"-"z","A"-"Z","-","_",".",":","/","#","\\","?"," ","!","$","%"])+ "\""> | <SPARQL_STRING: "%" (["0"-"9","a"-"z","A"-"Z","-","_",".",":","/","#","\\","?"," ","!","$","%","{","}","(",")","\"","<",">","=","+","\n","\t","&","|",","])+ "%"> | <BNODE: "_:" (["0"-"9","a"-"z","A"-"Z","-","_","."])+> } |