Functions to support interacting with a SPARQL endpoint.
See also https://www.w3.org/TR/sparql11-query.
Functions to support interacting with a SPARQL endpoint. See also `https://www.w3.org/TR/sparql11-query`.
(angle-bracket-uri s)returns <s> if it matches the scheme for a URI, else returns s.
returns <`s`> if it matches the scheme for a URI, else returns `s`.
A map with keys :uri :lang :datatype, each mapping to translator
Where
translator := (fn[var-value]) -> translated valuevar-value :={'value' value
'type' 'uri' | 'literal'
...maybe...
'xml:lang' lang (if literal)
'datatype' datatype (if literal)
}A map with keys :uri :lang :datatype, each mapping to `translator`
Where
- `translator` := (fn[var-value]) -> `translated value`
- `var-value` :={'value' `value`
'type' 'uri' | 'literal'
...maybe...
'xml:lang' `lang` (if literal)
'datatype' `datatype` (if literal)
}
(literal->LangStr literal)Returns an instance of LangStr for literal
Where
literal is a language-tagged literal returned from a queryReturns an instance of `LangStr` for `literal` Where - `literal` is a language-tagged literal returned from a query
(make-simplifier translators)Returns simplifier-fn -> for translators
Where
simplier-fn := fn[var-map] -> {var-keyword translated-value, ...}translators := m s.t. (keys m) = keysk is in keysvfn := fn [value] -> translated-valuekeys := #{:uri :lang :datatype :bnode}var-keyword is keyword corresponding to vartranslated-value is value from var-value, translated using translatorsReturns `simplifier-fn` -> for `translators`
Where
- `simplier-fn` := fn[`var-map`] -> {`var-keyword` `translated-value`, ...}
- `translators` := m s.t. (keys m) = `keys`
- `k` is in `keys`
- `vfn` := fn [`value`] -> `translated-value`
- `keys` := #{:uri :lang :datatype :bnode}
- `var-keyword` is keyword corresponding to `var`
- `translated-value` is `value` from `var-value`, translated using `translators` (meta-tagged-literal literal)Returns a reified object s.t. ^{:type type, k v, ...} Object.toString(this) -> value
Where
literal is a sparql binding value-map s.t.
{type literal, k v, value value ...}type is one of ::langString ::datatypek is any key in literal except 'type' and 'value', e.g. xml:lang or datatypev is the value associated with k in literal
NOTE: type ::langString keys to a print-method and the function
ont-app.vocabulary.lstr/read-LangStr, supporting the #langString reader macroReturns a reified object s.t. ^{:type `type`, `k` `v`, ...} Object.toString(this) -> value
Where
- `literal` is a sparql binding value-map s.t.
{type literal, `k` `v`, value `value` ...}
- `type` is one of ::langString ::datatype
- `k` is any key in `literal` except 'type' and 'value', e.g. xml:lang or datatype
- `v` is the value associated with `k` in `literal`
NOTE: type ::langString keys to a print-method and the function
`ont-app.vocabulary.lstr/read-LangStr`, supporting the #langString reader macro
(parse-prologue query)Returns [base, uri-to-qname, qname-to-uri] parsed from the
prologue to query
Where
base is a URI string for the base of queryuri-to-qname := fn[uri] -> quickname, or uri if there was no matching
prefix in prologqname-to-uri := fn[qname] -> uri or qname if there
was no matching prefix in prologueuri is typically a URI with a prefix defined in the prologue, but
may be any stringqname is typically a qname with a prefix defined in prologue,
but may be any stringprologue is the prologue parsed from query, for which see
spex at https://www.w3.org/TR/sparql11-query/.Returns [`base`, `uri-to-qname`, `qname-to-uri`] parsed from the `prologue` to `query` Where - `base` is a URI string for the base of `query` - `uri-to-qname` := fn[`uri`] -> `quickname`, or `uri` if there was no matching prefix in `prolog` - `qname-to-uri` := fn[`qname`] -> `uri` or `qname` if there was no matching prefix in `prologue` - `uri` is typically a URI with a prefix defined in the `prologue`, but may be any string - `qname` is typically a qname with a prefix defined in `prologue`, but may be any string - `prologue` is the prologue parsed from `query`, for which see spex at `https://www.w3.org/TR/sparql11-query/`.
(parse-xsd-value literal)Returns translated-value for literal
Where
literal is a sparql binding value-map s.t.
{type literal, datatype datatype, value value ...}translated-value is an instance of the xsd datatype associated with
datatype specified for value, or value if no translation can be
found.datatype is a string indicating the datatype associated with value,
which may be an xsd datatype
Returns `translated-value` for `literal`
Where
- `literal` is a sparql binding value-map s.t.
{type literal, datatype `datatype`, value `value` ...}
- `translated-value` is an instance of the xsd datatype associated with
`datatype` specified for `value`, or `value` if no translation can be
found.
- `datatype` is a string indicating the datatype associated with `value`,
which may be an xsd datatype
(simplifier-for-prologue query)(simplifier-for-prologue translators query)Returns a function (fn[var-map] -> {var-keyword translated-value, ...}
for each var in var-map, transating URIs into qnames derived from the
prologue to query, and otherwise using translators (default
default-translators)
Returns a function (fn[`var-map`] -> {`var-keyword` `translated-value`, ...}
for each `var` in `var-map`, transating URIs into qnames derived from the
prologue to `query`, and otherwise using `translators` (default
`default-translators`)A simplifier which translates URIs to keyword identifiers (KWIs). See the ont-app.vocabulary.core module
A simplifier which translates URIs to keyword identifiers (KWIs). See the ont-app.vocabulary.core module
(simplify var-map)(simplify translators var-map)Returns {var-keyword translated-value, ...} for each var in var-map,
translated according to translators (default default-translators)
Where
var-map := {var var-value...}var is a string typically corresponding to a variable in a SELECT queryvar-value := m s.t. (keys m) :~ #{type value xml:lang datatype},
per the SPARQL 1.1 specification for SELECT queries.var-keyword is keyword corresponding to vartranslated-value is value from var-value, translated using translatorstranslators := m s.t. (keys m) :~ #{:uri :lang :datatype}, each of which
maps to a (fn[var-value])-> translated-value, depending on whether
var-value represents a URI, a literal with a language tag, or a literal
with a specified datatype. Default is simply to render the 'value' field.https://www.w3.org/TR/sparql11-results-json/Returns {`var-keyword` `translated-value`, ...} for each `var` in `var-map`,
translated according to `translators` (default `default-translators`)
Where
- `var-map` := {`var` `var-value`...}
- `var` is a string typically corresponding to a variable in a SELECT query
- `var-value` := m s.t. (keys m) :~ #{type value xml:lang datatype},
per the SPARQL 1.1 specification for SELECT queries.
- `var-keyword` is keyword corresponding to `var`
- `translated-value` is `value` from `var-value`, translated using `translators`
- `translators` := m s.t. (keys m) :~ #{:uri :lang :datatype}, each of which
maps to a (fn[var-value])-> `translated-value`, depending on whether
`var-value` represents a URI, a literal with a language tag, or a literal
with a specified datatype. Default is simply to render the 'value' field.
- Note: see also `https://www.w3.org/TR/sparql11-results-json/`
(sparql-ask endpoint query)(sparql-ask endpoint query http-req)Returns boolean value per query posed to endpoint, through an
HTTP call possibly informed by http-req.
Where
query is a SPARQL ASK queryendpoint is a SPARQL endpointhttp-req := {param spec, ...}param is anything described in https://github.com/dakrone/clj-http
Though :form-params will be overridden.
Returns boolean value per `query` posed to `endpoint`, through an
HTTP call possibly informed by `http-req`.
Where
- `query` is a SPARQL ASK query
- `endpoint` is a SPARQL endpoint
- `http-req` := {`param` `spec`, ...}
- `param` is anything described in `https://github.com/dakrone/clj-http`
Though :form-params will be overridden.
(sparql-construct endpoint query)(sparql-construct endpoint query http-req)Returns expression for query posed to endpoint, possibly informed
by http-req
Where
query := a SPARQL CONSTRUCT queryendpoint the URL string of a SPARQL endpointhttp-req := {?param...}param is anything described in https://github.com/dakrone/clj-http
Though :form-params will be overridden.
The default :accept parameter is text/turtle.
Returns `expression` for `query` posed to `endpoint`, possibly informed
by `http-req`
Where
- `query` := a SPARQL CONSTRUCT query
- `endpoint` the URL string of a SPARQL endpoint
- `http-req` := {?param...}
- `param` is anything described in `https://github.com/dakrone/clj-http`
Though :form-params will be overridden.
The default :accept parameter is text/turtle.
(sparql-query endpoint query)(sparql-query endpoint query http-req)Returns output of response-body for SPARQL query
posed to endpoint, possibly informed by http-req
Where
response-body is the body of the response to query, posed to endpoint
via an HTTP GET call which may be informed by params in http-reqhttp-req := {param spec,...}, default is {}param is anything described in https://github.com/dakrone/clj-http
typically :debug or authentication parameters
:query-params will be overridden.
{:cookie-policy :standard} will be asserted by default
Returns output of `response-body` for SPARQL `query`
posed to `endpoint`, possibly informed by `http-req`
Where
- `response-body` is the body of the response to `query`, posed to `endpoint`
via an HTTP GET call which may be informed by `param`s in `http-req`
- `http-req` := {`param` `spec`,...}, default is {}
- `param` is anything described in ``https://github.com/dakrone/clj-http``
typically :debug or authentication parameters
:query-params will be overridden.
{:cookie-policy :standard} will be asserted by default
(sparql-select endpoint query)(sparql-select endpoint query http-req)Returns bindings for query posed to endpoint, using an HTTP call
informed by http-req
Where
query := a SPARQL SELECT queryendpoint the URL string of a SPARQL endpointbindings := [binding , ...]binding := {var var-value, ...}var is a variable specified in queryvar-value := uri-value or literal-valueuri-value := {type uri, value uri}literal-value := {type literal,
value value,
maybe datatype datatype,
maybe xml:lang lang
}https://www.w3.org/TR/sparql11-results-json/
Returns `bindings` for `query` posed to `endpoint`, using an HTTP call
informed by `http-req`
Where
- `query` := a SPARQL SELECT query
- `endpoint` the URL string of a SPARQL endpoint
- `bindings` := [`binding` , ...]
- `binding` := {`var` `var-value`, ...}
- `var` is a variable specified in `query`
- `var-value` := `uri-value` or `literal-value`
- `uri-value` := {type uri, value `uri`}
- `literal-value` := {type literal,
value `value`,
maybe datatype `datatype`,
maybe xml:lang `lang`
}
- Note: see also `https://www.w3.org/TR/sparql11-results-json/`
(sparql-update endpoint update)(sparql-update endpoint update http-req)Side Effect: Modifies the contents of endpoint per the update query
update, possibly informed by http parameters http-req' Returns the string returned byendpoint` if successful.
Where
endpoint is a SPARQL update endpointupdate is a SPARQL update expressionhttp-req := {?param...}param is anything described in https://github.com/dakrone/clj-http
Though :form-params will be overridden.
This may be used for authentication parameters for example.
Default parameters are {:cookie-policy :standard, :accept text/plain}Side Effect: Modifies the contents of `endpoint` per the update query
`update`, possibly informed by http parameters `http-req'
Returns the string returned by `endpoint` if successful.
Where
- `endpoint` is a SPARQL update endpoint
- `update` is a SPARQL update expression
- `http-req` := {?param...}
- `param` is anything described in `https://github.com/dakrone/clj-http`
Though :form-params will be overridden.
This may be used for authentication parameters for example.
Default parameters are {:cookie-policy :standard, :accept text/plain}
Maps datatype names to xsd datatypes
Maps datatype names to xsd datatypes
(update-translators translators k vfn)Returns translator', for k, per vfn
Where
translators := m s.t. (keys m) = keysk is in keysvfn := fn [value] -> translated-valuekeys := #{:uri :lang :datatype :bnode}Returns `translator`', for `k`, per `vfn`
Where
- `translators` := m s.t. (keys m) = `keys`
- `k` is in `keys`
- `vfn` := fn [`value`] -> `translated-value`
- `keys` := #{:uri :lang :datatype :bnode}
(xsd-type-uri x)Returns xsd URI for (type x), or nil if there is no mapping in type-mapper.
Example: [1] -> 'http://www.w3.org/2001/XMLSchema#long'
Where:
x is any value.Returns xsd URI for (type `x`), or nil if there is no mapping in `type-mapper`. Example: [1] -> 'http://www.w3.org/2001/XMLSchema#long' Where: - `x` is any value.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |