Skip to content

Commit 0fa3e3a

Browse files
committed
docs: sparql queries basic
1 parent 1300222 commit 0fa3e3a

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

README.md

+31-7
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,39 @@ This is done via methods which take a cytoscape node and return either a shape n
172172
| `endpoint` | SPARQL endpoint to use. Sends queries to this server. | `"https://www.snik.eu/sparql"` |
173173
| `graph` | Base URI / SPARQL graph to use. | `""http://www.snik.eu/ontology"` |
174174
| `instances` | Whether to display instances of classes. May not work. | `false` |
175-
| `queries` | SPARQL-queries to query for classes and triples. See below. ||
175+
| `queries` | SPARQL-queries to query for classes and triples. See below. | `{ nodes: ..., triples: ... }` |
176176

177177
There are two different queries run when filling the graph:
178-
1. A query to get the classes to display as nodes in the graph from the ontology, and
179-
2. a query to get the triples to show as edges between the nodes from the ontology.
180-
181-
> [!NOTE]
182-
> TODO. For more information on what the SPARQL queries need to return,
183-
> consult the `nodes` and `triples` queries in `js/config/config.snik.ts` and `js/config/config.hito.ts`.
178+
1. A query to get the classes to display as nodes in the graph from the ontology (the *nodes* query), and
179+
2. a query to get the triples to show as edges between the nodes from the ontology (the *triples* query).
180+
181+
If you want to take a look how the queries are used in the code, consider [`loadGraphFromSparql.ts`](js/loadGraphFromSparql.ts).
182+
183+
##### nodes query
184+
This method takes a `from` parameter
185+
which functions as a SPARQL `FROM` clause (specifying the RDF dataset)
186+
and returns a plain string which is executed as a SPARQL query.
187+
188+
The nodes query is a query which selects the following:
189+
- `?c` for all (distinct) classes that should be loaded (only loaded classes are contained in triples!)
190+
- `?l` for labels for the class in all languages as a single string (`GROUP_CONCAT(DISTINCT(CONCAT(?l,"@",lang(?l)));separator="|") AS ?l`)
191+
- `?src` is the class that `ov:define`s the class; it does not need to come from the same SPARQL graph and is not distinct
192+
- `?inst` instances, if you want instances; else use `SAMPLE(?inst) AS ?inst`
193+
- `?st` in SNIK is the *subtop* of the node, specifies whether this is a *role*, a *function* or an *entity type*; **if you don't use SNIK, this still needs to be selected**, consider using `SAMPLE(?st) AS ?st` to ignore it
194+
195+
##### triples query
196+
197+
This method takes:
198+
- a `from` parameter which functions as a SPARQL `FROM` clause (specifying the RDF dataset)
199+
- a `fromNamed` parameter which functions as a SPARQL `FROM NAMED` clause (specifying the RDF dataset)
200+
- a `virtualTriples`, boolean whether you want to include virtual triples - you can ignore this if you don't want it
201+
- a `instances`, boolean whether relations between instances should be queried for
202+
It returns a plain string which is executed as a SPARQL query.
203+
204+
The triples query is a query which selects the following:
205+
- `?g` as the [SPARQL `GRAPH`](https://www.w3.org/TR/sparql11-query#rdfDataset) of the triple
206+
- `?c`, `?p` and `?d` as subject, predicate and object of the triple
207+
- `?ax` for axioms, you probably want to shove this into an optional section and ignore it (also select `MIN(?ax) as ?ax`)
184208

185209
#### `multiview`
186210

0 commit comments

Comments
 (0)