/** * This method takes a immutable term and convert it into an old mutable function. */ public Function convertToMutableFunction(ImmutableFunctionalTerm functionalTerm) { return convertToMutableFunction(functionalTerm.getFunctionSymbol(), functionalTerm.getTerms()); }
/** * check if the term is {@code URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")} * * TODO: refactor so as to use RDFPredicate.getClassIRI() instead */ private static boolean isURIRDFType(ImmutableTerm term) { if (term instanceof ImmutableFunctionalTerm) { ImmutableFunctionalTerm func = (ImmutableFunctionalTerm) term; if (func.getArity() == 1 && (func.getFunctionSymbol() instanceof URITemplatePredicate)) { ImmutableTerm t0 = func.getTerm(0); if (t0 instanceof ValueConstant) return ((ValueConstant) t0).getValue().equals(RDF.TYPE.getIRIString()); } } return false; }
private static ImmutableTerm normalizeFunctionalTerm(ImmutableFunctionalTerm functionalTerm) { if (isSupportingNullArguments(functionalTerm)) { return functionalTerm; } ImmutableList<ImmutableTerm> newArguments = functionalTerm.getArguments().stream() .map(arg -> (arg instanceof ImmutableFunctionalTerm) ? normalizeFunctionalTerm((ImmutableFunctionalTerm) arg) : arg) .collect(ImmutableCollectors.toList()); if (newArguments.stream() .anyMatch(arg -> arg.equals(TermConstants.NULL))) { return TermConstants.NULL; } return TERM_FACTORY.getImmutableFunctionalTerm(functionalTerm.getFunctionSymbol(), newArguments); }
/** * TODO: refactor this weak code!!! */ private static ImmutableTerm tryToExtractIRITemplateString(ImmutableTerm term) { if (term instanceof ImmutableFunctionalTerm) { ImmutableFunctionalTerm functionalTerm = (ImmutableFunctionalTerm) term; return functionalTerm.getArity() > 0 ? tryToExtractIRITemplateString(functionalTerm.getTerm(0)) : term; } return term; }
/** * TODO: move it elsewhere */ private static boolean isSupportingNullArguments(ImmutableFunctionalTerm functionalTerm) { Predicate functionSymbol = functionalTerm.getFunctionSymbol(); if (functionSymbol instanceof ExpressionOperation) { switch((ExpressionOperation)functionSymbol) { case IS_NOT_NULL: case IS_NULL: // TODO: add COALESCE, EXISTS, NOT EXISTS return true; default: return false; } } else if ((functionSymbol instanceof URITemplatePredicate) || (functionSymbol instanceof BNodePredicate)) { return false; } return true; }
.filter(e -> e.getValue() instanceof ImmutableFunctionalTerm) .flatMap(e -> { ImmutableList<? extends ImmutableTerm> subTerms = ((ImmutableFunctionalTerm) e.getValue()).getTerms(); return IntStream.range(0, subTerms.size()) .filter(i -> subTerms.get(i) instanceof ImmutableFunctionalTerm) Variable v = e.getKey(); ImmutableFunctionalTerm def = (ImmutableFunctionalTerm) substitution.get(v); ImmutableList<ImmutableTerm> newArgs = IntStream.range(0, def.getArity()) .boxed() .map(i -> Optional.ofNullable((ImmutableTerm) subTermNames.get(v, i)) .orElseGet(() -> def.getTerm(i))) .collect(ImmutableCollectors.toList()); def.getFunctionSymbol(), newArgs); return Maps.immutableEntry(v, newDef); }) .collect(ImmutableCollectors.toMap( Table.Cell::getValue, c -> ((ImmutableFunctionalTerm) substitution.get(c.getRowKey())).getTerm(c.getColumnKey()))));
if (f1.isGround() && (!f2.isGround())) return 1; else if ((!f1.isGround()) && f2.isGround()) return -1; int functionSymbolComparison = f1.getFunctionSymbol().hashCode() - f2.getFunctionSymbol().hashCode(); if (functionSymbolComparison != 0) return functionSymbolComparison; ImmutableList<? extends ImmutableTerm> arguments1 = f1.getTerms(); ImmutableList<? extends ImmutableTerm> arguments2 = f2.getTerms();
if (predf.getFunctionSymbol() instanceof URITemplatePredicate) { if (predf.getTerms().size() == 1) { //fixed string predUri = rdfFactory.createIRI(((ValueConstant)(predf.getTerm(0))).getValue()); && ((ImmutableFunctionalTerm) object).getFunctionSymbol() instanceof URITemplatePredicate && ((ImmutableFunctionalTerm) object).getTerms().size() == 1) { IRI classIRI = rdfFactory.createIRI(((ValueConstant)(((ImmutableFunctionalTerm) object).getTerm(0))).getValue()); Predicate objectPred = o.getFunctionSymbol(); if (objectPred instanceof URITemplatePredicate) { ImmutableTerm objectTerm = o.getTerm(0); ImmutableTerm objectTerm = o.getTerm(0); Predicate functionSymbol = functionalObjectTerm.getFunctionSymbol(); ImmutableList<? extends ImmutableTerm> terms = functionalObjectTerm.getTerms(); TargetQueryRenderer.getNestedConcats(sb, terms.get(0),terms.get(1)); obm = mfact.createObjectMap(mfact.createTemplate(sb.toString()));
if (f1.isGround() && (!f2.isGround())) return 1; else if ((!f1.isGround()) && f2.isGround()) return -1; int functionSymbolComparison = f1.getFunctionSymbol().hashCode() - f2.getFunctionSymbol().hashCode(); if (functionSymbolComparison != 0) return functionSymbolComparison; ImmutableList<? extends ImmutableTerm> arguments1 = f1.getArguments(); ImmutableList<? extends ImmutableTerm> arguments2 = f2.getArguments();
private static String displayConcat(ImmutableFunctionalTerm function) { StringBuilder sb = new StringBuilder(); ImmutableList<? extends ImmutableTerm> terms = function.getTerms(); sb.append("\""); getNestedConcats(sb, terms.get(0), terms.get(1)); sb.append("\""); return sb.toString(); }
/** * TODO: make it more robust */ protected Optional<IRI> extractIRI(ImmutableTerm term) { if (term instanceof IRIConstant) { return Optional.of(((IRIConstant) term).getIRI()); } // TODO: look for the RDF building function (and check the type is an IRI) else if (term instanceof ImmutableFunctionalTerm) { return ((ImmutableFunctionalTerm) term).getArity() == 1 ? extractIRI(((ImmutableFunctionalTerm) term).getTerms().get(0)) : Optional.empty(); } else if (term instanceof ValueConstant) { return Optional.of(rdfFactory.createIRI( ((ValueConstant) term).getValue())); } return Optional.empty(); } }
for (Pattern pattern : patternsMatched) { ImmutableFunctionalTerm matchingFunction = uriTemplateMatcher.get(pattern); ImmutableTerm baseParameter = matchingFunction.getTerm(0); if (baseParameter instanceof Constant) {
private boolean hasNullableArgument(ImmutableFunctionalTerm functionalTerm, ImmutableSet<Variable> nullableVariables) { return functionalTerm.getArguments().stream() .anyMatch(t -> isNullable(t, nullableVariables)); }
/** * TODO: move it elsewhere */ private static boolean isSupportingNullArguments(ImmutableFunctionalTerm functionalTerm) { Predicate functionSymbol = functionalTerm.getFunctionSymbol(); if (functionSymbol instanceof ExpressionOperation) { switch((ExpressionOperation)functionSymbol) { case IS_NOT_NULL: case IS_NULL: // TODO: add COALESCE, EXISTS, NOT EXISTS return true; default: return false; } } else if ((functionSymbol instanceof URITemplatePredicate) || (functionSymbol instanceof BNodePredicate)) { return false; } return true; }
if (!sourceFunctionalTerm.getFunctionSymbol().equals( targetFunctionalTerm.getFunctionSymbol())) { return Optional.empty(); if (sourceFunctionalTerm.isGround()) { if (sourceFunctionalTerm.equals(targetFunctionalTerm)) { return Optional.of(substitutionFactory.getSubstitution()); ImmutableList<? extends ImmutableTerm> sourceChildren = sourceFunctionalTerm.getTerms(); ImmutableList<? extends ImmutableTerm> targetChildren = targetFunctionalTerm.getTerms();
private boolean hasNullableArgument(ImmutableFunctionalTerm functionalTerm, ImmutableSet<Variable> nullableVariables) { return functionalTerm.getTerms().stream() .anyMatch(t -> isNullable(t, nullableVariables)); }
for (Pattern pattern : patternsMatched) { ImmutableFunctionalTerm matchingFunction = uriTemplateMatcher.get(pattern); ImmutableTerm baseParameter = matchingFunction.getTerm(0); if (baseParameter instanceof Constant) {
public static boolean match(String keyword, ImmutableTerm term) { if (term instanceof ImmutableFunctionalTerm) { ImmutableFunctionalTerm functionTerm = (ImmutableFunctionalTerm) term; if (functionTerm.getFunctionSymbol().toString().contains(keyword)) { // match found! return true; } // Recursive return functionTerm.getTerms().stream() .anyMatch(t -> match(keyword, t)); } if (term instanceof Variable) { return ((Variable) term).getName().contains(keyword); // match found! } return false; } }