Skip to content

Commit 0cf1f51

Browse files
authored
feat(yasqe): suggest classes and properties used in the endpoint (#235)
* feat(yasqe): suggest classes and properties used in the endpoint Class and property autocompletion lists the terms the endpoint of the tab uses, most used first with their usage count, before the Linked Open Vocabularies suggestions. MatGUI takes them from the Endpoint overview (VoID partitions, complete Classes/Properties results, or one limited background query cached per endpoint) and inserts prefixed names with the missing PREFIX. The suggestions can be switched off per endpoint in the overview. Closes #195 * fix(yasqe): use the new LOV term API for class and property suggestions LOV moved its API from /dataset/lov/api/v2/autocomplete/terms (now 404) to /dataset/api/v2/term/autocomplete and /dataset/api/v2/term/search. IRIs and prefixed names use autocomplete, plain words the full text search. The uri of a result may be a string or a one-item list. * feat(yasqe): bundle LOV terms instead of calling the LOV API The LOV API is broken (404 on the old path, a search backend error on the new one). Class and property suggestions now search a bundled list of the classes and properties of the most used LOV vocabularies, generated from the LOV N-Quads dump by fetchLovData.js (npm run util:fetchLov) and refreshed monthly by a workflow that opens a pull request. LOV terms are inserted as prefixed names with their PREFIX. The lovTerms option replaces the list or, set to null, leaves out LOV suggestions. * fix: run fetchLovData.js on Windows too * fix: skip invalid lines of the LOV dump instead of aborting * chore: update package-lock * feat(yasqe): add lov terms * test: format the expected endpoint term count in the browser's locale * feat(yasqe): always bundle the ERA ontology terms The LOV dump has no graph for the ERA ontology (http://data.europa.eu/949/), so fetchLovData.js now reads its classes and properties from the ontology on GitLab. Namespaces in ALWAYS_INCLUDED are bundled first, regardless of their popularity and the size budget.
1 parent 227cf5a commit 0cf1f51

27 files changed

Lines changed: 10157 additions & 8973 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@matdata/yasgui": minor
3+
"@matdata/yasqe": minor
4+
---
5+
6+
Suggest the classes and properties used in the current endpoint in autocompletion, most used first with their usage count, before the Linked Open Vocabularies suggestions (#195).
7+
8+
The terms come from the Endpoint overview: VoID class/property partitions, complete Classes/Properties results, or otherwise one limited background query (with the tab's authentication) whose result is cached per endpoint. Picking a suggestion inserts a prefixed name and declares the missing prefix. The suggestions can be switched off per endpoint in the Endpoint overview, or for all endpoints with `endpointDescribe.autocomplete: false`. YASQE gets an `endpointTerms` option to provide such terms, and hints can now carry a detail, a section and prefixes to declare.

‎.changeset/lov-api-v2-term.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@matdata/yasqe": minor
3+
---
4+
5+
Class and property suggestions from Linked Open Vocabularies no longer call the LOV API, which is broken (HTTP 404 on the old path, a search backend error on the new one). Yasqe bundles the classes and properties of the most used LOV vocabularies (`packages/yasqe/src/lov-terms.json`, about 600 KB at most, refreshed with `npm run util:fetchLov` or the "Refresh LOV terms" workflow) and searches them in the browser. LOV suggestions are now inserted as prefixed names with their `PREFIX`. The new `lovTerms` option replaces the list, or leaves out LOV suggestions when set to `null`.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Refresh LOV terms
2+
3+
# Regenerates the bundled Linked Open Vocabularies term list (packages/yasqe/src/lov-terms.json)
4+
# from the LOV dump and opens a pull request when it changed.
5+
on:
6+
workflow_dispatch:
7+
schedule:
8+
- cron: "0 4 1 * *"
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
refresh:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v5
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v6
23+
with:
24+
node-version: "lts/*"
25+
cache: npm
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Build the LOV term list
31+
run: npm run util:fetchLov
32+
33+
- name: Open a pull request
34+
uses: peter-evans/create-pull-request@v7
35+
with:
36+
branch: chore/refresh-lov-terms
37+
commit-message: "chore(yasqe): refresh the bundled LOV terms"
38+
title: "chore(yasqe): refresh the bundled LOV terms"
39+
body: Regenerated `packages/yasqe/src/lov-terms.json` from the LOV dump with `npm run util:fetchLov`.
40+
add-paths: packages/yasqe/src/lov-terms.json

‎docs/developer-guide.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,38 @@ const yasqe = new Yasqe(document.getElementById('yasqe'), {
10191019
});
10201020
```
10211021

1022+
#### Endpoint Terms for Autocompletion
1023+
1024+
The class and property autocompleters list terms used in the endpoint before the Linked Open Vocabularies suggestions. MatGUI fills them from its Endpoint overview. A standalone Yasqe (or an embedding page that wants its own source) can provide them with `endpointTerms`:
1025+
1026+
```typescript
1027+
interface EndpointTerm {
1028+
iri: string;
1029+
count?: number; // shown next to the suggestion
1030+
prefix?: string; // with namespace: insert a prefixed name and declare the prefix
1031+
namespace?: string;
1032+
}
1033+
1034+
const yasqe = new Yasqe(element, {
1035+
endpointTerms: async (yasqe, type /* "class" | "property" */) => {
1036+
return [{ iri: "http://data.europa.eu/949/OperationalPoint", count: 52311, prefix: "era", namespace: "http://data.europa.eu/949/" }];
1037+
},
1038+
});
1039+
```
1040+
1041+
Return the terms most used first; Yasqe filters them on what the user typed and shows at most 50. Setting `yasqe.endpointTerms` in the MatGUI config replaces the Endpoint overview as the source.
1042+
1043+
#### Linked Open Vocabularies Terms
1044+
1045+
The LOV suggestions come from `packages/yasqe/src/lov-terms.json`, which is bundled with Yasqe: no request is made to the LOV API at runtime. The file holds the classes and properties of the most used LOV vocabularies (ranked by the number of vocabularies that use them, up to about 600 KB) and is generated from the LOV N-Quads dump:
1046+
1047+
```bash
1048+
npm run util:fetchLov # downloads https://lov.linkeddata.es/lov.nq.gz
1049+
node fetchLovData.js path/to/lov.nq.gz # or use a downloaded dump
1050+
```
1051+
1052+
The **Refresh LOV terms** GitHub workflow runs the same script monthly (or on demand) and opens a pull request when the list changed. Pass your own list with the `lovTerms` option (`{ namespaces: [[namespace, prefix, "ClassA ClassB", "propA propB"], ...] }`), or set it to `null` to leave out LOV suggestions.
1053+
10221054
#### Share Configuration
10231055

10241056
Configure how users can share their SPARQL queries with multiple output formats including URLs, cURL, PowerShell, and wget commands.
@@ -2018,6 +2050,10 @@ interface EndpointDescribeConfig {
20182050

20192051
// Fetch the service description and VoID when the panel opens
20202052
fetchMetadata: boolean; // default: true
2053+
2054+
// Suggest the classes and properties used in the endpoint in the editor's autocomplete.
2055+
// Users can still switch this off per endpoint in the panel.
2056+
autocomplete: boolean; // default: true
20212057
}
20222058

20232059
interface DescribeQuery {

‎docs/user-guide.md‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- [Endpoint Quick Switch](#endpoint-quick-switch)
4545
- [Configuration Import/Export](#configuration-importexport)
4646
- [URI Explorer](#uri-explorer)
47+
- [Class and Property Autocomplete](#class-and-property-autocomplete)
4748
- [IRI Hover Info](#iri-hover-info)
4849
- [Endpoint Overview](#endpoint-overview)
4950
- [Query Tabs](#query-tabs)
@@ -303,7 +304,7 @@ The query editor where you write and edit SPARQL queries.
303304
**Features:**
304305

305306
- Syntax highlighting for SPARQL
306-
- Auto-completion for keywords, prefixes, and URIs
307+
- Auto-completion for keywords, prefixes, and URIs (classes and properties used in the endpoint come first, see [Class and Property Autocomplete](#class-and-property-autocomplete))
307308
- Line numbers and code folding
308309
- Query validation with error highlighting
309310
- Find and replace functionality
@@ -852,6 +853,29 @@ Alternatively, use `Ctrl`+`Shift` and click on the URI to executes a CONSTRUCT q
852853
**Example:**
853854
Ctrl+clicking on `http://dbpedia.org/resource/European_Union` automatically queries for all triples where the European Union is the subject of.
854855

856+
### Class and Property Autocomplete
857+
858+
Press `Ctrl+Space` after `a` (or `rdf:type`) to get class suggestions, or in the position of a property to get property suggestions. MatGUI suggests:
859+
860+
1. **Used in this endpoint**: the classes and properties the endpoint of the tab actually uses, most used first, with the number of instances (classes) or triples (properties) next to them. This also covers vocabularies that are not registered anywhere, such as railML 3, the ERA ontology or your own ontologies.
861+
2. **Linked Open Vocabularies**: matching classes and properties of the most used vocabularies in [LOV](https://lov.linkeddata.es/dataset/lov/). MatGUI ships this list, so no request is made to LOV while you type. Terms that the endpoint already suggested are not repeated, and a term is inserted as a prefixed name with its `PREFIX` when LOV knows the vocabulary's preferred prefix.
862+
863+
Without typing anything, the endpoint's most used terms are listed. While you type, a suggestion matches on its full IRI, its prefixed name (`era:Op`) or, when you type a plain word (`Operat`), on any part of its local name.
864+
865+
Picking a suggestion inserts a prefixed name when MatGUI knows a prefix for it, and adds the missing `PREFIX` declaration to your query, just like clicking an IRI in the [Endpoint Overview](#endpoint-overview). When you are typing with a prefix that your query declares, that prefix is used.
866+
867+
**Where the suggestions come from**
868+
869+
MatGUI reuses what the endpoint overview already knows about the endpoint, so in most cases no extra query is needed:
870+
871+
- The class and property partitions of the endpoint's VoID description.
872+
- The results of the **Classes** and **Properties** overview queries, when they hold the complete list.
873+
- Otherwise MatGUI runs one limited query in the background (the 200 most used classes or properties) the first time you ask for suggestions, with the endpoint and authentication settings of the tab. The result is remembered per endpoint like the other overview results; use **Run again** on the overview's Classes or Properties query to refresh what is suggested. When this query fails or times out, it is not retried for an hour.
874+
875+
**Switching it off for an endpoint**
876+
877+
Counting all properties of a very large public endpoint is expensive. Open the [Endpoint Overview](#endpoint-overview) for that endpoint and clear **Suggest this endpoint's classes and properties in autocomplete**: MatGUI then neither queries the endpoint nor shows its terms, and only the Linked Open Vocabularies suggestions remain. The choice is remembered per endpoint.
878+
855879
### IRI Hover Info
856880

857881
Rest the mouse on an IRI or prefixed name in the query editor (for example `era:solNature`) to see what it means, without running anything or losing your results. After a short moment a tooltip shows:
@@ -901,6 +925,7 @@ The panel contains predefined queries, grouped in categories:
901925
- Public endpoints limit how many (expensive) queries you can run. When an endpoint answers that you are sending too many requests, wait a moment before running more queries. Errors of the endpoint are shown below the query (e.g. "estimated execution time exceeds the limit").
902926
- Describe queries run in the background with the endpoint and authentication settings of the current tab. They do not change your query or the results view. The default and named graphs configured for the tab are not applied, so the whole endpoint is described.
903927
- Click an IRI in the results to insert it into your query. MatGUI uses a prefixed name when it knows the prefix and adds the missing `PREFIX` declaration.
928+
- The classes and properties the overview knows are also suggested in the editor's autocomplete. The **Suggest this endpoint's classes and properties in autocomplete** checkbox at the top of the panel switches this off for the current endpoint (see [Class and Property Autocomplete](#class-and-property-autocomplete)).
904929
- Click the **Open query in a new tab** button next to a query to open it in a new tab, to adapt it further.
905930

906931
**Remembered results**
@@ -2405,7 +2430,7 @@ The proxy solves this by:
24052430
2. **Wait for Typing Pause**: Autocomplete appears after a brief delay
24062431
3. **Position Cursor Correctly**: Autocomplete context-dependent (prefixes, keywords, etc.)
24072432
4. **Manually Trigger**: Press `Ctrl+Space` to force autocomplete
2408-
5. **LOV ontology description**: The implementation uses https://lov.linkeddata.es/dataset/lov/ to retrieve classes and predicates from ontologies. If the ontology that you use cannot be found here, then the autocomplete will not work.
2433+
5. **Classes and properties**: Suggestions come from the endpoint of the tab and from a list of the most used vocabularies in LOV that ships with MatGUI. Rarely used vocabularies are not in that list. If your ontology is not in it, the endpoint suggestions still cover the terms the endpoint uses, unless they are switched off for that endpoint in the Endpoint overview, or the background query failed (it is retried after an hour; running the Classes or Properties overview query also fills the suggestions). See [Class and Property Autocomplete](#class-and-property-autocomplete).
24092434

24102435
#### Lost Queries
24112436

0 commit comments

Comments
 (0)