| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 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 | |
|
| 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 | |
} |