本文整理了Java中org.apache.jena.query.Query.addResultVar
方法的一些代码示例,展示了Query.addResultVar
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.addResultVar
方法的具体详情如下:
包路径:org.apache.jena.query.Query
类名称:Query
方法名:addResultVar
[英]Add a projection variable to a SELECT query
[中]将投影变量添加到SELECT查询
代码示例来源:origin: apache/jena
/** Add a collection of projection variables to a SELECT query */
public void addProjectVars(Collection<?> vars)
{
for ( Object obj : vars )
{
if ( obj instanceof String )
{
this.addResultVar( (String) obj );
continue;
}
if ( obj instanceof Var )
{
this.addResultVar( (Var) obj );
continue;
}
throw new QueryException( "Not a variable or variable name: " + obj );
}
resultVarsSet = true ;
}
代码示例来源:origin: apache/jena
/**
* Add an Expression as variable to the select.
*
* @param expr
* The expression to add.
* @param var
* The variable to add.
*/
public void addVar(Expr expr, Var var) {
if (expr == null) {
throw new IllegalArgumentException("expr may not be null");
}
if (var == null) {
throw new IllegalArgumentException("var may not be null");
}
query.setQueryResultStar(false);
query.addResultVar(var, expr);
aggHandler.add( expr, var );
}
代码示例来源:origin: org.apache.jena/jena-querybuilder
/**
* Add an Expression as variable to the select.
*
* @param expr
* The expression to add.
* @param var
* The variable to add.
*/
public void addVar(Expr expr, Var var) {
if (expr == null) {
throw new IllegalArgumentException("expr may not be null");
}
if (var == null) {
throw new IllegalArgumentException("var may not be null");
}
query.setQueryResultStar(false);
query.addResultVar(var, expr);
aggHandler.add( expr, var );
}
代码示例来源:origin: apache/jena
/**
* Add a variable to the select. If the variable is <code>null</code> the
* variables are set to star.
*
* @param var
* The variable to add.
*/
public void addVar(Var var) {
if (var == null) {
query.setQueryResultStar(true);
} else {
query.setQueryResultStar(false);
query.addResultVar(var);
}
}
代码示例来源:origin: org.apache.jena/jena-querybuilder
/**
* Add a variable to the select. If the variable is <code>null</code> the
* variables are set to star.
*
* @param var
* The variable to add.
*/
public void addVar(Var var) {
if (var == null) {
query.setQueryResultStar(true);
} else {
query.setQueryResultStar(false);
query.addResultVar(var);
}
}
代码示例来源:origin: apache/jena
@Override
public void visitSelectResultForm(Query query) {
newQuery.setQuerySelectType();
newQuery.setDistinct(query.isDistinct());
VarExprList x = query.getProject();
for (Var v : x.getVars()) {
Expr expr = x.getExpr(v);
if (expr == null)
newQuery.addResultVar(v);
else
newQuery.addResultVar(v, expr);
}
}
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
public static Query asQuery(Op op, Dialect dialect)
{
Query query = QueryFactory.make() ;
Converter v = new Converter(query, dialect) ;
//OpWalker.walk(op, v) ;
op.visit(v) ;
List<Var> vars = v.projectVars;
query.setQueryResultStar(vars.isEmpty()); // SELECT * unless we are projecting
Iterator<Var> iter = vars.iterator();
for (; iter.hasNext();) {
Var var = iter.next();
if (v.varExpression.containsKey(var))
query.addResultVar(var, v.varExpression.get(var));
else
query.addResultVar(var);
}
ElementGroup eg = v.currentGroup ;
query.setQueryPattern(eg) ;
query.setQuerySelectType() ;
query.setResultVars() ;
return query ;
}
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
@Override
public void visitSelectResultForm(Query query) {
newQuery.setQuerySelectType() ;
newQuery.setDistinct(query.isDistinct()) ;
VarExprList x = query.getProject() ;
for (Var v : x.getVars()) {
Expr expr = x.getExpr(v) ;
if ( expr == null )
newQuery.addResultVar(v) ;
else
newQuery.addResultVar(v, expr) ;
}
}
代码示例来源:origin: apache/jena
private void findAndAddNamedVars()
{
Iterator<Var> varIter = null ;
if ( hasGroupBy() )
varIter = groupVars.getVars().iterator() ;
else
{
// Binding variables -- in patterns, not in filters and not in EXISTS
LinkedHashSet<Var> queryVars = new LinkedHashSet<>() ;
PatternVars.vars(queryVars, this.getQueryPattern()) ;
if ( this.hasValues() )
queryVars.addAll(getValuesVariables()) ;
// if ( this.hasValues() )
// queryVars.addAll(getValuesVariables()) ;
varIter = queryVars.iterator() ;
}
// All query variables, including ones from bNodes in the query.
for ( ; varIter.hasNext() ; )
{
Object obj = varIter.next() ;
//Var var = (Var)iter.next() ;
Var var = (Var)obj ;
if ( var.isNamedVar() )
addResultVar(var) ;
}
}
代码示例来源:origin: apache/jena
public void addDescribeNode(Node node)
{
if ( node.isVariable() ) { addResultVar(node) ; return ; }
if ( node.isURI() || node.isBlank() )
{
if ( !resultNodes.contains(node) )
resultNodes.add(node);
return ;
}
if ( node.isLiteral() )
throw new QueryException("Result node is a literal: "+FmtUtils.stringForNode(node)) ;
throw new QueryException("Result node not recognized: "+node) ;
}
代码示例来源:origin: org.trellisldp/trellis-triplestore
/**
* This code is equivalent to the SPARQL query below.
*
* <p><pre><code>
* SELECT ?subject ?predicate ?object
* WHERE { GRAPH fromGraphName { ?subject ?predicate ?object } }
* </code></pre>
*/
private Stream<Quad> fetchAllFromGraph(final String fromGraphName, final IRI toGraphName) {
final Query q = new Query();
q.setQuerySelectType();
q.addResultVar(SUBJECT);
q.addResultVar(PREDICATE);
q.addResultVar(OBJECT);
final ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(create(SUBJECT, PREDICATE, OBJECT));
final ElementGroup elg = new ElementGroup();
elg.addElement(new ElementNamedGraph(createURI(fromGraphName), epb));
q.setQueryPattern(elg);
final Stream.Builder<Quad> builder = builder();
rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(toGraphName,
getSubject(qs), getPredicate(qs), getObject(qs))));
return builder.build();
}
代码示例来源:origin: trellis-ldp/trellis
/**
* This code is equivalent to the SPARQL query below.
*
* <p><pre><code>
* SELECT ?subject ?predicate ?object
* WHERE { GRAPH fromGraphName { ?subject ?predicate ?object } }
* </code></pre>
*/
private Stream<Quad> fetchAllFromGraph(final String fromGraphName, final IRI toGraphName) {
final Query q = new Query();
q.setQuerySelectType();
q.addResultVar(SUBJECT);
q.addResultVar(PREDICATE);
q.addResultVar(OBJECT);
final ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(create(SUBJECT, PREDICATE, OBJECT));
final ElementGroup elg = new ElementGroup();
elg.addElement(new ElementNamedGraph(createURI(fromGraphName), epb));
q.setQueryPattern(elg);
final Stream.Builder<Quad> builder = builder();
rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(toGraphName,
getSubject(qs), getPredicate(qs), getObject(qs))));
return builder.build();
}
代码示例来源:origin: apache/jena
case VAR2:
o = Var();
getQuery().addResultVar((Var)o) ; getQuery().addJsonMapping(s, o) ;
break;
case STRING_LITERAL1:
case STRING_LITERAL_LONG2:
o = RDFLiteral();
getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ;
break;
case INTEGER:
case DOUBLE_NEGATIVE:
o = NumericLiteral();
getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ;
break;
case TRUE:
case FALSE:
o = BooleanLiteral();
getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ;
break;
default:
代码示例来源:origin: org.trellisldp/trellis-triplestore
/**
* This code is equivalent to the SPARQL query below.
*
* <p><pre><code>
* SELECT ?object
* WHERE {
* GRAPH trellis:PreferServerManaged { ?object dc:isPartOf IDENTIFIER }
* }
* </code></pre>
*/
private Stream<Quad> fetchContainmentQuads() {
if (getInteractionModel().getIRIString().endsWith("Container")) {
final Query q = new Query();
q.setQuerySelectType();
q.addResultVar(OBJECT);
final ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(create(OBJECT, rdf.asJenaNode(DC.isPartOf), rdf.asJenaNode(identifier)));
final ElementNamedGraph ng = new ElementNamedGraph(rdf.asJenaNode(Trellis.PreferServerManaged), epb);
final ElementGroup elg = new ElementGroup();
elg.addElement(ng);
q.setQueryPattern(elg);
final Stream.Builder<Quad> builder = builder();
rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(LDP.PreferContainment,
identifier, LDP.contains, getObject(qs))));
return builder.build();
}
return Stream.empty();
}
代码示例来源:origin: trellis-ldp/trellis
/**
* This code is equivalent to the SPARQL query below.
*
* <p><pre><code>
* SELECT ?object
* WHERE {
* GRAPH trellis:PreferServerManaged { ?object dc:isPartOf IDENTIFIER }
* }
* </code></pre>
*/
private Stream<Quad> fetchContainmentQuads() {
if (getInteractionModel().getIRIString().endsWith("Container")) {
final Query q = new Query();
q.setQuerySelectType();
q.addResultVar(OBJECT);
final ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(create(OBJECT, rdf.asJenaNode(DC.isPartOf), rdf.asJenaNode(identifier)));
final ElementNamedGraph ng = new ElementNamedGraph(rdf.asJenaNode(Trellis.PreferServerManaged), epb);
final ElementGroup elg = new ElementGroup();
elg.addElement(ng);
q.setQueryPattern(elg);
final Stream.Builder<Quad> builder = builder();
rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(LDP.PreferContainment,
identifier, LDP.contains, getObject(qs))));
return builder.build();
}
return Stream.empty();
}
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
q.setResultVars();
for(String v : query.getResultVars()) {
q.addResultVar(v);
代码示例来源:origin: org.trellisldp/trellis-triplestore
final Query q = new Query();
q.setQuerySelectType();
q.addResultVar(SUBJECT);
q.addResultVar(PREDICATE);
q.addResultVar(OBJECT);
final Var s = Var.alloc("s");
代码示例来源:origin: trellis-ldp/trellis
final Query q = new Query();
q.setQuerySelectType();
q.addResultVar(PREDICATE);
q.addResultVar(OBJECT);
代码示例来源:origin: org.trellisldp/trellis-triplestore
final Query q = new Query();
q.setQuerySelectType();
q.addResultVar(PREDICATE);
q.addResultVar(OBJECT);
代码示例来源:origin: SmartDataAnalytics/DL-Learner
@Override
public Query toQuery(){
Query query = QueryFactory.make();
query.setQuerySelectType();
query.addResultVar(NodeFactory.createVariable("x0"));
query.setDistinct(true);
query.setPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
query.setPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
query.setPrefix("yago", "http://dbpedia.org/class/yago/");
query.setPrefix("cyc", "http://sw.opencyc.org/2008/06/10/concept/");
query.setPrefix("owl", "http://www.w3.org/2002/07/owl#");
query.setPrefix("dbp", "http://dbpedia.org/property/");
query.setPrefix("dbo", "http://dbpedia.org/ontology/");
query.setPrefix("dbr", "http://dbpedia.org/resource/");
query.setPrefix("dc", "http://purl.org/dc/terms/");
ElementGroup whereClause = new ElementGroup();
ElementTriplesBlock triples = new ElementTriplesBlock();
for(Triple t : buildTriples(this)){
triples.addTriple(t);
}
whereClause.addElement(triples);
query.setQueryPattern(whereClause);
return query;
}
内容来源于网络,如有侵权,请联系作者删除!