From 533b7cf0434ff0b82b6922649237656cbb4ca3a3 Mon Sep 17 00:00:00 2001
From: Victor Chavez <47216966+vChavezB@users.noreply.github.com>
Date: Sat, 9 Dec 2023 17:04:02 +0100
Subject: [PATCH] Fix parsing of LODE swrl rules
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
---
src/main/java/widoco/LODEParser.java | 35 +++++++++++++++++++++-------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/src/main/java/widoco/LODEParser.java b/src/main/java/widoco/LODEParser.java
index f27d770c..c002cdd9 100644
--- a/src/main/java/widoco/LODEParser.java
+++ b/src/main/java/widoco/LODEParser.java
@@ -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;
@@ -182,14 +183,14 @@ private void parse(String content, Properties langFile) {
"
"
+ langFile.getProperty(Constants.LANG_NAMED_INDIV) + "
");
break;
- /*missing: rules!*/
- case "rules":
+ case "swrlrules":
ruleList = (getTermList(html.item(i)));
- rules = (nodeToString(html.item(i)));
-// rules = rules.replace(
-// "" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "
",
-// ""
-// + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "
");
+ if (ruleList != null) {
+ rules = ruleList.replace(
+ "" + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "
",
+ ""
+ + langFile.getProperty(Constants.LANG_NAMED_INDIV) + "
");
+ }
break;
}
}
@@ -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;
}