private static String displayVariable(Variable term) { return "{" + ((Variable) term).getName() + "}"; }
@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 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 Function getFreshAtom(Function a, String suffix) { List<Term> termscopy = new ArrayList<>(a.getArity()); for (Term t : a.getTerms()) { if (t instanceof Variable) { Variable v = (Variable)t; termscopy.add(termFactory.getVariable(v.getName() + suffix)); } else termscopy.add(t.clone()); } return termFactory.getFunction(a.getFunctionSymbol(), termscopy); }
private IQ appendSuffixToVariableNames(IQ query, int suffix) { Map<Variable, Variable> substitutionMap = query.getTree().getKnownVariables().stream() .collect(Collectors.toMap( v -> v, v -> termFactory.getVariable(v.getName()+"m"+suffix))); QueryRenamer queryRenamer = transformerFactory.createRenamer(substitutionFactory.getInjectiveVar2VarSubstitution(substitutionMap)); return queryRenamer.transform(query); } }
private static IntermediateQuery appendSuffixToVariableNames(QueryTransformerFactory transformerFactory, IntermediateQuery query, int suffix) { Map<Variable, Variable> substitutionMap = query.getKnownVariables().stream() .collect(ImmutableCollectors.toMap( v -> v, v -> TERM_FACTORY.getVariable(v.getName()+"m"+suffix) )); QueryRenamer queryRenamer = transformerFactory.createRenamer(SUBSTITUTION_FACTORY.getInjectiveVar2VarSubstitution(substitutionMap)); return queryRenamer.transform(query); } }