You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@any23.apache.org by jg...@apache.org on 2017/12/07 12:28:04 UTC

[01/17] any23 git commit: Ref ANY23-312

Repository: any23
Updated Branches:
  refs/heads/master 781851827 -> f8e457985


Ref ANY23-312

- update example file
- update unit test
Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: af0a7e154e36564b315c253089900968d8df0a26
Parents: dfcccad
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Tue Oct 17 17:06:44 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Tue Oct 17 17:06:44 2017 +0100

----------------------------------------------------------------------
 .../java/org/apache/any23/extractor/yaml/YAMLExtractor.java    | 6 +++---
 .../org/apache/any23/extractor/yaml/YAMLExtractorTest.java     | 4 ++--
 .../resources/org/apache/any23/extractor/yaml/test-null.yml    | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/af0a7e15/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
index ab411da..dc80e0f 100644
--- a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
@@ -122,7 +122,7 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
         Resource nodeURI = Arrays.asList(parent).isEmpty() ? YAMLExtractor.this.makeUri(file) : parent[0];
         
 
-        for (String k : node.keySet()) {
+        node.keySet().forEach((k) -> {
             /* False prevents adding _<int> to the predicate.
             Thus the predicate pattern is:
             "some string" ---> ns:someString
@@ -133,7 +133,7 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
             out.writeTriple(nodeURI, (IRI) predicate, value);
             out.writeTriple(predicate, RDF.TYPE, RDF.PREDICATE);
             out.writeTriple(predicate, RDFS.LABEL, RDFUtils.literal(k));
-        }
+        });
         return nodeURI;
     }
 
@@ -204,7 +204,7 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
             uriString = uriString + "_" + Integer.toString(nodeId);
         }
 
-        Resource node = RDFUtils.uri(uriString);
+        Resource node = RDFUtils.iri(uriString);
         if (addId) {
             nodeId++;
         }

http://git-wip-us.apache.org/repos/asf/any23/blob/af0a7e15/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 fa8ae63..57588e9 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
@@ -89,8 +89,8 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
         assertExtract("/org/apache/any23/extractor/yaml/test-null.yml");
         log.debug(dumpModelToTurtle());
         assertModelNotEmpty();
-        RepositoryResult<Statement> docs = getStatements(null, null, RDF.NIL);
-        Assert.assertTrue(Iterations.asList(docs).size() == 2);
+        int statements = dumpAsListOfStatements().size();
+        Assert.assertTrue("Found " + statements + " statements",statements == 9);
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/any23/blob/af0a7e15/test-resources/src/test/resources/org/apache/any23/extractor/yaml/test-null.yml
----------------------------------------------------------------------
diff --git a/test-resources/src/test/resources/org/apache/any23/extractor/yaml/test-null.yml b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/test-null.yml
index 03cbe2b..2b16113 100644
--- a/test-resources/src/test/resources/org/apache/any23/extractor/yaml/test-null.yml
+++ b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/test-null.yml
@@ -2,4 +2,4 @@
 ---
 canonical: null
 tag: !!null
-    
\ No newline at end of file
+practice:
\ No newline at end of file


[04/17] any23 git commit: Create ElementProcessor

Posted by jg...@apache.org.
Create ElementProcessor

- add unit test

Signed-off-by: Jacek Grzebyta <gr...@gmail.com>


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

Branch: refs/heads/master
Commit: f787e42e0357949b44408645b4546cd447242862
Parents: c7dd09e
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Fri Oct 20 17:41:40 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Fri Oct 20 17:41:40 2017 +0100

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java | 117 +++++++++++++++++++
 .../extractor/yaml/ElementsProcessorTest.java   |  68 +++++++++++
 2 files changed, 185 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/f787e42e/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
new file mode 100644
index 0000000..f69ca0c
--- /dev/null
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/ElementsProcessor.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2017 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.any23.extractor.yaml;
+
+import java.util.AbstractMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.any23.rdf.RDFUtils;
+import org.apache.any23.vocab.YAML;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Literal;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.model.ModelFactory;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.ValueFactory;
+import org.eclipse.rdf4j.model.impl.LinkedHashModelFactory;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
+import org.eclipse.rdf4j.model.util.Literals;
+import org.eclipse.rdf4j.model.vocabulary.RDF;
+import org.eclipse.rdf4j.model.vocabulary.RDFS;
+
+/**
+ *
+ * @author Jacek Grzebyta (grzebyta.dev [at] gmail.com)
+ */
+public class ElementsProcessor {
+
+    private final ModelFactory modelFactory = new LinkedHashModelFactory();
+    private final YAML vocab = YAML.getInstance();
+    protected ValueFactory vf = SimpleValueFactory.getInstance();
+    
+    private Map.Entry<Value,Model> asMapEntry(Value v, Model m) {
+        return new AbstractMap.SimpleEntry(v, m);
+    }
+
+    /**
+     * Converts a data structure to {@link Map.Entry<Value,Model>}. where value is a 
+     * root node of the data structure and model is a content of the RDF graph.
+     * 
+     * If requested object is simple object (i.e. is neither List or Map) than 
+     * method returns map entry of relevant instance of {@link Literal} as key and
+     * null as value.
+     * 
+     * @param namespace Namespace for predicates
+     * @param t Object (or data structure) converting to RDF graph
+     * @param rootNode root node of the graph. If not given then blank node is created.
+     * @return 
+     */
+    public Map.Entry<Value,Model> asModel(IRI namespace, final Object t, Value rootNode) {
+        if (t == null) {
+            return null;
+        }
+
+        if (t instanceof List) {
+            //return processList(namespace, (List) t);
+        } else if (t instanceof Map) {
+            return processMap(namespace, (Map) t, rootNode);
+        } else {
+            return asMapEntry(Literals.createLiteral(vf, t), null);
+        }
+         return null;
+    }
+    
+    protected Map.Entry<Value,Model> processMap(IRI ns, Map<String, Object> object, Value rootNode) {
+        // check if map is empty of contains only null values
+        if (object.isEmpty() || (object.values().size() == 1 && object.values().contains(null))) {
+            return null;
+        }
+        assert ns != null : "Namespace value is null";
+        
+        Model model = modelFactory.createEmptyModel();
+        Value nodeURI = rootNode == null ? RDFUtils.makeIRI() : rootNode;
+        model.add(vf.createStatement((Resource) nodeURI, RDF.TYPE, vocab.mapping));
+        object.keySet().forEach( (k) -> {
+            /* False prevents adding _<int> to the predicate.
+            Thus the predicate pattern is:
+            "some string" ---> ns:someString
+            */
+            Resource predicate = RDFUtils.makeIRI(k, ns, false);
+            /* add map's key as statements:
+            predicate rdf:type rdf:predicate .
+            predicate rdfs:label predicate name
+            */
+            model.add(vf.createStatement(predicate, RDF.TYPE, RDF.PREDICATE));
+            model.add(vf.createStatement(predicate, RDFS.LABEL, RDFUtils.literal(k)));
+            Value subGraphRoot = RDFUtils.makeIRI();
+            Map.Entry<Value, Model> valInst = asModel(ns, object.get(k), subGraphRoot);
+            // if asModel returns null than 
+            if (valInst != null) {
+                /*
+            Subgraph root node is added always. If subgraph is null that root node is Literal.
+            Otherwise submodel in added to the current model.
+                 */
+                model.add(vf.createStatement((Resource) nodeURI, (IRI) predicate, valInst.getKey()));
+                if (valInst.getValue() != null) {
+                    model.addAll(valInst.getValue());
+                }
+            }
+            
+        });
+        return asMapEntry(nodeURI, model);
+    }
+}

http://git-wip-us.apache.org/repos/asf/any23/blob/f787e42e/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
new file mode 100644
index 0000000..94cf64a
--- /dev/null
+++ b/core/src/test/java/org/apache/any23/extractor/yaml/ElementsProcessorTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.any23.extractor.yaml;
+
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
+import org.eclipse.rdf4j.repository.sail.SailRepository;
+import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection;
+import org.eclipse.rdf4j.rio.RDFFormat;
+import org.eclipse.rdf4j.rio.Rio;
+import org.eclipse.rdf4j.sail.memory.MemoryStore;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Jacek Grzebyta (jgrzebyta [at] apache [dot] org)
+ */
+public class ElementsProcessorTest {
+    
+    private Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Test
+    public void processMap() throws Exception {
+        Map<String, Object> simpleMap = new HashMap<String, Object>() {
+            {
+                put("key1", "value1");
+                put("key2", "value2");
+                put("key3", 3);
+            }
+        };
+
+        ElementsProcessor ep = new ElementsProcessor();
+        Map.Entry<Value, Model> toTest = ep.processMap(ep.vf.createIRI("http://example.org/"), 
+                simpleMap, 
+                ep.vf.createIRI("http://example.org/node1"));
+        
+        Assert.assertEquals(toTest.getKey().stringValue(), "http://example.org/node1");
+        Assert.assertTrue(toTest.getValue().size() > 0);
+        log.debug("Model: \n{}\n", dumpModel(toTest.getValue(), RDFFormat.TURTLE));
+    }
+    
+    private String dumpModel(Model m, RDFFormat format) {
+        StringWriter writer = new StringWriter();
+        Rio.write(m, writer, format);
+        return writer.toString();
+    }
+}


[16/17] any23 git commit: Clean code

Posted by jg...@apache.org.
Clean code

- remove some tabs in empty rows

Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: 5d33154cc7b61c64b53b3a72451f0530bf18d4d6
Parents: d005d7f
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Thu Dec 7 12:19:42 2017 +0000
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Thu Dec 7 12:19:42 2017 +0000

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java     | 16 ++++++++--------
 .../any23/extractor/yaml/YAMLExtractorTest.java     | 10 +++++-----
 2 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/5d33154c/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 0112a45..0b05e31 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 {
 
         Model model = modelFactory.createEmptyModel();
         Value nodeURI = parentNode instanceof BNode ? RDFUtils.makeIRI("node", ns, true) : parentNode;
-        
+
         if (!isEmpty) {
             model.add(vf.createStatement((Resource) nodeURI, RDF.TYPE, vocab.mapping));
         }
@@ -169,28 +169,28 @@ public class ElementsProcessor {
         for (int i=0; i < objectSize; i++) {
             Map.Entry<Value, Model> node = asModel(ns, object.get(i), RDFUtils.bnode());
             BNode currentNode = RDFUtils.bnode();
-            
+
             if (i == 0) {
                 listRoot = currentNode;
             }
-            
+
             finalModel.add(currentNode, RDF.FIRST, node.getKey(), (Resource[]) null);
-            
+
             if (prevNode != null) {
                 finalModel.add(prevNode, RDF.REST, currentNode, (Resource[]) null);
             }
-            
+
             if (i == objectSize-1) {
                 finalModel.add(currentNode, RDF.REST, RDF.NIL, (Resource[]) null);
             }
-            
+
             if(node.getValue() != null) {
                 finalModel.addAll(node.getValue());
             }
-            
+
             prevNode = currentNode;
         }
-        
+
         finalModel.add((Resource) listRoot, RDF.TYPE, RDF.LIST, (Resource[]) null);
         return asMapEntry(listRoot, finalModel);
     }

http://git-wip-us.apache.org/repos/asf/any23/blob/5d33154c/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 1c8df9e..06e341e 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
@@ -132,13 +132,13 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
         // validate occurence of <urn:value1> resource
         assertContains(RDFUtils.triple(RDFUtils.bnode(), RDF.FIRST, RDFUtils.iri("urn:value1")));
     }
-    
+
     @Test
     public void treeTest2() throws Exception {
         assertExtract("/org/apache/any23/extractor/yaml/tree.yml");
         String sparql ="select ?nodes where "
                 + "{ [] <http://bob.example.com/key3.1> [ rdf:rest*/rdf:first ?nodes ;]}";
-        
+
         RepositoryConnection connection = getConnection();
         TupleQueryResult res = connection.prepareTupleQuery(sparql).evaluate();
         List<BindingSet> resList = Iterations.asList(res);
@@ -152,10 +152,10 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
         List<String> resString = resList.stream().map((Function<? super BindingSet, String>) (b) -> {
             return b.getValue("nodes").stringValue();
         }).collect(Collectors.toList());
-        
+
         log.debug("List output: {}", resString);
     }
-    
+
     /**
      * This test covers a typical situation when a document is a map.
      * 
@@ -185,7 +185,7 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
         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),


[02/17] any23 git commit: Ref ANY23-312

Posted by jg...@apache.org.
Ref ANY23-312

- buildNode method returns Optional wrapper


Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: 783434d55648990469f7bf958d687c98796adfad
Parents: af0a7e1
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Tue Oct 17 17:22:53 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Tue Oct 17 17:22:53 2017 +0100

----------------------------------------------------------------------
 .../any23/extractor/yaml/YAMLExtractor.java     | 33 +++++++++++---------
 1 file changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/783434d5/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
index dc80e0f..ceacaba 100644
--- a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
@@ -21,6 +21,7 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import org.apache.any23.extractor.ExtractionContext;
 import org.apache.any23.extractor.ExtractionException;
 import org.apache.any23.extractor.ExtractionParameters;
@@ -89,32 +90,32 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
         return YAMLExtractorFactory.getDescriptionInstance();
     }
 
-    private Value buildNode(IRI fileURI, Object treeData, ExtractionResult out, Resource... parent) {
+    private Optional<Value> buildNode(IRI fileURI, Object treeData, ExtractionResult out, Resource... parent) {
 
         if (treeData != null) {
             log.debug("object type: {}", treeData.getClass());
         }
 
         if (treeData == null) {
-            return RDF.NIL;
+            return Optional.empty();
         } else if (treeData instanceof Map) {
-            return processMap(fileURI, (Map) treeData, out, parent);
+            return Optional.ofNullable(processMap(fileURI, (Map) treeData, out, parent));
         } else if (treeData instanceof List) {
-            return processList(fileURI, (List) treeData, out, parent);
+            return Optional.ofNullable(processList(fileURI, (List) treeData, out, parent));
         } else if (treeData instanceof Long) {
-            return RDFUtils.literal(((Long) treeData));
+            return Optional.of(RDFUtils.literal(((Long) treeData)));
         } else if (treeData instanceof Integer) {
-            return RDFUtils.literal(((Integer) treeData));
+            return Optional.of(RDFUtils.literal(((Integer) treeData)));
         } else if (treeData instanceof Float) {
-            return RDFUtils.literal((Float) treeData);
+            return Optional.of(RDFUtils.literal((Float) treeData));
         } else if (treeData instanceof Double) {
-            return RDFUtils.literal((Double) treeData);
+            return Optional.of(RDFUtils.literal((Double) treeData));
         } else if (treeData instanceof Byte) {
-            return RDFUtils.literal((Byte) treeData);
+            return Optional.of(RDFUtils.literal((Byte) treeData));
         } else if (treeData instanceof Boolean) {
-            return RDFUtils.literal((Boolean) treeData);
+            return Optional.of(RDFUtils.literal((Boolean) treeData));
         } else {
-            return processString((String) treeData);
+            return Optional.of(processString((String) treeData));
         }
     }
 
@@ -128,9 +129,11 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
             "some string" ---> ns:someString
             */
             Resource predicate = RDFUtils.makeIRI(k, file, false);
-            Value value = buildNode(file, node.get(k), out);
+            Optional<Value> isValue = buildNode(file, node.get(k), out);
             out.writeTriple(nodeURI, RDF.TYPE, vocab.mapping);
-            out.writeTriple(nodeURI, (IRI) predicate, value);
+            if (isValue.isPresent()) {
+                out.writeTriple(nodeURI, (IRI) predicate, isValue.get());
+            }
             out.writeTriple(predicate, RDF.TYPE, RDF.PREDICATE);
             out.writeTriple(predicate, RDFS.LABEL, RDFUtils.literal(k));
         });
@@ -154,8 +157,8 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
                 out.writeTriple(pList, RDF.REST, cList);
             }
             // adds value to the current iter
