| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.any23.extractor; |
| 19 | |
|
| 20 | |
import org.openrdf.model.URI; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
public class ExtractionContext { |
| 27 | |
|
| 28 | |
public static final String ROOT_EXTRACTION_RESULT_ID = "root-extraction-result-id"; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
private final String extractorName; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
private final URI documentURI; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
private String defaultLanguage; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
private final String uniqueID; |
| 49 | |
|
| 50 | 0 | public ExtractionContext(String extractorName, URI documentURI, String defaultLanguage, String localID) { |
| 51 | 0 | checkNotNull(extractorName , "extractor name"); |
| 52 | 0 | checkNotNull(documentURI , "document URI"); |
| 53 | 0 | this.extractorName = extractorName; |
| 54 | 0 | this.documentURI = documentURI; |
| 55 | 0 | this.defaultLanguage = defaultLanguage; |
| 56 | 0 | this.uniqueID = |
| 57 | |
"urn:x-any23:" + extractorName + ":" + |
| 58 | |
(localID == null ? "" : localID) + ":" + documentURI; |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public ExtractionContext(String extractorName, URI documentURI, String defaultLanguage) { |
| 62 | 0 | this(extractorName, documentURI, defaultLanguage, ROOT_EXTRACTION_RESULT_ID); |
| 63 | 0 | } |
| 64 | |
|
| 65 | |
public ExtractionContext(String extractorName, URI documentURI) { |
| 66 | 0 | this(extractorName, documentURI, null); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
public ExtractionContext copy(String localID) { |
| 70 | 0 | return new ExtractionContext( |
| 71 | |
getExtractorName(), |
| 72 | |
getDocumentURI(), |
| 73 | |
getDefaultLanguage(), |
| 74 | |
localID |
| 75 | |
); |
| 76 | |
} |
| 77 | |
|
| 78 | |
public String getExtractorName() { |
| 79 | 0 | return extractorName; |
| 80 | |
} |
| 81 | |
|
| 82 | |
public URI getDocumentURI() { |
| 83 | 0 | return documentURI; |
| 84 | |
} |
| 85 | |
|
| 86 | |
public String getDefaultLanguage() { |
| 87 | 0 | return defaultLanguage; |
| 88 | |
} |
| 89 | |
|
| 90 | |
public String getUniqueID() { |
| 91 | 0 | return uniqueID; |
| 92 | |
} |
| 93 | |
|
| 94 | |
public int hashCode() { |
| 95 | 0 | return uniqueID.hashCode(); |
| 96 | |
} |
| 97 | |
|
| 98 | |
public boolean equals(Object other) { |
| 99 | 0 | if (!(other instanceof ExtractionContext)) return false; |
| 100 | 0 | return ((ExtractionContext) other).uniqueID.equals(uniqueID); |
| 101 | |
} |
| 102 | |
|
| 103 | |
public String toString() { |
| 104 | 0 | return String.format("ExtractionContext(%s)", uniqueID); |
| 105 | |
} |
| 106 | |
|
| 107 | |
private void checkNotNull(Object data, String desc) { |
| 108 | 0 | if(data == null) throw new NullPointerException(desc + " cannot be null."); |
| 109 | 0 | } |
| 110 | |
|
| 111 | |
} |