From a6841469f15fd573cecd39f2b731e3cf39354089 Mon Sep 17 00:00:00 2001 From: Luigi Asprino Date: Thu, 11 Apr 2024 18:13:19 +0200 Subject: [PATCH] Fix #472 --- .../sparqlanything/xml/XMLTriplifier.java | 1 + .../xml/MoreXMLTriplifierTest.java | 12 ++++ .../src/test/resources/Books_1.ttl | 42 ++++++------- .../src/test/resources/Books_2.ttl | 42 ++++++------- .../src/test/resources/SliceBooks.ttl | 42 ++++++------- .../src/test/resources/XPathAndSlice.ttl | 59 +++++++++++++++++++ .../src/test/resources/XPathAndSlice.xml | 40 +++++++++++++ 7 files changed, 175 insertions(+), 63 deletions(-) create mode 100644 sparql-anything-xml/src/test/resources/XPathAndSlice.ttl create mode 100644 sparql-anything-xml/src/test/resources/XPathAndSlice.xml diff --git a/sparql-anything-xml/src/main/java/com/github/sparqlanything/xml/XMLTriplifier.java b/sparql-anything-xml/src/main/java/com/github/sparqlanything/xml/XMLTriplifier.java index a7869749..48ffc5f5 100644 --- a/sparql-anything-xml/src/main/java/com/github/sparqlanything/xml/XMLTriplifier.java +++ b/sparql-anything-xml/src/main/java/com/github/sparqlanything/xml/XMLTriplifier.java @@ -166,6 +166,7 @@ public int transformFromXPath(VTDNav vn, int result, int child, String parentId, log.trace(" -- tag: {} ", tag); String childId = String.join("", parentId , "/" , Integer.toString(child), ":", tag); builder.addContainer(dataSourceId, parentId, child, childId); + builder.addType(dataSourceId, childId, XYZ_NS+tag); // Attributes int attrCount = vn.getAttrCount(); diff --git a/sparql-anything-xml/src/test/java/com/github/sparqlanything/xml/MoreXMLTriplifierTest.java b/sparql-anything-xml/src/test/java/com/github/sparqlanything/xml/MoreXMLTriplifierTest.java index 0a521750..e06aa43e 100644 --- a/sparql-anything-xml/src/test/java/com/github/sparqlanything/xml/MoreXMLTriplifierTest.java +++ b/sparql-anything-xml/src/test/java/com/github/sparqlanything/xml/MoreXMLTriplifierTest.java @@ -33,6 +33,7 @@ public MoreXMLTriplifierTest() { @Override protected void properties(Properties properties) { +// this.setPrintWholeGraph(true); if(name.getMethodName().equals("testSimple$1")){ properties.put("blank-nodes", "false"); }else @@ -50,6 +51,10 @@ protected void properties(Properties properties) { }else if(name.getMethodName().equals("testBooks_2$1")){ properties.put("blank-nodes", "false"); properties.put("xml.path", "//book"); + }else if(name.getMethodName().equals("testXPathAndSlice")){ + properties.put("blank-nodes", "true"); + properties.put("xml.path", "//Record"); + properties.put("slice", "true"); } } @@ -87,4 +92,11 @@ protected void properties(Properties properties) { //RDFDataMgr.write(System.err, result, Lang.TTL); assertResultIsIsomorphicWithExpected(); } + + @Test + public void testXPathAndSlice() { + L.debug("Test XML books (XPath //Record, with slicing)"); + //RDFDataMgr.write(System.err, result, Lang.TTL); + assertResultIsIsomorphicWithExpected(); + } } diff --git a/sparql-anything-xml/src/test/resources/Books_1.ttl b/sparql-anything-xml/src/test/resources/Books_1.ttl index 38ec0654..ff81e198 100644 --- a/sparql-anything-xml/src/test/resources/Books_1.ttl +++ b/sparql-anything-xml/src/test/resources/Books_1.ttl @@ -5,15 +5,15 @@ @prefix xsd: . - + a ; "Fantasy" . - + a ; "A former architect battles corporate zombies,\n an evil sorceress, and her own childhood to become queen\n of the world." . - + a ; "Gambardella, Matthew" . @@ -26,35 +26,35 @@ . - + a ; "Corets, Eva" . - + a ; "2000-10-01" . - + a ; "Fantasy" . - + a ; "2000-12-16" . - + a ; "5.95" . - + a ; "Computer" . - + a ; "Maeve Ascendant" . - + a ; ; @@ -70,39 +70,39 @@ "978-3-12-148410-0" . - + a ; "5.95" . - + a ; "An in-depth look at creating applications\n with XML." . - + a ; "2000-11-17" . - + a ; "Ralls, Kim" . - + a ; "Midnight Rain" . - + a ; "44.95" . - + a ; "XML Developer's Guide" . - + a ; "After the collapse of a nanotechnology\n society in England, the young survivors lay the\n foundation for a new society." . - + a ; ; @@ -118,7 +118,7 @@ "928-3-16-148410-0" . - + a ; ; diff --git a/sparql-anything-xml/src/test/resources/Books_2.ttl b/sparql-anything-xml/src/test/resources/Books_2.ttl index 38ec0654..68bda39b 100644 --- a/sparql-anything-xml/src/test/resources/Books_2.ttl +++ b/sparql-anything-xml/src/test/resources/Books_2.ttl @@ -5,15 +5,15 @@ @prefix xsd: . - + a xyz:genre ; "Fantasy" . - + a xyz:description ; "A former architect battles corporate zombies,\n an evil sorceress, and her own childhood to become queen\n of the world." . - + a xyz:author ; "Gambardella, Matthew" . @@ -26,35 +26,35 @@ . - + a xyz:author ; "Corets, Eva" . - + a xyz:publish_date ; "2000-10-01" . - + a xyz:genre ; "Fantasy" . - + a xyz:publish_date ; "2000-12-16" . - + a xyz:price ; "5.95" . - + a xyz:genre ; "Computer" . - + a xyz:title ; "Maeve Ascendant" . - + a xyz:book ; ; @@ -70,39 +70,39 @@ "978-3-12-148410-0" . - + a xyz:price ; "5.95" . - + a xyz:description ; "An in-depth look at creating applications\n with XML." . - + a xyz:publish_date ; "2000-11-17" . - + a xyz:author ; "Ralls, Kim" . - + a xyz:title ; "Midnight Rain" . - + a xyz:price ; "44.95" . - + a xyz:title ; "XML Developer's Guide" . - + a xyz:description ; "After the collapse of a nanotechnology\n society in England, the young survivors lay the\n foundation for a new society." . - + a xyz:book ; ; @@ -118,7 +118,7 @@ "928-3-16-148410-0" . - + a xyz:book ; ; diff --git a/sparql-anything-xml/src/test/resources/SliceBooks.ttl b/sparql-anything-xml/src/test/resources/SliceBooks.ttl index 38ec0654..68bda39b 100644 --- a/sparql-anything-xml/src/test/resources/SliceBooks.ttl +++ b/sparql-anything-xml/src/test/resources/SliceBooks.ttl @@ -5,15 +5,15 @@ @prefix xsd: . - + a xyz:genre ; "Fantasy" . - + a xyz:description ; "A former architect battles corporate zombies,\n an evil sorceress, and her own childhood to become queen\n of the world." . - + a xyz:author ; "Gambardella, Matthew" . @@ -26,35 +26,35 @@ . - + a xyz:author ; "Corets, Eva" . - + a xyz:publish_date ; "2000-10-01" . - + a xyz:genre ; "Fantasy" . - + a xyz:publish_date ; "2000-12-16" . - + a xyz:price ; "5.95" . - + a xyz:genre ; "Computer" . - + a xyz:title ; "Maeve Ascendant" . - + a xyz:book ; ; @@ -70,39 +70,39 @@ "978-3-12-148410-0" . - + a xyz:price ; "5.95" . - + a xyz:description ; "An in-depth look at creating applications\n with XML." . - + a xyz:publish_date ; "2000-11-17" . - + a xyz:author ; "Ralls, Kim" . - + a xyz:title ; "Midnight Rain" . - + a xyz:price ; "44.95" . - + a xyz:title ; "XML Developer's Guide" . - + a xyz:description ; "After the collapse of a nanotechnology\n society in England, the young survivors lay the\n foundation for a new society." . - + a xyz:book ; ; @@ -118,7 +118,7 @@ "928-3-16-148410-0" . - + a xyz:book ; ; diff --git a/sparql-anything-xml/src/test/resources/XPathAndSlice.ttl b/sparql-anything-xml/src/test/resources/XPathAndSlice.ttl new file mode 100644 index 00000000..e05a4666 --- /dev/null +++ b/sparql-anything-xml/src/test/resources/XPathAndSlice.ttl @@ -0,0 +1,59 @@ +@prefix fx: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix xyz: . + +[ rdf:type fx:root ; + rdf:_1 [ rdf:type xyz:Record ; + rdf:_1 [ rdf:type xyz:shape_id ; + rdf:_1 "0000000000000000000o" + ] ; + rdf:_2 [ rdf:type xyz:shape_pt_lat ; + rdf:_1 "39248" + ] ; + rdf:_3 [ rdf:type xyz:shape_pt_lon ; + rdf:_1 "39208" + ] ; + rdf:_4 [ rdf:type xyz:shape_pt_sequence ; + rdf:_1 "1008430" + ] ; + rdf:_5 [ rdf:type xyz:shape_dist_traveled ; + rdf:_1 "8429" + ] + ] ; + rdf:_2 [ rdf:type xyz:Record ; + rdf:_1 [ rdf:type xyz:shape_id ; + rdf:_1 "0000000000000000000k" + ] ; + rdf:_2 [ rdf:type xyz:shape_pt_lat ; + rdf:_1 "8469" + ] ; + rdf:_3 [ rdf:type xyz:shape_pt_lon ; + rdf:_1 "8429" + ] ; + rdf:_4 [ rdf:type xyz:shape_pt_sequence ; + rdf:_1 "1010130" + ] ; + rdf:_5 [ rdf:type xyz:shape_dist_traveled ; + rdf:_1 "21148" + ] + ] ; + rdf:_3 [ rdf:type xyz:Record ; + rdf:_1 [ rdf:type xyz:shape_id ; + rdf:_1 "0000000000000000000c" + ] ; + rdf:_2 [ rdf:type xyz:shape_pt_lat ; + rdf:_1 "39798" + ] ; + rdf:_3 [ rdf:type xyz:shape_pt_lon ; + rdf:_1 "39758" + ] ; + rdf:_4 [ rdf:type xyz:shape_pt_sequence ; + rdf:_1 "1001667" + ] ; + rdf:_5 [ rdf:type xyz:shape_dist_traveled ; + rdf:_1 "17663" + ] + ] +] . \ No newline at end of file diff --git a/sparql-anything-xml/src/test/resources/XPathAndSlice.xml b/sparql-anything-xml/src/test/resources/XPathAndSlice.xml new file mode 100644 index 00000000..de041898 --- /dev/null +++ b/sparql-anything-xml/src/test/resources/XPathAndSlice.xml @@ -0,0 +1,40 @@ + + + + + + 0000000000000000000o + 39248 + 39208 + 1008430 + 8429 + + + 0000000000000000000k + 8469 + 8429 + 1010130 + 21148 + + + 0000000000000000000c + 39798 + 39758 + 1001667 + 17663 + + \ No newline at end of file