use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class AbstractRDFInserter method handleStatement.
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
Resource subj = st.getSubject();
IRI pred = st.getPredicate();
Value obj = st.getObject();
Resource ctxt = st.getContext();
if (!preserveBNodeIDs) {
if (subj instanceof BNode) {
subj = mapBNode((BNode) subj);
}
if (obj instanceof BNode) {
obj = mapBNode((BNode) obj);
}
if (!enforcesContext() && ctxt instanceof BNode) {
ctxt = mapBNode((BNode) ctxt);
}
}
try {
addStatement(subj, pred, obj, ctxt);
} catch (RDF4JException e) {
throw new RDFHandlerException(e);
}
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class RepositoryUtil method statementsMatch.
private static boolean statementsMatch(Statement st1, Statement st2, Map<BNode, BNode> bNodeMapping) {
IRI pred1 = st1.getPredicate();
IRI pred2 = st2.getPredicate();
if (!pred1.equals(pred2)) {
// predicates don't match
return false;
}
Resource subj1 = st1.getSubject();
Resource subj2 = st2.getSubject();
if (!(subj1 instanceof BNode)) {
if (!subj1.equals(subj2)) {
// subjects are not bNodes and don't match
return false;
}
} else {
// subj1 instanceof BNode
BNode mappedBNode = bNodeMapping.get(subj1);
if (mappedBNode != null) {
// bNode 'subj1' was already mapped to some other bNode
if (!subj2.equals(mappedBNode)) {
// 'subj1' and 'subj2' do not match
return false;
}
} else {
// possible mapping candidate
if (bNodeMapping.containsValue(subj2)) {
// 'subj2' is already mapped to some other value.
return false;
}
}
}
Value obj1 = st1.getObject();
Value obj2 = st2.getObject();
if (!(obj1 instanceof BNode)) {
if (!obj1.equals(obj2)) {
// objects are not bNodes and don't match
return false;
}
} else {
// obj1 instanceof BNode
BNode mappedBNode = bNodeMapping.get(obj1);
if (mappedBNode != null) {
// bNode 'obj1' was already mapped to some other bNode
if (!obj2.equals(mappedBNode)) {
// 'obj1' and 'obj2' do not match
return false;
}
} else {
// possible mapping candidate
if (bNodeMapping.containsValue(obj2)) {
// 'obj2' is already mapped to some other value.
return false;
}
}
}
return true;
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class ContextAwareConfig method export.
@Override
public Resource export(Model model) {
Resource repImplNode = super.export(model);
ValueFactory vf = SimpleValueFactory.getInstance();
if (includeInferred != null) {
Literal bool = vf.createLiteral(includeInferred);
model.add(repImplNode, INCLUDE_INFERRED, bool);
}
if (maxQueryTime > 0) {
model.add(repImplNode, MAX_QUERY_TIME, vf.createLiteral(maxQueryTime));
}
if (queryLanguage != null) {
model.add(repImplNode, QUERY_LANGUAGE, vf.createLiteral(queryLanguage.getName()));
}
if (baseURI != null) {
model.add(repImplNode, BASE_URI, vf.createIRI(baseURI));
}
for (IRI uri : readContexts) {
model.add(repImplNode, READ_CONTEXT, uri);
}
for (IRI resource : addContexts) {
model.add(repImplNode, ADD_CONTEXT, resource);
}
for (IRI resource : removeContexts) {
model.add(repImplNode, REMOVE_CONTEXT, resource);
}
for (IRI resource : archiveContexts) {
model.add(repImplNode, ARCHIVE_CONTEXT, resource);
}
if (insertContext != null) {
model.add(repImplNode, INSERT_CONTEXT, insertContext);
}
return repImplNode;
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class NotifyingRepositoryConnectionWrapper method removeWithoutCommit.
@Override
public void removeWithoutCommit(Resource subj, IRI pred, Value obj, Resource... ctx) throws RepositoryException {
if (activated && reportDeltas()) {
RepositoryResult<Statement> stmts;
stmts = getDelegate().getStatements(subj, pred, obj, false, ctx);
List<Statement> list = new ArrayList<Statement>();
try {
while (stmts.hasNext()) {
list.add(stmts.next());
}
} finally {
stmts.close();
}
getDelegate().remove(subj, pred, obj, ctx);
for (RepositoryConnectionListener listener : listeners) {
for (Statement stmt : list) {
Resource s = stmt.getSubject();
IRI p = stmt.getPredicate();
Value o = stmt.getObject();
Resource c = stmt.getContext();
listener.remove(getDelegate(), s, p, o, c);
}
}
} else if (activated) {
getDelegate().remove(subj, pred, obj, ctx);
for (RepositoryConnectionListener listener : listeners) {
listener.remove(getDelegate(), subj, pred, obj, ctx);
}
} else {
getDelegate().remove(subj, pred, obj, ctx);
}
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class AbstractDelegatingRepositoryImplConfig method export.
@Override
public Resource export(Model model) {
Resource resource = super.export(model);
if (delegate != null) {
Resource delegateNode = delegate.export(model);
model.add(resource, DELEGATE, delegateNode);
}
return resource;
}
Aggregations