| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.any23.filter; |
| 19 | |
|
| 20 | |
import org.apache.any23.extractor.ExtractionContext; |
| 21 | |
import org.apache.any23.extractor.html.TitleExtractor; |
| 22 | |
import org.apache.any23.writer.TripleHandler; |
| 23 | |
import org.apache.any23.writer.TripleHandlerException; |
| 24 | |
import org.openrdf.model.Resource; |
| 25 | |
import org.openrdf.model.URI; |
| 26 | |
import org.openrdf.model.Value; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public class IgnoreTitlesOfEmptyDocuments implements TripleHandler { |
| 38 | |
|
| 39 | |
private final ExtractionContextBlocker blocker; |
| 40 | |
|
| 41 | 0 | public IgnoreTitlesOfEmptyDocuments(TripleHandler wrapped) { |
| 42 | 0 | blocker = new ExtractionContextBlocker(wrapped); |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public void startDocument(URI documentURI) throws TripleHandlerException { |
| 46 | 0 | blocker.startDocument(documentURI); |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
public void openContext(ExtractionContext context) throws TripleHandlerException { |
| 50 | 0 | blocker.openContext(context); |
| 51 | 0 | if (isTitleContext(context)) { |
| 52 | 0 | blocker.blockContext(context); |
| 53 | |
} |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context) |
| 57 | |
throws TripleHandlerException { |
| 58 | 0 | if (!isTitleContext(context)) { |
| 59 | 0 | blocker.unblockDocument(); |
| 60 | |
} |
| 61 | 0 | blocker.receiveTriple(s, p, o, g, context); |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
public void receiveNamespace(String prefix, String uri, |
| 65 | |
ExtractionContext context) throws TripleHandlerException { |
| 66 | 0 | blocker.receiveNamespace(prefix, uri, context); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
public void closeContext(ExtractionContext context) { |
| 70 | 0 | blocker.closeContext(context); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public void close() throws TripleHandlerException { |
| 74 | 0 | blocker.close(); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
private boolean isTitleContext(ExtractionContext context) { |
| 78 | 0 | return context.getExtractorName().equals(TitleExtractor.NAME); |
| 79 | |
} |
| 80 | |
|
| 81 | |
public void endDocument(URI documentURI) throws TripleHandlerException { |
| 82 | 0 | blocker.endDocument(documentURI); |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
public void setContentLength(long contentLength) { |
| 86 | |
|
| 87 | 0 | } |
| 88 | |
} |