use of org.openrdf.model.impl.LinkedHashModel in project stanbol by apache.
the class SesameModelWriter method toRDF.
private Model toRDF(QueryResultList<?> resultList) {
final Model resultGraph;
Class<?> type = resultList.getType();
if (String.class.isAssignableFrom(type)) {
//create a new ImmutableGraph
resultGraph = new LinkedHashModel();
for (Object result : resultList) {
//add a triple to each reference in the result set
resultGraph.add(QUERY_RESULT_LIST, QUERY_RESULT, sesameFactory.createURI(result.toString()));
}
} else {
//first determine the type of the resultList
final boolean isSignType;
if (Representation.class.isAssignableFrom(type)) {
isSignType = false;
} else if (Representation.class.isAssignableFrom(type)) {
isSignType = true;
} else {
//incompatible type -> throw an Exception
throw new IllegalArgumentException("Parsed type " + type + " is not supported");
}
//special treatment for RdfQueryResultList for increased performance
if (resultList instanceof SesameQueryResultList) {
resultGraph = ((SesameQueryResultList) resultList).getModel();
if (isSignType) {
//if we build a ResultList for Signs, we need to do more things
//first remove all triples representing results
resultGraph.filter(null, QUERY_RESULT, null).clear();
//to the Sign IDs
for (Object result : resultList) {
URI signId = sesameFactory.createURI(((Entity) result).getId());
addEntityTriplesToGraph(resultGraph, (Entity) result);
resultGraph.add(QUERY_RESULT_LIST, QUERY_RESULT, signId);
}
}
} else {
//any other implementation of the QueryResultList interface
//create a new graph
resultGraph = new LinkedHashModel();
if (Representation.class.isAssignableFrom(type)) {
for (Object result : resultList) {
URI resultId;
if (!isSignType) {
addRDFTo(resultGraph, (Representation) result);
resultId = sesameFactory.createURI(((Representation) result).getId());
} else {
addRDFTo(resultGraph, (Entity) result);
resultId = sesameFactory.createURI(((Entity) result).getId());
}
//Note: In case of Representation this Triple points to
// the representation. In case of Signs it points to
// the sign.
resultGraph.add(QUERY_RESULT_LIST, QUERY_RESULT, resultId);
}
}
}
}
return resultGraph;
}
use of org.openrdf.model.impl.LinkedHashModel in project stanbol by apache.
the class SesameModelWriter method toRDF.
private Model toRDF(Entity entity) {
Model graph = new LinkedHashModel();
addRDFTo(graph, entity);
return graph;
}
Aggregations