ontodev / ldtab.clj

Linked Data Tables
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

Bug: Annotations on SWRL rules #32

Open ckindermann opened 2 weeks ago

ckindermann commented 2 weeks ago

Annotations on SWRL rules do not end up in the annotation column because we translate SWRL rules as normal RDF. Since SWRL rules are grouped using an 'existential' blank node (meaning a blank node that doesn't get collapsed in LDTab), we

  1. generate a blank node for a SWRL rule that serves as the subject in LDTab
  2. use the value of its rdf:type as the predicate in LDTab (in this case swrl:Imp -- this is done in an attempt to indicate what an existential blank node points to)
  3. use the JSON object as the object in LDTab.

For example:

[ rdfs:comment "This can't be added as a property chain because it causes a circularity violation for 'part of'." ;
   rdf:type swrl:Imp ;
   swrl:body [ rdf:type swrl:AtomList ;
               rdf:first [ rdf:type swrl:IndividualPropertyAtom ;
                           swrl:propertyPredicate obo:BSPO_0000120 ;
                           swrl:argument1 <urn:swrl:var#y> ;
                           swrl:argument2 <urn:swrl:var#z>
                         ] ;
               rdf:rest [ rdf:type swrl:AtomList ;
                          rdf:first [ rdf:type swrl:IndividualPropertyAtom ;
                                      swrl:propertyPredicate obo:BFO_0000050 ;
                                      swrl:argument1 <urn:swrl:var#x> ;
                                      swrl:argument2 <urn:swrl:var#y>
                                    ] ;
                          rdf:rest rdf:nil
                        ]
             ] ;
   swrl:head [ rdf:type swrl:AtomList ;
               rdf:first [ rdf:type swrl:IndividualPropertyAtom ;
                           swrl:propertyPredicate obo:BSPO_0000120 ;
                           swrl:argument1 <urn:swrl:var#x> ;
                           swrl:argument2 <urn:swrl:var#z>
                         ] ;
               rdf:rest rdf:nil
             ]
 ] .

gets translated into the following JSON object:

{
  "<http://www.w3.org/2003/11/swrl#body>": [
    {
      "datatype": "_JSON",
      "object": {
        "rdf:first": [
          {
            "datatype": "_JSON",
            "object": {
              "<http://www.w3.org/2003/11/swrl#argument1>": [
                {
                  "datatype": "_IRI",
                  "object": "<urn:swrl:var#y>"
                }
              ],
              "<http://www.w3.org/2003/11/swrl#argument2>": [
                {
                  "datatype": "_IRI",
                  "object": "<urn:swrl:var#z>"
                }
              ],
              "<http://www.w3.org/2003/11/swrl#propertyPredicate>": [
                {
                  "datatype": "_IRI",
                  "object": "obo:BSPO_0000120"
                }
              ],
              "rdf:type": [
                {
                  "datatype": "_IRI",
                  "object": "<http://www.w3.org/2003/11/swrl#IndividualPropertyAtom>"
                }
              ]
            }
          }
        ],
        "rdf:rest": [
          {
            "datatype": "_JSON",
            "object": {
              "rdf:first": [
                {
                  "datatype": "_JSON",
                  "object": {
                    "<http://www.w3.org/2003/11/swrl#argument1>": [
                      {
                        "datatype": "_IRI",
                        "object": "<urn:swrl:var#x>"
                      }
                    ],
                    "<http://www.w3.org/2003/11/swrl#argument2>": [
                      {
                        "datatype": "_IRI",
                        "object": "<urn:swrl:var#y>"
                      }
                    ],
                    "<http://www.w3.org/2003/11/swrl#propertyPredicate>": [
                      {
                        "datatype": "_IRI",
                        "object": "obo:BFO_0000050"
                      }
                    ],
                    "rdf:type": [
                      {
                        "datatype": "_IRI",
                        "object": "<http://www.w3.org/2003/11/swrl#IndividualPropertyAtom>"
                      }
                    ]
                  }
                }
              ],
              "rdf:rest": [
                {
                  "datatype": "_IRI",
                  "object": "rdf:nil"
                }
              ],
              "rdf:type": [
                {
                  "datatype": "_IRI",
                  "object": "<http://www.w3.org/2003/11/swrl#AtomList>"
                }
              ]
            }
          }
        ],
        "rdf:type": [
          {
            "datatype": "_IRI",
            "object": "<http://www.w3.org/2003/11/swrl#AtomList>"
          }
        ]
      }
    }
  ],
  "<http://www.w3.org/2003/11/swrl#head>": [
    {
      "datatype": "_JSON",
      "object": {
        "rdf:first": [
          {
            "datatype": "_JSON",
            "object": {
              "<http://www.w3.org/2003/11/swrl#argument1>": [
                {
                  "datatype": "_IRI",
                  "object": "<urn:swrl:var#x>"
                }
              ],
              "<http://www.w3.org/2003/11/swrl#argument2>": [
                {
                  "datatype": "_IRI",
                  "object": "<urn:swrl:var#z>"
                }
              ],
              "<http://www.w3.org/2003/11/swrl#propertyPredicate>": [
                {
                  "datatype": "_IRI",
                  "object": "obo:BSPO_0000120"
                }
              ],
              "rdf:type": [
                {
                  "datatype": "_IRI",
                  "object": "<http://www.w3.org/2003/11/swrl#IndividualPropertyAtom>"
                }
              ]
            }
          }
        ],
        "rdf:rest": [
          {
            "datatype": "_IRI",
            "object": "rdf:nil"
          }
        ],
        "rdf:type": [
          {
            "datatype": "_IRI",
            "object": "<http://www.w3.org/2003/11/swrl#AtomList>"
          }
        ]
      }
    }
  ],
  "rdf:type": [
    {
      "datatype": "_IRI",
      "object": "<http://www.w3.org/2003/11/swrl#Imp>"
    }
  ],
  "rdfs:comment": [
    {
      "datatype": "xsd:string",
      "object": "This can't be added as a property chain because it causes a circularity violation for 'part of'."
    }
  ]
}

However, the representation of SWRL rules in OWL Functional Syntax would mark the rdfs:comment as an annotation:

DLSafeRule(
   Annotation(rdfs:comment "This can't be added as a property chain because it causes a circularity violation for 'part of'.")
   Body(ObjectPropertyAtom(obo:BSPO_0000120 Variable(<urn:swrl:var#y>) Variable(<urn:swrl:var#z>)) 
        ObjectPropertyAtom(obo:BFO_0000050 Variable(<urn:swrl:var#x>) Variable(<urn:swrl:var#y>)))
   Head(ObjectPropertyAtom(obo:BSPO_0000120 Variable(<urn:swrl:var#x>) Variable(<urn:swrl:var#z>))))

So, we need to decide whether LDTab should translate SWRL rules in a way that doesn't correspond to the standard RDF translation.

ckindermann commented 2 weeks ago

On second thought, this is not a bug in LDTab. But the decision on how SWRL rules are encoded in LDTab is important for wiring.{clj,rs} because we use OWL Functional Syntax to translate between syntaxes.

There is no 'correct' decision. The OWL spec doesn't include SWRL rules - meaning there is no W3C standard for SWRL rules in OWL Functional Syntax. All we have is a paper that defines a syntax for (DL Safe) SWRL rules in OWL and an implementation of this syntax in the OWL API (even this is not 100% true because there are differences between the grammar presented in the paper and the actual implementation...).

jamesaoverton commented 2 weeks ago

We discussed this on a call on 2024-10-29. My (mostly uninformed) opinion is to go with the RDF representation.