any23-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [2/8] any23 git commit: Fixed issue ANY23-310
Date Wed, 26 Jul 2017 20:42:06 GMT
Fixed issue ANY23-310

- pipe proper logger in Rover.performExtraction
- make the content length counted
- use StringUtils#join for merging with delimiter

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

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

Branch: refs/heads/master
Commit: e235954ebafdc075158a12d8a5b6377714c347d0
Parents: 1b68735
Author: Jacek Grzebyta <grzebyta.dev@gmail.com>
Authored: Fri Jul 14 16:27:16 2017 +0100
Committer: Jacek Grzebyta <grzebyta.dev@gmail.com>
Committed: Fri Jul 14 16:27:16 2017 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/any23/cli/Rover.java   |  2 +-
 cli/src/test/resources/log4j.properties         |  2 +-
 .../any23/writer/CompositeTripleHandler.java    |  4 ++-
 .../any23/writer/LoggingTripleHandler.java      | 29 ++++++++++++--------
 4 files changed, 22 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/e235954e/cli/src/main/java/org/apache/any23/cli/Rover.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/any23/cli/Rover.java b/cli/src/main/java/org/apache/any23/cli/Rover.java
index 26a8663..0798dc8 100644
--- a/cli/src/main/java/org/apache/any23/cli/Rover.java
+++ b/cli/src/main/java/org/apache/any23/cli/Rover.java
@@ -175,7 +175,7 @@ public class Rover implements Tool {
     }
 
     protected void performExtraction(DocumentSource documentSource) throws Exception {
-        if (!any23.extract(extractionParameters, documentSource, tripleHandler).hasMatchingExtractors())
{
+        if (!any23.extract(extractionParameters, documentSource, reportingTripleHandler).hasMatchingExtractors())
{
             throw new IllegalStateException(format("No suitable extractors found for source
%s", documentSource));
         }
     }

http://git-wip-us.apache.org/repos/asf/any23/blob/e235954e/cli/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/cli/src/test/resources/log4j.properties b/cli/src/test/resources/log4j.properties
index b6af94e..1e5e379 100644
--- a/cli/src/test/resources/log4j.properties
+++ b/cli/src/test/resources/log4j.properties
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 log4j.logger.org.apache.any23.cli.YAMLRoverTest=trace
-log4j.logger.org.apache.any23.cli.SimpleRoverTest=debug
+log4j.logger.org.apache.any23.cli.SimpleRoverTest=trace
 
 log4j.rootLogger=INFO, A1
 

http://git-wip-us.apache.org/repos/asf/any23/blob/e235954e/core/src/main/java/org/apache/any23/writer/CompositeTripleHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/writer/CompositeTripleHandler.java b/core/src/main/java/org/apache/any23/writer/CompositeTripleHandler.java
index d3bca97..769aa52 100644
--- a/core/src/main/java/org/apache/any23/writer/CompositeTripleHandler.java
+++ b/core/src/main/java/org/apache/any23/writer/CompositeTripleHandler.java
@@ -110,7 +110,9 @@ public class CompositeTripleHandler implements TripleHandler {
     }
 
     public void setContentLength(long contentLength) {
-        // Empty.
+        for (TripleHandler handler : children) {
+            handler.setContentLength(contentLength);
+        }
     }
     
 }

http://git-wip-us.apache.org/repos/asf/any23/blob/e235954e/core/src/main/java/org/apache/any23/writer/LoggingTripleHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/writer/LoggingTripleHandler.java b/core/src/main/java/org/apache/any23/writer/LoggingTripleHandler.java
index e214df7..90435b0 100644
--- a/core/src/main/java/org/apache/any23/writer/LoggingTripleHandler.java
+++ b/core/src/main/java/org/apache/any23/writer/LoggingTripleHandler.java
@@ -25,7 +25,9 @@ import org.eclipse.rdf4j.model.Value;
 import java.io.PrintWriter;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import org.apache.any23.util.StringUtils;
 
 /**
  * Triple handler decorator useful for logging purposes.
@@ -87,20 +89,23 @@ public class LoggingTripleHandler implements TripleHandler {
         underlyingHandler.receiveNamespace(prefix, uri, context);
     }
 
+    @Override
     public void endDocument(IRI documentIRI) throws TripleHandlerException {
         underlyingHandler.endDocument(documentIRI);
         long elapsedTime = System.currentTimeMillis() - startTime;
-        boolean success = true;
-        StringBuffer sb = new StringBuffer("[");
-        for (Entry<String, Integer> ent : contextTripleMap.entrySet()) {
-            sb.append(" ").append(ent.getKey()).append(":").append(ent.getValue());
-            if (ent.getValue() > 0) {
-                success = true;
-            }
-        }
-        sb.append("]");
+        final AtomicBoolean success = new AtomicBoolean(true);
+        
+        StringBuffer sb = new StringBuffer("[ ");
+        String[] parsers = contextTripleMap.entrySet().stream().map(e -> {
+                    if (e.getValue() > 0) {
+                        success.set(true);
+                    }
+                    return String.format("%s:%d", e.getKey(), e.getValue()); }
+                ).collect(Collectors.toList()).toArray(new String[] {});
+        sb.append(StringUtils.join(", ", parsers));
+        sb.append(" ]");
         destination.println(
-                documentIRI + "\t" + contentLength + "\t" + elapsedTime + "\t" + success
+ "\t" + sb.toString()
+                documentIRI + "\t" + contentLength + "\t" + elapsedTime + "\t" + success.get()
+ "\t" + sb.toString()
         );
         contextTripleMap.clear();
     }
@@ -111,6 +116,6 @@ public class LoggingTripleHandler implements TripleHandler {
     }
 
     private void printHeader(PrintWriter writer) {
-        writer.println("# Document-IRI\tContent-Length\tElapsed-Time\tSuccess\tExtractors");
+        writer.println("# Document-IRI\tContent-Length\tElapsed-Time\tSuccess\tExtractors:Triples");
     }
 }
\ No newline at end of file


Mime
View raw message