Java Code Examples for org.eclipse.rdf4j.query.algebra.Var#getName()
The following examples show how to use
org.eclipse.rdf4j.query.algebra.Var#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TupleFunctionFederatedService.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Value getValue(Var var, BindingSet bs) throws ValueExprEvaluationException { Value v = var.getValue(); if (v == null) { v = bs.getValue(var.getName()); } if (v == null) { throw new ValueExprEvaluationException("No value for binding: " + var.getName()); } return v; }
Example 2
Source File: ContextCollector.java From semagrow with Apache License 2.0 | 5 votes |
private boolean isSameCtx(Var v1, Var v2) { if ((v1 != null && v1.getValue() != null) && (v2 != null && v2.getValue() != null)) { return v1.getValue().equals(v2.getValue()); } else if ((v1 != null && v1.getName() != null) && (v2 != null && v2.getName() != null)) { return v1.getName().equals(v2.getName()); } return false; }
Example 3
Source File: GeoEnabledFilterFunctionOptimizer.java From rya with Apache License 2.0 | 5 votes |
@Override public void meet(final StatementPattern statement) { final Var object = statement.getObjectVar(); if (propertyVars.contains(object)) { if (usedVars.contains(object)) { throw new IllegalArgumentException("Illegal search, variable is used multiple times as object: " + object.getName()); } else { usedVars.add(object); matchStatements.add(statement); } } }
Example 4
Source File: FilterFunctionOptimizer.java From rya with Apache License 2.0 | 5 votes |
@Override public void meet(final StatementPattern statement) { final Var object = statement.getObjectVar(); if (propertyVars.contains(object)) { if (usedVars.contains(object)) { throw new IllegalArgumentException("Illegal search, variable is used multiple times as object: " + object.getName()); } else { usedVars.add(object); matchStatements.add(statement); } } }
Example 5
Source File: CopyRule.java From rya with Apache License 2.0 | 5 votes |
@Override public void meet(final Var node) { final String oldName = node.getName(); if (rule.varMap.containsKey(oldName)) { node.setName(rule.varMap.get(oldName).getName()); } else { if (node.hasValue() || node.equals(SUBJ_VAR) || node.equals(PRED_VAR) || node.equals(OBJ_VAR) || node.equals(CON_VAR)) { return; } node.setName(UNDEFINED_VAR.getName()); } }
Example 6
Source File: PeriodicQueryUtil.java From rya with Apache License 2.0 | 5 votes |
/** * * @param values - Values extracted from FunctionCall representing the PeriodicQuery Filter * @param arg - Argument of the PeriodicQueryNode that will be created (PeriodicQueryNode is a UnaryTupleOperator) * @return - PeriodicQueryNode to be inserted in place of the original FunctionCall * @throws Exception */ private static PeriodicQueryNode parseAndSetValues(List<ValueExpr> values, TupleExpr arg) throws Exception { // general validation of input Preconditions.checkArgument(values.size() == 4); Preconditions.checkArgument(values.get(0) instanceof Var); Preconditions.checkArgument(values.get(1) instanceof ValueConstant); Preconditions.checkArgument(values.get(2) instanceof ValueConstant); Preconditions.checkArgument(values.get(3) instanceof ValueConstant); // get temporal variable Var var = (Var) values.get(0); Preconditions.checkArgument(var.getValue() == null); String tempVar = var.getName(); // get TimeUnit TimeUnit unit = getTimeUnit((ValueConstant) values.get(3)); // get window and period durations double windowDuration = parseTemporalDuration((ValueConstant) values.get(1)); double periodDuration = parseTemporalDuration((ValueConstant) values.get(2)); long windowMillis = convertToMillis(windowDuration, unit); long periodMillis = convertToMillis(periodDuration, unit); // period must evenly divide window at least once Preconditions.checkArgument(windowMillis > periodMillis); Preconditions.checkArgument(windowMillis % periodMillis == 0, "Period duration does not evenly divide window duration."); // create PeriodicMetadata.Builder return new PeriodicQueryNode(windowMillis, periodMillis, TimeUnit.MILLISECONDS, tempVar, arg); }
Example 7
Source File: FluoStringConverter.java From rya with Apache License 2.0 | 5 votes |
/** * Provides a string representation of an SP which contains info about * whether each component (subj, pred, obj) is constant and its data and * data type if it is constant. * * @param sp - The statement pattern to convert. (not null) * @return A String representation of the statement pattern that may be * used to do triple matching. */ public static String toStatementPatternString(final StatementPattern sp) { checkNotNull(sp); final Var subjVar = sp.getSubjectVar(); String subj = subjVar.getName(); if(subjVar.getValue() != null) { final Value subjValue = subjVar.getValue(); subj = VarNameUtils.createSimpleConstVarName(subjVar); if (subjValue instanceof BNode ) { subj = subj + TYPE_DELIM + RyaSchema.BNODE_NAMESPACE + TYPE_DELIM + ((BNode) subjValue).getID(); } else { subj = subj + TYPE_DELIM + URI_TYPE; } } final Var predVar = sp.getPredicateVar(); String pred = predVar.getName(); if(predVar.getValue() != null) { pred = VarNameUtils.createSimpleConstVarName(predVar); pred = pred + TYPE_DELIM + URI_TYPE; } final Var objVar = sp.getObjectVar(); String obj = objVar.getName(); if (objVar.getValue() != null) { final Value objValue = objVar.getValue(); obj = VarNameUtils.createSimpleConstVarName(objVar); final RyaType rt = RdfToRyaConversions.convertValue(objValue); obj = obj + TYPE_DELIM + rt.getDataType().stringValue(); } return subj + DELIM + pred + DELIM + obj; }
Example 8
Source File: ContextCollector.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean isSameCtx(Var v1, Var v2) { if ((v1 != null && v1.getValue() != null) && (v2 != null && v2.getValue() != null)) { return v1.getValue().equals(v2.getValue()); } else if ((v1 != null && v1.getName() != null) && (v2 != null && v2.getName() != null)) { return v1.getName().equals(v2.getName()); } return false; }
Example 9
Source File: PrepareOwnedTupleExpr.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void appendVar(StringBuilder builder, Var var) { if (var.hasValue() && var.isAnonymous()) { Value value = var.getValue(); writeValue(builder, value); } else { String varName = var.getName(); appendVar(builder, varName); } builder.append(" "); }
Example 10
Source File: GeoRelationQuerySpecBuilder.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static String getVarName(ValueExpr v) { if (v instanceof Var) { Var var = (Var) v; if (!var.isConstant()) { return var.getName(); } } return null; }
Example 11
Source File: DistanceQuerySpec.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
static String getVarName(ValueExpr v) { if (v instanceof Var) { Var var = (Var) v; if (!var.isConstant()) { return var.getName(); } } return null; }
Example 12
Source File: QueryAlgebraUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Clone the specified variable and attach bindings, moreover change name of variable by appending "_varId" to it. * * @param var * @param varID * @param varNames * @param bindings * * @return the variable */ protected static Var appendVarId(Var var, String varID, Set<String> varNames, BindingSet bindings) { Var res = var.clone(); if (!var.hasValue()) { if (bindings.hasBinding(var.getName())) { res.setValue(bindings.getValue(var.getName())); } else { String newName = var.getName() + "_" + varID; varNames.add(newName); res.setName(newName); } } return res; }
Example 13
Source File: QueryStringUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Append the variable to the provided StringBuilder, however change name of variable by appending "_varId" to it. * * Cases: 1) unbound: check provided bindingset for possible match a) match found: append matching value b) no * match: append ?varName_varId and add to varNames 2) bound: append value * * @param sb * @param var * @param varNames * @param bindings * * @return the complemented string builder */ protected static StringBuilder appendVarId(StringBuilder sb, Var var, String varID, Set<String> varNames, BindingSet bindings) { if (!var.hasValue()) { if (bindings.hasBinding(var.getName())) { return appendValue(sb, bindings.getValue(var.getName())); } String newName = var.getName() + "_" + varID; varNames.add(newName); return sb.append("?").append(newName); } else { return appendValue(sb, var.getValue()); } }
Example 14
Source File: QueryAlgebraUtil.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
/** * Clone the specified variable and attach bindings, moreover change name of variable * by appending "_varId" to it. * * @param sb * @param var * @param varNames * @param bindings * * @return */ protected static Var appendVarId(Var var, String varID, Set<String> varNames, BindingSet bindings) { Var res = var.clone(); if (!var.hasValue()) { if (bindings.hasBinding(var.getName())) { res.setValue( bindings.getValue(var.getName()) ); } else { String newName = var.getName() + "_" + varID; varNames.add(newName); res.setName(newName); } } return res; }
Example 15
Source File: QueryStringUtil.java From CostFed with GNU Affero General Public License v3.0 | 4 votes |
public static String toString(Var var) { if (!var.hasValue()) return "?" + var.getName(); return getValueString(var.getValue()); }
Example 16
Source File: TupleExprBuilder.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
private TupleExpr processOrderClause(ASTOrderClause orderNode, TupleExpr tupleExpr, Group group) throws VisitorException { if (orderNode != null) { @SuppressWarnings("unchecked") List<OrderElem> orderElements = (List<OrderElem>) orderNode.jjtAccept(this, null); for (OrderElem orderElem : orderElements) { // retrieve any aggregate operators from the order element. AggregateCollector collector = new AggregateCollector(); collector.meet(orderElem); Extension extension = new Extension(); for (AggregateOperator operator : collector.getOperators()) { Var var = createAnonVar(); // replace occurrence of the operator in the order condition // with the variable. AggregateOperatorReplacer replacer = new AggregateOperatorReplacer(operator, var); replacer.meet(orderElem); // create an extension linking the operator to the variable // name. String alias = var.getName(); ExtensionElem pe = new ExtensionElem(operator, alias); extension.addElement(pe); // add the aggregate operator to the group. GroupElem ge = new GroupElem(alias, operator); group.addGroupElement(ge); } if (!extension.getElements().isEmpty()) { extension.setArg(tupleExpr); tupleExpr = extension; } } tupleExpr = new Order(tupleExpr, orderElements); } return tupleExpr; }
Example 17
Source File: QueryStringUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static String toString(Var var) { if (!var.hasValue()) { return "?" + var.getName(); } return getValueString(var.getValue()); }
Example 18
Source File: VarNameUtils.java From rya with Apache License 2.0 | 3 votes |
/** * Creates a simple constant name for a {@link Var} to replace the unique * hex string constant name. The simple constant name will be one of: * <ul> * <li>The var's original string value with "_const_" prepended to it if * it's a constant (i.e. the constant var name was already likely * derived from {@link TupleExprs#createConstVar(Value)})</li> * <li>The original var name if it's not a constant or if it has no * value to generate a simple constant name from</li> * <li>{@code null} if {@code var} is {@code null}</li> * </ul> * @param var the {@link Var}. * @return the simple constant var name. */ public static @Nullable String createSimpleConstVarName(@Nullable final Var var) { String varName = null; if (var != null) { if (var.getValue() != null && isConstant(var.getName())) { // Replaces the unique constant hex string name with a simple // readable constant name varName = prependConstant(var.getValue().stringValue()); } else { varName = var.getName(); } } return varName; }
Example 19
Source File: QueryStringUtil.java From CostFed with GNU Affero General Public License v3.0 | 3 votes |
/** * Append the variable to the provided StringBuilder, however change name of variable * by appending "_varId" to it. * * Cases: * 1) unbound: check provided bindingset for possible match * a) match found: append matching value * b) no match: append ?varName_varId and add to varNames * 2) bound: append value * * @param sb * @param var * @param varNames * @param bindings * * @return * the complemented string builder */ protected static StringBuilder appendVarId(StringBuilder sb, Var var, String varID, Set<String> varNames, BindingSet bindings) { if (!var.hasValue()) { if (bindings.hasBinding(var.getName())) return appendValue(sb, bindings.getValue(var.getName())); String newName = var.getName() + "_" + varID; varNames.add(newName); return sb.append("?").append(newName); } else return appendValue(sb, var.getValue()); }