use of org.ontoware.rdf2go.model.node.RDFTerm in project stanbol by apache.
the class RDF2GoUtils method urifyBlankNodes.
public static void urifyBlankNodes(Model model) {
HashMap<BlankNode, URI> nodeMap = new HashMap<BlankNode, URI>();
Model add = RDF2Go.getModelFactory().createModel();
add.open();
Model remove = RDF2Go.getModelFactory().createModel();
remove.open();
for (Statement stmt : model) {
RDFTerm subj = stmt.getSubject();
URI pred = stmt.getPredicate();
Node obj = stmt.getObject();
boolean match = false;
if (subj instanceof BlankNode) {
match = true;
URI newSubj = nodeMap.get(subj);
if (newSubj == null) {
newSubj = URIGenerator.createNewRandomUniqueURI();
nodeMap.put(subj.asBlankNode(), newSubj);
}
subj = newSubj;
}
if (obj instanceof BlankNode) {
match = true;
URI newObj = nodeMap.get(obj);
if (newObj == null) {
newObj = URIGenerator.createNewRandomUniqueURI();
nodeMap.put(obj.asBlankNode(), newObj);
}
obj = newObj;
}
if (match) {
remove.addStatement(stmt);
add.addStatement(subj, pred, obj);
}
}
ClosableIterator<Statement> addIt = add.iterator();
ClosableIterator<Statement> removeIt = remove.iterator();
model.update(new DiffImpl(addIt, removeIt));
addIt.close();
removeIt.close();
add.close();
remove.close();
}
use of org.ontoware.rdf2go.model.node.RDFTerm in project stanbol by apache.
the class MP3FileExtractor method addSimpleContact.
protected void addSimpleContact(URI property, String fullname, RDFContainer container) {
Model model = container.getModel();
RDFTerm resource = ModelUtil.generateRandomResource(model);
model.addStatement(resource, RDF.type, NCO.Contact);
model.addStatement(resource, NCO.fullname, fullname);
model.addStatement(container.getDescribedUri(), property, resource);
}
Aggregations