1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.extractor.rdf;
19
20 import org.apache.any23.extractor.ExtractionResult;
21 import org.eclipse.rdf4j.model.Resource;
22 import org.eclipse.rdf4j.model.Statement;
23 import org.eclipse.rdf4j.model.IRI;
24 import org.eclipse.rdf4j.rio.RDFHandler;
25 import org.eclipse.rdf4j.rio.RDFHandlerException;
26
27
28
29
30
31
32
33 public class RDFHandlerAdapter implements RDFHandler {
34
35 private ExtractionResult target;
36
37 public RDFHandlerAdapter(ExtractionResult target) {
38 this.target = target;
39 }
40
41 public void startRDF() throws RDFHandlerException {
42 }
43
44 public void handleNamespace(String prefix, String uri) {
45 target.writeNamespace(prefix, uri);
46 }
47
48 public void handleStatement(Statement stmt) {
49 if (stmt != null) {
50 final Resource context = stmt.getContext();
51 if (context instanceof IRI) {
52 target.writeTriple(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), (IRI) context);
53 } else {
54 target.writeTriple(stmt.getSubject(), stmt.getPredicate(), stmt.getObject());
55 }
56 }
57 }
58
59 public void handleComment(String comment) {
60
61 }
62
63 public void endRDF() throws RDFHandlerException {
64
65 }
66
67 }