| 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.ExtractionContext; |
| 21 | |
import org.apache.any23.extractor.ExtractionException; |
| 22 | |
import org.apache.any23.extractor.ExtractionParameters; |
| 23 | |
import org.apache.any23.extractor.ExtractionResult; |
| 24 | |
import org.apache.any23.extractor.Extractor; |
| 25 | |
import org.apache.any23.extractor.ExtractorDescription; |
| 26 | |
import org.openrdf.rio.RDFHandlerException; |
| 27 | |
import org.openrdf.rio.RDFParseException; |
| 28 | |
import org.openrdf.rio.RDFParser; |
| 29 | |
import org.openrdf.rio.helpers.RDFParserBase; |
| 30 | |
|
| 31 | |
import java.io.IOException; |
| 32 | |
import java.io.InputStream; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public abstract class BaseRDFExtractor implements Extractor.ContentExtractor { |
| 41 | |
|
| 42 | |
private boolean verifyDataType; |
| 43 | |
private boolean stopAtFirstError; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | 0 | public BaseRDFExtractor(boolean verifyDataType, boolean stopAtFirstError) { |
| 54 | 0 | this.verifyDataType = verifyDataType; |
| 55 | 0 | this.stopAtFirstError = stopAtFirstError; |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
public abstract ExtractorDescription getDescription(); |
| 59 | |
|
| 60 | |
protected abstract RDFParserBase getParser( |
| 61 | |
ExtractionContext extractionContext, |
| 62 | |
ExtractionResult extractionResult |
| 63 | |
); |
| 64 | |
|
| 65 | |
public BaseRDFExtractor() { |
| 66 | 0 | this(false, false); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
public boolean isVerifyDataType() { |
| 70 | 0 | return verifyDataType; |
| 71 | |
} |
| 72 | |
|
| 73 | |
public void setVerifyDataType(boolean verifyDataType) { |
| 74 | 0 | this.verifyDataType = verifyDataType; |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
public boolean isStopAtFirstError() { |
| 78 | 0 | return stopAtFirstError; |
| 79 | |
} |
| 80 | |
|
| 81 | |
public void setStopAtFirstError(boolean b) { |
| 82 | 0 | stopAtFirstError = b; |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
public void run( |
| 86 | |
ExtractionParameters extractionParameters, |
| 87 | |
ExtractionContext extractionContext, |
| 88 | |
InputStream in, |
| 89 | |
ExtractionResult extractionResult |
| 90 | |
) throws IOException, ExtractionException { |
| 91 | |
try { |
| 92 | 0 | final RDFParser parser = getParser(extractionContext, extractionResult); |
| 93 | 0 | parser.parse(in, extractionContext.getDocumentURI().stringValue()); |
| 94 | 0 | } catch (RDFHandlerException ex) { |
| 95 | 0 | throw new IllegalStateException("Unexpected exception.", ex); |
| 96 | 0 | } catch (RDFParseException ex) { |
| 97 | 0 | throw new ExtractionException("Error while parsing RDF document.", ex, extractionResult); |
| 98 | 0 | } |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
} |