use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SPARQLParser10 method Project.
public final void Project() throws ParseException {
Var v;
Expr expr;
Node n;
jj_consume_token(SELECT);
getQuery().setQuerySelectType();
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case DISTINCT:
case REDUCED:
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case DISTINCT:
jj_consume_token(DISTINCT);
getQuery().setDistinct(true);
break;
case REDUCED:
jj_consume_token(REDUCED);
getQuery().setReduced(true);
break;
default:
jj_la1[4] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
jj_la1[5] = jj_gen;
;
}
allowAggregatesInExpressions = true;
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case VAR1:
case VAR2:
label_3: while (true) {
v = Var();
getQuery().addResultVar(v);
getQuery().setQueryResultStar(false);
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case VAR1:
case VAR2:
;
break;
default:
jj_la1[6] = jj_gen;
break label_3;
}
}
break;
case STAR:
jj_consume_token(STAR);
getQuery().setQueryResultStar(true);
break;
default:
jj_la1[7] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
allowAggregatesInExpressions = false;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SingleQuadHolder method mapValue.
// convert variable if in map
private Node mapValue(Node n, Map<Var, Node> values) {
Node retval = null;
if (n.isVariable()) {
Var v = Var.alloc(n);
retval = values.get(v);
}
return retval == null ? n : retval;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class ValuesHandler method addValueRow.
/**
* Add the values for the variables. There must be one value for each value
* var.
*
* @param values
* the collection of values to add.
* @return The builder for chaining.
*/
public void addValueRow(Collection<Node> values) {
if (values.size() != valuesTable.size()) {
throw new IllegalArgumentException(String.format("Number of values (%s) must match number of columns %s", values.size(), valuesTable.size()));
}
Iterator<Node> iter = values.iterator();
for (Var v : valuesTable.keySet()) {
List<Node> lst = getNodesList(v);
lst.add(iter.next());
}
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class ValuesHandler method addAll.
/**
* Add the ValuesHandler values to this values Handler.
*
* @param handler
* the handler that has the values to add.
*/
public void addAll(ValuesHandler handler) {
if (handler.valuesTable.size() == 0) {
return;
}
// assume our table is square.
int count = 0;
if (valuesTable.size() > 0) {
count = valuesTable.values().iterator().next().size();
}
for (Var var : handler.valuesTable.keySet()) {
List<Node> lst = valuesTable.get(var);
if (lst == null) {
lst = new ArrayList<Node>();
lst.addAll(Arrays.asList(new Node[count]));
valuesTable.put(var, lst);
}
lst.addAll(handler.valuesTable.get(var));
}
// keep table square by adding nulls to the vars that are not in the
// other table.
List<Var> lst = new ArrayList<Var>(valuesTable.keySet());
lst.removeAll(handler.valuesTable.keySet());
if (!lst.isEmpty()) {
count = handler.valuesTable.values().iterator().next().size();
for (Var var : lst) {
List<Node> lst2 = valuesTable.get(var);
lst2.addAll(Arrays.asList(new Node[count]));
}
}
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class DatasetHandler method setVars.
/**
* Set the variables for field names that contain lists of strings.
*
* Strings that start with "?" are assumed to be variable names and will be replaced
* with matching node.toString() values.
*
* @param values The values to set.
* @param fieldName The field name in Query that contain a list of strings.
*/
private void setVars(Map<Var, Node> values, List<String> lst) {
if (values.isEmpty() || lst == null || lst.isEmpty()) {
return;
}
for (int i = 0; i < lst.size(); i++) {
String s = lst.get(i);
Node n = null;
if (s.startsWith("?")) {
Var v = Var.alloc(s.substring(1));
n = values.get(v);
lst.set(i, n == null ? s : n.toString());
}
}
}
Aggregations