private static String displayVariable(Variable term) { return "{" + ((Variable) term).getName() + "}"; }
Variable fakeClone = (Variable) currentVariable.clone(); return query.getChildren(currentNode).stream() .flatMap(n -> getDefinitions(
@Override public int compareTo(Variable other) { return name.compareTo(other.getName()); } }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof Variable)) { return false; } Variable name2 = (Variable) obj; return name.equals(name2.getName()); }
@Override public int compareTo(Variable other) { return name.compareTo(other.getName()); } }
@Override public String sqlGroupBy(List<Variable> groupby, String viewname) { String sql = "GROUP BY "; boolean needComma = false; for (Variable v : groupby) { if (needComma) { sql += ", "; } //sql += sqlQualifiedColumn(viewname, v.getName()); sql += String.format("\"%s\"", v.getName()); needComma = true; } return sql; }
@Override public String sqlGroupBy(List<Variable> groupby, String viewname) { String sql = "GROUP BY "; boolean needComma = false; for (Variable v : groupby) { if (needComma) { sql += ", "; } //sql += sqlQualifiedColumn(viewname, v.getName()); sql += String.format("\"%s\"", v.getName()); needComma = true; } return sql; }
@Override public String sqlGroupBy(List<Variable> groupby, String viewname) { String sql = "GROUP BY "; boolean needComma = false; for (Variable v : groupby) { if (needComma) { sql += ", "; } //sql += sqlQualifiedColumn(viewname, v.getName()); sql += String.format("\"%s\"", v.getName()); needComma = true; } return sql; }
@Override public void registerAdditionalVariables(Collection<Variable> additionalVariables) { additionalVariables .forEach(v -> knownVariableMap.put(v.getName(), v)); }
private static int compareVariable(Variable v1, ImmutableTerm a2) { if (a2 instanceof Variable) // TODO: should we normalize? return v1.getName().hashCode() - ((Variable)a2).getName().hashCode(); else if (a2 instanceof Constant) { return -1; } else if (a2 instanceof ImmutableFunctionalTerm) { return 1; } else { throw new IllegalStateException("Unexpected term:" + a2); } }
private static int compareVariable(Variable v1, ImmutableTerm a2) { if (a2 instanceof Variable) // TODO: should we normalize? return v1.getName().hashCode() - ((Variable)a2).getName().hashCode(); else if (a2 instanceof Constant) { return -1; } else if (a2 instanceof ImmutableFunctionalTerm) { return 1; } else { throw new IllegalStateException("Unexpected term:" + a2); } }
@Override public Variable generateNewVariableFromVar(Variable previousVariable) { knownVariableMap.put(previousVariable.getName(), previousVariable); Matcher matcher = PREFIX_PATTERN.matcher(previousVariable.getName()); String prefix = matcher.matches() ? matcher.group(1) : DEFAULT_PREFIX; return generateNewVariable(prefix); }
public Variable generateNewVariableFromVar(Variable previousVariable) { knownVariables.add(previousVariable); Variable newVariable; do { newVariable = termFactory.getVariable(previousVariable.getName() + SUFFIX_PREFIX + (count++)); } while(knownVariables.contains(newVariable)); knownVariables.add(newVariable); return newVariable; }
/** * Generates a new variable if a conflict is detected. */ public Variable generateNewVariableIfConflicting(Variable previousVariable) { Variable newVariable = previousVariable; while(knownVariables.contains(newVariable)) { newVariable = TERM_FACTORY.getVariable(previousVariable.getName() + SUFFIX_PREFIX + (count++)); } knownVariables.add(newVariable); return newVariable; }
public Variable generateNewVariableIfConflicting(Variable previousVariable) { Variable newVariable = previousVariable; while(knownVariables.contains(newVariable)) { newVariable = termFactory.getVariable(previousVariable.getName() + SUFFIX_PREFIX + (count++)); } knownVariables.add(newVariable); return newVariable; }
private static String appendTerms(Term term){ if (term instanceof Constant){ String st = ((Constant) term).getValue(); if (st.contains("{")){ st = st.replace("{", "\\{"); st = st.replace("}", "\\}"); } return st; }else{ return "{"+((Variable) term).getName()+"}"; } }
/** * Generates a new non-conflicting variable from a previous one. * It will reuse its name. */ public Variable generateNewVariableFromVar(Variable previousVariable) { Variable newVariable; do { newVariable = TERM_FACTORY.getVariable(previousVariable.getName() + SUFFIX_PREFIX + (count++)); } while(knownVariables.contains(newVariable)); knownVariables.add(newVariable); return newVariable; }
private static String appendTerms(ImmutableTerm term) { if (term instanceof Constant) { String st = ((Constant) term).getValue(); if (st.contains("{")) { st = st.replace("{", "\\{"); st = st.replace("}", "\\}"); } return st; } else { return "{" + ((Variable) term).getName() + "}"; } }
private static Map<String, List<IndexedPosition>> createIndex(List<Function> body) { Map<String, List<IndexedPosition>> termOccurenceIndex = new HashMap<>(); for (Function a : body) { List<Term> terms = a.getTerms(); int i = 1; // position index for (Term t : terms) { if (t instanceof Variable) { Variable var = (Variable) t; List<IndexedPosition> aux = termOccurenceIndex.get(var.getName()); if (aux == null) aux = new LinkedList<>(); aux.add(new IndexedPosition(a, i)); termOccurenceIndex.put(var.getName(), aux); } else if (t instanceof FunctionalTermImpl) { // NO-OP } else if (t instanceof ValueConstant) { // NO-OP } else if (t instanceof IRIConstant) { // NO-OP } // fabad (4 Oct 2017) Quick fix if there are constants in arguments. // Increase i in all cases. If there are terms that are not variables // and i is not incremented then indexedPosition.pos contains a wrong // index that may points to terms that are not variables. i++; // increase the position index for the next variable } } return termOccurenceIndex; }