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 java.util.Locale;
21
22 import org.apache.any23.extractor.ExtractionContext;
23 import org.eclipse.rdf4j.model.Resource;
24 import org.eclipse.rdf4j.model.IRI;
25 import org.eclipse.rdf4j.model.Value;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30
31
32
33
34
35 public class CountingTripleHandler implements TripleHandler {
36
37 private static final Logger logger = LoggerFactory.getLogger(CountingTripleHandler.class);
38
39 private final boolean logTriples;
40
41 private int count = 0;
42
43 public CountingTripleHandler(boolean logTriples) {
44 this.logTriples = logTriples;
45 }
46
47 public CountingTripleHandler() {
48 this(false);
49 }
50
51 public int getCount() {
52 return count;
53 }
54
55 public void reset() {
56 count = 0;
57 }
58
59 public void startDocument(IRI documentIRI) throws TripleHandlerException {
60
61 }
62
63 public void openContext(ExtractionContext context) throws TripleHandlerException {
64
65 }
66
67 public void closeContext(ExtractionContext context) throws TripleHandlerException {
68
69 }
70
71 public void receiveTriple(Resource s, IRI p, Value o, IRI g, ExtractionContext context)
72 throws TripleHandlerException {
73 count++;
74 if (logTriples)
75 logger.debug(String.format(Locale.ROOT, "%s %s %s %s %s\n", s, p, o, g, context));
76 }
77
78 public void receiveNamespace(String prefix, String uri, ExtractionContext context) throws TripleHandlerException {
79
80 }
81
82 public void close() throws TripleHandlerException {
83
84 }
85
86 public void endDocument(IRI documentIRI) throws TripleHandlerException {
87
88 }
89
90 public void setContentLength(long contentLength) {
91
92 }
93 }