Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

try to define in N3 logic a list member predi

2009-08-30
2013-04-05
  • Hi

    In N3 examples, I tried to reproduce in N3 logic the classic definition of member/2 in Prolog.
    Here are the rules I tried, but they give no result :

    {
      ?LIST a rdf:List .
      ?LIST rdf:first ?FIRST .
    } => {
      ?FIRST :member1 ?LIST .
    } .

    # member(X,[Y|R]) :- member(X,R).
    @forAll :X, :R, :Y .
    {
      ?X a rdf:List .
      ?X :member1 ?R .
    } => {
      ?R1 a rdf:List .
      ?R1 rdf:first ?Y .
      ?R1 rdf:rest  ?R .
      ?X :member1 ?R1 .
    } .

    The full test is here:
    http://eulergui.svn.sourceforge.net/viewvc/eulergui/trunk/eulergui/examples/list1.n3
    And the EuelrGUI project:
    http://eulergui.svn.sourceforge.net/viewvc/eulergui/trunk/eulergui/examples/list1.n3p

     
    • Jos De Roo
      Jos De Roo
      2009-08-30

      There list:in in http://eulersharp.sourceforge.net/2003/03swap/rpo-rules.n3
      which is how it was done in the beginning and it worked fine.
      Since a while this is a builtin and there is actually another list:member too
      see http://www.w3.org/2000/10/swap/doc/CwmBuiltins

       
    • Indeed the builtin for list:in works fine, as fine as Prolog member/2 which implements it , cf
      http://eulergui.svn.sourceforge.net/viewvc/eulergui/trunk/eulergui/examples/list3.n3

      However, there seems to be problems when testing the same definition of list:in as in rpo-rules.n3 :
      http://eulergui.svn.sourceforge.net/viewvc/eulergui/trunk/eulergui/examples/list2.n3

      These simple triples do not pass :

        "1" mylist:in ( "1" "2" ) .
        :a1 mylist:in ( :a1 :a2 ) .

       
      • Jos De Roo
        Jos De Roo
        2009-09-01

        in the case of mylist:in there is no built-in knowledge
        even not that (i j k) is a rdf:List
        so tell eye all the rules or give the facts straight
        ("1" "2") a rdf:List.
        (:a1 :a2) a rdf:List.

         
        • Indded when declaring the facts straight
          ("1" "2") a rdf:List.
          (:a1 :a2) a rdf:List.

          it works.

          However I think it should not be necessary to specify that.
          It seems that per the RDF spec. :
          http://www.w3.org/TR/REC-rdf-syntax/#collections

          something that is the subject of rdf:first and  rdf:rest is necessarily a rdf:List .
          And the parenthesis notation in N3 is just a short form for a chain of rdf:first and rdf:rest properties.

           
          • Jos De Roo
            Jos De Roo
            2009-09-01

            that's exactly what I meant with "tell eye all the rules":

            rdf:first rdfs:domain rdf:List.
            rdf:rest rdfs:domain rdf:List; rdfs:range rdf:List.

            {?P rdfs:domain ?C. ?S ?P ?O} => {?S a ?C}.
            {?P rdfs:range ?C. ?S ?P ?O} => {?O a ?C}.

            etc..

            as per RDF MT