Fix ANY23-312

- solved blank nodes creation problem for maps
- add another unit test example typical for configuration files

Signed-off-by: Jacek Grzebyta <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/any23/repo
Commit: http://git-wip-us.apache.org/repos/asf/any23/commit/29d3cf17
Tree: http://git-wip-us.apache.org/repos/asf/any23/tree/29d3cf17
Diff: http://git-wip-us.apache.org/repos/asf/any23/diff/29d3cf17

Branch: refs/heads/master
Commit: 29d3cf179be85374c01049efd62cafa8d9540e71
Parents: 66ffee0
Author: Jacek Grzebyta <[email protected]>
Authored: Mon Nov 6 12:35:00 2017 +0000
Committer: Jacek Grzebyta <[email protected]>
Committed: Mon Nov 6 12:42:00 2017 +0000

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java |  2 +-
 .../extractor/yaml/ElementsProcessorTest.java   |  2 +-
 .../any23/extractor/yaml/YAMLExtractorTest.java | 39 +++++++++++++++++++-
 .../org/apache/any23/extractor/yaml/tree2.yml   | 27 ++++++++++++++
 4 files changed, 67 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/29d3cf17/core/src/main/java/org/apache/any23/extractor/yaml/ElementsProcessor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/any23/extractor/yaml/ElementsProcessor.java 
b/core/src/main/java/org/apache/any23/extractor/yaml/ElementsProcessor.java
index 6819b88..8a9b65f 100644
--- a/core/src/main/java/org/apache/any23/extractor/yaml/ElementsProcessor.java
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/ElementsProcessor.java
@@ -118,7 +118,7 @@ public class ElementsProcessor {
         assert ns != null : "Namespace value is null";
 
         Model model = modelFactory.createEmptyModel();
-        Value nodeURI =RDFUtils.makeIRI("node", ns, true);
+        Value nodeURI = parentNode instanceof BNode ? RDFUtils.makeIRI("node", 
ns, true) : parentNode;
         
         if (!isEmpty) {
             model.add(vf.createStatement((Resource) nodeURI, RDF.TYPE, 
vocab.mapping));

http://git-wip-us.apache.org/repos/asf/any23/blob/29d3cf17/core/src/test/java/org/apache/any23/extractor/yaml/ElementsProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/any23/extractor/yaml/ElementsProcessorTest.java 
b/core/src/test/java/org/apache/any23/extractor/yaml/ElementsProcessorTest.java
index 5f9a7d8..61e6550 100644
--- 
a/core/src/test/java/org/apache/any23/extractor/yaml/ElementsProcessorTest.java
+++ 
b/core/src/test/java/org/apache/any23/extractor/yaml/ElementsProcessorTest.java
@@ -54,7 +54,7 @@ public class ElementsProcessorTest {
                 simpleMap,
                 ep.vf.createIRI("http://example.org/node1";));
         
-        Assert.assertEquals("http://example.org/node_0";, 
toTest.getKey().stringValue());
+        Assert.assertEquals("http://example.org/node1";, 
toTest.getKey().stringValue()); // if parent node is not blank than returns it 
as key
         Assert.assertTrue(toTest.getValue().size() > 0);
         log.debug("Model: \n{}\n", dumpModel(toTest.getValue(), 
RDFFormat.TURTLE));
     }

http://git-wip-us.apache.org/repos/asf/any23/blob/29d3cf17/core/src/test/java/org/apache/any23/extractor/yaml/YAMLExtractorTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/any23/extractor/yaml/YAMLExtractorTest.java 
b/core/src/test/java/org/apache/any23/extractor/yaml/YAMLExtractorTest.java
index 9dba216..82c2ddc 100644
--- a/core/src/test/java/org/apache/any23/extractor/yaml/YAMLExtractorTest.java
+++ b/core/src/test/java/org/apache/any23/extractor/yaml/YAMLExtractorTest.java
@@ -105,7 +105,7 @@ public class YAMLExtractorTest extends 
AbstractExtractorTestCase {
          */
         assertNotContains(RDF.TYPE, vocab.mapping); 
         int statements = dumpAsListOfStatements().size();
-        Assert.assertTrue("Found " + statements + " statements", statements == 
10);
+        Assert.assertTrue("Found " + statements + " statements", statements == 
9);
     }
 
     @Test
@@ -125,4 +125,41 @@ public class YAMLExtractorTest extends 
AbstractExtractorTestCase {
         // validate occurence of <urn:value1> resource
         assertContains(RDFUtils.triple(RDFUtils.bnode(), RDF.FIRST, 
RDFUtils.iri("urn:value1")));
     }
+    
+    /**
+     * This test covers a typical situation when a document is a map.
+     * 
+     * <br/><b>NB:</b> Following yaml standard those 2 cases are parsed to 
different graphs:
+     * <br/><br/>Case 1:
+     * 
+     * <pre>
+     * ---
+     * key1: value1
+     * key2: value2
+     * key3: Some text  value, maybe description
+     * </pre>
+     * 
+     * Case 2:
+     * <pre>
+     * ---
+     * - key1: value1
+     * - key2: value2
+     * - key3: Some text  value, maybe description
+     * </pre>
+     * 
+     * @throws Exception
+     * @see #treeTest() 
+     */
+    @Test
+    public void tree2Test() throws Exception {
+        assertExtract("/org/apache/any23/extractor/yaml/tree2.yml");
+        log.debug("\n{}", dumpModelToTurtle());
+        assertModelNotEmpty();
+        
+        // check if document is type of mapping.
+        assertContainsModel(new Statement[]{
+            RDFUtils.triple(RDFUtils.bnode("10"), RDF.TYPE, vocab.document),
+            RDFUtils.triple(RDFUtils.bnode("10"), RDF.TYPE, vocab.mapping)
+        });
+    }
 }

http://git-wip-us.apache.org/repos/asf/any23/blob/29d3cf17/test-resources/src/test/resources/org/apache/any23/extractor/yaml/tree2.yml
----------------------------------------------------------------------
diff --git 
a/test-resources/src/test/resources/org/apache/any23/extractor/yaml/tree2.yml 
b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/tree2.yml
new file mode 100644
index 0000000..c45914d
--- /dev/null
+++ 
b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/tree2.yml
@@ -0,0 +1,27 @@
+%YAML 1.2
+---
+key1: 
+   - value1
+   - value1.1
+key2:
+   - value 2
+   - value 2.1
+   - longText: >
+        Aenean sodales suscipit porta.
+        Pellentesque tincidunt tincidunt
+        tortor in dapibus. Etiam quis nisl
+        eu velit consequat lobortis eu quis
+        turpis. Vestibulum luctus auctor diam,
+        a dapibus lacus efficitur congue.
+        Phasellus eu fermentum sem. Morbi
+        eget porta ante. Nunc sapien lorem,
+        dignissim ut purus sit amet, consequat
+        vulputate tortor. Sed dolor dui, porta
+        eu tincidunt at, mattis sit amet
+        risus. Class aptent taciti sociosqu ad
+        litora torquent per conubia nostra,
+        per inceptos himenaeos. Phasellus
+        lobortis dolor risus. Fusce at elit
+        magna. Cras et sapien vitae libero
+        dignissim sagittis suscipit sed risus.
+        Suspendisse interdum imperdiet aliquam.

Reply via email to