private Optional<Function> getFirstFunctionalTerm (Function inputFunction) { return inputFunction.getTerms().stream() .findFirst() .filter(t -> t instanceof Function) .map(t -> (Function) t); }
public static void addReferencedVariablesTo(Collection<Variable> vars, Function f) { for (Term t : f.getTerms()) { if (t instanceof Variable) vars.add((Variable)t); else if (t instanceof Function) addReferencedVariablesTo(vars, (Function)t); // else (t instanceof BNode) || (t instanceof URIConstant) || (t instanceof ValueConstant) // no-op } }
public static boolean isGrounded(Term term) { boolean result = true; if (term instanceof Variable) { result = false; } else if (term instanceof Function) { Function func = (Function) term; for (Term subTerm : func.getTerms()) { if (!isGrounded(subTerm)) result = false; } } return result; } }
public static void getNestedConcats(StringBuilder stb, Term term1, Term term2){ if (term1 instanceof Function){ Function f = (Function) term1; getNestedConcats(stb, f.getTerms().get(0), f.getTerms().get(1)); }else{ stb.append(appendTerms(term1)); } if (term2 instanceof Function){ Function f = (Function) term2; getNestedConcats(stb, f.getTerms().get(0), f.getTerms().get(1)); }else{ stb.append(appendTerms(term2)); } }
protected CQIEImpl(Function head, Function[] body) { // The syntax for CQ may contain no body, thus, this condition will // check whether the construction of the link list is possible or not. if (body != null) { EventGeneratingList<Function> eventbody = new EventGeneratingLinkedList<Function>(); Collections.addAll(eventbody, body); this.body = eventbody; registerListeners(eventbody); // TODO possible memory leak!!! we should also de-register when objects are removed } // The syntax for CQ may also contain no head, thus, this condition // will check whether we can look for the head terms or not. if (head != null) { this.head = head; EventGeneratingList<Term> headterms = (EventGeneratingList<Term>) head.getTerms(); headterms.addListener(this); } }
private void registerListeners(EventGeneratingList<? extends Term> functions) { functions.addListener(this); for (Object o : functions) { if (!(o instanceof Function)) { continue; } Function f = (Function) o; EventGeneratingList<Term> list = (EventGeneratingList<Term>) f.getTerms(); list.addListener(this); registerListeners(list); } }
public void updateHead(Function head) { this.head = head; EventGeneratingList<Term> headterms = (EventGeneratingLinkedList<Term>) head.getTerms(); headterms.removeListener(this); headterms.addListener(this); listChanged(); }
private void registerListeners(EventGeneratingList<? extends Term> functions) { functions.addListener(this); for (Object o : functions) { if (!(o instanceof Function)) { continue; } Function f = (Function) o; EventGeneratingList<Term> list = (EventGeneratingList<Term>) f.getTerms(); list.addListener(this); registerListeners(list); } }
int len = uriTermForPredicate.getTerms().size(); List<Variable> vars;
private Term getFreshTerm(Term term, int suff) { Term newTerm; if (term instanceof Variable) { Variable variable = (Variable) term; newTerm = getVariable(variable.getName() + "_" + suff); } else if (term instanceof Function) { Function functionalTerm = (Function) term; List<Term> innerTerms = functionalTerm.getTerms(); List<Term> newInnerTerms = new LinkedList<>(); for (int j = 0; j < innerTerms.size(); j++) { Term innerTerm = innerTerms.get(j); newInnerTerms.add(getFreshTerm(innerTerm, suff)); } Predicate newFunctionSymbol = functionalTerm.getFunctionSymbol(); Function newFunctionalTerm = getFunction(newFunctionSymbol, newInnerTerms); newTerm = newFunctionalTerm; } else if (term instanceof Constant) { newTerm = term.clone(); } else { throw new RuntimeException("Unsupported term: " + term); } return newTerm; }
Term var = function.getTerms().get(0); sb.append(getDisplayName(var, prefixManager)); sb.append("^^rdfs:Literal"); } else if (arity == 2) { Term var = function.getTerms().get(0); Term lang = function.getTerms().get(1); sb.append(getDisplayName(var, prefixManager)); sb.append("@"); Term var = function.getTerms().get(0); sb.append(getDisplayName(var, prefixManager)); sb.append("^^"); Term firstTerm = function.getTerms().get(0); for (Term innerTerm : function.getTerms()) { if (innerTerm instanceof Variable) { varNames.add(getDisplayName(innerTerm, prefixManager)); List<Term> terms = function.getTerms(); sb.append("\""); getNestedConcats(sb, terms.get(0),terms.get(1)); sb.append("("); boolean separator = false; for (Term innerTerm : function.getTerms()) { if (separator) { sb.append(", ");
protected CQIEImpl(Function head, List<Function> body) { // The syntax for CQ may contain no body, thus, this condition will // check whether the construction of the link list is possible or not. if (body != null) { EventGeneratingList<Function> eventbody = new EventGeneratingLinkedList<Function>(); eventbody.addAll(body); this.body = eventbody; registerListeners(eventbody); // TODO possible memory leak!!! we should also de-register when objects are removed } // The syntax for CQ may also contain no head, thus, this condition // will check whether we can look for the head terms or not. if (head != null) { this.head = head; EventGeneratingList<Term> headterms = (EventGeneratingList<Term>) head.getTerms(); headterms.addListener(this); } }
List<Term> terms = func.getTerms(); List<Term> newTerms = new ArrayList<>(terms.size()); for (Term innerTerm : terms)
if (predf.getTerms().size() == 1) //fixed string
if (predf.getTerms().size() == 1) { //fixed string pred = OBDADataFactoryImpl.getInstance().getPredicate(((ValueConstant)(predf.getTerm(0))).getValue(), 1); predUri = vf.createURI(pred.getName()); List<Term> terms = ((Function)objectTerm).getTerms(); TargetQueryRenderer.getNestedConcats(sb, terms.get(0),terms.get(1)); obm = mfact.createObjectMap(mfact.createTemplate(sb.toString()));