use of org.openrdf.model.Value in project vcell by virtualcell.
the class RDFEvaluator method getProperties.
public <T> RDFValueSets getProperties(T subject, RDFObjectPool<T> pool, URI property) {
Set<Value> objects = new HashSet<Value>();
Set<Resource> subjectResources = pool.getResources(subject);
for (Graph graph : graphs) {
for (Resource subjectResource : subjectResources) {
Iterator<Statement> stmtIter = graph.match(subjectResource, property, null);
while (stmtIter.hasNext()) {
objects.add(stmtIter.next().getObject());
}
}
}
return new RDFValueSets(objects);
}
use of org.openrdf.model.Value in project vcell by virtualcell.
the class RDFResourceProjection method project.
public Statement project(Statement statement, ValueFactory factory) {
Resource subjectMapped = project(statement.getSubject());
URI predicateMapped = project(statement.getPredicate());
Value objectMapped = project(statement.getObject());
return factory.createStatement(subjectMapped, predicateMapped, objectMapped);
}
use of org.openrdf.model.Value in project vcell by virtualcell.
the class SameAsCrystalizer method smelt.
public Graph smelt(Graph rdf) {
Map<Resource, Set<Resource>> sameAsSetsMap = new HashMap<Resource, Set<Resource>>();
Iterator<Statement> sameAsStmtIter = rdf.match(null, OWL.SAMEAS, null);
while (sameAsStmtIter.hasNext()) {
Statement sameAsStatement = sameAsStmtIter.next();
Value objectNode = sameAsStatement.getObject();
if (objectNode instanceof Resource) {
Resource subject = sameAsStatement.getSubject();
Resource object = (Resource) objectNode;
Set<Resource> subjectSameAsSet = sameAsSetsMap.get(subject);
Set<Resource> objectSameAsSet = sameAsSetsMap.get(object);
if (subjectSameAsSet != null && objectSameAsSet != null) {
if (!subjectSameAsSet.equals(objectSameAsSet)) {
Set<Resource> sameAsUnionSet = new HashSet<Resource>();
sameAsUnionSet.addAll(subjectSameAsSet);
sameAsUnionSet.addAll(objectSameAsSet);
sameAsSetsMap.put(subject, sameAsUnionSet);
sameAsSetsMap.put(object, sameAsUnionSet);
}
} else if (subjectSameAsSet != null) {
subjectSameAsSet.add(object);
sameAsSetsMap.put(object, subjectSameAsSet);
} else if (objectSameAsSet != null) {
objectSameAsSet.add(subject);
sameAsSetsMap.put(subject, objectSameAsSet);
} else {
Set<Resource> sameAsUnionSet = new HashSet<Resource>();
sameAsUnionSet.add(subject);
sameAsUnionSet.add(object);
sameAsSetsMap.put(subject, sameAsUnionSet);
sameAsSetsMap.put(object, sameAsUnionSet);
}
}
}
Set<Set<Resource>> sameAsSets = new HashSet<Set<Resource>>();
for (Map.Entry<Resource, Set<Resource>> sameAsSetsEntry : sameAsSetsMap.entrySet()) {
sameAsSets.add(sameAsSetsEntry.getValue());
}
Map<Resource, Resource> projectionMap = new HashMap<Resource, Resource>();
for (Set<Resource> sameAsSet : sameAsSets) {
Resource preferredResource = null;
for (Resource resource : sameAsSet) {
if (preferredResource == null || comparator.compare(resource, preferredResource) > 0) {
preferredResource = resource;
}
}
for (Resource resource : sameAsSet) {
if (resource != preferredResource) {
projectionMap.put(resource, preferredResource);
}
}
}
RDFResourceProjection rdfResourceProjection = new RDFResourceProjection(projectionMap);
Graph rdfSmelted = rdfResourceProjection.smelt(rdf);
Iterator<Statement> iter = rdfSmelted.match(null, OWL.SAMEAS, null);
while (iter.hasNext()) {
iter.next();
iter.remove();
}
for (Map.Entry<Resource, Resource> projectionEntry : projectionMap.entrySet()) {
Resource subject = projectionEntry.getValue();
Resource object = projectionEntry.getKey();
if (!subject.equals(object)) {
rdfSmelted.add(subject, OWL.SAMEAS, object);
}
}
return rdfSmelted;
}
use of org.openrdf.model.Value in project vcell by virtualcell.
the class NamespaceAssimilator method smelt.
public Graph smelt(Graph rdf) {
Graph rdfNew = new HashGraph();
for (Statement statement : rdf) {
Resource subjectNew = smelt(rdf, statement.getSubject());
URI predicateNew = smelt(rdf, statement.getPredicate());
Value objectNew = statement.getObject() instanceof Resource ? smelt(rdf, (Resource) statement.getObject()) : statement.getObject();
rdfNew.add(subjectNew, predicateNew, objectNew);
}
for (Map.Entry<Resource, Resource> entry : resourceMap.entrySet()) {
rdfNew.add(entry.getKey(), OWL.SAMEAS, entry.getValue());
}
return rdfNew;
}
use of org.openrdf.model.Value in project vcell by virtualcell.
the class IndexedGraph method removeFromAllMaps.
protected void removeFromAllMaps(Statement statement) {
Resource subject = statement.getSubject();
URI predicate = statement.getPredicate();
Value object = statement.getObject();
removeFromMap(sMap, subject, statement);
removeFromMap(pMap, predicate, statement);
removeFromMap(oMap, object, statement);
removeFromMap(spMap, new ListOfTwo<Value>(subject, predicate), statement);
removeFromMap(soMap, new ListOfTwo<Value>(subject, object), statement);
removeFromMap(poMap, new ListOfTwo<Value>(predicate, object), statement);
}
Aggregations