-            Value val = buildNode(fileURI, listIter.next(), out);
-            out.writeTriple(cList, RDF.FIRST, val);
+            Optional<Value> isValue = buildNode(fileURI, listIter.next(), out);
+            out.writeTriple(cList, RDF.FIRST, isValue.orElse(RDF.NIL));
             // makes current node the previuos one and generate new current node
             pList = cList;
             cList = YAMLExtractor.this.makeUri();


[13/17] any23 git commit: Update License information if files heads.

Posted by jg...@apache.org.
Update License information if files heads.


Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: a4208ea15322daca9a9c6d70ff394875262ac417
Parents: 29d3cf1
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Sat Nov 18 23:20:05 2017 +0000
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Sat Nov 18 23:20:05 2017 +0000

----------------------------------------------------------------------
 .../apache/any23/extractor/yaml/ElementsProcessor.java | 13 +++++++------
 .../org/apache/any23/extractor/yaml/YAMLExtractor.java | 13 +++++++------
 .../any23/extractor/yaml/YAMLProcessorException.java   | 13 +++++++------
 .../any23/extractor/yaml/ElementsProcessorTest.java    | 13 +++++++------
 .../any23/extractor/yaml/YAMLTikaParserTest.java       | 13 +++++++------
 5 files changed, 35 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/a4208ea1/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 8a9b65f..ca0811c 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
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,

http://git-wip-us.apache.org/repos/asf/any23/blob/a4208ea1/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
index 7e03733..00df8a4 100644
--- a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,

http://git-wip-us.apache.org/repos/asf/any23/blob/a4208ea1/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java
index 6c113b1..db242c6 100644
--- a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,

http://git-wip-us.apache.org/repos/asf/any23/blob/a4208ea1/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 61e6550..5533b4b 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
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,

http://git-wip-us.apache.org/repos/asf/any23/blob/a4208ea1/core/src/test/java/org/apache/any23/extractor/yaml/YAMLTikaParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/any23/extractor/yaml/YAMLTikaParserTest.java b/core/src/test/java/org/apache/any23/extractor/yaml/YAMLTikaParserTest.java
index ebfe513..c2b93a5 100644
--- a/core/src/test/java/org/apache/any23/extractor/yaml/YAMLTikaParserTest.java
+++ b/core/src/test/java/org/apache/any23/extractor/yaml/YAMLTikaParserTest.java
@@ -1,11 +1,12 @@
 /*
- * Copyright 2017 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,


[05/17] any23 git commit: Create ElementProcessor - RDF-izer

Posted by jg...@apache.org.
Create ElementProcessor - RDF-izer

- Add RDF-iser based on types
- add unit tests

Signed-off-by: Jacek Grzebyta <gr...@gmail.com>


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

Branch: refs/heads/master
Commit: 9f0cb636d51fee439310b1180685f48402431516
Parents: f787e42
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Sat Oct 21 10:27:06 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Sat Oct 21 10:35:32 2017 +0100

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java | 94 +++++++++++++++-----
 .../extractor/yaml/ElementsProcessorTest.java   | 55 ++++++++++--
 2 files changed, 120 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/9f0cb636/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 f69ca0c..58bc003 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
@@ -16,10 +16,13 @@
 package org.apache.any23.extractor.yaml;
 
 import java.util.AbstractMap;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Stream;
 import org.apache.any23.rdf.RDFUtils;
 import org.apache.any23.vocab.YAML;
+import org.eclipse.rdf4j.model.BNode;
 import org.eclipse.rdf4j.model.IRI;
 import org.eclipse.rdf4j.model.Literal;
 import org.eclipse.rdf4j.model.Model;
@@ -34,6 +37,16 @@ import org.eclipse.rdf4j.model.vocabulary.RDF;
 import org.eclipse.rdf4j.model.vocabulary.RDFS;
 
 /**
+ * Converts Object into RDF graph encoded to {@link Map.Entry}. Where key is a
+ * graph root node and value is a graph itself inside a {@link Model}.
+ *
+ * This parser performs conversion for three main types:
+ * <ul>
+ * <li> List - Creates RDF:List with bnode as root
+ * <li> Map - Creates simple graph where {key: value} is converted to
+ * predicate:object pair
+ * <li> Simple type - Crates RDF Literal
+ * </ul>
  *
  * @author Jacek Grzebyta (grzebyta.dev [at] gmail.com)
  */
