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
276 stars 86 forks source link

Fix SWRL parsing #654

Closed vChavezB closed 6 months ago

vChavezB commented 7 months ago

Addes support for correct xslt transformation for TOC and SWRL display. The transformation checks if rdfs:label is defined if not the rules are generically number as they appear in the XML serialization of the ontology.

Fixes #651

TOC

grafik

Contents

grafik

vChavezB commented 7 months ago

The only bug I notice is that it seems that the TOC and numbering starting at 3. Cross reference does not match number-wise.

grafik

grafik

vChavezB commented 7 months ago

Attached is one of the test ontologies from this repo (turtle) with two rules just to test this PR.

bne.txt

dgarijo commented 7 months ago

@vChavezB thanks! Can you please merge against the develop branch? The numbering is generated dynamically based on the anchors you have. Maybe you are introducing a new anchor?

vChavezB commented 7 months ago

@vChavezB thanks! Can you please merge against the develop branch? The numbering is generated dynamically based on the anchors you have. Maybe you are introducing a new anchor?

I think I fixed this bug. Still trying to show the SWRL rules as its own section, it does not appear in the TOC but only in the overview and the contents.

Will update the PR.

vChavezB commented 7 months ago

Changed to develop. TOC and section numbering is correct but the section SWRL Rules in TOC is missing. Do you have any suggestions on what it could be?

vChavezB commented 7 months ago

It appears just as

grafik

Without the section number also at the TOC as mentioned in my previous comment.

grafik

dgarijo commented 7 months ago

I'll have to have a look. Probably a missing id or class.

dgarijo commented 7 months ago

Thanks for your quick response btw! I am a little overwhelmed this week, but I'd like to add all these changes before the holidays.

vChavezB commented 7 months ago

Maybe you are introducing a new anchor?

Is this what you mean by anchor ? This is what I did

https://github.com/vChavezB/Widoco/blob/63c46209082e2e107026905d3e073c79a62a61cd/src/main/java/widoco/LODEParser.java#L286

Reason is that SWRL rules do not have an IRI, this is how they look serialized as xml rdf

   <rdf:Description rdf:about="http://datos.bne.es/vocab/a">
        <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Variable"/>
    </rdf:Description>
    <rdf:Description>
        <swrla:isRuleEnabled rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</swrla:isRuleEnabled>
        <rdfs:comment>comment s2</rdfs:comment>
        <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Imp"/>
        <swrl:body>
            <rdf:Description>
                <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                        <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1001"/>
                        <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
            </rdf:Description>
        </swrl:body>
        <swrl:head>
            <rdf:Description>
                <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                        <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1002"/>
                        <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
            </rdf:Description>
        </swrl:head>
    </rdf:Description>
    <rdf:Description>
        <swrla:isRuleEnabled rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</swrla:isRuleEnabled>
        <rdfs:comment>comment s1</rdfs:comment>
        <rdfs:label>S1</rdfs:label>
        <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Imp"/>
        <swrl:body>
            <rdf:Description>
                <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                        <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1001"/>
                        <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
            </rdf:Description>
        </swrl:body>
        <swrl:head>
            <rdf:Description>
                <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                        <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1002"/>
                        <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
            </rdf:Description>
        </swrl:head>
    </rdf:Description>

and the xslt html transformation

        <div id="swrlrules">
            <h2>SWRL rules</h2>
            <ul class="hlist"></ul>
            <div id="d4e4498" class="entity">
                <h3>Rule #1 
                    <span class="backlink">back to 
                        <a href="#toc">ToC</a>
                    </span>
                </h3>
                <p>
                    <strong>Comment: </strong>comment s2
                    <br />
                    <br />
                    <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="d4e4554" class="entity">
                <h3>Rule #2
                    <span class="backlink">back to 
                        <a href="#toc">ToC</a>
                    </span>
                </h3>
                <p>
                    <strong>Comment: </strong>comment s1
                    <br />
                    <br />
                    <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>
dgarijo commented 7 months ago

It looks like you are not at fault, I need to review this a little bit in detail @vChavezB. I just need a little time

vChavezB commented 7 months ago

Thanks for your quick response btw! I am a little overwhelmed this week, but I'd like to add all these changes before the holidays.

sure no prob!

dgarijo commented 7 months ago

Sorry, but the tests don't pass. Are you sure you pass them locally? Which version of Java are you using?

vChavezB commented 7 months ago

Let me check why they didnt pass. Btw i found the bug I think it has to do with h2 tag replacement in the LodeParser

vChavezB commented 7 months ago

I think there was a missing import. Also solved the hyperlink of swrl rule sections. I did not use the language properties and at the moment replace it directly see

https://github.com/vChavezB/Widoco/blob/8c9838d12c1b4b418cda4aea6e9d28a27a419d53/src/main/java/widoco/LODEParser.java#L208

vChavezB commented 7 months ago

I was experimenting with the project AOWLN, a Protégé plugin to generate images from SWRL rules. I modified it to be used independent of protege to try to integrate it with widoco and named it aowln-sa.

I wanted to integrate it in widoco but due to dependency conflicts (owl-api 4.5.25) and my limted experience with java I am using it separately by generating the images and then modifying the cross-ref-xx.html section. However sometimes if the SWRL graph is small then the ratio of images looks different. Do you have any suggestions on how to achieve a more proportionate ratio ? I am not that good at css,html and javascript for websites. This is my css and this is an example of how I attach the images to the cross-ref-xx.hml page.

<div class="grid-container">
    <div class="swrl-container">Body
    <img src="swrlrules/rule_R3_AOs_are_transitive_from_device_profile-body.png" style="width: 350px; display: inline-block;" title="SWRL Body">
    </div>
    <div class="swrl-container">Head<img src="swrlrules/rule_R3_AOs_are_transitive_from_device_profile-head.png" style="width: 350px; display: inline-block;" title="SWRL Head">
    </div>
</div>

Big graph

Small graph

vChavezB commented 7 months ago

After some chat gpt and debugging I have made a javascript to scale the swrl images so they have the same ratio.

grafik

This is not part of the PR but just wanted to give some ideas on how this might look integrated into Widoco :)

dgarijo commented 7 months ago

@vChavezB thanks for your edits. I guess that if you want to add images for rules, we can introduce a metadata property for annotating them in the ontology, so you don't need to add them manually. Something like widoco:hasRuleImage, or something like that. I am bringing this up in case this helps things. Are you done with your edits? I see that you are still committing to this PR.

vChavezB commented 7 months ago

Yes, you can do a review now.

About the metadata... Im afk so I will post later some feedback about it.

vChavezB commented 7 months ago

Hello @dgarijo

we can introduce a metadata property for annotating them in the ontology

Would you annotate this for each rule? If yes, I do not know if this would work for my use case (i.e. Protege). In protege you can define SWRL rules over the SWRL Tab. As far as I know you can add a name (rdfs:label) and a comment (rdfs:comment). You would need to manually add the widoco:hasRuleImage annotation in the serialized representation of the ontology outside of Protege.

grafik

dgarijo commented 6 months ago

Thanks, I opened a new issue #662 to follow up on this. Merging this PR (about time!)