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 dgarijo#651
  • Loading branch information
vChavezB authored Dec 9, 2023
1 parent 4da92b2 commit f144ac7
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/main/java/widoco/LODEParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,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 +230,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 f144ac7

Please sign in to comment.