From: <jm...@us...> - 2010-03-23 21:22:01
|
Revision: 1344 http://eulergui.svn.sourceforge.net/eulergui/?rev=1344&view=rev Author: jmvanel Date: 2010-03-23 21:21:55 +0000 (Tue, 23 Mar 2010) Log Message: ----------- swrl-n3-rules.n3: At last ! I could do recursive variable substitution: from {:x :sibling :y} :substituteVariableList ( (:x ?X)(:y ?Y) ) . to: ({_:sk1 :sibling :y} (:y _:sk12)) :variableSubstitution {_:sk1 :sibling _:sk12} Modified Paths: -------------- trunk/eulergui/examples/swrl-n3-rules.n3 trunk/eulergui/examples/swrl-n3-rulesQ.n3 Modified: trunk/eulergui/examples/swrl-n3-rules.n3 =================================================================== --- trunk/eulergui/examples/swrl-n3-rules.n3 2010-03-23 18:38:34 UTC (rev 1343) +++ trunk/eulergui/examples/swrl-n3-rules.n3 2010-03-23 21:21:55 UTC (rev 1344) @@ -31,7 +31,10 @@ ?RULE :hasVariableTable ?VT. ?VT :has_variable ( ?A1 ?VAR ) . } => { - ?RULE :n3_antecedent_has { ?VAR rdf:type ?CLASS } . + ?CRIT :criterium_in_n3_is { ?VAR rdf:type ?CLASS } . + ?CRIT :criterium_in_n3_is2{ ?A1 rdf:type ?CLASS } . + ?RULE :n3_antecedent_has { ?VAR rdf:type ?CLASS } . + ?RULE :n3_antecedent_has_var_subject ?CRIT . }. { @@ -41,10 +44,13 @@ swrl:argument2 ?A2 ; swrl:propertyPredicate ?P . ?RULE :hasVariableTable ?VT. - ?VT :has_variable ( ?A1 ?VAR1 ) . - ?VT :has_variable ( ?A2 ?VAR2 ) . + ?VT :has_variable ?A1 . + ?VT :has_variable ?A2 . } => { - ?RULE :n3_antecedent_has { ?VAR1 ?P ?VAR2 } . + ?CRIT :criterium_in_n3_is { ?VAR1 ?P ?VAR2 } . + ?CRIT :criterium_in_n3_is2{ ?A1 ?P ?A2 } . + ?RULE :n3_antecedent_has { ?VAR1 ?P ?VAR2 } . + ?RULE :n3_antecedent_has_var_subject_object ?CRIT . }. ######### consequent ######### @@ -68,22 +74,13 @@ swrl:argument1 ?A1 ; swrl:classPredicate ?CLASS . ?RULE :hasVariableTable ?VT. - ?VT :has_variable ( ?A1 ?VAR ) . + ?VT :has_variable ?A1 . } => { ?RULE :n3_consequent_has { ?VAR rdf:type ?CLASS } . }. ######### gather variables ######### -{ # create variable table - ?RULE a swrl:Imp ; -} => { - ?RULE :hasVariableTable ?VT. - # ?RULE :hasVariableTableBody ?VTB. - # ?RULE :hasVariableTableHead ?VTH. - ?VT a :VariableTable. -}. - { ?CRIT :swrl_body_in ?RULE ; swrl:argument1 ?A @@ -110,35 +107,84 @@ ?A :swrl_head_variable_in ?RULE . }. +{ # create variable table + ?RULE a swrl:Imp ; +} => { + ?RULE :hasVariableTable ?VT. + ?VT a :VariableTable. +}. + { ?A :swrl_body_variable_in ?RULE . ?RULE :hasVariableTable ?VT. } => { - ?VT :has_variable ( ?A ?VAR ) . + ?RULE :hasVariable ?A . + ?VT :has_variable ?A . }. { ?A :swrl_head_variable_in ?RULE . ?RULE :hasVariableTable ?VT. } => { - ?VT :has_variable ( ?A ?VAR ) . # a blank node that will become a ? variable in the final query + ?RULE :hasVariable ?A . + ?VT :has_variable ?A . }. -######## assembly ######### +{ + ?RULE a swrl:Imp . + _:d e:findall ( ?A + { ?RULE :hasVariable ?A . } + ?LA ). + ?LA e:distinct ?LAD . +} => { + ?RULE :distinctVariables ?LAD . +}. +######## variable substitution ######### + +# variable substitution of ?V by ?VT in a triple ?T == {?S ?P ?O} +{ {?V ?P ?O} :substituteVariable (?V ?VT). +} => { # the subject is substituted + ( {?V ?P ?O} (?V ?VT) ) :variableSubstitution {?VT ?P ?O} +}. +{ {?S ?P ?V} :substituteVariable (?V ?VT). +} => { # the object is substituted + ( {?S ?P ?V} (?V ?VT) ) :variableSubstitution {?S ?P ?VT} +}. + +#** What: :substituteVariableList - substitution of a list of variable substitutions ?L in a triple +# @subject an RDF statement +# @object list of variable substitutions, e.g. ( (:x ?X)(:y ?Y) ) +{ + ?STAT :substituteVariableList ?L . + ?STAT log:includes {?S ?P ?O} . + ?L a rdf:List . + ?L rdf:first (?V ?VT) . + # _:d e:trace ( rdf:first :substituteVariableList ?L log:includes {?V ?P ?O} ). +} => { + {?S ?P ?O} :substituteVariable (?V ?VT). +}. + { - _:d e:findall ( ?A {?RULE :n3_antecedent_has ?A} ?LA ). - _:d e:findall ( ?C {?RULE :n3_consequent_has ?C} ?LC ). - ?LA log:conjunction ?FA . - ?LC log:conjunction ?FC . + ?STAT :substituteVariableList ?L . + ?STAT log:includes {?S ?P ?O} . + ?L a rdf:List . + ?L rdf:rest ?REST . + + # recover result from preceding rule: + ?L rdf:first (?V ?VT) . + ( {?S ?P ?O} (?V ?VT) ) :variableSubstitution {?SS ?P ?OS} . + + #_:d e:trace ( rdf:rest :substituteVariableList ?L + # :variableSubstitution {?SS ?P ?OS} ). } => { - ?RULE :n3RuleParts ( ?FA ?FC ) . + ?REST a rdf:List . + {?SS ?P ?OS} :substituteVariableList ?REST . }. -# { -# _:d e:findall ( ?A {?RULE :n3_antecedent_has ?A} ?LA ). -# _:d e:findall ( ?C {?RULE :n3_consequent_has ?C} ?LC ). -# ?LA log:conjunction ?FA . -# ?LC log:conjunction ?FC . -# } => { -# ?RULE :asN3 { ?FA => ?FC } -# }. +# test +{:x :sibling :y} :substituteVariableList +( (:x ?X)(:y ?Y) ) . +( (:x ?X)(:y ?Y) ) a rdf:List . + +{ ?LC :substituteVariable ?L . } => { _:dd :print (?LC :substituteVariable ?L) . }. +{ ?LC :variableSubstitution ?L . } => { _:dd :print (?LC :variableSubstitution ?L) . }. Modified: trunk/eulergui/examples/swrl-n3-rulesQ.n3 =================================================================== --- trunk/eulergui/examples/swrl-n3-rulesQ.n3 2010-03-23 18:38:34 UTC (rev 1343) +++ trunk/eulergui/examples/swrl-n3-rulesQ.n3 2010-03-23 21:21:55 UTC (rev 1344) @@ -11,16 +11,19 @@ @prefix fn: <http://www.w3.org/2005/xpath-functions#>. { - ?RULE :n3RuleParts ( ?FA ?FC ) . + _:d e:findall ( ?A { ?RULE :n3_antecedent_has ?A } ?LA ). + _:d e:findall ( ?C {?RULE :n3_consequent_has ?C} ?LC ). + ?LA log:conjunction ?FA . + ?LC log:conjunction ?FC . } => { - ?FA => ?FC + ?FA => ?FC }. -# { -# ?RULE :asN3 { ?FA => ?FC } -# } => { -# ?FA => ?FC -# }. +{ ?BC a :BadChild} => { ?BC a :BadChild}. -{ ?BC a :BadChild} => -{ ?BC a :BadChild}. \ No newline at end of file +# { ?C rdf:first ?D} => { ?C rdf:first ?D}. +# { ?C rdf:rest ?D} => { ?C rdf:rest ?D}. +# { ?C ?D rdf:nil } => { ?C ?D rdf:nil }. +# +{ ?LC :print ?L . } => { ?LC :print ?L . }. + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |