use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class ClerezzaRDFUtils method urifyBlankNodes.
public static void urifyBlankNodes(Graph model) {
HashMap<BlankNode, IRI> blankNodeMap = new HashMap<BlankNode, IRI>();
Graph remove = new SimpleGraph();
Graph add = new SimpleGraph();
for (Triple t : model) {
BlankNodeOrIRI subj = t.getSubject();
RDFTerm obj = t.getObject();
IRI pred = t.getPredicate();
boolean match = false;
if (subj instanceof BlankNode) {
match = true;
IRI ru = blankNodeMap.get(subj);
if (ru == null) {
ru = createRandomUri();
blankNodeMap.put((BlankNode) subj, ru);
}
subj = ru;
}
if (obj instanceof BlankNode) {
match = true;
IRI ru = blankNodeMap.get(obj);
if (ru == null) {
ru = createRandomUri();
blankNodeMap.put((BlankNode) obj, ru);
}
obj = ru;
}
if (match) {
remove.add(t);
add.add(new TripleImpl(subj, pred, obj));
}
}
model.removeAll(remove);
model.addAll(add);
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class BlankNodeAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.BlankNodeAtom tmp = (org.apache.stanbol.rules.manager.atoms.BlankNodeAtom) ruleAtom;
UriRefOrVariable subject;
UriRefOrVariable predicate;
ResourceOrVariable object;
IObjectAtom argument2UriResource = tmp.getArgument2();
IObjectAtom argument1UriResource = tmp.getArgument1();
ClerezzaSparqlObject subjectCSO = (ClerezzaSparqlObject) adapter.adaptTo(argument2UriResource, ConstructQuery.class);
ClerezzaSparqlObject predicateCSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1UriResource, ConstructQuery.class);
subject = new UriRefOrVariable((IRI) subjectCSO.getClerezzaObject());
predicate = new UriRefOrVariable((IRI) predicateCSO.getClerezzaObject());
object = new ResourceOrVariable(new BlankNode());
return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class ResourceMapping method apply.
@Override
public boolean apply(Graph graph, BlankNodeOrIRI subject, Metadata metadata) {
boolean added = false;
BlankNodeOrIRI s = new BlankNode();
mappingLogger.log(subject, ontProperty, null, s);
if (!required.isEmpty()) {
Graph g = new SimpleGraph();
for (Mapping m : required) {
if (!m.apply(g, s, metadata)) {
return false;
}
}
graph.addAll(g);
added = true;
}
for (Mapping m : optional) {
if (m.apply(graph, s, metadata)) {
added = true;
}
}
if (added) {
for (Mapping m : additional) {
m.apply(graph, s, metadata);
}
graph.add(new TripleImpl(subject, ontProperty, s));
}
return added;
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class TestMetaxaCore method printTriples.
/**
* This prints out the Stanbol Enhancer triples that would be created for the metadata
* contained in the given model.
*
* @param m a {@link Model}
*
* @return an {@code int} with the number of added triples
*/
private int printTriples(Model m) {
int tripleCounter = 0;
HashMap<BlankNode, BlankNode> blankNodeMap = new HashMap<BlankNode, BlankNode>();
ClosableIterator<Statement> it = m.iterator();
while (it.hasNext()) {
Statement oneStmt = it.next();
BlankNodeOrIRI subject = (BlankNodeOrIRI) MetaxaEngine.asClerezzaResource(oneStmt.getSubject(), blankNodeMap);
IRI predicate = (IRI) MetaxaEngine.asClerezzaResource(oneStmt.getPredicate(), blankNodeMap);
RDFTerm object = MetaxaEngine.asClerezzaResource(oneStmt.getObject(), blankNodeMap);
if (null != subject && null != predicate && null != object) {
Triple t = new TripleImpl(subject, predicate, object);
LOG.debug("adding " + t);
tripleCounter++;
} else {
LOG.debug("skipped " + oneStmt.toString());
}
}
it.close();
return tripleCounter;
}
use of org.apache.clerezza.commons.rdf.BlankNode in project stanbol by apache.
the class ClerezzaTripleCallback method getBlankNode.
private BlankNode getBlankNode(String s) {
if (bNodeMap.containsKey(s)) {
return bNodeMap.get(s);
} else {
final BlankNode result = new BlankNode();
bNodeMap.put(s, result);
return result;
}
}
Aggregations