Skip to content

Commit f8742d8

Browse files
committed
Add variable scope information for select
1 parent c9d1695 commit f8742d8

File tree

1 file changed

+21
-5
lines changed
  • src/app/docs/woql-explanation

1 file changed

+21
-5
lines changed

src/app/docs/woql-explanation/page.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ nextjs:
1111
media: []
1212
---
1313

14+
This page explains various topics regarding the WOQL datalog query language.
15+
1416
## WOQL fluent vs. functional style
1517

1618
WOQL supports both **functional** and **fluent** styles for writing queries. Overall, the functional style is recommended to avoid snags. The fluent style may help for simplifying complex compound query expressions.
@@ -112,10 +114,12 @@ and(
112114

113115
## WOQL and JSON-LD
114116

115-
WOQL uses JSON-LD and a formally specified [ontology](/docs/glossary/#ontology) to define the language and transmit queries.
117+
The WOQL composable logic is expressed internally in JSON-LD and a formally specified [ontology](/docs/glossary/#ontology) to define the language and transmit queries.
116118

117119
JSON-LD is sometimes tedious for us to read and write. Therefore, WOQL.js is designed to be as easy as possible for developers to write. All WOQL.js queries are translated into the equivalent JSON-LD format for transmission over networks.
118120

121+
Javascript and Python clients convert the in-language supported WOQL queries to an internal Abstract Syntax Tree for transmission to the server, enabling advanced software to compose logic on the fly. This allows higher order logical constructs to be generated automatically.
122+
119123
### The WOQLQuery object
120124

121125
The WOQL.js `json()` function translates any WOQL query to its JSON-LD format, and JSON-LD to its WOQL.js equivalent - a `WOQLQuery()` object.
@@ -145,17 +149,23 @@ triple(a, b, 1) == triple(a, b, {"@type": "xsd:integer", "@value": 1})
145149

146150
WOQL allows variables or constants to be substituted for any argument to all its functions, except for the resource identifier functions: `using`, `with`, `into`, `from`. These functions are used for specifying the graphs against which operations such as queries are carried out.
147151

152+
### Variable scope
153+
154+
Variables are locally scoped to be available across the WOQL query. They can be further scoped down using the `select()` WOQL function that filters the result of a subfunction so that only the selected variables are exposed to the rest of the query.
155+
156+
This is useful for creating powerful higher order constructs. Make sure to clarify what variables are made available through such composable logic block and use unique and specific names for them so that the higher order functions do not conflict.
157+
148158
### Unification
149159

150160
WOQL uses the formal-logical approach to variables known as unification borrowed from the Prolog engine that implements WOQL within TerminusDB.
151161

152-
### Unification in variables
162+
This means that variables start as floating variables that can match any possible value in a range, initially any value in scope, such as the subject, predicate or objects of triples and quads.
153163

154-
Unification in variables means each valid value for a variable, as constrained by the totality of the query, will produce a new row in the results. For multiple variables, the rows returned are the cartesian product of all the possible combinations of variable values in the query.
164+
Some variables are deterministic, such as when a CSV file has been loaded, and bound to their specific values which prevents values that reference them to for example have optional values.
155165

156-
### Unification in functions
166+
### Unification in variables
157167

158-
Unification in functions enables most WOQL functions to serve as both pattern matchers and pattern generators, depending on whether a variable or constant is provided as an argument. If a variable is provided, WOQL will generate all possible valid solutions which fill the variable value. If a constant is provided, WOQL will match only those solutions with exactly that value. Except for resource identifiers, WOQL functions accept either variables or constants in virtually all of their arguments.
168+
Unification in variables means each valid value for a variable, as constrained by the totality of the query, will produce a new row in the results. For multiple variables, the rows returned are the cartesian product of all the possible combinations of variable values in the query.
159169

160170
### Expressing variables
161171

@@ -174,6 +184,12 @@ triple(a, b, c)
174184
triple('v:a', 'v:b', 'v:c')
175185
```
176186

187+
## Unification in functions
188+
189+
Unification in functions enables most WOQL functions to serve as both pattern matchers and pattern generators, depending on whether a variable or constant is provided as an argument. If a variable is provided, WOQL will generate all possible valid solutions which fill the variable value.
190+
191+
If a constant is provided, WOQL will match only those solutions with exactly that value. Except for resource identifiers, WOQL functions accept either variables or constants in virtually all of their arguments.
192+
177193
## WOQL prefixes
178194

179195
Internally, TerminusDB uses strict [RDF](/docs/glossary/#rdf) rules to represent all data. This means all identifiers and properties are represented by [IRIs](/docs/glossary/#iri) (a superset of URLs.)

0 commit comments

Comments
 (0)