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