diff --git a/src/main/java/widoco/LODEParser.java b/src/main/java/widoco/LODEParser.java index f27d770..c312278 100644 --- a/src/main/java/widoco/LODEParser.java +++ b/src/main/java/widoco/LODEParser.java @@ -182,14 +182,13 @@ private void parse(String content, Properties langFile) { "<h3 id=\"namedindividuals\" class=\"list\">" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h3>"); break; - /*missing: rules!*/ - case "rules": + case "swrlrules": ruleList = (getTermList(html.item(i))); rules = (nodeToString(html.item(i))); -// rules = rules.replace( -// "<h2>" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h2>", -// "<h3 id=\"rules\" class=\"list\">" -// + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h3>"); + rules = rules.replace( + "<h2>" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h2>", + "<h3 id=\"rules\" class=\"list\">" + + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h3>"); break; } } @@ -263,6 +262,12 @@ private String nodeToString(Node n) { // (the second one) private Node fixAnchor(Node nodeToFix) { try { + String AttrID = nodeToFix.getAttributes().item(0).getTextContent(); + // Do nothing for swrl rules, they do not have + // <a> and <h3> + if (Objects.equals(AttrID, "swrlrules")) { + return nodeToFix; + } NodeList outerDiv = nodeToFix.getChildNodes(); for (int i = 0; i < outerDiv.getLength(); i++) { Node currentNode = outerDiv.item(i); diff --git a/src/main/resources/lode.zip b/src/main/resources/lode.zip index 9d55f37..6c1c8fe 100644 Binary files a/src/main/resources/lode.zip and b/src/main/resources/lode.zip differ diff --git a/src/main/resources/lode/swrl-module.xsl b/src/main/resources/lode/swrl-module.xsl index 7079e70..8c5ae74 100644 --- a/src/main/resources/lode/swrl-module.xsl +++ b/src/main/resources/lode/swrl-module.xsl @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2010-2013, Silvio Peroni <essepuntato@gmail.com> +Copyright (C) 2023, Victor Chavez <vchavezb@protonmail.de> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -28,18 +29,59 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. xmlns:f="http://www.essepuntato.it/xslt/function" xmlns:dcterms="http://purl.org/dc/terms/" xmlns="http://www.w3.org/1999/xhtml"> - + + + <xsl:template match="rdf:Description" mode="toc"> + <li> + <a href="#{generate-id()}"> + <xsl:choose> + <xsl:when test="string(rdfs:label)"> + <xsl:value-of select="rdfs:label"/> + </xsl:when> + <xsl:otherwise> + <xsl:text>Rule #</xsl:text> + <xsl:value-of select="count(preceding-sibling::rdf:Description[rdf:type[@rdf:resource = 'http://www.w3.org/2003/11/swrl#Imp']]) + 1"/> + </xsl:otherwise> + </xsl:choose> + </a> + </li> + </xsl:template> + + <xsl:template name="get.swrl.toc"> + <ul class="hlist"> + <xsl:apply-templates select="/rdf:RDF/rdf:Description[rdf:type[@rdf:resource='http://www.w3.org/2003/11/swrl#Imp']]" mode="toc"> + <xsl:sort select="rdfs:comment" order="ascending" data-type="text"/> + </xsl:apply-templates> + </ul> + </xsl:template> + <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>Rule #<xsl:value-of select="count(preceding-sibling::swrl:Imp | preceding-sibling::rdf:Description[rdf:type[@rdf:resource = 'http://www.w3.org/2003/11/swrl#Imp']]) + 1" /> <xsl:call-template name="get.backlink.to.top" /></h3> + <h3> + <xsl:choose> + <xsl:when test="string(rdfs:label)"> + <xsl:value-of select="rdfs:label"/> + </xsl:when> + <xsl:otherwise> + <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)"/> + </xsl:otherwise> + </xsl:choose> + <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> - + <xsl:template match="swrl:body | swrl:head | swrl:AtomList/rdf:first | rdf:Description[rdf:type[@rdf:resource = 'http://www.w3.org/2003/11/swrl#AtomList']]/rdf:first"> <xsl:apply-templates /> </xsl:template> @@ -140,6 +182,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. <xsl:if test="exists(//(swrl:Imp | rdf:Description[rdf:type[@rdf:resource = 'http://www.w3.org/2003/11/swrl#Imp']]))"> <div id="swrlrules"> <h2>SWRL rules</h2> + <xsl:call-template name="get.swrl.toc"/> <xsl:apply-templates select="//(swrl:Imp | rdf:Description[rdf:type[@rdf:resource = 'http://www.w3.org/2003/11/swrl#Imp']])" /> </div> </xsl:if>