dgarijo / Widoco

Wizard for documenting ontologies. WIDOCO is a step by step generator of HTML templates with the documentation of your ontology. It uses the LODE environment to create part of the template.
Apache License 2.0
288 stars 88 forks source link

SWRL rules dont appear. #651

Closed vChavezB closed 9 months ago

vChavezB commented 10 months ago

I am trying to generate the SWRL rules I declare in my ontology but they dont apper after I generate the project.

The rules section appears empty with just a the title "4.6 Rules" and a blue rectangle

grafik

Do you have an example ontology that is known to be working and I can use to check if its just on my side?

Here is an excerpt of how I declare my SWRL rules (generated with protege)

@prefix swrl: <http://www.w3.org/2003/11/swrl#> .
[ <http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean ;
   rdfs:label "My rule" ;
   rdf:type swrl:Imp ;
   swrl:body [ rdf:type swrl:AtomList ;
               rdf:first [ rdf:type swrl:ClassAtom ;
                           swrl:classPredicate :ApplicationDataObject ;
                           swrl:argument1 :ao
                         ] ;
               rdf:rest [ rdf:type swrl:AtomList ;
                          rdf:first [ rdf:type swrl:DatavaluedPropertyAtom ;
                                      swrl:propertyPredicate :isProcessData ;
                                      swrl:argument1 :ao ;
                                      swrl:argument2 "true"^^xsd:boolean
                                    ] ;
                          rdf:rest rdf:nil
                        ]
             ] ;
   swrl:head [ rdf:type swrl:AtomList ;
               rdf:first [ rdf:type swrl:ClassAtom ;
                           swrl:classPredicate :ProcessDataObject ;
                           swrl:argument1 :ao
                         ] ;
               rdf:rest rdf:nil
             ]
 ] .
vChavezB commented 10 months ago

I debugged the app and I am not sure if swr rules are parsed

the XLST output for swr rules looks as this. In this example I added two rules to an ontology.

    <div id="swrlrules">
            <h2>SWRL rules</h2>
            <div id="d4e4498" class="entity">
                <h3>Rule #1
                    <span class="backlink">back to 
                        <a href="#toc">ToC</a>
                    </span>
                </h3>
                <p>
                    <a href="#d4e4288" title="http://datos.bne.es/def/C1001">Work</a>
                    <sup title="class" class="type-c">c</sup>(?) -&gt; 
                    <a href="#d4e4316" title="http://datos.bne.es/def/C1002">Expression</a>
                    <sup title="class" class="type-c">c</sup>(?)
                </p>
            </div>
            <div id="d4e4558" class="entity">
                <h3>Rule #2
                    <span class="backlink">back to 
                        <a href="#toc">ToC</a>
                    </span>
                </h3>
                <p>
                    <a href="#d4e4288" title="http://datos.bne.es/def/C1001">Work</a>
                    <sup title="class" class="type-c">c</sup>(?) -&gt; 
                    <a href="#d4e4316" title="http://datos.bne.es/def/C1002">Expression</a>
                    <sup title="class" class="type-c">c</sup>(?)
                </p>
            </div>
        </div>

So my guess is that the SWRL html parser is not implemented in widoco due to the fact that I was debugging and the id for the html div is different. I changed the id to swrlrules but the program crashes.

https://github.com/dgarijo/Widoco/blob/4da92b23995c37a95662bce03a8a174ccaa44f7f/src/main/java/widoco/LODEParser.java#L186

vChavezB commented 10 months ago

Ok I made a PR #652 perhaps you can check if it looks fine. The rules are now displayed. However as you see the first element is "null".

grafik

vChavezB commented 10 months ago

ok an update now the rules look much better with annotation from rdfs:comment and rdfs:label

grafik

this requires changing the xslt of swrl-rules in specific , havent made a PR as I hope this gets merged first :) #653

    <xsl:template match="swrl:Imp | rdf:Description[rdf:type[@rdf:resource = 'http://www.w3.org/2003/11/swrl#Imp']]">
        <div id="{generate-id()}" class="entity">
            <h3>
                <xsl:value-of select="concat('Rule #', count(preceding-sibling::swrl:Imp | preceding-sibling::rdf:Description[rdf:type[@rdf:resource = 'http://www.w3.org/2003/11/swrl#Imp']]) + 1, ' ', rdfs:label)" />
                <xsl:call-template name="get.backlink.to.top" />
            </h3>
            <p>
                <!-- Add rdfs:comment -->
                <xsl:if test="rdfs:comment">
                    <strong>Comment: </strong>
                    <xsl:value-of select="rdfs:comment" /><br/><br/>
                </xsl:if>
                <!-- Continue with the existing content -->
                <xsl:apply-templates select="swrl:body" />
                <xsl:text> -> </xsl:text>
                <xsl:apply-templates select="swrl:head" />
            </p>
        </div>
    </xsl:template>
dgarijo commented 10 months ago

Thanks a lot. So far, I think no swrl rules were considered, as I did not have a use case for them (I may have simplified them from the XSLT output). I will need to review the PR, since in the develop branch I was considering other types of rules I had been asked to include (but not SWRL). This is a great addition!

dgarijo commented 10 months ago

Just pls make sure you send your PRs to the right branch @vChavezB (see https://github.com/dgarijo/Widoco#contribution-guidelines)

vChavezB commented 10 months ago

I read the code again and the xlst sources. So if I understand correctly the "rules" extraction uses annotations from owl Individuals or which type of rules does it parse.

https://github.com/dgarijo/Widoco/blob/4da92b23995c37a95662bce03a8a174ccaa44f7f/src/main/resources/lode/extraction.xsl#L2334

I did not found a sample ontology that uses this transformation. This would be helpful to know as it was not clear to me. I will update the PR and refine it.

dgarijo commented 10 months ago

@vChavezB sorry, the rules stuff I added is for very specific owl annotations for a specific project I am doing.

The SWRL module you added recovers the original SWRL annotations, and I think they should be added, but separately. Please just ignore the module I did for annotations of rules and use a new one with the id you gave, as you were doing. Thanks in advance!

dgarijo commented 9 months ago

This issue should now be closed and will be up in the next release See #654 for more info. Thanks @vChavezB for your work!!