@@ -42,59 +55,60 @@ public class ElementsProcessor {
     private final ModelFactory modelFactory = new LinkedHashModelFactory();
     private final YAML vocab = YAML.getInstance();
     protected ValueFactory vf = SimpleValueFactory.getInstance();
-    
-    private Map.Entry<Value,Model> asMapEntry(Value v, Model m) {
+
+    private Map.Entry<Value, Model> asMapEntry(Value v, Model m) {
         return new AbstractMap.SimpleEntry(v, m);
     }
 
     /**
-     * Converts a data structure to {@link Map.Entry<Value,Model>}. where value is a 
-     * root node of the data structure and model is a content of the RDF graph.
-     * 
-     * If requested object is simple object (i.e. is neither List or Map) than 
-     * method returns map entry of relevant instance of {@link Literal} as key and
-     * null as value.
-     * 
+     * Converts a data structure to {@link Map.Entry<Value,Model>}. where value
+     * is a root node of the data structure and model is a content of the RDF
+     * graph.
+     *
+     * If requested object is simple object (i.e. is neither List or Map) than
+     * method returns map entry of relevant instance of {@link Literal} as key
+     * and null as value.
+     *
      * @param namespace Namespace for predicates
      * @param t Object (or data structure) converting to RDF graph
-     * @param rootNode root node of the graph. If not given then blank node is created.
-     * @return 
+     * @param rootNode root node of the graph. If not given then blank node is
+     * created.
+     * @return
      */
-    public Map.Entry<Value,Model> asModel(IRI namespace, final Object t, Value rootNode) {
+    public Map.Entry<Value, Model> asModel(IRI namespace, final Object t, Value rootNode) {
         if (t == null) {
             return null;
         }
 
         if (t instanceof List) {
-            //return processList(namespace, (List) t);
+            return processList(namespace, (List) t);
         } else if (t instanceof Map) {
             return processMap(namespace, (Map) t, rootNode);
         } else {
             return asMapEntry(Literals.createLiteral(vf, t), null);
         }
-         return null;
     }
-    
-    protected Map.Entry<Value,Model> processMap(IRI ns, Map<String, Object> object, Value rootNode) {
+
+    protected Map.Entry<Value, Model> processMap(IRI ns, Map<String, Object> object, Value rootNode) {
         // check if map is empty of contains only null values
         if (object.isEmpty() || (object.values().size() == 1 && object.values().contains(null))) {
             return null;
         }
         assert ns != null : "Namespace value is null";
-        
+
         Model model = modelFactory.createEmptyModel();
         Value nodeURI = rootNode == null ? RDFUtils.makeIRI() : rootNode;
         model.add(vf.createStatement((Resource) nodeURI, RDF.TYPE, vocab.mapping));
-        object.keySet().forEach( (k) -> {
+        object.keySet().forEach((k) -> {
             /* False prevents adding _<int> to the predicate.
             Thus the predicate pattern is:
             "some string" ---> ns:someString
-            */
+             */
             Resource predicate = RDFUtils.makeIRI(k, ns, false);
             /* add map's key as statements:
             predicate rdf:type rdf:predicate .
             predicate rdfs:label predicate name
-            */
+             */
             model.add(vf.createStatement(predicate, RDF.TYPE, RDF.PREDICATE));
             model.add(vf.createStatement(predicate, RDFS.LABEL, RDFUtils.literal(k)));
             Value subGraphRoot = RDFUtils.makeIRI();
@@ -110,8 +124,46 @@ public class ElementsProcessor {
                     model.addAll(valInst.getValue());
                 }
             }
-            
+
         });
         return asMapEntry(nodeURI, model);
     }
+
+    protected Map.Entry<Value, Model> processList(IRI ns, List<Object> object) {
+
+        if (object.isEmpty() || object.stream().noneMatch((i) -> {
+            return i != null;
+        })) {
+            return null;
+        }
+        assert ns != null : "Namespace value is null";
+
+        // revers order
+        Collections.reverse(object);
+
+        Stream<Map.Entry<Value, Model>> nodesStream = object
+                .stream()
+                .map((i) -> {
+                    return asModel(ns, i, vf.createBNode());
+                });
+        // add last element
+        Map.Entry<Value, Model> outcome = Stream.concat(Stream.of(asMapEntry(RDF.NIL, modelFactory.createEmptyModel())), nodesStream)
+                .reduce((res, i) -> {
+                    BNode currentNode = vf.createBNode();
+                    Value val = res.getKey();
+                    Model mod = res.getValue();
+
+                    mod.add(vf.createStatement(currentNode, RDF.FIRST, i.getKey()));
+                    mod.add(vf.createStatement(currentNode, RDF.REST, val));
+
+                    if (i.getValue() != null) {
+                        mod.addAll(i.getValue());
+                    }
+
+                    return asMapEntry(currentNode, mod);
+                }).get();
+
+        outcome.getValue().add(vf.createStatement((Resource) outcome.getKey(), RDF.TYPE, RDF.LIST));
+        return outcome;
+    }
 }

http://git-wip-us.apache.org/repos/asf/any23/blob/9f0cb636/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 94cf64a..d800d9e 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
@@ -16,17 +16,16 @@
 package org.apache.any23.extractor.yaml;
 
 import java.io.StringWriter;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import org.eclipse.rdf4j.model.Literal;
 import org.eclipse.rdf4j.model.Model;
-import org.eclipse.rdf4j.model.Resource;
 import org.eclipse.rdf4j.model.Value;
-import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
-import org.eclipse.rdf4j.repository.sail.SailRepository;
-import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection;
+import org.eclipse.rdf4j.model.vocabulary.RDF;
 import org.eclipse.rdf4j.rio.RDFFormat;
 import org.eclipse.rdf4j.rio.Rio;
-import org.eclipse.rdf4j.sail.memory.MemoryStore;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -49,10 +48,10 @@ public class ElementsProcessorTest {
                 put("key3", 3);
             }
         };
-
+        
         ElementsProcessor ep = new ElementsProcessor();
-        Map.Entry<Value, Model> toTest = ep.processMap(ep.vf.createIRI("http://example.org/"), 
-                simpleMap, 
+        Map.Entry<Value, Model> toTest = ep.processMap(ep.vf.createIRI("http://example.org/"),
+                simpleMap,
                 ep.vf.createIRI("http://example.org/node1"));
         
         Assert.assertEquals(toTest.getKey().stringValue(), "http://example.org/node1");
@@ -60,6 +59,46 @@ public class ElementsProcessorTest {
         log.debug("Model: \n{}\n", dumpModel(toTest.getValue(), RDFFormat.TURTLE));
     }
     
+    @Test
+    public void processList() throws Exception {
+        List<Object> simpleList = new ArrayList<Object>() {
+            {
+                add("Ala");
+                add(6);
+                add("ma");
+                add("k".getBytes()[0]);
+            }
+        };
+        
+        ElementsProcessor ep = new ElementsProcessor();
+        Map.Entry<Value, Model> toTest = ep.processList(ep.vf.createIRI("http://example.org/data"), simpleList);
+        Assert.assertNotNull(toTest);
+        Assert.assertTrue(toTest.getValue().contains(null, RDF.FIRST, ep.vf.createLiteral("Ala"), null));
+        Assert.assertTrue(toTest.getValue().contains(null, RDF.FIRST, ep.vf.createLiteral(6), null));
+        Assert.assertTrue(toTest.getValue().contains(null, RDF.FIRST, ep.vf.createLiteral("ma"), null));
+        Assert.assertTrue(toTest.getValue().contains(null, RDF.FIRST, ep.vf.createLiteral("k".getBytes()[0]), null));
+        log.debug("Model: \n{}\n", dumpModel(toTest.getValue(), RDFFormat.TURTLE));
+    }
+    
+    @Test
+    public void processSimple() throws Exception {
+        List<Object> simpleList = new ArrayList<Object>() {
+            {
+                add("Ala");
+                add(6);
+                add("ma");
+                add("k".getBytes()[0]);
+            }
+        };
+        ElementsProcessor ep = new ElementsProcessor();
+        
+        simpleList.forEach((i) -> {
+            Map.Entry<Value, Model> out = ep.asModel(ep.vf.createIRI("urn:test/"), i, null);
+            Assert.assertTrue(out.getKey() instanceof Literal);
+            Assert.assertNull(out.getValue());
+        });
+    }
+    
     private String dumpModel(Model m, RDFFormat format) {
         StringWriter writer = new StringWriter();
         Rio.write(m, writer, format);


[17/17] any23 git commit: Merge branch 'ANY23-312'

Posted by jg...@apache.org.
Merge branch 'ANY23-312'

- Fixed yaml parser
- add more unit tests


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

Branch: refs/heads/master
Commit: f8e457985d5c4c0548158d0e41651741641ac1ab
Parents: 7818518 5d33154
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Thu Dec 7 12:24:26 2017 +0000
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Thu Dec 7 12:24:26 2017 +0000

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java | 205 +++++++++++++++++++
 .../any23/extractor/yaml/YAMLExtractor.java     | 158 +++-----------
 .../extractor/yaml/YAMLProcessorException.java  |  65 ++++++
 .../java/org/apache/any23/rdf/RDFUtils.java     |  26 ++-
 .../extractor/yaml/ElementsProcessorTest.java   | 106 ++++++++++
 .../any23/extractor/yaml/YAMLExtractorTest.java | 100 ++++++++-
 .../extractor/yaml/YAMLTikaParserTest.java      |  13 +-
 .../apache/any23/extractor/yaml/simple-312.yml  |   4 +
 .../apache/any23/extractor/yaml/test-null.yml   |   2 +-
 .../org/apache/any23/extractor/yaml/tree2.yml   |  27 +++
 10 files changed, 556 insertions(+), 150 deletions(-)
----------------------------------------------------------------------



[15/17] any23 git commit: Fixed problem with list parser

Posted by jg...@apache.org.
Fixed problem with list parser

- in raw rdf nodes are not reversed

Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: d005d7f306c16e75f4f6e4e395bd50e68bf73a06
Parents: a4f2cd4
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Mon Nov 20 00:41:12 2017 +0000
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Mon Nov 20 00:41:12 2017 +0000

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java | 61 ++++++++++----------
 1 file changed, 32 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/d005d7f3/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 ca0811c..0112a45 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
@@ -18,11 +18,9 @@ package org.apache.any23.extractor.yaml;
 
 import com.google.common.collect.Sets;
 import java.util.AbstractMap;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Stream;
 import org.apache.any23.rdf.RDFUtils;
 import org.apache.any23.vocab.YAML;
 import org.eclipse.rdf4j.model.BNode;
@@ -154,6 +152,7 @@ public class ElementsProcessor {
         return asMapEntry(nodeURI, model);
     }
 
+    @SuppressWarnings("UnusedAssignment")
     protected Map.Entry<Value, Model> processList(IRI ns, List<Object> object) {
 
         if (object.isEmpty() || object.stream().noneMatch((i) -> {
@@ -163,33 +162,37 @@ public class ElementsProcessor {
         }
         assert ns != null : "Namespace value is null";
 
-        // revers order
-        Collections.reverse(object);
-
-        Stream<Map.Entry<Value, Model>> nodesStream = object
-                .stream()
-                .map((i) -> {
-                    return asModel(ns, i, vf.createBNode());
-                });
-        // add last element
-        Map.Entry<Value, Model> outcome = Stream.concat(Stream.of(asMapEntry(RDF.NIL, modelFactory.createEmptyModel())), nodesStream)
-                .reduce((res, i) -> {
-                    BNode currentNode = vf.createBNode();
-                    Value val = res.getKey();
-                    Model mod = res.getValue();
-
-                    mod.add(vf.createStatement(currentNode, RDF.FIRST, i.getKey()));
-                    mod.add(vf.createStatement(currentNode, RDF.REST, val));
-
-                    if (i.getValue() != null) {
-                        mod.addAll(i.getValue());
-                    }
-
-                    return asMapEntry(currentNode, mod);
-                }).get();
-
-        outcome.getValue().add(vf.createStatement((Resource) outcome.getKey(), RDF.TYPE, RDF.LIST));
-        return outcome;
+        int objectSize = object.size();
+        Value listRoot = null;
+        Resource prevNode = null;
+        Model finalModel = modelFactory.createEmptyModel();
+        for (int i=0; i < objectSize; i++) {
+            Map.Entry<Value, Model> node = asModel(ns, object.get(i), RDFUtils.bnode());
+            BNode currentNode = RDFUtils.bnode();
+            
+            if (i == 0) {
+                listRoot = currentNode;
+            }
+            
+            finalModel.add(currentNode, RDF.FIRST, node.getKey(), (Resource[]) null);
+            
+            if (prevNode != null) {
+                finalModel.add(prevNode, RDF.REST, currentNode, (Resource[]) null);
+            }
+            
+            if (i == objectSize-1) {
+                finalModel.add(currentNode, RDF.REST, RDF.NIL, (Resource[]) null);
+            }
+            
+            if(node.getValue() != null) {
+                finalModel.addAll(node.getValue());
+            }
+            
+            prevNode = currentNode;
+        }
+        
+        finalModel.add((Resource) listRoot, RDF.TYPE, RDF.LIST, (Resource[]) null);
+        return asMapEntry(listRoot, finalModel);
     }
 
     // hide constructor


[08/17] any23 git commit: Ref ANY23-312

Posted by jg...@apache.org.
Ref ANY23-312

- ElementProcessor: fix issue in map validation
                    returns always empty model if parsed to literal
- YamlExtractor: fix issue with yaml containing only literals
- update unit tests


Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: 246af9b3d038046579add68b23598f9d9f8be14b
Parents: 657912b
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Mon Oct 23 14:55:55 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Mon Oct 23 14:55:55 2017 +0100

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java | 21 ++++++++++++++------
 .../any23/extractor/yaml/YAMLExtractor.java     |  8 ++++----
 .../any23/extractor/yaml/YAMLExtractorTest.java |  4 ++--
 .../apache/any23/extractor/yaml/simple-312.yml  |  2 +-
 4 files changed, 22 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/246af9b3/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 8fd0875..7d15576 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
@@ -15,8 +15,10 @@
  */
 package org.apache.any23.extractor.yaml;
 
+import com.google.common.collect.Sets;
 import java.util.AbstractMap;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Stream;
@@ -69,7 +71,7 @@ public class ElementsProcessor {
      *
      * If requested object is simple object (i.e. is neither List or Map) than
      * method returns map entry of relevant instance of {@link Literal} as key
-     * and null as value.
+     * and empty model as value.
      *
      * @param namespace Namespace for predicates
      * @param t Object (or data structure) converting to RDF graph
@@ -87,22 +89,29 @@ public class ElementsProcessor {
         } else if (t instanceof Map) {
             return processMap(namespace, (Map) t, rootNode);
         } else if (t instanceof String) {
-            return asMapEntry(RDFUtils.makeIRI(t.toString()), null);
+            return asMapEntry(RDFUtils.makeIRI(t.toString()), modelFactory.createEmptyModel());
         } else {
-            return asMapEntry(Literals.createLiteral(vf, t), null);
+            return asMapEntry(Literals.createLiteral(vf, t), modelFactory.createEmptyModel());
         }
     }
 
     protected Map.Entry<Value, Model> processMap(IRI ns, Map<String, Object> object, Value rootNode) {
-        // check if map is empty of contains only null values
-        if (object.isEmpty() || (object.values().size() == 1 && object.values().contains(null))) {
+        // check if map is empty
+        if (object.isEmpty()) {
             return null;
         }
+        HashSet<Object> vals = Sets.newHashSet(object.values());
+        boolean isEmpty = false;
+        if (vals.size() == 1 && vals.contains(null)) {
+            isEmpty = true;
+        }
         assert ns != null : "Namespace value is null";
 
         Model model = modelFactory.createEmptyModel();
         Value nodeURI = rootNode == null ? RDFUtils.makeIRI() : rootNode;
-        model.add(vf.createStatement((Resource) nodeURI, RDF.TYPE, vocab.mapping));
+        if (!isEmpty) {
+            model.add(vf.createStatement((Resource) nodeURI, RDF.TYPE, vocab.mapping));
+        }
         object.keySet().forEach((k) -> {
             /* False prevents adding _<int> to the predicate.
             Thus the predicate pattern is:

http://git-wip-us.apache.org/repos/asf/any23/blob/246af9b3/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
index 7d8221f..7e03733 100644
--- a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
@@ -17,11 +17,7 @@ package org.apache.any23.extractor.yaml;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import org.apache.any23.extractor.ExtractionContext;
 import org.apache.any23.extractor.ExtractionException;
 import org.apache.any23.extractor.ExtractionParameters;
@@ -86,6 +82,10 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
                 continue;
             }
             
+            if (!rootNode.getKey().equals(pageNode)) {
+                out.writeTriple(pageNode, vocab.contains, rootNode.getKey());
+            }
+            
             log.debug("Subgraph root node: {}", rootNode.getKey().stringValue());
             
             rootNode.getValue().forEach((s) ->{

http://git-wip-us.apache.org/repos/asf/any23/blob/246af9b3/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 9f6d01e..2dc884c 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
@@ -61,7 +61,7 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
     public void simpleFileLoading()
             throws Exception {
         assertExtract("/org/apache/any23/extractor/yaml/simple-load.yml");
-        log.debug(dumpModelToTurtle());
+        log.debug("\n{}",dumpModelToTurtle());
         assertModelNotEmpty();
 
     }
@@ -111,7 +111,7 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
     @Test
     public void treeTest() throws Exception {
         assertExtract("/org/apache/any23/extractor/yaml/tree.yml");
-        log.debug(dumpModelToTurtle());
+        log.debug("\n{}",dumpModelToTurtle());
         assertModelNotEmpty();
         // validate part of the tree structure
         assertContainsModel(new Statement[]{

http://git-wip-us.apache.org/repos/asf/any23/blob/246af9b3/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml
----------------------------------------------------------------------
diff --git a/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml
index ecf7768..5502558 100644
--- a/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml
+++ b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml
@@ -1,4 +1,4 @@
 %YAML 1.2
 ---
 Some test
-is fast
\ No newline at end of file
+is fast


[07/17] any23 git commit: Update YamlExtractor

Posted by jg...@apache.org.
Update YamlExtractor

- update unit tests
- add test to simple text file
Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: 657912b3aa22b1f46918fb39f2dc1a0a459303d8
Parents: f1b26df
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Mon Oct 23 12:40:21 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Mon Oct 23 12:40:21 2017 +0100

----------------------------------------------------------------------
 .../any23/extractor/yaml/YAMLExtractor.java     | 140 ++-----------------
 .../extractor/yaml/YAMLProcessorException.java  |  64 +++++++++
 .../any23/extractor/yaml/YAMLExtractorTest.java |  27 +++-
 .../apache/any23/extractor/yaml/simple-312.yml  |   4 +
 4 files changed, 103 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/657912b3/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
index ceacaba..7d8221f 100644
--- a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLExtractor.java
@@ -29,10 +29,10 @@ import org.apache.any23.extractor.ExtractionResult;
 import org.apache.any23.extractor.Extractor;
 import org.apache.any23.extractor.ExtractorDescription;
 import org.apache.any23.rdf.RDFUtils;
-import org.apache.any23.util.StringUtils;
 import org.apache.any23.vocab.YAML;
 import org.eclipse.rdf4j.model.Resource;
 import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Model;
 import org.eclipse.rdf4j.model.Value;
 import org.eclipse.rdf4j.model.vocabulary.RDF;
 import org.eclipse.rdf4j.model.vocabulary.RDFS;
@@ -51,7 +51,7 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
 
     private static final YAML vocab = YAML.getInstance();
 
-    private int nodeId = 0;
+    private final ElementsProcessor ep = ElementsProcessor.getInstance();
 
     private Resource documentRoot;
 
@@ -80,7 +80,18 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
             Resource pageNode = RDFUtils.makeIRI("document", documentIRI, true);
             out.writeTriple(documentRoot, vocab.contains, pageNode);
             out.writeTriple(pageNode, RDF.TYPE, vocab.document);
-            buildNode(documentIRI, p, out, pageNode);
+            Map.Entry<Value, Model> rootNode = ep.asModel(documentIRI, p, pageNode);
+            
+            if (rootNode == null) {
+                continue;
+            }
+            
+            log.debug("Subgraph root node: {}", rootNode.getKey().stringValue());
+            
+            rootNode.getValue().forEach((s) ->{
+                out.writeTriple(s.getSubject(), s.getPredicate(), s.getObject());
+            });
+            
         }
 
     }
@@ -90,127 +101,4 @@ public class YAMLExtractor implements Extractor.ContentExtractor {
         return YAMLExtractorFactory.getDescriptionInstance();
     }
 
-    private Optional<Value> buildNode(IRI fileURI, Object treeData, ExtractionResult out, Resource... parent) {
-
-        if (treeData != null) {
-            log.debug("object type: {}", treeData.getClass());
-        }
-
-        if (treeData == null) {
-            return Optional.empty();
-        } else if (treeData instanceof Map) {
-            return Optional.ofNullable(processMap(fileURI, (Map) treeData, out, parent));
-        } else if (treeData instanceof List) {
-            return Optional.ofNullable(processList(fileURI, (List) treeData, out, parent));
-        } else if (treeData instanceof Long) {
-            return Optional.of(RDFUtils.literal(((Long) treeData)));
-        } else if (treeData instanceof Integer) {
-            return Optional.of(RDFUtils.literal(((Integer) treeData)));
-        } else if (treeData instanceof Float) {
-            return Optional.of(RDFUtils.literal((Float) treeData));
-        } else if (treeData instanceof Double) {
-            return Optional.of(RDFUtils.literal((Double) treeData));
-        } else if (treeData instanceof Byte) {
-            return Optional.of(RDFUtils.literal((Byte) treeData));
-        } else if (treeData instanceof Boolean) {
-            return Optional.of(RDFUtils.literal((Boolean) treeData));
-        } else {
-            return Optional.of(processString((String) treeData));
-        }
-    }
-
-    private Value processMap(IRI file, Map<String, Object> node, ExtractionResult out, Resource... parent) {
-        Resource nodeURI = Arrays.asList(parent).isEmpty() ? YAMLExtractor.this.makeUri(file) : parent[0];
-        
-
-        node.keySet().forEach((k) -> {
-            /* False prevents adding _<int> to the predicate.
-            Thus the predicate pattern is:
-            "some string" ---> ns:someString
-            */
-            Resource predicate = RDFUtils.makeIRI(k, file, false);
-            Optional<Value> isValue = buildNode(file, node.get(k), out);
-            out.writeTriple(nodeURI, RDF.TYPE, vocab.mapping);
-            if (isValue.isPresent()) {
-                out.writeTriple(nodeURI, (IRI) predicate, isValue.get());
-            }
-            out.writeTriple(predicate, RDF.TYPE, RDF.PREDICATE);
-            out.writeTriple(predicate, RDFS.LABEL, RDFUtils.literal(k));
-        });
-        return nodeURI;
-    }
-
-    private Value processList(IRI fileURI, Iterable iter, ExtractionResult out, Resource... parent) {
-        Resource node = YAMLExtractor.this.makeUri();
-        out.writeTriple(node, RDF.TYPE, RDF.LIST);
-        
-        if (!Arrays.asList(parent).isEmpty()) {
-            out.writeTriple(parent[0], vocab.contains, node);
-        }
-
-        Resource pList = null; // previous RDF iter node
-        Resource cList = node; // cutternt RDF iter node
-        Iterator<?> listIter = iter.iterator();
-        while (listIter.hasNext()) {
-            // If previous RDF iter node is given lint with current one
-            if (pList != null) {
-                out.writeTriple(pList, RDF.REST, cList);
-            }
-            // adds value to the current iter
-            Optional<Value> isValue = buildNode(fileURI, listIter.next(), out);
-            out.writeTriple(cList, RDF.FIRST, isValue.orElse(RDF.NIL));
-            // makes current node the previuos one and generate new current node
-            pList = cList;
-            cList = YAMLExtractor.this.makeUri();
-        }
-        out.writeTriple(pList, RDF.REST, RDF.NIL);
-
-        return node;
-    }
-    
-    private Value processString(String str) {
-        if (RDFUtils.isAbsoluteIRI(str)) {
-            return RDFUtils.iri(str);
-        } else {
-            return RDFUtils.literal(str);
-        }
-    }
-
-    private Resource makeUri() {
-        Resource bnode = RDFUtils.bnode(Integer.toString(nodeId));
-        nodeId++;
-        return bnode;
-    }
-
-    private Resource makeUri(IRI docUri) {
-        return makeUri("node", docUri);
-}
-
-    private Resource makeUri(String type, IRI docUri) {
-        return makeUri(type, docUri, true);
-    }
-
-    private Resource makeUri(String type, IRI docUri, boolean addId) {
-
-        // preprocess string: converts - -> _
-        //                    converts <space>: word1 word2 -> word1Word2
-        String newType = StringUtils.implementJavaNaming(type);
-
-        String uriString;
-        if (docUri.toString().endsWith("/")) {
-            uriString = docUri.toString() + newType;
-        } else {
-            uriString = docUri.toString() + "#" + newType;
-        }
-
-        if (addId) {
-            uriString = uriString + "_" + Integer.toString(nodeId);
-        }
-
-        Resource node = RDFUtils.iri(uriString);
-        if (addId) {
-            nodeId++;
-        }
-        return node;
-    }
 }

http://git-wip-us.apache.org/repos/asf/any23/blob/657912b3/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java
new file mode 100644
index 0000000..6c113b1
--- /dev/null
+++ b/core/src/main/java/org/apache/any23/extractor/yaml/YAMLProcessorException.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.any23.extractor.yaml;
+
+import javax.annotation.Nullable;
+
+/**
+ *
+ * @author Jacek Grzebyta (grzebyta.dev [at] gmail.com)
+ */
+public class YAMLProcessorException extends RuntimeException {
+    
+    @Nullable
+    private Object reason;
+
+    public Object getReason() {
+        return reason;
+    }
+
+    public YAMLProcessorException() {
+        super();
+    }
+
+    public YAMLProcessorException(Object reason) {
+        this.reason = reason;
+    }
+
+    public YAMLProcessorException(Object reason, String message) {
+        super(message);
+        this.reason = reason;
+    }
+
+    public YAMLProcessorException(Object reason, String message, Throwable cause) {
+        super(message, cause);
+        this.reason = reason;
+    }
+
+    public YAMLProcessorException(Object reason, Throwable cause) {
+        super(cause);
+        this.reason = reason;
+    }
+
+    public YAMLProcessorException(Object reason, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+        super(message, cause, enableSuppression, writableStackTrace);
+        this.reason = reason;
+    }
+    
+    
+    
+    
+}

http://git-wip-us.apache.org/repos/asf/any23/blob/657912b3/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 57588e9..9f6d01e 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
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Test {@link YAMLExtractor}.
  *
- * @author Jacek Grzebyta (grzebyta.dev [at] gmail.com)
+ * @author Jacek Grzebyta (jgrzebyta [at] apache [dot] org)
  */
 public class YAMLExtractorTest extends AbstractExtractorTestCase {
 
@@ -46,6 +46,17 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
         return new YAMLExtractorFactory();
     }
 
+    /**
+     * Test to validate simple yaml file for ANY23-312
+     */
+    @Test
+    public void simpleTest312()
+            throws Exception {
+        assertExtract("/org/apache/any23/extractor/yaml/simple-312.yml");
+        log.debug(dumpModelToTurtle());
+        assertModelNotEmpty();
+    }
+
     @Test
     public void simpleFileLoading()
             throws Exception {
@@ -89,24 +100,28 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
         assertExtract("/org/apache/any23/extractor/yaml/test-null.yml");
         log.debug(dumpModelToTurtle());
         assertModelNotEmpty();
+        /**
+         * Since the map is empty it should not contain any document marked type mapping.
+         */
+        assertNotContains(RDF.TYPE, vocab.mapping); 
         int statements = dumpAsListOfStatements().size();
-        Assert.assertTrue("Found " + statements + " statements",statements == 9);
+        Assert.assertTrue("Found " + statements + " statements", statements == 9);
     }
-    
+
     @Test
     public void treeTest() throws Exception {
         assertExtract("/org/apache/any23/extractor/yaml/tree.yml");
         log.debug(dumpModelToTurtle());
         assertModelNotEmpty();
         // validate part of the tree structure
-        assertContainsModel(new Statement[] {
+        assertContainsModel(new Statement[]{
             RDFUtils.triple(RDFUtils.bnode(), RDFUtils.iri(ns, "value3"), RDFUtils.bnode("10")),
             RDFUtils.triple(RDFUtils.bnode("10"), RDF.FIRST, RDFUtils.bnode("11")),
             RDFUtils.triple(RDFUtils.bnode("11"), RDFUtils.iri(ns, "key3.1"), RDFUtils.bnode("12")),
             RDFUtils.triple(RDFUtils.bnode("12"), RDF.TYPE, RDF.LIST),
-            RDFUtils.triple(RDFUtils.bnode("12"), RDF.FIRST, RDFUtils.literal("value3.1.1" ))
+            RDFUtils.triple(RDFUtils.bnode("12"), RDF.FIRST, RDFUtils.literal("value3.1.1"))
         });
-        
+
         // validate occurence of <urn:value1> resource
         assertContains(RDFUtils.triple(RDFUtils.bnode(), RDF.FIRST, RDFUtils.iri("urn:value1")));
     }

http://git-wip-us.apache.org/repos/asf/any23/blob/657912b3/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml
----------------------------------------------------------------------
diff --git a/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml
new file mode 100644
index 0000000..ecf7768
--- /dev/null
+++ b/test-resources/src/test/resources/org/apache/any23/extractor/yaml/simple-312.yml
@@ -0,0 +1,4 @@
+%YAML 1.2
+---
+Some test
+is fast
\ No newline at end of file


[11/17] any23 git commit: Update ElementProcessor

Posted by jg...@apache.org.
Update ElementProcessor

- instantiate a map's root node
- update unit tests
Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: 66ffee03937bc23536628f8b9fa1504bbcd95efe
Parents: 52c199b
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Fri Nov 3 22:25:29 2017 +0000
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Fri Nov 3 22:25:29 2017 +0000

----------------------------------------------------------------------
 .../any23/extractor/yaml/ElementsProcessor.java      | 15 +++++++++++++--
 .../any23/extractor/yaml/ElementsProcessorTest.java  |  2 +-
 .../any23/extractor/yaml/YAMLExtractorTest.java      |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/66ffee03/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 7d15576..6819b88 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
@@ -95,7 +95,17 @@ public class ElementsProcessor {
         }
     }
 
-    protected Map.Entry<Value, Model> processMap(IRI ns, Map<String, Object> object, Value rootNode) {
+    /**
+     * This method creates a map with non bnode root.
+     * 
+     * If a map has instantiated root (not a blank node) it is simpler to create SPARQL query.
+     * 
+     * @param ns
+     * @param object
+     * @param parentNode
+     * @return 
+     */
+    protected Map.Entry<Value, Model> processMap(IRI ns, Map<String, Object> object, Value parentNode) {
         // check if map is empty
         if (object.isEmpty()) {
             return null;
@@ -108,7 +118,8 @@ public class ElementsProcessor {
         assert ns != null : "Namespace value is null";
 
         Model model = modelFactory.createEmptyModel();
-        Value nodeURI = rootNode == null ? RDFUtils.makeIRI() : rootNode;
+        Value nodeURI =RDFUtils.makeIRI("node", ns, true);
+        
         if (!isEmpty) {
             model.add(vf.createStatement((Resource) nodeURI, RDF.TYPE, vocab.mapping));
         }

http://git-wip-us.apache.org/repos/asf/any23/blob/66ffee03/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 6332776..5f9a7d8 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(toTest.getKey().stringValue(), "http://example.org/node1");
+        Assert.assertEquals("http://example.org/node_0", toTest.getKey().stringValue());
         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/66ffee03/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 2dc884c..9dba216 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 == 9);
+        Assert.assertTrue("Found " + statements + " statements", statements == 10);
     }
 
     @Test


[12/17] any23 git commit: Fix ANY23-312

Posted by jg...@apache.org.
Fix ANY23-312

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

Signed-off-by: Jacek Grzebyta <gr...@gmail.com>


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 <gr...@gmail.com>
Authored: Mon Nov 6 12:35:00 2017 +0000
Committer: Jacek Grzebyta <gr...@gmail.com>
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.


[06/17] any23 git commit: Update ElementProcessor - RDF-izer

Posted by jg...@apache.org.
Update ElementProcessor - RDF-izer

- make processor singleton
- update unit tests
Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: f1b26dfdc634c7e70e762319b60c968935a5be93
Parents: 9f0cb63
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Mon Oct 23 12:36:04 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Mon Oct 23 12:36:04 2017 +0100

----------------------------------------------------------------------
 .../apache/any23/extractor/yaml/ElementsProcessor.java  | 12 ++++++++++++
 core/src/main/java/org/apache/any23/rdf/RDFUtils.java   |  9 +++++++++
 .../any23/extractor/yaml/ElementsProcessorTest.java     |  6 ++----
 3 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/f1b26dfd/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 58bc003..8fd0875 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
@@ -56,6 +56,8 @@ public class ElementsProcessor {
     private final YAML vocab = YAML.getInstance();
     protected ValueFactory vf = SimpleValueFactory.getInstance();
 
+    private static final ElementsProcessor _ep = new ElementsProcessor();
+
     private Map.Entry<Value, Model> asMapEntry(Value v, Model m) {
         return new AbstractMap.SimpleEntry(v, m);
     }
@@ -84,6 +86,8 @@ public class ElementsProcessor {
             return processList(namespace, (List) t);
         } else if (t instanceof Map) {
             return processMap(namespace, (Map) t, rootNode);
+        } else if (t instanceof String) {
+            return asMapEntry(RDFUtils.makeIRI(t.toString()), null);
         } else {
             return asMapEntry(Literals.createLiteral(vf, t), null);
         }
@@ -166,4 +170,12 @@ public class ElementsProcessor {
         outcome.getValue().add(vf.createStatement((Resource) outcome.getKey(), RDF.TYPE, RDF.LIST));
         return outcome;
     }
+
+    // hide constructor
+    private ElementsProcessor() {
+    }
+
+    public static final ElementsProcessor getInstance() {
+        return _ep;
+    }
 }

http://git-wip-us.apache.org/repos/asf/any23/blob/f1b26dfd/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
index c1fbd54..1e6cbd4 100644
--- a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
+++ b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
@@ -626,6 +626,15 @@ public class RDFUtils {
         return node;
     }
     
+    /**
+     * Convert string to either IRI or Literal.
+     * 
+     * If string value expresses valid IRI than IRI is created. Otherwise method 
+     * creates simple literal xsd:string.
+     * 
+     * @param inString
+     * @return 
+     */
     public static Value makeIRI(String inString) {
         if (RDFUtils.isAbsoluteIRI(inString)) {
             return RDFUtils.iri(inString);

http://git-wip-us.apache.org/repos/asf/any23/blob/f1b26dfd/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 d800d9e..26899bb 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
@@ -37,7 +37,8 @@ import org.slf4j.LoggerFactory;
  */
 public class ElementsProcessorTest {
     
-    private Logger log = LoggerFactory.getLogger(getClass());
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private static final ElementsProcessor ep = ElementsProcessor.getInstance();
     
     @Test
     public void processMap() throws Exception {
@@ -49,7 +50,6 @@ public class ElementsProcessorTest {
             }
         };
         
-        ElementsProcessor ep = new ElementsProcessor();
         Map.Entry<Value, Model> toTest = ep.processMap(ep.vf.createIRI("http://example.org/"),
                 simpleMap,
                 ep.vf.createIRI("http://example.org/node1"));
@@ -70,7 +70,6 @@ public class ElementsProcessorTest {
             }
         };
         
-        ElementsProcessor ep = new ElementsProcessor();
         Map.Entry<Value, Model> toTest = ep.processList(ep.vf.createIRI("http://example.org/data"), simpleList);
         Assert.assertNotNull(toTest);
         Assert.assertTrue(toTest.getValue().contains(null, RDF.FIRST, ep.vf.createLiteral("Ala"), null));
@@ -90,7 +89,6 @@ public class ElementsProcessorTest {
                 add("k".getBytes()[0]);
             }
         };
-        ElementsProcessor ep = new ElementsProcessor();
         
         simpleList.forEach((i) -> {
             Map.Entry<Value, Model> out = ep.asModel(ep.vf.createIRI("urn:test/"), i, null);


[14/17] any23 git commit: Add unit test for extracting lists.

Posted by jg...@apache.org.
Add unit test for extracting lists.


Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: a4f2cd4739e9555eb1eff2ee97042b650a51bc3f
Parents: a4208ea
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Sun Nov 19 00:11:56 2017 +0000
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Sun Nov 19 00:11:56 2017 +0000

----------------------------------------------------------------------
 .../any23/extractor/yaml/YAMLExtractorTest.java | 30 ++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/a4f2cd47/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 82c2ddc..1c8df9e 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
@@ -16,6 +16,9 @@
  */
 package org.apache.any23.extractor.yaml;
 
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 import org.apache.any23.extractor.ExtractorFactory;
 import org.apache.any23.extractor.html.AbstractExtractorTestCase;
 import org.apache.any23.rdf.RDFUtils;
@@ -26,7 +29,11 @@ import org.eclipse.rdf4j.common.iteration.Iterations;
 import org.eclipse.rdf4j.model.Statement;
 import org.eclipse.rdf4j.model.vocabulary.RDF;
 import org.eclipse.rdf4j.model.vocabulary.RDFS;
+import org.eclipse.rdf4j.query.BindingSet;
+import org.eclipse.rdf4j.query.TupleQueryResult;
+import org.eclipse.rdf4j.repository.RepositoryConnection;
 import org.eclipse.rdf4j.repository.RepositoryResult;
+import org.junit.ComparisonFailure;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -126,6 +133,29 @@ public class YAMLExtractorTest extends AbstractExtractorTestCase {
         assertContains(RDFUtils.triple(RDFUtils.bnode(), RDF.FIRST, RDFUtils.iri("urn:value1")));
     }
     
+    @Test
+    public void treeTest2() throws Exception {
+        assertExtract("/org/apache/any23/extractor/yaml/tree.yml");
+        String sparql ="select ?nodes where "
+                + "{ [] <http://bob.example.com/key3.1> [ rdf:rest*/rdf:first ?nodes ;]}";
+        
+        RepositoryConnection connection = getConnection();
+        TupleQueryResult res = connection.prepareTupleQuery(sparql).evaluate();
+        List<BindingSet> resList = Iterations.asList(res);
+        try {
+            Assert.assertEquals("value3.1.1", resList.get(0).getValue("nodes").stringValue());
+        } catch (ComparisonFailure e) {
+            if ("value3.1.1".equals(resList.get(0).getValue("nodes").stringValue())) {
+                throw new RuntimeException("there should be no error");
+            }
+        }
+        List<String> resString = resList.stream().map((Function<? super BindingSet, String>) (b) -> {
+            return b.getValue("nodes").stringValue();
+        }).collect(Collectors.toList());
+        
+        log.debug("List output: {}", resString);
+    }
+    
     /**
      * This test covers a typical situation when a document is a map.
      * 


[09/17] any23 git commit: Fix ANY23-312

Posted by jg...@apache.org.
Fix ANY23-312

- fix unit test for literals

Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: e2ff945d1a58b35f461b0650e17b2f413867b0b2
Parents: 246af9b
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Fri Oct 27 17:17:10 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Fri Oct 27 17:17:10 2017 +0100

----------------------------------------------------------------------
 .../org/apache/any23/extractor/yaml/ElementsProcessorTest.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/e2ff945d/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 26899bb..6332776 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
@@ -93,7 +93,7 @@ public class ElementsProcessorTest {
         simpleList.forEach((i) -> {
             Map.Entry<Value, Model> out = ep.asModel(ep.vf.createIRI("urn:test/"), i, null);
             Assert.assertTrue(out.getKey() instanceof Literal);
-            Assert.assertNull(out.getValue());
+            Assert.assertTrue(out.getValue().isEmpty());
         });
     }
     


[10/17] any23 git commit: Fix ANY23-312

Posted by jg...@apache.org.
Fix ANY23-312

- fix problem with making wrong IRI if docIRI ends with # character

Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: 52c199b30b89596d3d452f13812d6e4a5e8898ab
Parents: e2ff945
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Fri Oct 27 20:03:18 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Fri Oct 27 20:03:18 2017 +0100

----------------------------------------------------------------------
 core/src/main/java/org/apache/any23/rdf/RDFUtils.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/52c199b3/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
index 1e6cbd4..2d6b697 100644
--- a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
+++ b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
@@ -609,7 +609,7 @@ public class RDFUtils {
         String newType = StringUtils.implementJavaNaming(type);
 
         String iriString;
-        if (docIRI.toString().endsWith("/")) {
+        if (docIRI.toString().endsWith("/") || docIRI.toString().endsWith("#")) {
             iriString = docIRI.toString() + newType;
         } else {
             iriString = docIRI.toString() + "#" + newType;


[03/17] any23 git commit: Update RDFUtils

Posted by jg...@apache.org.
Update RDFUtils

- remove some converters to util class


Signed-off-by:Jacek Grzebyta <gr...@gmail.com>

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

Branch: refs/heads/master
Commit: c7dd09e22810763f75131e38fea66475f39573c2
Parents: 783434d
Author: Jacek Grzebyta <gr...@gmail.com>
Authored: Wed Oct 18 18:50:30 2017 +0100
Committer: Jacek Grzebyta <gr...@gmail.com>
Committed: Wed Oct 18 18:50:30 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/any23/rdf/RDFUtils.java | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/c7dd09e2/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
index f10ca92..c1fbd54 100644
--- a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
+++ b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
@@ -625,6 +625,21 @@ public class RDFUtils {
         }
         return node;
     }
+    
+    public static Value makeIRI(String inString) {
+        if (RDFUtils.isAbsoluteIRI(inString)) {
+            return RDFUtils.iri(inString);
+        } else {
+            return RDFUtils.literal(inString);
+        }
+    }
+    
+    public static Value makeIRI() {
+        BNode bnode = bnode(Integer.toString(nodeId));
+        nodeId++;
+        return bnode;
+    }
+    
     private RDFUtils() {}
 
 }