Coverage Report - org.apache.any23.writer.ReportingTripleHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ReportingTripleHandler
0%
0/31
0%
0/2
1.154
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *  http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.any23.writer;
 19  
 
 20  
 import org.apache.any23.extractor.ExtractionContext;
 21  
 import org.openrdf.model.Resource;
 22  
 import org.openrdf.model.URI;
 23  
 import org.openrdf.model.Value;
 24  
 
 25  
 import java.util.Collection;
 26  
 import java.util.HashSet;
 27  
 
 28  
 /**
 29  
  * A {@link TripleHandler} that collects
 30  
  * various information about the extraction process, such as
 31  
  * the extractors used and the total number of triples.
 32  
  *
 33  
  * @author Richard Cyganiak (richard@cyganiak.de)
 34  
  */
 35  
 public class ReportingTripleHandler implements TripleHandler {
 36  
 
 37  
     private final TripleHandler wrapped;
 38  
 
 39  0
     private final Collection<String> extractorNames = new HashSet<String>();
 40  0
     private int totalTriples   = 0;
 41  0
     private int totalDocuments = 0;
 42  
 
 43  0
     public ReportingTripleHandler(TripleHandler wrapped) {
 44  0
         if(wrapped == null) {
 45  0
             throw new NullPointerException("wrapped cannot be null.");
 46  
         }
 47  0
         this.wrapped = wrapped;
 48  0
     }
 49  
 
 50  
     public Collection<String> getExtractorNames() {
 51  0
         return extractorNames;
 52  
     }
 53  
 
 54  
     public int getTotalTriples() {
 55  0
         return totalTriples;
 56  
     }
 57  
 
 58  
     public int getTotalDocuments() {
 59  0
         return totalDocuments;
 60  
     }
 61  
 
 62  
     /**
 63  
      * @return a human readable report.
 64  
      */
 65  
     public String printReport() {
 66  0
         return String.format("Total Documents: %d, Total Triples: %d", getTotalDocuments(), getTotalTriples());
 67  
     }
 68  
 
 69  
     public void startDocument(URI documentURI) throws TripleHandlerException {
 70  0
         totalDocuments++;
 71  0
         wrapped.startDocument(documentURI);
 72  0
     }
 73  
 
 74  
     public void openContext(ExtractionContext context) throws TripleHandlerException {
 75  0
         wrapped.openContext(context);
 76  0
     }
 77  
 
 78  
     public void receiveNamespace(
 79  
             String prefix,
 80  
             String uri,
 81  
             ExtractionContext context
 82  
     ) throws TripleHandlerException {
 83  0
         wrapped.receiveNamespace(prefix, uri, context);
 84  0
     }
 85  
 
 86  
     public void receiveTriple(
 87  
             Resource s,
 88  
             URI p,
 89  
             Value o,
 90  
             URI g,
 91  
             ExtractionContext context
 92  
     ) throws TripleHandlerException {
 93  0
         extractorNames.add(context.getExtractorName());
 94  0
         totalTriples++;
 95  0
         wrapped.receiveTriple(s, p, o, g, context);
 96  0
     }
 97  
 
 98  
     public void setContentLength(long contentLength) {
 99  0
         wrapped.setContentLength(contentLength);
 100  0
     }
 101  
 
 102  
     public void closeContext(ExtractionContext context) throws TripleHandlerException {
 103  0
         wrapped.closeContext(context);
 104  0
     }
 105  
 
 106  
     public void endDocument(URI documentURI) throws TripleHandlerException {
 107  0
         wrapped.endDocument(documentURI);
 108  0
     }
 109  
 
 110  
     public void close() throws TripleHandlerException {
 111  0
         wrapped.close();
 112  0
     }
 113  
 
 114  
 }