Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for rules #628

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/java/widoco/CreateResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void generateDocumentation(String outFolder, Configuration c, File
if (c.isIncludeOverview()) {
overview = createOverviewSection(folderOut + File.separator + "sections", c, lode.getClassList(),
lode.getPropertyList(), lode.getDataPropList(), lode.getAnnotationPropList(),
lode.getNamedIndividualList(), languageFile);
lode.getNamedIndividualList(), lode.getRuleList(), languageFile);
}
if (c.isIncludeDescription()) {
description = createDescriptionSection(folderOut + File.separator + "sections", c, languageFile);
Expand Down Expand Up @@ -253,7 +253,7 @@ private static String createIntroductionSection(String path, Configuration c,Pro

// the lists passed onto this method are the fixed lists
private static String createOverviewSection(String path, Configuration c, String classesList, String propList,
String dataPropList, String annotationProps, String namedIndividuals, Properties lang) {
String dataPropList, String annotationProps, String namedIndividuals, String rules, Properties lang) {
String textToWrite = "";
if ((c.getOverviewPath() != null) && (!"".equals(c.getOverviewPath()))) {
textToWrite = WidocoUtils.readExternalResource(c.getOverviewPath());
Expand All @@ -279,6 +279,11 @@ private static String createOverviewSection(String path, Configuration c, String
textToWrite += ("<h4>" + lang.getProperty(Constants.LANG_NAMED_INDIV) + "</h4>");
textToWrite += (namedIndividuals);
}
if (!"".equals(rules) && rules != null ) {
//only eng support for now
textToWrite += ("<h4> Rules </h4>");
textToWrite += (rules);
}
// add the webvowl diagram, if selected
if (c.isCreateWebVowlVisualization()) {
textToWrite += "<iframe align=\"center\" width=\"100%\" height =\"500px\" src=\"webvowl/index.html\"></iframe> ";
Expand Down Expand Up @@ -337,6 +342,10 @@ private static String createCrossReferenceSection(String path, LODEParser lodePa
if (includesNamedIndividual) {
textToWrite += lodeParser.getNamedIndividuals();
}
//since rules are an edge case, if they exist we add them
if(lodeParser.getRuleList()!=null && !lodeParser.getRuleList().isEmpty()){
textToWrite += lodeParser.getRules();
}

// Add legend (for ontology components actually used).
textToWrite += Constants.getLegend(lang, includesClass, includesProperty,
Expand Down
114 changes: 67 additions & 47 deletions src/main/java/widoco/LODEParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class LODEParser {
private String annotationPropList;
private String namedIndividuals;
private String namedIndividualList;
private String rules;
private String ruleList;
Configuration c;

/**
Expand Down Expand Up @@ -123,6 +125,14 @@ public String getNamedIndividualList() {
return namedIndividualList;
}

public String getRules() {
return rules;
}

public String getRuleList() {
return ruleList;
}

private void parse(String content, Properties langFile) {

try {
Expand All @@ -134,40 +144,54 @@ private void parse(String content, Properties langFile) {
// String cList = "", pList= "", dPList= "", c= "", p= "", dp="";
for (int i = 0; i < html.getLength(); i++) {
String attrID = html.item(i).getAttributes().item(0).getTextContent();
if (attrID.equals("classes")) {
classList = getTermList(html.item(i));
classes = nodeToString(html.item(i));
classes = classes.replace("<h2>" + langFile.getProperty(Constants.LANG_CLASSES) + "</h2>",
"<h3 id=\"classes-headline\" class=\"list\">" + langFile.getProperty(Constants.LANG_CLASSES)
+ "</h3>");
} else if (attrID.equals("objectproperties")) {
propertyList = getTermList(html.item(i));
properties = (nodeToString(html.item(i)));
properties = properties.replace("<h2>" + langFile.getProperty(Constants.LANG_OBJ_PROP) + "</h2>",
"<h3 id=\"properties\" class=\"list\">" + langFile.getProperty(Constants.LANG_OBJ_PROP)
+ "</h3>");
} else if (attrID.equals("dataproperties")) {
dataPropList = (getTermList(html.item(i)));
dataProp = (nodeToString(html.item(i)));
dataProp = dataProp.replace("<h2>" + langFile.getProperty(Constants.LANG_DATA_PROP) + "</h2>",
"<h3 id=\"dataproperties-headline\" class=\"list\">"
+ langFile.getProperty(Constants.LANG_DATA_PROP) + "</h3>");
} else if (attrID.equals("annotationproperties")) {
annotationPropList = (getTermList(html.item(i)));
annotationProp = (nodeToString(html.item(i)));
annotationProp = annotationProp.replace(
"<h2>" + langFile.getProperty(Constants.LANG_ANN_PROP) + "</h2>",
"<h3 id=\"annotationproperties\" class=\"list\">"
+ langFile.getProperty(Constants.LANG_ANN_PROP) + "</h3>");
} else if (attrID.equals("namedindividuals")) {
namedIndividualList = (getTermList(html.item(i)));
namedIndividuals = (nodeToString(html.item(i)));
namedIndividuals = namedIndividuals.replace(
"<h2>" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h2>",
"<h3 id=\"namedindividuals\" class=\"list\">"
+ langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h3>");
switch (attrID) {
case "classes":
classList = getTermList(html.item(i));
classes = nodeToString(html.item(i));
classes = classes.replace("<h2>" + langFile.getProperty(Constants.LANG_CLASSES) + "</h2>",
"<h3 id=\"classes-headline\" class=\"list\">" + langFile.getProperty(Constants.LANG_CLASSES)
+ "</h3>");
break;
case "objectproperties":
propertyList = getTermList(html.item(i));
properties = (nodeToString(html.item(i)));
properties = properties.replace("<h2>" + langFile.getProperty(Constants.LANG_OBJ_PROP) + "</h2>",
"<h3 id=\"properties\" class=\"list\">" + langFile.getProperty(Constants.LANG_OBJ_PROP)
+ "</h3>");
break;
case "dataproperties":
dataPropList = (getTermList(html.item(i)));
dataProp = (nodeToString(html.item(i)));
dataProp = dataProp.replace("<h2>" + langFile.getProperty(Constants.LANG_DATA_PROP) + "</h2>",
"<h3 id=\"dataproperties-headline\" class=\"list\">"
+ langFile.getProperty(Constants.LANG_DATA_PROP) + "</h3>");
break;
case "annotationproperties":
annotationPropList = (getTermList(html.item(i)));
annotationProp = (nodeToString(html.item(i)));
annotationProp = annotationProp.replace(
"<h2>" + langFile.getProperty(Constants.LANG_ANN_PROP) + "</h2>",
"<h3 id=\"annotationproperties\" class=\"list\">"
+ langFile.getProperty(Constants.LANG_ANN_PROP) + "</h3>");
break;
case "namedindividuals":
namedIndividualList = (getTermList(html.item(i)));
namedIndividuals = (nodeToString(html.item(i)));
namedIndividuals = namedIndividuals.replace(
"<h2>" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h2>",
"<h3 id=\"namedindividuals\" class=\"list\">"
+ langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h3>");
break;
/*missing: rules!*/
case "rules":
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>");
break;
}
/*missing: rules!*/
}
// fix ids
if (!"".equals(classList) && classList != null) {
Expand All @@ -190,14 +214,17 @@ private void parse(String content, Properties langFile) {
namedIndividualList = fixIds(namedIndividualList);
namedIndividuals = fixIds(namedIndividuals);
}
if (!"".equals(ruleList) && ruleList != null) {
ruleList = fixIds(ruleList);
rules = fixIds(rules);
//hack so "named individuals" appear as rules
rules = rules.replace("<a href=\"#namedindividuals\">Named Individual ToC</a>",
"<a href=\"#rules\">Rules ToC</a>");
}
logger.info("Parsing Complete!");
} catch (ParserConfigurationException ex) {
} catch (ParserConfigurationException | DOMException ex) {
logger.error("Exception interpreting the resource: " + ex.getMessage());
} catch (DOMException ex) {
logger.error("Exception interpreting the resource: " + ex.getMessage());
} catch (SAXException ex) {
logger.error(MarkerFactory.getMarker("FATAL"), ex.getMessage());
} catch (IOException ex) {
} catch (SAXException | IOException ex) {
logger.error(MarkerFactory.getMarker("FATAL"), ex.getMessage());
}
}
Expand All @@ -223,15 +250,8 @@ private String nodeToString(Node n) {
DOMSource source = new DOMSource(fixAnchor(n));
trans.transform(source, result);
return sw.toString();
// String returnValue= sw.toString().replace("\n", "");
// return(returnValue);
} catch (IllegalArgumentException ex) {
logger.error("Error while writing to xml " + ex.getMessage());
// ex.printStackTrace();
return null;
} catch (TransformerException ex) {
} catch (IllegalArgumentException | TransformerException ex) {
logger.error("Error while writing to xml " + ex.getMessage());
// ex.printStackTrace();
return null;
}
}
Expand Down
Binary file modified src/main/resources/lode.zip
Binary file not shown.
18 changes: 9 additions & 9 deletions src/main/resources/lode/extraction.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:sw="http://www.w3.org/2003/06/sw-vocab-status/ns#"
xmlns:extra="https://w3id.org/extra#"
xmlns:widoco="https://w3id.org/widoco/vocab#"
xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.oxygenxml.com/ns/doc/xsl
http://www.oxygenxml.com/ns/doc/xsl ">
Expand Down Expand Up @@ -1823,7 +1823,7 @@ http://www.oxygenxml.com/ns/doc/xsl ">
<xsl:value-of select="f:getDescriptionLabel('namedindividuals')"/>
</h2>
<xsl:call-template name="get.namedindividuals.toc"/>
<xsl:apply-templates select="/rdf:RDF/owl:NamedIndividual[element() and not(rdf:type/@rdf:resource = 'https://w3id.org/extra#Rule')]">
<xsl:apply-templates select="/rdf:RDF/owl:NamedIndividual[element() and not(rdf:type/@rdf:resource = 'https://w3id.org/widoco/vocab#Rule')]">
<xsl:sort select="lower-case(f:getLabel(@*:about|@*:ID))"
order="ascending" data-type="text"/>
<xsl:with-param name="type" tunnel="yes" as="xs:string" select="'individual'"/>
Expand All @@ -1834,7 +1834,7 @@ http://www.oxygenxml.com/ns/doc/xsl ">

<xsl:template name="get.namedindividuals.toc">
<ul class="hlist">
<xsl:apply-templates select="/rdf:RDF/owl:NamedIndividual[element() and not(rdf:type/@rdf:resource = 'https://w3id.org/extra#Rule')]" mode="toc">
<xsl:apply-templates select="/rdf:RDF/owl:NamedIndividual[element() and not(rdf:type/@rdf:resource = 'https://w3id.org/widoco/vocab#Rule')]" mode="toc">
<xsl:sort select="lower-case(f:getLabel(@*:about|@*:ID))"
order="ascending" data-type="text"/>
<xsl:with-param name="type" tunnel="yes" as="xs:string" select="'individual'"/>
Expand Down Expand Up @@ -2289,12 +2289,12 @@ http://www.oxygenxml.com/ns/doc/xsl ">

<!-- CUSTOM: ADD FOR LINKING RULES TO TERMS-->
<xsl:template name="get.rule.antecedent">
<xsl:if test="exists(extra:usedByRuleInAntecedent)">
<xsl:if test="exists(widoco:usedByRuleInAntecedent)">
<dl>
<dt>
<xsl:value-of select="f:getDescriptionLabel('usedByRuleInAntecedent')"/>
</dt>
<xsl:for-each select="extra:usedByRuleInAntecedent">
<xsl:for-each select="widoco:usedByRuleInAntecedent">
<dd>
<xsl:choose>
<xsl:when test="normalize-space(@*:resource) = ''">
Expand All @@ -2315,12 +2315,12 @@ http://www.oxygenxml.com/ns/doc/xsl ">
</xsl:template>

<xsl:template name="get.rule.consequent">
<xsl:if test="exists(extra:usedByRuleInConsequent)">
<xsl:if test="exists(widoco:usedByRuleInConsequent)">
<dl>
<dt>
<xsl:value-of select="f:getDescriptionLabel('usedByRuleInConsequent')"/>
</dt>
<xsl:for-each select="extra:usedByRuleInConsequent">
<xsl:for-each select="widoco:usedByRuleInConsequent">
<dd>
<a href="#{text()}">
<xsl:value-of select="text()"/>
Expand All @@ -2334,9 +2334,9 @@ http://www.oxygenxml.com/ns/doc/xsl ">
<xsl:template name="get.rules">
<xsl:if test="exists(//owl:NamedIndividual/element())">
<div id="rules">
<h2>
<h3 id="rule" class="list">
<xsl:value-of select="f:getDescriptionLabel('otherRules')"/>
</h2>
</h3>
<xsl:call-template name="get.rules.toc"/>
<xsl:apply-templates select="/rdf:RDF/owl:NamedIndividual[element() and (rdf:type/@rdf:resource = 'https://w3id.org/widoco/vocab#Rule')]">
<xsl:sort select="lower-case(f:getLabel(@*:about|@*:ID))"
Expand Down