use of org.openrdf.model.Value in project backstage by zepheira.
the class DomLensNode method generateContentWithInnerTemplates.
protected void generateContentWithInnerTemplates(Value value, Scriptable result, Database database, SailRepositoryConnection connection) {
ScriptableArrayBuilder arrayBuilder = new ScriptableArrayBuilder();
try {
ExpressionQueryResult eqr = _contentExpression.computeOutputOnValue(value, database, connection);
if (eqr != null) {
TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
try {
while (queryResult.hasNext()) {
BindingSet bindingSet = queryResult.next();
Value value2 = bindingSet.getValue(eqr.resultVar.getName());
arrayBuilder.add(generateInnerContentWithInnerTemplates(value2, database, connection));
}
} finally {
queryResult.close();
}
} else {
arrayBuilder.add(generateInnerContentWithInnerTemplates(value, database, connection));
}
} catch (Exception e) {
_logger.error("", e);
}
result.put("content", result, arrayBuilder.toArray());
}
use of org.openrdf.model.Value in project stanbol by apache.
the class AbstractSesameBackend method listObjectsInternal.
protected Collection<Value> listObjectsInternal(RepositoryConnection connection, Resource subject, org.openrdf.model.URI property, boolean includeInferred, Resource... context) throws RepositoryException {
ValueFactory valueFactory = connection.getValueFactory();
Set<Value> result = new HashSet<Value>();
RepositoryResult<Statement> qResult = connection.getStatements(merge(subject, connection.getValueFactory()), merge(property, connection.getValueFactory()), null, includeInferred, context);
try {
while (qResult.hasNext()) {
result.add(qResult.next().getObject());
}
} finally {
qResult.close();
}
return result;
}
use of org.openrdf.model.Value in project stanbol by apache.
the class RdfIndexingSource method extractRepresentation.
/**
* Extracts all {@link Statement}s part of the Representation. If
* {@link #followBNodeState} this is called recursively for {@link Statement}s
* where the value is an {@link BNode}.
*/
protected void extractRepresentation(RepositoryConnection con, Model model, Resource node, Set<BNode> visited) throws RepositoryException {
//we need all the outgoing relations and also want to follow bNodes until
//the next UriRef. However we are not interested in incoming relations!
RepositoryResult<Statement> outgoing = con.getStatements(node, null, null, includeInferred, contexts);
Statement statement;
Set<BNode> bnodes = followBNodeState ? new HashSet<BNode>() : null;
while (outgoing.hasNext()) {
statement = outgoing.next();
model.add(statement);
if (followBNodeState) {
Value object = statement.getObject();
if (object instanceof BNode && !visited.contains(object)) {
bnodes.add((BNode) object);
}
}
//else do not follow values beeing BNodes
}
outgoing.close();
if (followBNodeState) {
for (BNode bnode : bnodes) {
visited.add(bnode);
//TODO: recursive calls could cause stackoverflows with wired graphs
extractRepresentation(con, model, bnode, visited);
}
}
}
use of org.openrdf.model.Value in project stanbol by apache.
the class SesameYard method findReferences.
@Override
public QueryResultList<String> findReferences(FieldQuery parsedQuery) throws YardException, IllegalArgumentException {
if (parsedQuery == null) {
throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
}
final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
RepositoryConnection con = null;
TupleQueryResult results = null;
try {
con = repository.getConnection();
con.begin();
//execute the query
int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(), getConfig().getMaxQueryResultNumber());
results = executeSparqlFieldQuery(con, query, limit, false);
//parse the results
List<String> ids = limit > 0 ? new ArrayList<String>(limit) : new ArrayList<String>();
while (results.hasNext()) {
BindingSet result = results.next();
Value value = result.getValue(query.getRootVariableName());
if (value instanceof Resource) {
ids.add(value.stringValue());
}
}
con.commit();
return new QueryResultListImpl<String>(query, ids, String.class);
} catch (RepositoryException e) {
throw new YardException("Unable to execute findReferences query", e);
} catch (QueryEvaluationException e) {
throw new YardException("Unable to execute findReferences query", e);
} finally {
if (results != null) {
//close the result if present
try {
results.close();
} catch (QueryEvaluationException ignore) {
/* ignore */
}
}
if (con != null) {
try {
con.close();
} catch (RepositoryException ignore) {
/* ignore */
}
}
}
}
use of org.openrdf.model.Value in project stanbol by apache.
the class SesameYard method extractRepresentation.
/**
* Recursive Method internally doing all the work for
* {@link #createRepresentationGraph(UriRef, TripleCollection)}
* @param con the repository connection to read the data from
* @param model The model to add the statements retrieved
* @param node the current node. Changes in recursive calls as it follows
* @param visited holding all the visited BNodes to avoid cycles. Other nodes
* need not be added because this implementation would not follow it anyway
* outgoing relations if the object is a {@link BNode} instance.
* @throws RepositoryException
*/
private void extractRepresentation(RepositoryConnection con, Model model, Resource node, Set<BNode> visited) throws RepositoryException {
//we need all the outgoing relations and also want to follow bNodes until
//the next UriRef. However we are not interested in incoming relations!
RepositoryResult<Statement> outgoing = con.getStatements(node, null, null, includeInferred, contexts);
Statement statement;
Set<BNode> bnodes = new HashSet<BNode>();
while (outgoing.hasNext()) {
statement = outgoing.next();
model.add(statement);
Value object = statement.getObject();
if (object instanceof BNode && !visited.contains(object)) {
bnodes.add((BNode) object);
}
}
outgoing.close();
for (BNode bnode : bnodes) {
visited.add(bnode);
//TODO: recursive calls could cause stackoverflows with wired graphs
extractRepresentation(con, model, bnode, visited);
}
}
Aggregations