use of org.apache.clerezza.commons.rdf.Literal in project stanbol by apache.
the class MetaGraphManager method buildResource.
protected IRI buildResource(final OWLOntologyID publicKey) {
if (publicKey == null)
throw new IllegalArgumentException("Cannot build a IRI resource on a null public key!");
// The IRI is of the form ontologyIRI[:::versionIRI] (TODO use something less conventional?)
// XXX should versionIRI also include the version IRI set by owners? Currently not
// Remember not to sanitize logical identifiers.
org.semanticweb.owlapi.model.IRI ontologyIri = publicKey.getOntologyIRI(), versionIri = publicKey.getVersionIRI();
if (ontologyIri == null)
throw new IllegalArgumentException("Cannot build a IRI resource on an anonymous public key!");
log.debug("Searching for a meta graph entry for public key:");
log.debug(" -- {}", publicKey);
IRI match = null;
LiteralFactory lf = LiteralFactory.getInstance();
Literal oiri = lf.createTypedLiteral(new IRI(ontologyIri.toString()));
Literal viri = versionIri == null ? null : lf.createTypedLiteral(new IRI(versionIri.toString()));
for (Iterator<Triple> it = graph.filter(null, HAS_ONTOLOGY_IRI_URIREF, oiri); it.hasNext(); ) {
RDFTerm subj = it.next().getSubject();
log.debug(" -- Ontology IRI match found. Scanning");
log.debug(" -- RDFTerm : {}", subj);
if (!(subj instanceof IRI)) {
log.debug(" ---- (uncomparable: skipping...)");
continue;
}
if (viri != null) {
// Must find matching versionIRI
if (graph.contains(new TripleImpl((IRI) subj, HAS_VERSION_IRI_URIREF, viri))) {
log.debug(" ---- Version IRI match!");
match = (IRI) subj;
// Found
break;
} else {
log.debug(" ---- Expected version IRI match not found.");
// There could be another with the right versionIRI.
continue;
}
} else {
// Must find unversioned resource
if (graph.filter((IRI) subj, HAS_VERSION_IRI_URIREF, null).hasNext()) {
log.debug(" ---- Unexpected version IRI found. Skipping.");
continue;
} else {
log.debug(" ---- Unversioned match!");
match = (IRI) subj;
// Found
break;
}
}
}
log.debug("Matching IRI in graph : {}", match);
if (match == null)
return new IRI(OntologyUtils.encode(publicKey));
else
return match;
}
Aggregations