You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@any23.apache.org by an...@apache.org on 2017/01/13 22:25:45 UTC
[06/25] any23 git commit: ANY23-276 : Convert from Sesame to RDF4J
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java b/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
index 4e45b73..2b9c028 100644
--- a/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
+++ b/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
@@ -21,11 +21,11 @@ import org.apache.any23.extractor.IssueReport;
import org.apache.any23.extractor.ExtractionResult;
import org.apache.any23.extractor.html.DomUtils;
import org.apache.any23.rdf.RDFUtils;
-import org.openrdf.model.Literal;
-import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.vocabulary.RDF;
+import org.eclipse.rdf4j.model.Literal;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@@ -55,9 +55,9 @@ public class RDFa11Parser {
private static final Logger logger = LoggerFactory.getLogger(RDFa11Parser.class);
public static final String CURIE_SEPARATOR = ":";
- public static final char URI_PREFIX_SEPARATOR = ':';
- public static final String URI_SCHEMA_SEPARATOR = "://";
- public static final String URI_PATH_SEPARATOR = "/";
+ public static final char IRI_PREFIX_SEPARATOR = ':';
+ public static final String IRI_SCHEMA_SEPARATOR = "://";
+ public static final String IRI_PATH_SEPARATOR = "/";
public static final String HEAD_TAG = "HEAD";
public static final String BODY_TAG = "BODY";
@@ -100,7 +100,7 @@ public class RDFa11Parser {
private URL documentBase;
- private final Stack<URIMapping> uriMappingStack = new Stack<URIMapping>();
+ private final Stack<IRIMapping> IRIMappingStack = new Stack<IRIMapping>();
private final Stack<Vocabulary> vocabularyStack = new Stack<Vocabulary>();
@@ -134,7 +134,7 @@ public class RDFa11Parser {
i++;
continue;
}
- if(part.charAt( part.length() -1 ) == URI_PREFIX_SEPARATOR) {
+ if(part.charAt( part.length() -1 ) == IRI_PREFIX_SEPARATOR) {
i++;
while(i < parts.length && parts[i].length() == 0) i++;
out.add( part + (i < parts.length ? parts[i] : "") );
@@ -147,8 +147,8 @@ public class RDFa11Parser {
return out.toArray( new String[out.size()] );
}
- protected static boolean isAbsoluteURI(String uri) {
- return uri.contains(URI_SCHEMA_SEPARATOR);
+ protected static boolean isAbsoluteIRI(String IRI) {
+ return IRI.contains(IRI_SCHEMA_SEPARATOR);
}
protected static boolean isCURIE(String curie) {
@@ -248,7 +248,7 @@ public class RDFa11Parser {
public void reset() {
issueReport = null;
documentBase = null;
- uriMappingStack.clear();
+ IRIMappingStack.clear();
listOfIncompleteTriples.clear();
evaluationContextStack.clear();
}
@@ -262,31 +262,31 @@ public class RDFa11Parser {
final String vocabularyStr = DomUtils.readAttribute(currentNode, VOCAB_ATTRIBUTE, null);
if(vocabularyStr == null) return;
try {
- pushVocabulary(currentNode, RDFUtils.uri(vocabularyStr));
+ pushVocabulary(currentNode, RDFUtils.iri(vocabularyStr));
} catch (Exception e) {
- reportError(currentNode, String.format("Invalid vocabulary [%s], must be a URI.", vocabularyStr));
+ reportError(currentNode, String.format("Invalid vocabulary [%s], must be a IRI.", vocabularyStr));
}
}
/**
- * Updates the URI mapping with the XMLNS attributes declared in the current node.
+ * Updates the IRI mapping with the XMLNS attributes declared in the current node.
*
* @param node input node.
*/
- protected void updateURIMapping(Node node) {
+ protected void updateIRIMapping(Node node) {
final NamedNodeMap attributes = node.getAttributes();
if (null == attributes) return;
Node attribute;
final List<PrefixMap> prefixMapList = new ArrayList<PrefixMap>();
- final String namespacePrefix = XMLNS_ATTRIBUTE + URI_PREFIX_SEPARATOR;
+ final String namespacePrefix = XMLNS_ATTRIBUTE + IRI_PREFIX_SEPARATOR;
for (int a = 0; a < attributes.getLength(); a++) {
attribute = attributes.item(a);
if (attribute.getNodeName().startsWith(namespacePrefix)) {
prefixMapList.add(
new PrefixMap(
attribute.getNodeName().substring(namespacePrefix.length()),
- resolveURI(attribute.getNodeValue())
+ resolveIRI(attribute.getNodeValue())
)
);
}
@@ -302,14 +302,14 @@ public class RDFa11Parser {
}
/**
- * Returns a URI mapping for a given prefix.
+ * Returns a IRI mapping for a given prefix.
*
* @param prefix input prefix.
- * @return URI mapping.
+ * @return IRI mapping.
*/
- protected URI getMapping(String prefix) {
- for (URIMapping uriMapping : uriMappingStack) {
- final URI mapping = uriMapping.map.get(prefix);
+ protected IRI getMapping(String prefix) {
+ for (IRIMapping IRIMapping : IRIMappingStack) {
+ final IRI mapping = IRIMapping.map.get(prefix);
if (mapping != null) {
return mapping;
}
@@ -325,53 +325,53 @@ public class RDFa11Parser {
* @return list of resolved URIs.
* @throws URISyntaxException if there is an error processing CURIE or URL
*/
- protected URI[] resolveCurieOrURIList(Node n, String curieOrURIList, boolean termAllowed)
+ protected IRI[] resolveCIRIeOrIRIList(Node n, String curieOrIRIList, boolean termAllowed)
throws URISyntaxException {
- if(curieOrURIList == null || curieOrURIList.trim().length() == 0) return new URI[0];
-
- final String[] curieOrURIListParts = curieOrURIList.split("\\s");
- final List<URI> result = new ArrayList<URI>();
- Resource curieOrURI;
- for(String curieORURIListPart : curieOrURIListParts) {
- curieOrURI = resolveCURIEOrURI(curieORURIListPart, termAllowed);
- if(curieOrURI != null && curieOrURI instanceof URI) {
- result.add((URI) curieOrURI);
+ if(curieOrIRIList == null || curieOrIRIList.trim().length() == 0) return new IRI[0];
+
+ final String[] curieOrIRIListParts = curieOrIRIList.split("\\s");
+ final List<IRI> result = new ArrayList<IRI>();
+ Resource curieOrIRI;
+ for(String curieORIRIListPart : curieOrIRIListParts) {
+ curieOrIRI = resolveCURIEOrIRI(curieORIRIListPart, termAllowed);
+ if(curieOrIRI != null && curieOrIRI instanceof IRI) {
+ result.add((IRI) curieOrIRI);
} else {
- reportError(n, String.format("Invalid CURIE '%s' : expected URI, found BNode.", curieORURIListPart));
+ reportError(n, String.format("Invalid CURIE '%s' : expected IRI, found BNode.", curieORIRIListPart));
}
}
- return result.toArray(new URI[result.size()]);
+ return result.toArray(new IRI[result.size()]);
}
/**
- * Resolves a URI string as URI.
+ * Resolves a IRI string as IRI.
*
- * @param uriStr (partial) URI string to be resolved.
- * @return the resolved URI.
+ * @param IRIStr (partial) IRI string to be resolved.
+ * @return the resolved IRI.
*/
- protected URI resolveURI(String uriStr) {
+ protected IRI resolveIRI(String IRIStr) {
return
- isAbsoluteURI(uriStr)
+ isAbsoluteIRI(IRIStr)
?
- RDFUtils.uri(uriStr)
+ RDFUtils.iri(IRIStr)
:
- RDFUtils.uri( this.documentBase.toExternalForm(), uriStr );
+ RDFUtils.iri( this.documentBase.toExternalForm(), IRIStr );
}
/**
- * Resolves a <i>CURIE</i> or <i>URI</i> string.
+ * Resolves a <i>CURIE</i> or <i>IRI</i> string.
*
- * @param curieOrURI
+ * @param curieOrIRI
* @param termAllowed if <code>true</code> the resolution can be a term.
* @return the resolved resource.
*/
- protected Resource resolveCURIEOrURI(String curieOrURI, boolean termAllowed) {
- if( isCURIE(curieOrURI) ) {
- return resolveNamespacedURI(curieOrURI.substring(1, curieOrURI.length() - 1), ResolutionPolicy.NSRequired);
+ protected Resource resolveCURIEOrIRI(String curieOrIRI, boolean termAllowed) {
+ if( isCURIE(curieOrIRI) ) {
+ return resolveNamespacedIRI(curieOrIRI.substring(1, curieOrIRI.length() - 1), ResolutionPolicy.NSRequired);
}
- if(isAbsoluteURI(curieOrURI)) return resolveURI(curieOrURI);
- return resolveNamespacedURI(
- curieOrURI,
+ if(isAbsoluteIRI(curieOrIRI)) return resolveIRI(curieOrIRI);
+ return resolveNamespacedIRI(
+ curieOrIRI,
termAllowed ? ResolutionPolicy.TermAllowed : ResolutionPolicy.NSNotRequired
);
}
@@ -410,16 +410,16 @@ public class RDFa11Parser {
* Pushes a new vocabulary definition.
*
* @param currentNode node proving the vocabulary.
- * @param vocab the vocabulary URI.
+ * @param vocab the vocabulary IRI.
*/
- private void pushVocabulary(Node currentNode, URI vocab) {
+ private void pushVocabulary(Node currentNode, IRI vocab) {
vocabularyStack.push( new Vocabulary(currentNode, vocab) );
}
/**
* @return the current peek vocabulary.
*/
- private URI getVocabulary() {
+ private IRI getVocabulary() {
if(vocabularyStack.isEmpty()) return null;
return vocabularyStack.peek().prefix;
}
@@ -465,7 +465,7 @@ public class RDFa11Parser {
);
final int[] errorLocation = DomUtils.getNodeLocation(n);
this.issueReport.notifyIssue(
- IssueReport.IssueLevel.Warning,
+ IssueReport.IssueLevel.WARNING,
errorMsg,
errorLocation == null ? -1 : errorLocation[0],
errorLocation == null ? -1 : errorLocation[1]
@@ -514,7 +514,7 @@ public class RDFa11Parser {
* @param o
* @param extractionResult
*/
- private void writeTriple(Resource s, URI p, Value o, ExtractionResult extractionResult) {
+ private void writeTriple(Resource s, IRI p, Value o, ExtractionResult extractionResult) {
// if(logger.isTraceEnabled()) logger.trace(String.format("writeTriple(%s %s %s)" , s, p, o));
assert s != null : "subject is null.";
assert p != null : "predicate is null.";
@@ -548,7 +548,7 @@ public class RDFa11Parser {
// RDFa1.0[5.5.2] / RDFa1.1[7.5.4]
//Node currentElement = node;
- updateURIMapping(currentElement);
+ updateIRIMapping(currentElement);
// RDFa1.0[5.5.3] / RDFa1.1[7.5.5]
updateLanguage(currentElement, currentEvaluationContext);
@@ -566,7 +566,7 @@ public class RDFa11Parser {
/*
if(currentEvaluationContext.newSubject == null) {
- currentEvaluationContext.newSubject = resolveURI(documentBase.toExternalForm());
+ currentEvaluationContext.newSubject = resolveIRI(documentBase.toExternalForm());
}
assert currentEvaluationContext.newSubject != null : "newSubject must be not null.";
*/
@@ -574,16 +574,16 @@ public class RDFa11Parser {
if(logger.isDebugEnabled()) logger.debug("newSubject: " + currentEvaluationContext.newSubject);
// RDFa1.0[5.5.6] / RDFa1.1[7.5.8]
- final URI[] types = getTypes(currentElement);
- for(URI type : types) {
+ final IRI[] types = getTypes(currentElement);
+ for(IRI type : types) {
writeTriple(currentEvaluationContext.newSubject, RDF.TYPE, type, extractionResult);
}
// RDFa1.0[5.5.7] / RDFa1.1[7.5.9]
- final URI[] rels = getRels(currentElement);
- final URI[] revs = getRevs(currentElement);
+ final IRI[] rels = getRels(currentElement);
+ final IRI[] revs = getRevs(currentElement);
if(currentEvaluationContext.currentObjectResource != null) {
- for (URI rel : rels) {
+ for (IRI rel : rels) {
writeTriple(
currentEvaluationContext.newSubject,
rel,
@@ -591,7 +591,7 @@ public class RDFa11Parser {
extractionResult
);
}
- for (URI rev : revs) {
+ for (IRI rev : revs) {
writeTriple(
currentEvaluationContext.currentObjectResource,
rev,
@@ -599,7 +599,7 @@ public class RDFa11Parser {
);
}
} else { // RDFa1.0[5.5.8] / RDFa1.1[7.5.10]
- for(URI rel : rels) {
+ for(IRI rel : rels) {
listOfIncompleteTriples.add(
new IncompleteTriple(
currentElement,
@@ -609,7 +609,7 @@ public class RDFa11Parser {
)
);
}
- for(URI rev : revs) {
+ for(IRI rev : revs) {
listOfIncompleteTriples.add(
new IncompleteTriple(
currentElement,
@@ -623,9 +623,9 @@ public class RDFa11Parser {
// RDFa1.0[5.5.9] / RDFa1.1[7.5.11]
final Value currentObject = getCurrentObject(currentElement);
- final URI[] predicates = getPredicate(currentElement);
+ final IRI[] predicates = getPredicate(currentElement);
if (currentObject != null && predicates != null) {
- for (URI predicate : predicates) {
+ for (IRI predicate : predicates) {
writeTriple(currentEvaluationContext.newSubject, predicate, currentObject, extractionResult);
}
}
@@ -673,7 +673,7 @@ public class RDFa11Parser {
}
/**
- * Extract URI namespaces (prefixes) from the current node.
+ * Extract IRI namespaces (prefixes) from the current node.
*
* @param node
* @param prefixMapList
@@ -683,27 +683,27 @@ public class RDFa11Parser {
if(prefixAttribute == null) return;
final String[] prefixParts = extractPrefixSections(prefixAttribute);
for(String prefixPart : prefixParts) {
- int splitPoint = prefixPart.indexOf(URI_PREFIX_SEPARATOR);
+ int splitPoint = prefixPart.indexOf(IRI_PREFIX_SEPARATOR);
final String prefix = prefixPart.substring(0, splitPoint);
if(prefix.length() == 0) {
reportError(node, String.format("Invalid prefix length in prefix attribute '%s'", prefixAttribute));
continue;
}
- final URI uri;
- final String uriStr = prefixPart.substring(splitPoint + 1);
+ final IRI IRI;
+ final String IRIStr = prefixPart.substring(splitPoint + 1);
try {
- uri = resolveURI(uriStr);
+ IRI = resolveIRI(IRIStr);
} catch (Exception e) {
reportError(
node,
String.format(
- "Resolution of prefix '%s' defines an invalid URI: '%s'",
- prefixAttribute, uriStr
+ "Resolution of prefix '%s' defines an invalid IRI: '%s'",
+ prefixAttribute, IRIStr
)
);
continue;
}
- prefixMapList.add( new PrefixMap(prefix, uri) );
+ prefixMapList.add( new PrefixMap(prefix, IRI) );
}
}
@@ -728,17 +728,17 @@ public class RDFa11Parser {
*/
private void establishNewSubject(Node node, EvaluationContext currentEvaluationContext)
throws URISyntaxException {
- String candidateURIOrCURIE;
+ String candidateIRIOrCURIE;
for(String subjectAttribute : SUBJECT_ATTRIBUTES) {
- candidateURIOrCURIE = DomUtils.readAttribute(node, subjectAttribute, null);
- if(candidateURIOrCURIE != null) {
- currentEvaluationContext.newSubject = resolveCURIEOrURI(candidateURIOrCURIE, false);
+ candidateIRIOrCURIE = DomUtils.readAttribute(node, subjectAttribute, null);
+ if(candidateIRIOrCURIE != null) {
+ currentEvaluationContext.newSubject = resolveCURIEOrIRI(candidateIRIOrCURIE, false);
return;
}
}
if(node.getNodeName().equalsIgnoreCase(HEAD_TAG) || node.getNodeName().equalsIgnoreCase(BODY_TAG)) {
- currentEvaluationContext.newSubject = resolveURI(currentEvaluationContext.base.toString());
+ currentEvaluationContext.newSubject = resolveIRI(currentEvaluationContext.base.toString());
return;
}
@@ -770,17 +770,17 @@ public class RDFa11Parser {
private void establishNewSubjectCurrentObjectResource(Node node, EvaluationContext currentEvaluationContext)
throws URISyntaxException {
// Subject.
- String candidateURIOrCURIE;
- candidateURIOrCURIE = DomUtils.readAttribute(node, ABOUT_ATTRIBUTE, null);
- if(candidateURIOrCURIE != null) {
- currentEvaluationContext.newSubject = resolveCURIEOrURI(candidateURIOrCURIE, false);
+ String candidateIRIOrCURIE;
+ candidateIRIOrCURIE = DomUtils.readAttribute(node, ABOUT_ATTRIBUTE, null);
+ if(candidateIRIOrCURIE != null) {
+ currentEvaluationContext.newSubject = resolveCURIEOrIRI(candidateIRIOrCURIE, false);
} else {
- candidateURIOrCURIE = DomUtils.readAttribute(node, SRC_ATTRIBUTE, null);
- if (candidateURIOrCURIE != null) {
- currentEvaluationContext.newSubject = resolveURI(candidateURIOrCURIE);
+ candidateIRIOrCURIE = DomUtils.readAttribute(node, SRC_ATTRIBUTE, null);
+ if (candidateIRIOrCURIE != null) {
+ currentEvaluationContext.newSubject = resolveIRI(candidateIRIOrCURIE);
} else {
if (node.getNodeName().equalsIgnoreCase(HEAD_TAG) || node.getNodeName().equalsIgnoreCase(BODY_TAG)) {
- currentEvaluationContext.newSubject = resolveURI(currentEvaluationContext.base.toString());
+ currentEvaluationContext.newSubject = resolveIRI(currentEvaluationContext.base.toString());
} else {
if (DomUtils.hasAttribute(node, TYPEOF_ATTRIBUTE)) {
currentEvaluationContext.newSubject = RDFUtils.bnode();
@@ -794,39 +794,39 @@ public class RDFa11Parser {
}
// Object.
- candidateURIOrCURIE = DomUtils.readAttribute(node, RESOURCE_ATTRIBUTE, null);
- if(candidateURIOrCURIE != null) {
- currentEvaluationContext.currentObjectResource = resolveCURIEOrURI(candidateURIOrCURIE, false);
+ candidateIRIOrCURIE = DomUtils.readAttribute(node, RESOURCE_ATTRIBUTE, null);
+ if(candidateIRIOrCURIE != null) {
+ currentEvaluationContext.currentObjectResource = resolveCURIEOrIRI(candidateIRIOrCURIE, false);
return;
}
- candidateURIOrCURIE = DomUtils.readAttribute(node, HREF_ATTRIBUTE, null);
- if(candidateURIOrCURIE != null) {
- currentEvaluationContext.currentObjectResource = resolveURI(candidateURIOrCURIE);
+ candidateIRIOrCURIE = DomUtils.readAttribute(node, HREF_ATTRIBUTE, null);
+ if(candidateIRIOrCURIE != null) {
+ currentEvaluationContext.currentObjectResource = resolveIRI(candidateIRIOrCURIE);
return;
}
currentEvaluationContext.currentObjectResource = null;
}
- private URI[] getTypes(Node node) throws URISyntaxException {
+ private IRI[] getTypes(Node node) throws URISyntaxException {
final String typeOf = DomUtils.readAttribute(node, TYPEOF_ATTRIBUTE, null);
- return resolveCurieOrURIList(node, typeOf, true);
+ return resolveCIRIeOrIRIList(node, typeOf, true);
}
- private URI[] getRels(Node node) throws URISyntaxException {
+ private IRI[] getRels(Node node) throws URISyntaxException {
final String rel = DomUtils.readAttribute(node, REL_ATTRIBUTE, null);
- return resolveCurieOrURIList(node, rel, true);
+ return resolveCIRIeOrIRIList(node, rel, true);
}
- private URI[] getRevs(Node node) throws URISyntaxException {
+ private IRI[] getRevs(Node node) throws URISyntaxException {
final String rev = DomUtils.readAttribute(node, REV_ATTRIBUTE, null);
- return resolveCurieOrURIList(node, rev, true);
+ return resolveCIRIeOrIRIList(node, rev, true);
}
- private URI[] getPredicate(Node node) throws URISyntaxException {
- final String candidateURI = DomUtils.readAttribute(node, PROPERTY_ATTRIBUTE, null);
- if(candidateURI == null) return null;
- return resolveCurieOrURIList(node, candidateURI, true);
+ private IRI[] getPredicate(Node node) throws URISyntaxException {
+ final String candidateIRI = DomUtils.readAttribute(node, PROPERTY_ATTRIBUTE, null);
+ if(candidateIRI == null) return null;
+ return resolveCIRIeOrIRIList(node, candidateIRI, true);
}
/**
@@ -843,7 +843,7 @@ public class RDFa11Parser {
throws URISyntaxException, IOException, TransformerException {
final String candidateObject = DomUtils.readAttribute(node, HREF_ATTRIBUTE, null);
if(candidateObject != null) {
- return resolveURI(candidateObject);
+ return resolveIRI(candidateObject);
} else {
return gerCurrentObjectLiteral(node);
}
@@ -888,39 +888,39 @@ public class RDFa11Parser {
if (datatype == null || datatype.trim().length() == 0 || XML_LITERAL_DATATYPE.equals(datatype.trim()) ) {
return null;
}
- final Resource curieOrURI = resolveCURIEOrURI(datatype, true);
- return RDFUtils.literal(getNodeContent(node), curieOrURI instanceof URI ? (URI) curieOrURI : null);
+ final Resource curieOrIRI = resolveCURIEOrIRI(datatype, true);
+ return RDFUtils.literal(getNodeContent(node), curieOrIRI instanceof IRI ? (IRI) curieOrIRI : null);
}
private void pushMappings(Node sourceNode, List<PrefixMap> prefixMapList) {
// logger.trace("pushMappings()");
- final Map<String, URI> mapping = new HashMap<String, URI>();
+ final Map<String, IRI> mapping = new HashMap<String, IRI>();
for (PrefixMap prefixMap : prefixMapList) {
- mapping.put(prefixMap.prefix, prefixMap.uri);
+ mapping.put(prefixMap.prefix, prefixMap.IRI);
}
- uriMappingStack.push( new URIMapping(sourceNode, mapping) );
+ IRIMappingStack.push( new IRIMapping(sourceNode, mapping) );
}
private void popMappings(Node node) {
- if(uriMappingStack.isEmpty()) return;
- final URIMapping peek = uriMappingStack.peek();
+ if(IRIMappingStack.isEmpty()) return;
+ final IRIMapping peek = IRIMappingStack.peek();
if( ! DomUtils.isAncestorOf(peek.sourceNode, node) ) {
// logger.trace("popMappings()");
- uriMappingStack.pop();
+ IRIMappingStack.pop();
}
}
/**
- * Resolve a namespaced URI, if <code>safe</code> is <code>true</code>
+ * Resolve a namespaced IRI, if <code>safe</code> is <code>true</code>
* then the mapping must define a prefix, otherwise it is considered relative.
*
* @param mapping
* @param resolutionPolicy
* @return
*/
- private Resource resolveNamespacedURI(String mapping, ResolutionPolicy resolutionPolicy) {
- if(mapping.indexOf(URI_PATH_SEPARATOR) == 0) { // Begins with '/'
+ private Resource resolveNamespacedIRI(String mapping, ResolutionPolicy resolutionPolicy) {
+ if(mapping.indexOf(IRI_PATH_SEPARATOR) == 0) { // Begins with '/'
mapping = mapping.substring(1);
}
@@ -932,17 +932,17 @@ public class RDFa11Parser {
);
}
if (resolutionPolicy == ResolutionPolicy.TermAllowed) {
- final URI currentVocabulary = getVocabulary();
+ final IRI currentVocabulary = getVocabulary();
// Mapping is a TERM.
if (currentVocabulary != null) {
- return resolveURI(currentVocabulary.toString() + mapping);
+ return resolveIRI(currentVocabulary.toString() + mapping);
}
}
- return resolveURI(documentBase.toString() + mapping);
+ return resolveIRI(documentBase.toString() + mapping);
}
final String prefix = mapping.substring(0, prefixSeparatorIndex);
- final URI curieMapping = getMapping(prefix);
+ final IRI curieMapping = getMapping(prefix);
if(curieMapping == null) {
throw new IllegalArgumentException( String.format("Cannot map prefix '%s'", prefix) );
}
@@ -950,10 +950,10 @@ public class RDFa11Parser {
final java.net.URI candidateCURIE;
try {
candidateCURIE = new java.net.URI(candidateCURIEStr);
- } catch (URISyntaxException urise) {
+ } catch (URISyntaxException IRIse) {
throw new IllegalArgumentException(String.format("Invalid CURIE '%s'", candidateCURIEStr) );
}
- return resolveURI(
+ return resolveIRI(
candidateCURIE.isAbsolute()
?
candidateCURIE.toString()
@@ -963,7 +963,7 @@ public class RDFa11Parser {
}
/**
- * The resolution policy provided to the method {@link #resolveNamespacedURI(String, ResolutionPolicy)}.
+ * The resolution policy provided to the method {@link #resolveNamespacedIRI(String, ResolutionPolicy)}.
*/
enum ResolutionPolicy {
NSNotRequired,
@@ -992,7 +992,7 @@ public class RDFa11Parser {
*/
EvaluationContext(URL base) {
this.base = base;
- this.parentSubject = resolveURI( base.toExternalForm() );
+ this.parentSubject = resolveIRI( base.toExternalForm() );
this.parentObject = null;
this.language = null;
this.recourse = true;
@@ -1007,21 +1007,21 @@ public class RDFa11Parser {
*/
private class PrefixMap {
final String prefix;
- final URI uri;
- public PrefixMap(String prefix, URI uri) {
+ final IRI IRI;
+ public PrefixMap(String prefix, IRI IRI) {
this.prefix = prefix;
- this.uri = uri;
+ this.IRI = IRI;
}
}
/**
- * Defines a URI mapping.
+ * Defines a IRI mapping.
*/
- private class URIMapping {
+ private class IRIMapping {
final Node sourceNode;
- final Map<String, URI> map;
+ final Map<String, IRI> map;
- public URIMapping(Node sourceNode, Map<String, URI> map) {
+ public IRIMapping(Node sourceNode, Map<String, IRI> map) {
this.sourceNode = sourceNode;
this.map = map;
}
@@ -1041,13 +1041,13 @@ public class RDFa11Parser {
private class IncompleteTriple {
final Node originatingNode;
final Resource subject;
- final URI predicate;
+ final IRI predicate;
final IncompleteTripleDirection direction;
public IncompleteTriple(
Node originatingNode,
Resource subject,
- URI predicate,
+ IRI predicate,
IncompleteTripleDirection direction
) {
if(originatingNode == null || subject == null || predicate == null || direction == null)
@@ -1082,9 +1082,9 @@ public class RDFa11Parser {
*/
private class Vocabulary {
final Node originatingNode;
- final URI prefix;
+ final IRI prefix;
- public Vocabulary(Node originatingNode, URI prefix) {
+ public Vocabulary(Node originatingNode, IRI prefix) {
this.originatingNode = originatingNode;
this.prefix = prefix;
}
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/rdfa/RDFaExtractor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/rdfa/RDFaExtractor.java b/core/src/main/java/org/apache/any23/extractor/rdfa/RDFaExtractor.java
index fc11ba8..615b16f 100644
--- a/core/src/main/java/org/apache/any23/extractor/rdfa/RDFaExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/rdfa/RDFaExtractor.java
@@ -22,7 +22,7 @@ import org.apache.any23.extractor.ExtractionResult;
import org.apache.any23.extractor.ExtractorDescription;
import org.apache.any23.extractor.rdf.BaseRDFExtractor;
import org.apache.any23.extractor.rdf.RDFParserFactory;
-import org.openrdf.rio.RDFParser;
+import org.eclipse.rdf4j.rio.RDFParser;
/**
* {@link org.apache.any23.extractor.Extractor} implementation for
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/rdfa/XSLTStylesheet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/rdfa/XSLTStylesheet.java b/core/src/main/java/org/apache/any23/extractor/rdfa/XSLTStylesheet.java
index 7012b78..4a41089 100644
--- a/core/src/main/java/org/apache/any23/extractor/rdfa/XSLTStylesheet.java
+++ b/core/src/main/java/org/apache/any23/extractor/rdfa/XSLTStylesheet.java
@@ -88,7 +88,7 @@ public class XSLTStylesheet {
log.error("------ BEGIN XSLT Transformer Exception ------");
log.error("Exception in XSLT Stylesheet transformation.", te);
log.error("Input DOM node:", document);
- log.error("Input DOM node getBaseURI:", document.getBaseURI());
+ log.error("Input DOM node getBaseIRI:", document.getBaseURI());
log.error("Output writer:", output);
log.error("------ END XSLT Transformer Exception ------");
throw new XSLTStylesheetException(" An error occurred during the XSLT transformation", te);
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/QuadTemplate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/QuadTemplate.java b/core/src/main/java/org/apache/any23/extractor/xpath/QuadTemplate.java
index 57a7b68..8fef9b1 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/QuadTemplate.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/QuadTemplate.java
@@ -18,9 +18,9 @@
package org.apache.any23.extractor.xpath;
import org.apache.any23.extractor.ExtractionResult;
-import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Value;
import java.util.Map;
@@ -116,10 +116,10 @@ public class QuadTemplate {
*/
public void printOut(ExtractionResult er, Map<String,String> variableAssignment) {
final Resource s = subject.getValue(variableAssignment);
- final URI p = predicate.getValue(variableAssignment);
+ final IRI p = predicate.getValue(variableAssignment);
final Value o = object.getValue(variableAssignment);
if(graph != null) {
- final URI g = graph.getValue(variableAssignment);
+ final IRI g = graph.getValue(variableAssignment);
er.writeTriple(s, p, o, g);
} else {
er.writeTriple(s, p, o);
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/TemplateGraph.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateGraph.java b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateGraph.java
index 420976b..851af01 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateGraph.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateGraph.java
@@ -17,15 +17,15 @@
package org.apache.any23.extractor.xpath;
-import org.openrdf.model.URI;
-import org.openrdf.model.impl.URIImpl;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
/**
- * Represents an <i>Quad</i> graph <i>URI template</i>.
+ * Represents an <i>Quad</i> graph <i>IRI template</i>.
*
* @author Michele Mostarda (mostarda@fbk.eu)
*/
-public class TemplateGraph extends Term<URI> {
+public class TemplateGraph extends Term<IRI> {
/**
* Constructor.
@@ -39,8 +39,8 @@ public class TemplateGraph extends Term<URI> {
}
@Override
- protected URI getValueInternal(String value) {
- return new URIImpl(value);
+ protected IRI getValueInternal(String value) {
+ return SimpleValueFactory.getInstance().createIRI(value);
}
@Override
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/TemplateObject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateObject.java b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateObject.java
index a8f95a3..d9156a5 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateObject.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateObject.java
@@ -17,10 +17,9 @@
package org.apache.any23.extractor.xpath;
-import org.openrdf.model.Value;
-import org.openrdf.model.impl.BNodeImpl;
-import org.openrdf.model.impl.LiteralImpl;
-import org.openrdf.model.impl.ValueFactoryImpl;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.impl.BNodeImpl;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
/**
* Represents a <i>Quad</i> object <i>template</i>.
@@ -64,17 +63,17 @@ public class TemplateObject extends Term {
switch (type) {
case uri:
try {
- return ValueFactoryImpl.getInstance().createURI(value);
+ return SimpleValueFactory.getInstance().createIRI(value);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException(
- String.format("Expected a valid URI for object template, found '%s'", value),
+ String.format("Expected a valid IRI for object template, found '%s'", value),
iae
);
}
case bnode:
- return new BNodeImpl(value);
+ return SimpleValueFactory.getInstance().createBNode(value);
case literal:
- return new LiteralImpl(value);
+ return SimpleValueFactory.getInstance().createLiteral(value);
default:
throw new IllegalStateException();
}
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/TemplatePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/TemplatePredicate.java b/core/src/main/java/org/apache/any23/extractor/xpath/TemplatePredicate.java
index ad8cf20..28d93ac 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/TemplatePredicate.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/TemplatePredicate.java
@@ -17,15 +17,15 @@
package org.apache.any23.extractor.xpath;
-import org.openrdf.model.URI;
-import org.openrdf.model.impl.ValueFactoryImpl;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
/**
* Represents a <i>Quad</i> predicate <i>template</i>.
*
* @author Michele Mostarda (mostarda@fbk.eu)
*/
-public class TemplatePredicate extends Term<URI> {
+public class TemplatePredicate extends Term<IRI> {
/**
* Constructor.
@@ -39,12 +39,12 @@ public class TemplatePredicate extends Term<URI> {
}
@Override
- protected URI getValueInternal(String value) {
+ protected IRI getValueInternal(String value) {
try {
- return ValueFactoryImpl.getInstance().createURI(value);
+ return SimpleValueFactory.getInstance().createIRI(value);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException(
- String.format("Expected a valid URI for predicate template, found '%s'", value),
+ String.format("Expected a valid IRI for predicate template, found '%s'", value),
iae
);
}
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/TemplateSubject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateSubject.java b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateSubject.java
index 5094f36..a4ce270 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateSubject.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateSubject.java
@@ -17,9 +17,9 @@
package org.apache.any23.extractor.xpath;
-import org.openrdf.model.Resource;
-import org.openrdf.model.impl.BNodeImpl;
-import org.openrdf.model.impl.URIImpl;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.impl.BNodeImpl;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
/**
* Represents a <i>Quad</i> subject <i>template</i>.
@@ -61,9 +61,9 @@ public class TemplateSubject extends Term<Resource> {
protected Resource getValueInternal(String value) {
switch (type) {
case uri:
- return new URIImpl(value);
+ return SimpleValueFactory.getInstance().createIRI(value);
case bnode:
- return new BNodeImpl(value);
+ return SimpleValueFactory.getInstance().createBNode(value);
default:
throw new IllegalStateException();
}
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/TemplateXPathExtractionRuleImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateXPathExtractionRuleImpl.java b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateXPathExtractionRuleImpl.java
index 0271585..c66d1fb 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/TemplateXPathExtractionRuleImpl.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/TemplateXPathExtractionRuleImpl.java
@@ -19,7 +19,7 @@ package org.apache.any23.extractor.xpath;
import org.apache.any23.extractor.ExtractionResult;
import org.apache.any23.extractor.html.DomUtils;
-import org.openrdf.model.URI;
+import org.eclipse.rdf4j.model.IRI;
import org.w3c.dom.Document;
import java.util.ArrayList;
@@ -91,7 +91,7 @@ public class TemplateXPathExtractionRuleImpl implements TemplateXPathExtractionR
return name;
}
- public boolean acceptURI(URI uri) {
+ public boolean acceptIRI(IRI uri) {
if(uriRegexPattern == null) {
return true;
}
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/Term.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/Term.java b/core/src/main/java/org/apache/any23/extractor/xpath/Term.java
index a0bcead..c6e1382 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/Term.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/Term.java
@@ -17,7 +17,7 @@
package org.apache.any23.extractor.xpath;
-import org.openrdf.model.Value;
+import org.eclipse.rdf4j.model.Value;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractionRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractionRule.java b/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractionRule.java
index a4bb7bc..9ff2325 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractionRule.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractionRule.java
@@ -18,7 +18,7 @@
package org.apache.any23.extractor.xpath;
import org.apache.any23.extractor.ExtractionResult;
-import org.openrdf.model.URI;
+import org.eclipse.rdf4j.model.IRI;
import org.w3c.dom.Document;
@@ -35,12 +35,12 @@ public interface XPathExtractionRule {
String getName();
/**
- * Checks if the rule can be applied on the given document <i>URI</i>.
+ * Checks if the rule can be applied on the given document <i>IRI</i>.
*
- * @param uri input document URI.
+ * @param uri input document IRI.
* @return <code>true</code> if applied, <code>false</code> otherwise.
*/
- boolean acceptURI(URI uri);
+ boolean acceptIRI(IRI uri);
/**
* Processes this extraction rule on the given document.
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractor.java b/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractor.java
index b580afa..b04533c 100644
--- a/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractor.java
+++ b/core/src/main/java/org/apache/any23/extractor/xpath/XPathExtractor.java
@@ -23,7 +23,7 @@ import org.apache.any23.extractor.ExtractionParameters;
import org.apache.any23.extractor.ExtractionResult;
import org.apache.any23.extractor.Extractor;
import org.apache.any23.extractor.ExtractorDescription;
-import org.openrdf.model.URI;
+import org.eclipse.rdf4j.model.IRI;
import org.w3c.dom.Document;
import java.io.IOException;
@@ -68,9 +68,9 @@ public class XPathExtractor implements Extractor.TagSoupDOMExtractor {
ExtractionResult out
)
throws IOException, ExtractionException {
- final URI documentURI = extractionContext.getDocumentURI();
+ final IRI documentIRI = extractionContext.getDocumentIRI();
for(XPathExtractionRule rule : xPathExtractionRules) {
- if(rule.acceptURI(documentURI)) {
+ if(rule.acceptIRI(documentIRI)) {
rule.process(in, out);
}
}
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/filter/ExtractionContextBlocker.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/filter/ExtractionContextBlocker.java b/core/src/main/java/org/apache/any23/filter/ExtractionContextBlocker.java
index bac8876..16d8378 100644
--- a/core/src/main/java/org/apache/any23/filter/ExtractionContextBlocker.java
+++ b/core/src/main/java/org/apache/any23/filter/ExtractionContextBlocker.java
@@ -20,9 +20,9 @@ package org.apache.any23.filter;
import org.apache.any23.extractor.ExtractionContext;
import org.apache.any23.writer.TripleHandler;
import org.apache.any23.writer.TripleHandlerException;
-import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Value;
import java.util.ArrayList;
import java.util.HashMap;
@@ -73,8 +73,8 @@ public class ExtractionContextBlocker implements TripleHandler {
}
}
- public synchronized void startDocument(URI documentURI) throws TripleHandlerException {
- wrapped.startDocument(documentURI);
+ public synchronized void startDocument(IRI documentIRI) throws TripleHandlerException {
+ wrapped.startDocument(documentIRI);
documentBlocked = true;
}
@@ -98,7 +98,7 @@ public class ExtractionContextBlocker implements TripleHandler {
}
}
- public synchronized void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context)
+ public synchronized void receiveTriple(Resource s, IRI p, Value o, IRI g, ExtractionContext context)
throws TripleHandlerException {
try {
contextQueues.get(context.getUniqueID()).receiveTriple(s, p, o, g);
@@ -127,9 +127,9 @@ public class ExtractionContextBlocker implements TripleHandler {
wrapped.close();
}
- public synchronized void endDocument(URI documentURI) throws TripleHandlerException {
+ public synchronized void endDocument(IRI documentIRI) throws TripleHandlerException {
closeDocument();
- wrapped.endDocument(documentURI);
+ wrapped.endDocument(documentIRI);
}
public void setContentLength(long contentLength) {
@@ -169,11 +169,11 @@ public class ExtractionContextBlocker implements TripleHandler {
private final List<Resource> subjects = new ArrayList<Resource>();
- private final List<URI> predicates = new ArrayList<URI>();
+ private final List<IRI> predicates = new ArrayList<IRI>();
private final List<Value> objects = new ArrayList<Value>();
- private final List<URI> graphs = new ArrayList<URI>();
+ private final List<IRI> graphs = new ArrayList<IRI>();
private final List<String> prefixes = new ArrayList<String>();
@@ -187,7 +187,7 @@ public class ExtractionContextBlocker implements TripleHandler {
this.context = context;
}
- void receiveTriple(Resource s, URI p, Value o, URI g) throws ValvedTriplePipeException {
+ void receiveTriple(Resource s, IRI p, Value o, IRI g) throws ValvedTriplePipeException {
if (blocked) {
subjects.add(s);
predicates.add(p);
@@ -233,7 +233,7 @@ public class ExtractionContextBlocker implements TripleHandler {
}
}
- private void sendTriple(Resource s, URI p, Value o, URI g) throws ValvedTriplePipeException {
+ private void sendTriple(Resource s, IRI p, Value o, IRI g) throws ValvedTriplePipeException {
if (!hasReceivedTriples) {
try {
wrapped.openContext(context);
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/filter/IgnoreAccidentalRDFa.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/filter/IgnoreAccidentalRDFa.java b/core/src/main/java/org/apache/any23/filter/IgnoreAccidentalRDFa.java
index 9c14744..a06c8b8 100644
--- a/core/src/main/java/org/apache/any23/filter/IgnoreAccidentalRDFa.java
+++ b/core/src/main/java/org/apache/any23/filter/IgnoreAccidentalRDFa.java
@@ -18,14 +18,13 @@
package org.apache.any23.filter;
import org.apache.any23.extractor.ExtractionContext;
-import org.apache.any23.extractor.rdfa.RDFaExtractor;
import org.apache.any23.extractor.rdfa.RDFaExtractorFactory;
import org.apache.any23.vocab.XHTML;
import org.apache.any23.writer.TripleHandler;
import org.apache.any23.writer.TripleHandlerException;
-import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Value;
/**
* A {@link TripleHandler} that suppresses output of the RDFa
@@ -59,8 +58,8 @@ public class IgnoreAccidentalRDFa implements TripleHandler {
this(wrapped, false);
}
- public void startDocument(URI documentURI) throws TripleHandlerException {
- blocker.startDocument(documentURI);
+ public void startDocument(IRI documentIRI) throws TripleHandlerException {
+ blocker.startDocument(documentIRI);
}
public void openContext(ExtractionContext context) throws TripleHandlerException {
@@ -70,7 +69,7 @@ public class IgnoreAccidentalRDFa implements TripleHandler {
}
}
- public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context)
+ public void receiveTriple(Resource s, IRI p, Value o, IRI g, ExtractionContext context)
throws TripleHandlerException {
// Suppress stylesheet triples.
if(alwaysSuppressCSSTriples && p.stringValue().equals(vXHTML.stylesheet.stringValue())) {
@@ -99,8 +98,8 @@ public class IgnoreAccidentalRDFa implements TripleHandler {
return context.getExtractorName().equals(RDFaExtractorFactory.NAME);
}
- public void endDocument(URI documentURI) throws TripleHandlerException {
- blocker.endDocument(documentURI);
+ public void endDocument(IRI documentIRI) throws TripleHandlerException {
+ blocker.endDocument(documentIRI);
}
public void setContentLength(long contentLength) {
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/filter/IgnoreTitlesOfEmptyDocuments.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/filter/IgnoreTitlesOfEmptyDocuments.java b/core/src/main/java/org/apache/any23/filter/IgnoreTitlesOfEmptyDocuments.java
index 8c75eb3..eec5669 100644
--- a/core/src/main/java/org/apache/any23/filter/IgnoreTitlesOfEmptyDocuments.java
+++ b/core/src/main/java/org/apache/any23/filter/IgnoreTitlesOfEmptyDocuments.java
@@ -22,9 +22,9 @@ import org.apache.any23.extractor.html.TitleExtractor;
import org.apache.any23.extractor.html.TitleExtractorFactory;
import org.apache.any23.writer.TripleHandler;
import org.apache.any23.writer.TripleHandlerException;
-import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Value;
/**
* A {@link TripleHandler} that suppresses output of the
@@ -43,8 +43,8 @@ public class IgnoreTitlesOfEmptyDocuments implements TripleHandler {
blocker = new ExtractionContextBlocker(wrapped);
}
- public void startDocument(URI documentURI) throws TripleHandlerException {
- blocker.startDocument(documentURI);
+ public void startDocument(IRI documentIRI) throws TripleHandlerException {
+ blocker.startDocument(documentIRI);
}
public void openContext(ExtractionContext context) throws TripleHandlerException {
@@ -54,7 +54,7 @@ public class IgnoreTitlesOfEmptyDocuments implements TripleHandler {
}
}
- public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context)
+ public void receiveTriple(Resource s, IRI p, Value o, IRI g, ExtractionContext context)
throws TripleHandlerException {
if (!isTitleContext(context)) {
blocker.unblockDocument();
@@ -79,8 +79,8 @@ public class IgnoreTitlesOfEmptyDocuments implements TripleHandler {
return context.getExtractorName().equals(TitleExtractorFactory.NAME);
}
- public void endDocument(URI documentURI) throws TripleHandlerException {
- blocker.endDocument(documentURI);
+ public void endDocument(IRI documentIRI) throws TripleHandlerException {
+ blocker.endDocument(documentIRI);
}
public void setContentLength(long contentLength) {
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/http/DefaultHTTPClient.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/http/DefaultHTTPClient.java b/core/src/main/java/org/apache/any23/http/DefaultHTTPClient.java
index c148009..d520441 100644
--- a/core/src/main/java/org/apache/any23/http/DefaultHTTPClient.java
+++ b/core/src/main/java/org/apache/any23/http/DefaultHTTPClient.java
@@ -29,7 +29,7 @@ import java.util.List;
import java.util.regex.Pattern;
/**
- * Opens an {@link InputStream} on an HTTP URI. Is configured
+ * Opens an {@link InputStream} on an HTTP IRI. Is configured
* with sane values for timeouts, default headers and so on.
*
* @author Paolo Capriotti
@@ -47,7 +47,7 @@ public class DefaultHTTPClient implements HTTPClient {
private long _contentLength = -1;
- private String actualDocumentURI = null;
+ private String actualDocumentIRI = null;
private String contentType = null;
@@ -73,7 +73,7 @@ public class DefaultHTTPClient implements HTTPClient {
/**
*
- * Opens an {@link java.io.InputStream} from a given URI.
+ * Opens an {@link java.io.InputStream} from a given IRI.
* It follows redirects.
*
* @param uri to be opened
@@ -91,7 +91,7 @@ public class DefaultHTTPClient implements HTTPClient {
// [scheme:][//authority][path][?query][#fragment]
uriStr = uriObj.toString();
} catch (URIException e) {
- throw new IllegalArgumentException("Invalid URI string.", e);
+ throw new IllegalArgumentException("Invalid IRI string.", e);
}
method = new GetMethod(uriStr);
method.setFollowRedirects(true);
@@ -104,7 +104,7 @@ public class DefaultHTTPClient implements HTTPClient {
"Failed to fetch " + uri + ": " + method.getStatusCode() + " " + method.getStatusText()
);
}
- actualDocumentURI = method.getURI().toString();
+ actualDocumentIRI = method.getURI().toString();
byte[] response = method.getResponseBody();
return new ByteArrayInputStream(response);
@@ -126,8 +126,8 @@ public class DefaultHTTPClient implements HTTPClient {
return _contentLength;
}
- public String getActualDocumentURI() {
- return actualDocumentURI;
+ public String getActualDocumentIRI() {
+ return actualDocumentIRI;
}
public String getContentType() {
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/http/HTTPClient.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/http/HTTPClient.java b/core/src/main/java/org/apache/any23/http/HTTPClient.java
index 93b726b..0bc4dbc 100644
--- a/core/src/main/java/org/apache/any23/http/HTTPClient.java
+++ b/core/src/main/java/org/apache/any23/http/HTTPClient.java
@@ -22,7 +22,7 @@ import java.io.InputStream;
/**
* Abstraction for opening an {@link InputStream} on an
- * HTTP URI.
+ * HTTP IRI.
*
* @author Richard Cyganiak (richard@cyganiak.de)
*/
@@ -36,11 +36,11 @@ public interface HTTPClient {
public abstract void init(HTTPClientConfiguration configuration);
/**
- * Opens the input stream for the given target URI.
+ * Opens the input stream for the given target IRI.
*
- * @param uri target URI.
- * @return input stream to access URI content.
- * @throws IOException if any error occurs while reading the URI content.
+ * @param uri target IRI.
+ * @return input stream to access IRI content.
+ * @throws IOException if any error occurs while reading the IRI content.
*/
public abstract InputStream openInputStream(String uri) throws IOException;
@@ -66,13 +66,13 @@ public interface HTTPClient {
public abstract long getContentLength();
/**
- * Returns the actual URI from which the document was fetched.
- * This might differ from the URI passed to openInputStream()
+ * Returns the actual IRI from which the document was fetched.
+ * This might differ from the IRI passed to openInputStream()
* if a redirect was performed. A return value of <tt>null</tt>
- * means that the URI is unchanged and the original URI was used.
+ * means that the IRI is unchanged and the original IRI was used.
*
- * @return actual document URI.
+ * @return actual document IRI.
*/
- public abstract String getActualDocumentURI();
+ public abstract String getActualDocumentIRI();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/rdf/Any23ValueFactoryWrapper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/rdf/Any23ValueFactoryWrapper.java b/core/src/main/java/org/apache/any23/rdf/Any23ValueFactoryWrapper.java
index 0f93151..48dd4fc 100644
--- a/core/src/main/java/org/apache/any23/rdf/Any23ValueFactoryWrapper.java
+++ b/core/src/main/java/org/apache/any23/rdf/Any23ValueFactoryWrapper.java
@@ -17,16 +17,19 @@
package org.apache.any23.rdf;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.Date;
import org.apache.any23.extractor.IssueReport;
-import org.openrdf.model.BNode;
-import org.openrdf.model.Literal;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
+import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.Literal;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Statement;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.ValueFactory;
+import org.eclipse.rdf4j.model.impl.ValueFactoryBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -98,7 +101,11 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
public Literal createLiteral(String content) {
if (content == null) return null;
- return wrappedFactory.createLiteral(content, defaultLiteralLanguage);
+ if (defaultLiteralLanguage == null) {
+ return wrappedFactory.createLiteral(content);
+ } else {
+ return wrappedFactory.createLiteral(content, defaultLiteralLanguage);
+ }
}
public Literal createLiteral(boolean b) {
@@ -129,6 +136,16 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
return wrappedFactory.createLiteral(v);
}
+ @Override
+ public Literal createLiteral(BigDecimal v) {
+ return wrappedFactory.createLiteral(v);
+ }
+
+ @Override
+ public Literal createLiteral(BigInteger v) {
+ return wrappedFactory.createLiteral(v);
+ }
+
public Literal createLiteral(XMLGregorianCalendar calendar) {
return wrappedFactory.createLiteral(calendar);
}
@@ -138,7 +155,7 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
return wrappedFactory.createLiteral(label, language);
}
- public Literal createLiteral(String pref, URI value) {
+ public Literal createLiteral(String pref, IRI value) {
if (pref == null) return null;
return wrappedFactory.createLiteral(pref, value);
}
@@ -148,26 +165,26 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
return wrappedFactory.createLiteral(date);
}
- public Statement createStatement(Resource sub, URI pre, Value obj) {
+ public Statement createStatement(Resource sub, IRI pre, Value obj) {
if (sub == null || pre == null || obj == null) {
return null;
}
return wrappedFactory.createStatement(sub, pre, obj);
}
- public Statement createStatement(Resource sub, URI pre, Value obj, Resource context) {
+ public Statement createStatement(Resource sub, IRI pre, Value obj, Resource context) {
if (sub == null || pre == null || obj == null) return null;
return wrappedFactory.createStatement(sub, pre, obj, context);
}
/**
* @param uriStr input string to create URI from.
- * @return a valid sesame URI or null if any exception occurred
+ * @return a valid sesame IRI or null if any exception occurred
*/
- public URI createURI(String uriStr) {
+ public IRI createIRI(String uriStr) {
if (uriStr == null) return null;
try {
- return wrappedFactory.createURI(RDFUtils.fixURIWithException(uriStr));
+ return wrappedFactory.createIRI(RDFUtils.fixIRIWithException(uriStr));
} catch (Exception e) {
reportError(e);
return null;
@@ -175,23 +192,23 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
}
/**
- * @return a valid sesame URI or null if any exception occurred
+ * @return a valid sesame IRI or null if any exception occurred
*/
- public URI createURI(String namespace, String localName) {
+ public IRI createIRI(String namespace, String localName) {
if (namespace == null || localName == null) return null;
- return wrappedFactory.createURI(RDFUtils.fixURIWithException(namespace), localName);
+ return wrappedFactory.createIRI(RDFUtils.fixIRIWithException(namespace), localName);
}
/**
- * Fixes typical errors in URIs, and resolves relative URIs against a base URI.
+ * Fixes typical errors in IRIs, and resolves relative IRIs against a base IRI.
*
- * @param uri A URI, relative or absolute, can have typical syntax errors
- * @param baseURI A base URI to use for resolving relative URIs
- * @return An absolute URI, sytnactically valid, or null if not fixable
+ * @param uri A IRI, relative or absolute, can have typical syntax errors
+ * @param baseIRI A base IRI to use for resolving relative IRIs
+ * @return An absolute IRI, sytnactically valid, or null if not fixable
*/
- public URI resolveURI(String uri, java.net.URI baseURI) {
+ public IRI resolveIRI(String uri, java.net.URI baseIRI) {
try {
- return wrappedFactory.createURI(baseURI.resolve(RDFUtils.fixURIWithException(uri)).toString());
+ return wrappedFactory.createIRI(baseIRI.resolve(RDFUtils.fixIRIWithException(uri)).toString());
} catch (IllegalArgumentException iae) {
reportError(iae);
return null;
@@ -199,12 +216,12 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
}
/**
- * @param uri input string to attempt fix on.
- * @return a valid sesame URI or null if any exception occurred
+ * @param uri
+ * @return a valid sesame IRI or null if any exception occurred
*/
- public URI fixURI(String uri) {
+ public IRI fixIRI(String uri) {
try {
- return wrappedFactory.createURI(RDFUtils.fixURIWithException(uri));
+ return wrappedFactory.createIRI(RDFUtils.fixIRIWithException(uri));
} catch (Exception e) {
reportError(e);
return null;
@@ -217,14 +234,14 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
* @param defaultSchema schema to add the URI
* @return a valid {@link org.openrdf.model.URI}
*/
- public URI fixLink(String link, String defaultSchema) {
+ public IRI fixLink(String link, String defaultSchema) {
if (link == null) return null;
link = fixWhiteSpace(link);
if ("".equals(link)) return null;
if (defaultSchema != null && !link.startsWith(defaultSchema + ":")) {
link = defaultSchema + ":" + link;
}
- return fixURI(link);
+ return fixIRI(link);
}
public String fixWhiteSpace(String name) {
@@ -240,7 +257,7 @@ public class Any23ValueFactoryWrapper implements ValueFactory {
if(issueReport == null) {
logger.warn(e.getMessage());
} else {
- issueReport.notifyIssue(IssueReport.IssueLevel.Warning, e.getMessage(), -1, -1);
+ issueReport.notifyIssue(IssueReport.IssueLevel.WARNING, e.getMessage(), -1, -1);
}
}
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/rdf/PopularPrefixes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/rdf/PopularPrefixes.java b/core/src/main/java/org/apache/any23/rdf/PopularPrefixes.java
index cf95855..7535b8b 100644
--- a/core/src/main/java/org/apache/any23/rdf/PopularPrefixes.java
+++ b/core/src/main/java/org/apache/any23/rdf/PopularPrefixes.java
@@ -50,13 +50,13 @@ public class PopularPrefixes {
}
popularPrefixes = new Prefixes();
for (Map.Entry entry : properties.entrySet()) {
- if (testURICompliance((String) entry.getValue())) {
+ if (testIRICompliance((String) entry.getValue())) {
prefixes.add(
(String) entry.getKey(),
(String) entry.getValue()
);
} else {
- logger.warn(String.format("Prefixes entry '%s' is not a well-formad URI. Skipped.", entry.getValue()));
+ logger.warn(String.format("Prefixes entry '%s' is not a well-formad IRI. Skipped.", entry.getValue()));
}
}
return prefixes;
@@ -81,13 +81,13 @@ public class PopularPrefixes {
}
/**
- * Checks the compliance of the <i>URI</i>.
+ * Checks the compliance of the <i>IRI</i>.
*
- * @param stringUri the string of the URI to be checked
- * @return <code>true</code> if <i> stringUri</i> is a valid URI,
+ * @param stringUri the string of the IRI to be checked
+ * @return <code>true</code> if <i> stringUri</i> is a valid IRI,
* <code>false</code> otherwise.
*/
- private static boolean testURICompliance(String stringUri) {
+ private static boolean testIRICompliance(String stringUri) {
try {
new URI(stringUri);
} catch (URISyntaxException e) {
http://git-wip-us.apache.org/repos/asf/any23/blob/445d13ab/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
index 7244bdb..c3ad8ec 100644
--- a/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
+++ b/core/src/main/java/org/apache/any23/rdf/RDFUtils.java
@@ -18,23 +18,25 @@
package org.apache.any23.rdf;
import org.apache.any23.util.MathUtils;
-import org.openrdf.model.BNode;
-import org.openrdf.model.Literal;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.impl.URIImpl;
-import org.openrdf.model.impl.ValueFactoryImpl;
-import org.openrdf.model.vocabulary.RDF;
-import org.openrdf.rio.RDFFormat;
-import org.openrdf.rio.RDFHandlerException;
-import org.openrdf.rio.RDFParseException;
-import org.openrdf.rio.RDFParser;
-import org.openrdf.rio.RDFWriter;
-import org.openrdf.rio.Rio;
-import org.openrdf.rio.helpers.StatementCollector;
+import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.Literal;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Statement;
+import org.eclipse.rdf4j.model.URI;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.ValueFactory;
+import org.eclipse.rdf4j.model.impl.SimpleIRI;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
+import org.eclipse.rdf4j.model.vocabulary.RDF;
+import org.eclipse.rdf4j.rio.RDFFormat;
+import org.eclipse.rdf4j.rio.RDFHandlerException;
+import org.eclipse.rdf4j.rio.RDFParseException;
+import org.eclipse.rdf4j.rio.RDFParser;
+import org.eclipse.rdf4j.rio.RDFParserRegistry;
+import org.eclipse.rdf4j.rio.RDFWriter;
+import org.eclipse.rdf4j.rio.Rio;
+import org.eclipse.rdf4j.rio.helpers.StatementCollector;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
@@ -50,6 +52,7 @@ import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.Optional;
/**
* Basic class providing a set of utility methods when dealing with <i>RDF</i>.
@@ -59,19 +62,19 @@ import java.util.GregorianCalendar;
*/
public class RDFUtils {
- private static final ValueFactory valueFactory = ValueFactoryImpl.getInstance();
+ private static final ValueFactory valueFactory = SimpleValueFactory.getInstance();
/**
- * Fixes typical errors in an absolute URI, such as unescaped spaces.
+ * Fixes typical errors in an absolute IRI, such as unescaped spaces.
*
- * @param uri An absolute URI, can have typical syntax errors
- * @return An absolute URI that is valid against the URI syntax
- * @throws IllegalArgumentException if URI is not fixable
- */
- public static String fixAbsoluteURI(String uri) {
- String fixed = fixURIWithException(uri);
- if (!fixed.matches("[a-zA-Z0-9]+:/.*")) throw new IllegalArgumentException("not a absolute URI: " + uri);
- // Add trailing slash if URI has only authority but no path.
+ * @param uri An absolute IRI, can have typical syntax errors
+ * @return An absolute IRI that is valid against the IRI syntax
+ * @throws IllegalArgumentException if IRI is not fixable
+ */
+ public static String fixAbsoluteIRI(String uri) {
+ String fixed = fixIRIWithException(uri);
+ if (!fixed.matches("[a-zA-Z0-9]+:/.*")) throw new IllegalArgumentException("not a absolute IRI: " + uri);
+ // Add trailing slash if IRI has only authority but no path.
if (fixed.matches("https?://[a-zA-Z0-9.-]+(:[0-9+])?")) {
fixed = fixed + "/";
}
@@ -124,71 +127,89 @@ public class RDFUtils {
* Truncate ">.*$ from end of lines (Neko didn't quite manage to fix broken markup)
* Drop the triple if any of these appear in the URL: <>[]|*{}"<>\
*
- * @param unescapedURI uri string to be unescaped.
+ * @param unescapedIRI uri string to be unescaped.
* @return the unescaped string.
*/
- public static String fixURIWithException(String unescapedURI) {
- if (unescapedURI == null) throw new IllegalArgumentException("URI was null");
+ public static String fixIRIWithException(String unescapedIRI) {
+ if (unescapedIRI == null) throw new IllegalArgumentException("IRI was null");
// Remove starting and ending whitespace
- String escapedURI = unescapedURI.trim();
+ String escapedIRI = unescapedIRI.trim();
//Replace space with %20
- escapedURI = escapedURI.replaceAll(" ", "%20");
+ escapedIRI = escapedIRI.replaceAll(" ", "%20");
//strip linebreaks
- escapedURI = escapedURI.replaceAll("\n", "");
+ escapedIRI = escapedIRI.replaceAll("\n", "");
//'Remove starting "\" or '"'
- if (escapedURI.startsWith("\\") || escapedURI.startsWith("\"")) escapedURI = escapedURI.substring(1);
+ if (escapedIRI.startsWith("\\") || escapedIRI.startsWith("\"")) escapedIRI = escapedIRI.substring(1);
//Remove ending "\" or '"'
- if (escapedURI.endsWith("\\") || escapedURI.endsWith("\""))
- escapedURI = escapedURI.substring(0, escapedURI.length() - 1);
+ if (escapedIRI.endsWith("\\") || escapedIRI.endsWith("\""))
+ escapedIRI = escapedIRI.substring(0, escapedIRI.length() - 1);
//Drop the triple if it matches this regex (only protocol): ^[a-zA-Z0-9]+:/?/?$
- if (escapedURI.matches("^[a-zA-Z0-9]+:/?/?$"))
- throw new IllegalArgumentException("no authority in URI: " + unescapedURI);
+ if (escapedIRI.matches("^[a-zA-Z0-9]+:/?/?$"))
+ throw new IllegalArgumentException("no authority in IRI: " + unescapedIRI);
//Drop the triple if it matches this regex: ^javascript:
- if (escapedURI.matches("^javascript:"))
- throw new IllegalArgumentException("URI starts with javascript: " + unescapedURI);
+ if (escapedIRI.matches("^javascript:"))
+ throw new IllegalArgumentException("IRI starts with javascript: " + unescapedIRI);
// stripHTML
- // escapedURI = escapedURI.replaceAll("\\<.*?\\>", "");
+ // escapedIRI = escapedIRI.replaceAll("\\<.*?\\>", "");
//>.*$ from end of lines (Neko didn't quite manage to fix broken markup)
- escapedURI = escapedURI.replaceAll(">.*$", "");
+ escapedIRI = escapedIRI.replaceAll(">.*$", "");
//Drop the triple if any of these appear in the URL: <>[]|*{}"<>\
- if (escapedURI.matches("[<>\\[\\]|\\*\\{\\}\"\\\\]"))
- throw new IllegalArgumentException("Invalid character in URI: " + unescapedURI);
+ if (escapedIRI.matches("[<>\\[\\]|\\*\\{\\}\"\\\\]"))
+ throw new IllegalArgumentException("Invalid character in IRI: " + unescapedIRI);
- return escapedURI;
+ return escapedIRI;
}
/**
- * Creates a {@link URI}.
- * @param uri string representation of the {@link URI}
- * @return a valid {@link URI}
+ * Creates a {@link IRI}.
+ * @param uri string representation of the {@link IRI}
+ * @return a valid {@link IRI}
+ * @deprecated Use {@link #iri(String)} instead.
*/
- public static URI uri(String uri) {
- return valueFactory.createURI(uri);
+ @Deprecated
+ public static IRI uri(String uri) {
+ return iri(uri);
}
/**
- * Creates a {@link URI}.
- * @param namespace a base namespace for the {@link URI}
+ * Creates a {@link IRI}.
+ * @param namespace a base namespace for the {@link IRI}
* @param localName a local name to associate with the namespace
- * @return a valid {@link URI}
+ * @return a valid {@link IRI}
*/
- public static URI uri(String namespace, String localName) {
- return valueFactory.createURI(namespace, localName);
+ public static IRI iri(String uri) {
+ return valueFactory.createIRI(uri);
+ }
+
+ /**
+ * Creates a {@link IRI}.
+ * @deprecated Use {@link #iri(String, String)} instead.
+ */
+ @Deprecated
+ public static IRI uri(String namespace, String localName) {
+ return valueFactory.createIRI(namespace, localName);
+ }
+
+ /**
+ * Creates a {@link IRI}.
+ */
+ public static IRI iri(String namespace, String localName) {
+ return valueFactory.createIRI(namespace, localName);
}
/**
* Creates a {@link Literal}.
- * @param s string representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param s string representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(String s) {
return valueFactory.createLiteral(s);
@@ -196,8 +217,8 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
- * @param b boolean representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param b boolean representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(boolean b) {
return valueFactory.createLiteral(b);
@@ -205,8 +226,8 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
- * @param b byte representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param b byte representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(byte b) {
return valueFactory.createLiteral(b);
@@ -214,8 +235,8 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
- * @param s short representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param s short representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(short s) {
return valueFactory.createLiteral(s);
@@ -223,8 +244,8 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
- * @param i int representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param i int representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(int i) {
return valueFactory.createLiteral(i);
@@ -232,8 +253,8 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
- * @param l long representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param l long representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(long l) {
return valueFactory.createLiteral(l);
@@ -241,8 +262,8 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
- * @param f float representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param f float representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(float f) {
return valueFactory.createLiteral(f);
@@ -250,8 +271,8 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
- * @param d double representation of the {@link org.openrdf.model.Literal}
- * @return valid {@link org.openrdf.model.Literal}
+ * @param d double representation of the {@link org.eclipse.rdf4j.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(double d) {
return valueFactory.createLiteral(d);
@@ -260,29 +281,43 @@ public class RDFUtils {
/**
* Creates a {@link Literal}.
* @param s string representation of the base namespace for the
- * {@link org.openrdf.model.Literal}
+ * {@link org.eclipse.rdf4j.model.Literal}
* @param l the local name to associate with the namespace.
- * @return valid {@link org.openrdf.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
*/
public static Literal literal(String s, String l) {
- return valueFactory.createLiteral(s, l);
+ if(l == null) {
+ // HACK: Workaround for ANY23 code that passes null in for language tag
+ return valueFactory.createLiteral(s);
+ } else {
+ return valueFactory.createLiteral(s, l);
+ }
}
/**
* Creates a {@link Literal}.
* @param s string representation of the base namespace for the
- * {@link org.openrdf.model.Literal}
+ * {@link org.eclipse.rdf4j.model.Literal}
* @param datatype the datatype to associate with the namespace.
- * @return valid {@link org.openrdf.model.Literal}
+ * @return valid {@link org.eclipse.rdf4j.model.Literal}
+ * @deprecated Use {@link #literal(String, IRI)} instead.
*/
+ @Deprecated
public static Literal literal(String s, URI datatype) {
return valueFactory.createLiteral(s, datatype);
}
/**
+ * Creates a {@link Literal}.
+ */
+ public static Literal literal(String s, IRI datatype) {
+ return valueFactory.createLiteral(s, datatype);
+ }
+
+ /**
* Creates a {@link BNode}.
- * @param id string representation of the {@link org.openrdf.model.BNode}
- * @return the valid {@link org.openrdf.model.BNode}
+ * @param id string representation of the {@link org.eclipse.rdf4j.model.BNode}
+ * @return the valid {@link org.eclipse.rdf4j.model.BNode}
*/
// TODO: replace this with all occurrences of #getBNode()
public static BNode bnode(String id) {
@@ -298,9 +333,9 @@ public class RDFUtils {
/**
* Creates a {@link BNode}.
- * @param id string representation of the {@link org.openrdf.model.BNode}
+ * @param id string representation of the {@link org.eclipse.rdf4j.model.BNode}
* name for which we will create a md5 hash.
- * @return the valid {@link org.openrdf.model.BNode}
+ * @return the valid {@link org.eclipse.rdf4j.model.BNode}
*/
public static BNode getBNode(String id) {
return valueFactory.createBNode(
@@ -310,12 +345,12 @@ public class RDFUtils {
/**
* Creates a {@link Statement}.
- * @param s subject {@link org.openrdf.model.Resource}
- * @param p predicate {@link org.openrdf.model.URI}
- * @param o object {@link org.openrdf.model.Value}
- * @return valid {@link org.openrdf.model.Statement}
+ * @param s subject {@link org.eclipse.rdf4j.model.Resource}
+ * @param p predicate {@link org.eclipse.rdf4j.model.URI}
+ * @param o object {@link org.eclipse.rdf4j.model.Value}
+ * @return valid {@link org.eclipse.rdf4j.model.Statement}
*/
- public static Statement triple(Resource s, URI p, Value o) {
+ public static Statement triple(Resource s, IRI p, Value o) {
return valueFactory.createStatement(s, p, o);
}
@@ -328,7 +363,7 @@ public class RDFUtils {
* @return a statement instance.
*/
public static Statement triple(String s, String p, String o) {
- return valueFactory.createStatement((Resource) toValue(s), (URI) toValue(p), toValue(o));
+ return valueFactory.createStatement((Resource) toValue(s), (IRI) toValue(p), toValue(o));
}
/**
@@ -339,7 +374,7 @@ public class RDFUtils {
* @param g quad resource
* @return a statement instance.
*/
- public static Statement quad(Resource s, URI p, Value o, Resource g) {
+ public static Statement quad(Resource s, IRI p, Value o, Resource g) {
return valueFactory.createStatement(s, p, o, g);
}
@@ -352,7 +387,7 @@ public class RDFUtils {
* @return a statement instance.
*/
public static Statement quad(String s, String p, String o, String g) {
- return valueFactory.createStatement((Resource) toValue(s), (URI) toValue(p), toValue(o), (Resource) toValue(g));
+ return valueFactory.createStatement((Resource) toValue(s), (IRI) toValue(p), toValue(o), (Resource) toValue(g));
}
/**
@@ -379,7 +414,7 @@ public class RDFUtils {
* @see org.openrdf.rio.RDFFormat#values()
*/
public static Collection<RDFFormat> getFormats() {
- return RDFFormat.values();
+ return RDFParserRegistry.getInstance().getKeys();
}
/**
@@ -424,24 +459,24 @@ public class RDFUtils {
* @return parser matching the extension.
* @throws IllegalArgumentException if no extension matches.
*/
- public static RDFFormat getFormatByExtension(String ext) {
+ public static Optional<RDFFormat> getFormatByExtension(String ext) {
if( ! ext.startsWith(".") ) ext = "." + ext;
return Rio.getParserFormatForFileName(ext);
}
/**
* Parses the content of <code>is</code> input stream with the
- * specified parser <code>p</code> using <code>baseURI</code>.
+ * specified parser <code>p</code> using <code>baseIRI</code>.
*
* @param format input format type.
- * @param is input stream containing <code>RDF</code>.
- * @param baseURI base uri.
+ * @param is input stream containing <code>RDF</data>.
+ * @param baseIRI base uri.
* @return list of statements detected within the input stream.
* @throws RDFHandlerException if there is an error handling the RDF
* @throws IOException if there is an error reading the {@link java.io.InputStream}
* @throws RDFParseException if there is an error handling the RDF
*/
- public static Statement[] parseRDF(RDFFormat format, InputStream is, String baseURI)
+ public static Statement[] parseRDF(RDFFormat format, InputStream is, String baseIRI)
throws RDFHandlerException, IOException, RDFParseException {
final StatementCollector handler = new StatementCollector();
final RDFParser parser = getParser(format);
@@ -449,13 +484,13 @@ public class RDFUtils {
parser.setStopAtFirstError(true);
parser.setPreserveBNodeIDs(true);
parser.setRDFHandler(handler);
- parser.parse(is, baseURI);
+ parser.parse(is, baseIRI);
return handler.getStatements().toArray( new Statement[handler.getStatements().size()] );
}
/**
* Parses the content of <code>is</code> input stream with the
- * specified parser <code>p</code> using <code>''</code> as base URI.
+ * specified parser <code>p</code> using <code>''</code> as base IRI.
*
* @param format input format type.
* @param is input stream containing <code>RDF</code>.
@@ -471,7 +506,7 @@ public class RDFUtils {
/**
* Parses the content of <code>in</code> string with the
- * specified parser <code>p</code> using <code>''</code> as base URI.
+ * specified parser <code>p</code> using <code>''</code> as base IRI.
*
* @param format input format type.
* @param in input string containing <code>RDF</code>.
@@ -500,19 +535,20 @@ public class RDFUtils {
if(extIndex == -1)
throw new IllegalArgumentException("Error while detecting the extension in resource name " + resource);
final String extension = resource.substring(extIndex + 1);
- return parseRDF( getFormatByExtension(extension), RDFUtils.class.getResourceAsStream(resource) );
+ return parseRDF( getFormatByExtension(extension).orElseThrow(Rio.unsupportedFormat(extension))
+ , RDFUtils.class.getResourceAsStream(resource) );
}
/**
* Checks if <code>href</code> is absolute or not.
*
- * @param href candidate URI.
+ * @param href candidate IRI.
* @return <code>true</code> if <code>href</code> is absolute,
* <code>false</code> otherwise.
*/
- public static boolean isAbsoluteURI(String href) {
+ public static boolean isAbsoluteIRI(String href) {
try {
- new URIImpl(href.trim());
+ SimpleValueFactory.getInstance().createIRI(href.trim());
new java.net.URI(href.trim());
return true;
} catch (IllegalArgumentException e) {