本文整理了Java中com.hp.hpl.jena.query.Query.addResultVar
方法的一些代码示例,展示了Query.addResultVar
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.addResultVar
方法的具体详情如下:
包路径:com.hp.hpl.jena.query.Query
类名称:Query
方法名:addResultVar
[英]Add an to a SELECT query (a name will be created for it)
[中]向SELECT查询中添加(将为其创建名称)
代码示例来源:origin: Quetzal-RDF/quetzal
public void addResultVar(String var) {
query.addResultVar(var);
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
/** Add a collection of projection variables to a SELECT query */
public void addProjectVars(Collection<?> vars)
{
for ( Iterator<?> iter = vars.iterator() ; iter.hasNext() ; )
{
Object obj = iter.next();
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: com.hp.hpl.jena/arq
/** Add a collection of projection variables to a SELECT query */
public void addProjectVars(Collection<?> vars)
{
for ( Iterator<?> iter = vars.iterator() ; iter.hasNext() ; )
{
Object obj = iter.next();
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: com.hp.hpl.jena/arq
private void extractVarList(Query q, RDQL_Node node)
{
int n = node.jjtGetNumChildren() ;
selectAllVars = ( n == 0 ) ;
for ( int i = 0 ; i < n ; i++ )
{
RDQL_Node c = node.jjtGetChild(i) ;
if ( ! (c instanceof Q_Var) )
throw new ARQInternalErrorException("Internal error: parser created '"+c.getClass().getName()+"' when Q_Var expected") ;
Q_Var v = (Q_Var)c ;
q.addResultVar(v.varName) ;
}
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
Query convert() {
if (hasRun) {
return this.query;
} else {
try {
op.visit(this) ;
Collection<Var> vars = this.projectVars;
query.setQueryResultStar(vars.isEmpty()); // SELECT * unless we are projecting
Iterator<Var> iter = vars.iterator();
for (; iter.hasNext();) {
Var var = iter.next();
if (this.varExpression.containsKey(var))
query.addResultVar(var, this.varExpression.get(var));
else
query.addResultVar(var);
}
ElementGroup eg = this.currentGroup ;
query.setQueryPattern(eg) ;
query.setQuerySelectType() ;
query.setResultVars() ; // Variables from the group.
return query ;
} finally {
this.hasRun = true;
}
}
}
代码示例来源:origin: com.hp.hpl.jena/arq
public static Query asQuery(Op op)
{
Query query = QueryFactory.make() ;
Converter v = new Converter(query) ;
//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: com.hp.hpl.jena/arq
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<Var>() ;
PatternVars.vars(queryVars, this.getQueryPattern()) ;
if ( this.hasBindings() )
queryVars.addAll(getBindingVariables()) ;
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: org.apache.clerezza.ext/org.apache.jena.jena-arq
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<Var>() ;
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: org.apache.clerezza.ext/org.apache.jena.jena-arq
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: com.hp.hpl.jena/arq
private void extractVarOrURIList(Query q, RDQL_Node node)
{
int n = node.jjtGetNumChildren() ;
selectAllVars = ( n == 0 ) ;
for ( int i = 0 ; i < n ; i++ )
{
RDQL_Node c = node.jjtGetChild(i) ;
if ( c instanceof Q_Var )
{
Q_Var v = (Q_Var)c ;
q.addResultVar(v.varName) ;
continue ;
}
if ( ( c instanceof Q_URI ) || ( c instanceof Q_QName ) )
{
Q_URI v = (Q_URI)c ;
q.addDescribeNode(v.getNode()) ;
continue ;
}
throw new ARQInternalErrorException("Internal error: parser created '"+c.getClass().getName()+"' when Q_Var expected") ;
}
}
代码示例来源:origin: com.hp.hpl.jena/arq
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: com.github.ansell.pellet/pellet-query
q.addResultVar( var45 );
代码示例来源:origin: anno4j/anno4j
leftGroup.addElement(new ElementBind(subVar, new NodeValueNode(leftVar.asNode())));
leftSubQuery.setQueryPattern(leftGroup);
leftSubQuery.addResultVar(var);
leftSubQuery.addResultVar(subVar);
leftSubQuery.setQuerySelectType();
ElementSubQuery leftESubQuery = new ElementSubQuery(leftSubQuery);
rightGroup.addElement(new ElementBind(subVar, new NodeValueNode(rightVar.asNode())));
rightSubQuery.setQueryPattern(rightGroup);
rightSubQuery.addResultVar(var);
rightSubQuery.addResultVar(subVar);
rightSubQuery.setQuerySelectType();
ElementSubQuery rightESubQuery = new ElementSubQuery(rightSubQuery);
代码示例来源:origin: Quetzal-RDF/quetzal
public ConjunctiveQuery cloneConjQuery(boolean copyResultVars) {
//return new ConjunctiveQuery(query.cloneQuery());
ConjunctiveQuery ret = new ConjunctiveQuery();
ElementTriplesBlock pattern = new ElementTriplesBlock();
for (Triple t: getTriples()) {
pattern.addTriple(new Triple(t.getSubject(), t.getPredicate(), t.getObject()));
}
ret.setQueryPattern(pattern);
for (ElementFilter f: getFilters()) {
ret.addFilter(f.getExpr());
}
if (copyResultVars) {
for (String v: getResultVars()) {
ret.query.addResultVar(v);
}
}
return ret;
}
public Set<String> getAllVariables() {
代码示例来源:origin: Quetzal-RDF/quetzal
protected static Query ruleToQuery(RuleSystem rules, Rule rule,
Map<Predicate, Query> headPred2Query, NewVariableGenerator varGen) {
Query cq = new QueryWithRepeatedResultVars();
cq.setQuerySelectType();
for (Expr e: rule.getHead().getArguments()) {
assert e.isVariable() : e;
cq.addResultVar(((VariableExpr)e).getName());
}
ElementGroup group = new ElementGroup();
cq.setQueryPattern(group);
Set<VariableExpr> unboundVars = new HashSet<VariableExpr>(rule.getUnboundVariables());
for (AtomicFormula af :rule.getBody()) {
af = renameUnboundVariables(af, unboundVars, varGen);
Predicate pred = af.getPredicate();
Element elt;
if (rules.isIDB(pred)) {
Query conjunctQuery = getUnionQuery(rules,pred, headPred2Query, varGen);
elt = instantiateBody(conjunctQuery, af.getArguments());
} else {
elt = instantiateBody( af, af.getArguments());
}
group.addElement(elt);
}
return cq;
}
代码示例来源:origin: anno4j/anno4j
public static <T extends ResourceObject> Query evaluate(QueryServiceConfiguration queryServiceDTO, URI rootType) throws ParseException {
Query query = QueryFactory.make();
query.setQuerySelectType();
ElementGroup elementGroup = new ElementGroup();
Var objectVar = Var.alloc("root");
// Creating and adding the first triple - could be something like: "?objectVar rdf:type oa:Annotation
Triple t1 = new Triple(objectVar, RDF.type.asNode(), NodeFactory.createURI(rootType.toString()));
elementGroup.addTriplePattern(t1);
// Evaluating the criteria
for (Criteria c : queryServiceDTO.getCriteria()) {
SesameValueBackend backend = new SesameValueBackend();
LdPathParser parser = new LdPathParser(backend, queryServiceDTO.getConfiguration(), new StringReader(c.getLdpath()));
Var var = LDPathEvaluator.evaluate(parser.parseSelector(queryServiceDTO.getPrefixes()), elementGroup, objectVar, queryServiceDTO.getEvaluatorConfiguration());
if (c.getConstraint() != null) {
String resolvedConstraint = resolveConstraintPrefix(c.getConstraint(), queryServiceDTO, parser);
EvalComparison.evaluate(elementGroup, c, var, resolvedConstraint);
}
}
// Adding all generated patterns to the query object
query.setQueryPattern(elementGroup);
// Choose what we want so select - SELECT ?annotation in this case
query.addResultVar(objectVar);
// Setting the default prefixes, like rdf: or dc:
query.getPrefixMapping().setNsPrefixes(queryServiceDTO.getPrefixes());
return query;
}
代码示例来源:origin: com.hp.hpl.jena/arq
q.addResultVar(varName) ;
代码示例来源:origin: com.hp.hpl.jena/arq
case VAR2:
v = Var();
getQuery().addResultVar(v) ;
break;
case LPAREN:
v = Var();
jj_consume_token(RPAREN);
getQuery().addResultVar(v, expr) ;
getQuery().setQueryResultStar(false) ;
break;
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
while (true) {
v = Var();
getQuery().addResultVar(v) ;
getQuery().setQueryResultStar(false) ;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
代码示例来源:origin: com.hp.hpl.jena/arq
while (true) {
v = Var();
getQuery().addResultVar(v) ;
getQuery().setQueryResultStar(false) ;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
内容来源于网络,如有侵权,请联系作者删除!