You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@any23.apache.org by ha...@apache.org on 2018/04/13 16:09:46 UTC

any23 git commit: ANY23-337 fixed: BenchmarkTripleHandler reported inaccurate runtimes

Repository: any23
Updated Branches:
  refs/heads/master b13472c20 -> c0db95e7c


ANY23-337 fixed: BenchmarkTripleHandler reported inaccurate runtimes


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

Branch: refs/heads/master
Commit: c0db95e7c370eac13bbfcb9018eb960295a12faa
Parents: b13472c
Author: Hans <fi...@gmail.com>
Authored: Fri Apr 13 11:07:03 2018 -0500
Committer: Hans <fi...@gmail.com>
Committed: Fri Apr 13 11:07:03 2018 -0500

----------------------------------------------------------------------
 .../any23/extractor/ExtractionResultImpl.java   | 38 ++++++++++----------
 1 file changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/any23/blob/c0db95e7/core/src/main/java/org/apache/any23/extractor/ExtractionResultImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/ExtractionResultImpl.java b/core/src/main/java/org/apache/any23/extractor/ExtractionResultImpl.java
index be411e6..7a2d123 100644
--- a/core/src/main/java/org/apache/any23/extractor/ExtractionResultImpl.java
+++ b/core/src/main/java/org/apache/any23/extractor/ExtractionResultImpl.java
@@ -64,9 +64,9 @@ public class ExtractionResultImpl implements TagSoupExtractionResult {
 
     private final TripleHandler tripleHandler;
 
-    private final Collection<ExtractionResult> subResults = new ArrayList<ExtractionResult>();
+    private final Collection<ExtractionResult> subResults = new ArrayList<>();
 
-    private final Set<Object> knownContextIDs = new HashSet<Object>();
+    private final Set<Object> knownContextIDs = new HashSet<>();
 
     private boolean isClosed = false;
 
@@ -83,7 +83,7 @@ public class ExtractionResultImpl implements TagSoupExtractionResult {
             Extractor<?> extractor,
             TripleHandler tripleHandler
     ) {
-        this(context, extractor, tripleHandler, new ArrayList<Issue>());
+        this(context, extractor, tripleHandler, new ArrayList<>());
     }
 
     private ExtractionResultImpl(
@@ -108,6 +108,15 @@ public class ExtractionResultImpl implements TagSoupExtractionResult {
         this.issues          = issues;
 
         knownContextIDs.add( context.getUniqueID() );
+
+        try {
+            // openContext() must be called before extraction begins
+            // so that BenchmarkTripleHandler can report accurate times.
+            // See https://issues.apache.org/jira/browse/ANY23-337
+            tripleHandler.openContext(context);
+        } catch (TripleHandlerException e) {
+            throw new RuntimeException("Error while opening context", e);
+        }
     }
 
     public boolean hasIssues() {
@@ -203,23 +212,16 @@ public class ExtractionResultImpl implements TagSoupExtractionResult {
         for (ExtractionResult subResult : subResults) {
             subResult.close();
         }
-        if (isInitialized) {
-            try {
-                tripleHandler.closeContext(context);
-            } catch (TripleHandlerException e) {
-                throw new RuntimeException("Error while opening context", e);
-            }
+        try {
+            tripleHandler.closeContext(context);
+        } catch (TripleHandlerException e) {
+            throw new RuntimeException("Error while opening context", e);
         }
     }
 
     private void checkOpen() {
         if (!isInitialized) {
             isInitialized = true;
-            try {
-                tripleHandler.openContext(context);
-            } catch (TripleHandlerException e) {
-                throw new RuntimeException("Error while opening context", e);
-            }
             Prefixes prefixes = extractor.getDescription().getPrefixes();
             for (String prefix : prefixes.allPrefixes()) {
                 try {
@@ -239,14 +241,14 @@ public class ExtractionResultImpl implements TagSoupExtractionResult {
     @Override
     public void addResourceRoot(String[] path, Resource root, Class<? extends MicroformatExtractor> extractor) {
         if(resourceRoots == null) {
-            resourceRoots = new ArrayList<ResourceRoot>();
+            resourceRoots = new ArrayList<>();
         }
         resourceRoots.add( new ResourceRoot(path, root, extractor) );
     }
 
     @Override
     public List<ResourceRoot> getResourceRoots() {
-        List<ResourceRoot> allRoots = new ArrayList<ResourceRoot>();
+        List<ResourceRoot> allRoots = new ArrayList<>();
         if(resourceRoots != null) {
             allRoots.addAll( resourceRoots );
         }
@@ -268,14 +270,14 @@ public class ExtractionResultImpl implements TagSoupExtractionResult {
             String[] path
     ) {
         if(propertyPaths == null) {
-            propertyPaths = new ArrayList<PropertyPath>();
+            propertyPaths = new ArrayList<>();
         }
         propertyPaths.add( new PropertyPath(path, propertySubject, property, object, extractor) );
     }
 
     @Override
     public List<PropertyPath> getPropertyPaths() {
-        List<PropertyPath> allPaths = new ArrayList<PropertyPath>();
+        List<PropertyPath> allPaths = new ArrayList<>();
         if(propertyPaths != null) {
             allPaths.addAll( propertyPaths );
         }