Class BaseTransform
java.lang.Object
org.eclipse.rdf4j.queryrender.sparql.ir.util.transform.BaseTransform
- Direct Known Subclasses:
ApplyCollectionsTransform, ApplyNegatedPropertySetTransform, ApplyNormalizeGraphInnerPathsTransform, ApplyPathsFixedPointTransform, ApplyPathsTransform, CanonicalizeBareNpsOrientationTransform, CanonicalizeGroupedTailStepTransform, CanonicalizeNpsByProjectionTransform, CanonicalizeUnionBranchOrderTransform, CoalesceAdjacentGraphsTransform, FlattenSingletonUnionsTransform, FuseAltInverseTailBGPTransform, FusePathPlusTailAlternationUnionTransform, FusePrePathThenUnionAlternationTransform, FuseServiceNpsUnionLateTransform, FuseUnionOfNpsBranchesTransform, FuseUnionOfPathTriplesPartialTransform, FuseUnionOfSimpleTriplesTransform, GroupFilterExistsWithPrecedingTriplesTransform, GroupUnionOfSameGraphBranchesTransform, GroupValuesAndNpsInUnionBranchTransform, LiftPathUnionScopeInsideGraphTransform, MergeAdjacentValuesTransform, MergeFilterExistsIntoPrecedingGraphTransform, MergeOptionalIntoPrecedingGraphTransform, NormalizeFilterNotInTransform, NormalizeNpsMemberOrderTransform, NormalizeZeroOrOneSubselectTransform, ReorderFiltersInOptionalBodiesTransform, SimplifyPathParensTransform, UnwrapSingleBgpInUnionBranchesTransform
Shared helpers and small utilities for IR transform passes.
Conventions and invariants: - Transforms are functional: they do not mutate input nodes; instead they build new IR
blocks as needed. - Path/chain fusions are conservative and only cross intermediate variables that the parser created
for property paths (variable names prefixed with
_anon_path_). This prevents accidental elimination or
inversion of user-defined variables. - Text helpers respect property path precedence and add parentheses only when
required for correctness. - Container nodes (GRAPH/OPTIONAL/MINUS/UNION/SERVICE) are preserved, and recursion uses
transformChildren to keep transform code small and predictable.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IrBGPbgpWithLines(IrBGP original, List<IrNode> lines) Build a new IrBGP with the same scope flag and the provided lines.static booleanbranchHasAnonPathBridge(IrBGP branch) True if the given branch contains at least one variable with the parser-generated _anon_path_ (or inverse variant) prefix anywhere in its simple triple-like structures.static voidcopyAllExcept(IrBGP from, IrBGP to, IrNode except) static IrBGPFuse adjacent IrPathTriple nodes when the first's object equals the second's subject.static IrBGPstatic IrBGPFuse a path triple whose object is a bridge var with a constant-IRI tail triple that also uses the bridge var, producing a new path with an added '/^p' or '/p' segment.static IrBGPFuse a three-line sequence: IrPathTriple (A), IrStatementPattern (B), IrPathTriple (C) into A then ( ^B.p / C ).static StringinvertNegatedPropertySet(String npsText) If the given path text is a negated property set of the form !static Stringiri(Var pred, TupleExprIRRenderer r) Convenience: render a constant-IRI predicate Var to text.static booleanTrue when the anonymous path var explicitly encodes inverse orientation.static booleanisAnonPathVar(Var v) static booleanConvenience: true iff SP has a constant-IRI predicate.static IrBGPstatic StringmergeNpsMembers(String a, String b) Merge NPS members of two canonical strings '!static StringnormalizeCompactNps(String path) Normalize compact negated-property-set forms into the canonical parenthesized variant.static IrBGPRe-orient a bare negated property set path "!static IrNoderewriteContainers(IrNode n, Function<IrBGP, IrBGP> f) Utility: rewrite container nodes by applying a given function to their inner IrBGP children.static booleanstatic booleansameVarOrValue(Var a, Var b) True when both variables denote the same term: compares names if both are variables without value, or compares values if both are constants.static booleanTrue if all UNION branches contain at least one _anon_path_* variable (or inverse variant).static booleanNew-scope UNION safety: true iff the two UNION branches share at least one _anon_path_* variable name.static booleanTrue if all UNION branches share at least one common variable name that starts with the _anon_path_ prefix.static booleanUniversal safeguard for explicit user UNIONs: true iff the UNION is marked as new scope and all its branches are also marked as new scope.static StringvarOrValue(Var v, TupleExprIRRenderer r)
-
Field Details
-
ANON_PATH_PREFIX
- See Also:
-
ANON_PATH_INVERSE_PREFIX
- See Also:
-
-
Constructor Details
-
BaseTransform
public BaseTransform()
-
-
Method Details
-
isConstantIriPredicate
Convenience: true iff SP has a constant-IRI predicate. -
iri
Convenience: render a constant-IRI predicate Var to text. Returns null if not a constant IRI. -
normalizeCompactNps
-
mergeNpsMembers
-
unionIsExplicitAndAllBranchesScoped
Universal safeguard for explicit user UNIONs: true iff the UNION is marked as new scope and all its branches are also marked as new scope. Such a UNION should never be fused into a single path expression. -
rewriteContainers
Utility: rewrite container nodes by applying a given function to their inner IrBGP children. Non-container nodes are returned unchanged. This abstracts common recursion boilerplate across many transforms and ensures newScope and other flags are preserved consistently for containers. Containers handled: IrGraph, IrOptional, IrMinus, IrService, IrUnion. Nested IrBGP lines that appear directly inside a parent IrBGP (explicit grouping) are intentionally left unchanged here — transforms should decide if and how to recurse into such explicit groups. -
bgpWithLines
-
copyAllExcept
-
fuseAdjacentPtThenPt
-
fusePtSpPtSequence
Fuse a three-line sequence: IrPathTriple (A), IrStatementPattern (B), IrPathTriple (C) into A then ( ^B.p / C ). Pattern constraints: - A.object equals B.object (inverse join candidate) and A.object is an _anon_path_* var. - B.subject equals C.subject and both B.subject and B.object are _anon_path_* vars. -
orientBareNpsForNext
-
fuseAdjacentSpThenPt
-
joinPathWithLaterSp
-
sameVar
-
sameVarOrValue
-
isAnonPathVar
-
isAnonPathInverseVar
True when the anonymous path var explicitly encodes inverse orientation. -
branchHasAnonPathBridge
True if the given branch contains at least one variable with the parser-generated _anon_path_ (or inverse variant) prefix anywhere in its simple triple-like structures. Used as a safety valve to allow certain fusions across UNION branches that were marked as introducing a new scope in the algebra: if every branch contains an anonymous path bridge var, the fusion is considered safe and preserves user-visible bindings. -
unionBranchesAllHaveAnonPathBridge
True if all UNION branches contain at least one _anon_path_* variable (or inverse variant). Rationale: when there is no explicit UNION scope, this safety gate ensures branch bodies are derived from path-decoding internals rather than user variables, so fusing to an alternation/NPS preserves semantics. -
invertNegatedPropertySet
-
fuseAltInverseTailBGP
Fuse a path triple whose object is a bridge var with a constant-IRI tail triple that also uses the bridge var, producing a new path with an added '/^p' or '/p' segment. This version indexes join candidates and works inside GRAPH bodies as well. It is conservative: only constant predicate tails are fused and containers are preserved. -
varOrValue
-