use of org.openrdf.model.Statement 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.Statement in project vcell by virtualcell.
the class RDFEvaluator method createAllObjectsForPool.
public <T> Set<T> createAllObjectsForPool(RDFObjectPool<T> pool) {
Set<T> objects = new HashSet<T>();
Set<Resource> supportedTypes = pool.getSupportedTypes();
for (Graph graph : graphs) {
for (Resource type : supportedTypes) {
Iterator<Statement> stmtIter = graph.match(null, RDF.TYPE, type);
while (stmtIter.hasNext()) {
Statement statement = stmtIter.next();
try {
objects.add(pool.getOrCreateObject(statement.getSubject(), Collections.singleton(type)));
} catch (UnsupportedRDFTypeException e) {
e.printStackTrace();
}
}
}
}
return objects;
}
use of org.openrdf.model.Statement in project vcell by virtualcell.
the class ModelComparer method extractSubModels.
private void extractSubModels(Graph diff, Set<Graph> subModels) {
MultiMap<Resource, Resource> bNodesMap = new MultiHashMap<Resource, Resource>();
MultiMap<Resource, Statement> triples = new MultiHashMap<Resource, Statement>();
for (Statement statement : diff) {
Set<Resource> bNodesInTriple = new HashSet<Resource>();
recordIfBlankNode(statement.getSubject(), statement, bNodesInTriple, triples);
recordIfBlankNode(statement.getPredicate(), statement, bNodesInTriple, triples);
recordIfBlankNode(statement.getObject(), statement, bNodesInTriple, triples);
Set<Resource> bNodesUnion = new HashSet<Resource>();
bNodesUnion.addAll(bNodesInTriple);
for (Resource bNode : bNodesInTriple) {
Set<Resource> bNodes = bNodesMap.get(bNode);
if (bNodes != null) {
bNodesUnion.addAll(bNodes);
}
}
for (Resource bNode : bNodesUnion) {
bNodesMap.put(bNode, bNodesUnion);
}
}
for (Set<Resource> bNodes : bNodesMap.values()) {
Graph model = new HashGraph();
for (Resource bNode : bNodes) {
for (Statement statement : triples.get(bNode)) {
model.add(statement);
}
}
subModels.add(model);
}
}
use of org.openrdf.model.Statement 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.Statement 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;
}
Aggregations