From: <jm...@us...> - 2010-03-21 12:37:26
|
Revision: 1335 http://eulergui.svn.sourceforge.net/eulergui/?rev=1335&view=rev Author: jmvanel Date: 2010-03-21 12:37:18 +0000 (Sun, 21 Mar 2010) Log Message: ----------- n3_rules_good_practices.html : WIP Modified Paths: -------------- trunk/eulergui/html/n3_rules_good_practices.html Modified: trunk/eulergui/html/n3_rules_good_practices.html =================================================================== --- trunk/eulergui/html/n3_rules_good_practices.html 2010-03-19 20:34:52 UTC (rev 1334) +++ trunk/eulergui/html/n3_rules_good_practices.html 2010-03-21 12:37:18 UTC (rev 1335) @@ -5,13 +5,329 @@ <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>N3 rules good practices</title> + <style type="text/css"> + + .CREATION {color:#09b409; +font-weight:bold; }</style> <meta name="generator" content="Amaya, see http://www.w3.org/Amaya/" /> </head> <body> +<p style="font-size: 20pt">N3 rules: good practices, design patterns, +refactoring</p> -<h2>N3 refactoring: extract part of antecedent</h2> +<p>\xA9 Jean-Marc Vanel - $Date$</p> +<p>TOC</p> + +<div class="toc"> +<ul> + <li><a href="#L470">Introduction</a></li> + <li><a href="#L587">The limitations of RDF</a> + <ul> + <li><a href="#L930">Open world assumption</a></li> + <li><a href="#L1262">Monotonicity</a></li> + </ul> + </li> + <li><a href="#L593">The limitations of N3 logic</a></li> + <li><a href="#L944">Using OWL ontologies</a></li> + <li><a href="#L387">Variables patterns</a> + <ul> + <li><a href="#L398">Quantification</a></li> + <li><a href="#L420">Multiple occurences</a></li> + </ul> + </li> + <li><a href="#L180">Design patterns</a> + <ul> + <li><a href="#L432">Annotate the existing objects</a></li> + <li><a href="#L445">Create new objects</a></li> + </ul> + </li> + <li><a href="#L557">Data structures</a></li> + <li><a href="#L255">Lists variants</a> + <ul> + <li><a href="#L215">Lists OWL style</a></li> + <li><a href="#L303">Cloning a list</a></li> + <li><a href="#L170">Accumulating by recursion</a></li> + </ul> + </li> + <li><a href="#L26">N3 refactorings</a> + <ul> + <li><a href="#L135">Extract part of antecedent</a></li> + </ul> + </li> +</ul> +</div> + +<h2 id="L470">Introduction</h2> + +<p>This is a tutorial on writing N3 rules, and various design patterns.</p> + +<p>It will address issues of business rules, transformations, validation, +processing lists, etc..</p> + +<p>There is little material directly on the N3 rules, but there are things +about other rule languages: SWRL, Drools, etc..</p> + +<p><a href="http://www.google.fr/search?q=SWRL+design+pattern">Google search +SWRL+design+pattern</a></p> + +<p><a href="http://protege.cim3.net/cgi-bin/wiki.pl?SWRLLanguageFAQ">Prot\xE9g\xE9 +wiki SWRL Language FAQ</a></p> + +<p></p> + +<p>http://en.wikipedia.org/wiki/Graph_rewriting</p> + +<p>http://rewriting.loria.fr/</p> + +<p>http://en.wikipedia.org/wiki/Rewriting</p> + +<p></p> + +<p>Throughout this document, we will put variables corresponding to resource +(object) creation, that is existentially qualified variables, in <span +class="CREATION">bold green</span>.</p> + +<p><strong>Abreviations</strong></p> + +<p>KB == Knowledge Base</p> + +<p>LSH == Left Hand Side (a.k.a. antecedent) </p> + +<p>RSH == Right Hand Side (a.k.a. consequent) </p> + +<p></p> + +<h2 id="L587">The limitations of RDF</h2> + +<p>The whole point of this paragraph is that there is really no limitation.</p> + +<p>First let's say that in terms of expressive power for an object graph data +language, there is no limitation. Everything that can be expressed in XML, XMI, +SQL, JSON, can also be expressed in RDF and N3. Moreover, RDF is by design +adapted to Internet: URI are globally unique identifiers that can be +dererenced, and it has SWRL for query language and protocol.</p> + +<p>Then the principles of the Semantic Web imply the Open World Assumption, +which is a necessary limitation for the huge and ever changing Web.</p> + +<h3 id="L930"><a +href="http://www.betaversion.org/~stefano/linotype/news/91/">Open world +assumption</a></h3> + +<p>The closed world assumption implies that everything we don’t know is +false, while the open world assumption states that everything we don’t +know is undefined. </p> + +<p>The closed world is the point of vue of all databases, except RDF databases. +Related to closed world assumption, there is a the unique name assumption, +which mean that a concept has a unique string representation (URI in RDF case); +or converselly two different string representations are necessarily distinct +concepts.</p> + +<p>The semantic web, N3 logic, and OWL, are based on Open World Assumption. But +we will see later that there are extension builtins predicates that allow some +features of closed world.</p> + +<h3 id="L1262">Monotonicity</h3> + +<p>Monotonicity means that learning a new piece of (non contradictory) +knowledge cannot reduce the set of what is known ( taken from <a +href="http://en.wikipedia.org/wiki/Non-monotonic_logic">wikipedia.org / +Non-monotonic_logic</a> ). This is closely related to Open World Assumption.</p> + +<p>A monotonic logic forbids such things as default reasoning ( birds fly +except ostriches ).</p> + +<p>For the same reason, global negation is forbiden ( "no Papuan pilots an +airplane" ). The authors of N3 logic invented "scoped negation" as a weaker +form of negation; see the paragraph "Motivation" of <a +href="http://www.w3.org/DesignIssues/N3Logic">DesignIssues / N3Logic</a> .</p> + +<h2 id="L593">The limitations of N3 logic</h2> + +<p>The original N3 logic (like SWRL) follows strictly the principles of the +Semantic Web: Open World Assumption, no Unique Name Assumption, and +monotonicity.</p> + +<p>However, the orignal CWM, Euler and Drools/N3 engines have builtins +predicates that allow some features of closed world:</p> +<ul> + <li><code>log:equalTo</code> and <code>log:notEqualTo</code> allows a form of + Unique Name Assumption</li> + <li><code>e:findall</code> allows to by-pass monotonicity; example: find all + married couples with more than 1 child: <a + href="../test/findall2.n3">test/findall2.n3</a></li> +</ul> + +<p>Breaking monotonicity is not a problem if one is aware of the underlying +principles. In this respect it is not recommanded to add to the current KB the +consequences of non-monotonic rules. EulerGUI should flag rules and documents +containing such rules.</p> + +<h2 id="L944">Using OWL ontologies</h2> + +<p>add the revelant rules from Euler project. </p> + +<p>???</p> + +<h2 id="L387">Variables patterns</h2> + +<h3 id="L398">Quantification</h3> + +<p>existential, universal</p> + +<p>variable binding</p> + +<p>???</p> + +<h3 id="L420">Multiple occurences</h3> + +<p>Multiple occurences in LHS means adding constraints, which diminishes the +set of matching statements for the rule.</p> + +<p>Multiple occurences in RHS means adding new statements to the KB.</p> + +<h2 id="L180">Design patterns</h2> + +<h3 id="L432">Annotate the existing objects</h3> + +<p>This is the simplest pattern, and the most efficient on all engines. It is +particuliar adapted to problems with a 1 to 1 correspondence between the +asserted objects and the inferred objects. It is opposed to the following +pattern "Create new objects".</p> + +<h3 id="L445">Create new objects</h3> + +<p>keep track</p> + +<p>often not possible with Euler engine</p> + +<p>???</p> + +<h2 id="L557">Data structures</h2> + +<p>No sets ? Why ? Because ordinary RDF properties act as sets.</p> + +<p>RDF is a bunch of associative arrays (called maps in Java and C++). ????</p> + +<h2 id="L255">Lists variants</h2> + +<p>RDF lists, OWL, linked list.</p> + +<p>transitive properties</p> + +<h3 id="L215">Lists OWL style</h3> + +<p>????</p> + +<p>There is a paper describing the list pattern in OWL:</p> + +<p>Drummond, N., Rector, A.L., Stevens, R., Moulton, G., Horridge, M., Wang, H, +Seidenberg, J. Putting OWL in Order: Patterns for Sequences in OWL, in 2nd OWL +Experiences and Directions Workshop, Athens, GA</p> + +<p><a +href="http://www.webont.org/owled/2006/acceptedLong/submission_12.pdf">http://www.webont.org/owled/2006/acceptedLong/submission_12.pdf</a></p> + +<p></p> + +<h3 id="L303">Cloning a list</h3> + +<p>Here is an example with user specific :first and :rest properties , <a +href="../examples/clone-list-forward.n3">clone-list-forward.n3</a>. It clones +the list in the forward direction.</p> +<pre>{ ?L :first ?F . + ?L :rest ?R . + ?LC :clone_of ?L . +} => { + ?LC :first ?F . + ?LC :rest <strong><span class="CREATION">?<span style="font-weight:bold;"></span>RC</span></strong> . + <span class="CREATION">?RC</span> :clone_of ?R . +} .</pre> + +<p>It must be provided with a start statement, e.g.:</p> +<pre>:newNode :clone_of :existingNode .</pre> + +<p></p> + +<p>Due to limitations in Euler/Eye engine, it is not possible to generate +rdf:first and rdf:rest properties. However, this is possible </p> + +<p>with Drools/N3 engine. With both engines, it is possible to to clone an RDF +list using a rule similar to the above, matching rdf:first and rdf:rest +properties in the LSH : <a +href="../examples/clone-rdf-list-forward.n3">clone-rdf-list-forward.n3</a> .</p> + +<p></p> + +<p>Here is another example with user specific :first and :rest properties, <a +href="../examples/clone-list.n3">clone-list.n3</a>. It clones the list in the +"backward" direction, that is starting from the end.</p> +<pre>{ # initial condition + ?L :first ?F . + ?L :rest :nil . +} => { + <span class="CREATION">?LC</span> :first ?F . + <span class="CREATION">?LC</span> :rest_clone :nil . + <span class="CREATION">?LC</span> :clone_of ?L . +} . +{ # recursion + ?L :first ?F . + ?L :rest ?R . + ?RC :clone_of ?R . +} => { + ?LC :first ?F . + ?LC :rest_clone ?RC . + ?LC :clone_of ?L . +} .</pre> + +<p></p> + +<p>Note the difference in semantics with the preceding example, where the +cloning was triggered by a "start statement". Here, whenever there is a list +made with the :first and :rest properties, a clone is created.</p> + +<p></p> + +<p>These examples are just design patterns. I real life, for cloning to be +useful, domain logic will be added, like:</p> +<ul> + <li>filtering some items in the list (e.g. creating a list of good customers + from a list of customers)</li> + <li>assigning some properties to the cloned nodes (e.g. associating a sales + representative to each customer in the list)</li> +</ul> + +<p></p> + +<h3 id="L170">Accumulating by recursion</h3> + +<p>Itinerary is a linked list, and each Itinerary is also a step.</p> +<pre>{ + ?I a itin:Itinerary . + ?I itin:distance ?D . + ?I list:hasNext ?N . + ?N :totalDistance ?NT . + (?D ?NT) math:sum ?T . +} => { + ?I :totalDistance ?T . +} . + +{ + ?I a itin:Itinerary . + ?I list:hasNext itin:emptyItinerary . +} => { + ?I :totalDistance 0.0 . +} .</pre> + +<p></p> + +<h2 id="L26">N3 refactorings</h2> + +<h3 id="L135">Extract part of antecedent</h3> + <p><strong>Motivation</strong></p> <p>Suppose the original rule OR is writen as :</p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jm...@us...> - 2010-04-15 12:18:23
|
Revision: 1456 http://eulergui.svn.sourceforge.net/eulergui/?rev=1456&view=rev Author: jmvanel Date: 2010-04-15 12:18:10 +0000 (Thu, 15 Apr 2010) Log Message: ----------- n3_rules_good_practices.html : add "The power of findall", e:disjunction examples, Rules languages links Modified Paths: -------------- trunk/eulergui/html/n3_rules_good_practices.html This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |