Skip to content

Commit

Permalink
Fix parsing of LODE swrl rules
Browse files Browse the repository at this point in the history
The output of the XLST transformation for SWRL rules does not provide an hlist div element. Instead each rule is provide as a class entity. Fixes #651
  • Loading branch information
vChavezB authored and Victor Chavez committed Dec 10, 2023
1 parent 4da92b2 commit 533b7cf
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/main/java/widoco/LODEParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.StringWriter;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Objects;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -182,14 +183,14 @@ 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>");
if (ruleList != null) {
rules = ruleList.replace(
"<h2>" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h2>",
"<h3 id=\"rules\" class=\"list\">"
+ langFile.getProperty(Constants.LANG_NAMED_INDIV) + "</h3>");
}
break;
}
}
Expand Down Expand Up @@ -230,12 +231,28 @@ private void parse(String content, Properties langFile) {
}

private String getTermList(Node n) {
String AttrID = n.getAttributes().item(0).getTextContent();
NodeList divs = n.getChildNodes();
StringBuilder swrl_list = new StringBuilder();
boolean is_swrl = Objects.equals(AttrID, "swrlrules");
for (int j = 0; j < divs.getLength(); j++) {
if (divs.item(j).getNodeName().equals("ul")) {
return (nodeToString(divs.item(j)));
Node node = divs.item(j);
if (!is_swrl) {
if (node.getNodeName().equals("ul")) {
return (nodeToString(node));
}
} else {
if (node.getNodeName().equals("div")) {
Node classAttribute = node.getAttributes().getNamedItem("class");
if (classAttribute != null && classAttribute.getNodeValue().equals("entity")) {
swrl_list.append(nodeToString(node));
}
}
}
}
if (is_swrl && swrl_list.length()>0) {
return swrl_list.toString();
}
return null;
}

Expand Down

0 comments on commit 533b7cf

Please sign in to comment.