From 383f0802aa56ddd6b51f8552a95a5be75ea70800 Mon Sep 17 00:00:00 2001 From: David de Boer Date: Thu, 19 Dec 2024 22:15:57 +0100 Subject: [PATCH] feat: Parameterize results limit --- jest.config.js | 8 +- .../catalog/queries/search/aat-materials.rq | 81 +++++++++--------- .../search/aat-processes-and-techniques.rq | 81 +++++++++--------- .../queries/search/aat-styles-and-periods.rq | 83 +++++++++---------- .../catalog/queries/search/aat.rq | 82 +++++++++--------- .../queries/search/adamlink-adressen.rq | 20 +++-- .../queries/search/adamlink-straten.rq | 16 ++-- .../queries/search/brabantse-gebouwen.rq | 15 ++-- .../catalog/queries/search/brinkman.rq | 19 +++-- .../catalog/queries/search/cht-materials.rq | 19 +++-- .../queries/search/cht-styles-and-periods.rq | 19 +++-- .../catalog/queries/search/cht.rq | 14 ++-- .../catalog/queries/search/eurovoc.rq | 21 +++-- .../catalog/queries/search/geonames.rq | 22 +++-- .../search/goudatijdmachine-straten.rq | 11 ++- .../catalog/queries/search/gtaa.rq | 16 ++-- .../catalog/queries/search/iconclass.rq | 13 +-- .../catalog/queries/search/ied.rq | 22 +++-- .../search/muziekschatten-klassiekewerken.rq | 18 ++-- .../search/muziekschatten-onderwerpen.rq | 17 ++-- .../queries/search/muziekschatten-personen.rq | 19 +++-- .../queries/search/mw-genresstijlen.rq | 15 +++- .../queries/search/mw-personengroepen.rq | 14 ++-- .../catalog/queries/search/nmvw.rq | 13 ++- .../catalog/queries/search/nta.rq | 14 ++-- .../catalog/queries/search/picot.rq | 19 +++-- .../catalog/queries/search/poolparty.rq | 16 ++-- .../catalog/queries/search/rijksmonumenten.rq | 12 ++- .../catalog/queries/search/rkdartists.rq | 14 ++-- .../catalog/queries/search/stcn-drukkers.rq | 18 ++-- .../queries/search/uitvoeringsmedium.rq | 21 +++-- .../queries/search/wikidata-entities-all.rq | 9 +- .../search/wikidata-entities-persons.rq | 42 ++++++---- .../search/wikidata-entities-streets.rq | 1 + .../catalog/queries/search/wo2thesaurus.rq | 22 +++-- packages/network-of-terms-cli/src/query.ts | 1 + .../network-of-terms-graphql/src/resolvers.ts | 1 + .../network-of-terms-graphql/src/schema.ts | 3 + .../src/distributions.ts | 32 +++---- packages/network-of-terms-query/src/query.ts | 34 +++++++- .../src/query.ts | 1 + 41 files changed, 544 insertions(+), 374 deletions(-) diff --git a/jest.config.js b/jest.config.js index 0cdda559f..212db0c0d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -10,10 +10,10 @@ export default { ], coverageThreshold: { global: { - lines: 91.41, - statements: 91.41, - branches: 92.62, - functions: 90.9, + lines: 91.53, + statements: 91.53, + branches: 92.65, + functions: 91, }, }, transform: { diff --git a/packages/network-of-terms-catalog/catalog/queries/search/aat-materials.rq b/packages/network-of-terms-catalog/catalog/queries/search/aat-materials.rq index 28b31e9e6..ae899635d 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/aat-materials.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/aat-materials.rq @@ -22,46 +22,47 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - SELECT * WHERE { - ?uri luc:term ?query ; - a ?type ; - void:inDataset ; - gvp:broaderPreferred+ . # limit results to the "materials hierarchy name" (300010357) - - ?type rdfs:subClassOf gvp:Subject . - FILTER (?type != gvp:Subject) . - ?uri skosxl:prefLabel ?prefLabel_uri . - ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?prefLabel_uri skosxl:literalForm ?prefLabel . - OPTIONAL { - ?uri skosxl:altLabel ?altLabel_uri . - ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?altLabel_uri skosxl:literalForm ?altLabel . - } - OPTIONAL { - ?uri skos:scopeNote ?scopeNote_uri . - ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) - ?scopeNote_uri rdf:value ?scopeNote . - } - OPTIONAL { - ?uri rdfs:seeAlso ?rdfs_seeAlso - } - OPTIONAL { - ?uri gvp:broaderPreferred ?broader_uri . - ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . - ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . - } - OPTIONAL { - ?uri skos:narrower ?narrower_uri . - ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . - ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . - } - OPTIONAL { - ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. - FILTER(?exactMatch_uri != ?uri) # Exclude self-reference. + { + SELECT * WHERE { + ?uri luc:term ?query ; + a ?type ; + void:inDataset ; + gvp:broaderPreferred+ . # limit results to the "materials hierarchy name" (300010357) + ?type rdfs:subClassOf gvp:Subject . + FILTER (?type != gvp:Subject) . + ?uri skosxl:prefLabel ?prefLabel_uri . + ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?prefLabel_uri skosxl:literalForm ?prefLabel . } + #LIMIT# + } + OPTIONAL { + ?uri skosxl:altLabel ?altLabel_uri . + ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?altLabel_uri skosxl:literalForm ?altLabel . + } + OPTIONAL { + ?uri skos:scopeNote ?scopeNote_uri . + ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) + ?scopeNote_uri rdf:value ?scopeNote . + } + OPTIONAL { + ?uri rdfs:seeAlso ?rdfs_seeAlso + } + OPTIONAL { + ?uri gvp:broaderPreferred ?broader_uri . + ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . + ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . + } + OPTIONAL { + ?uri skos:narrower ?narrower_uri . + ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . + ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . + } + OPTIONAL { + ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. + FILTER(?exactMatch_uri != ?uri) # Exclude self-reference. } - LIMIT 1000 } diff --git a/packages/network-of-terms-catalog/catalog/queries/search/aat-processes-and-techniques.rq b/packages/network-of-terms-catalog/catalog/queries/search/aat-processes-and-techniques.rq index f2229f851..7bd5d512f 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/aat-processes-and-techniques.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/aat-processes-and-techniques.rq @@ -21,46 +21,47 @@ CONSTRUCT { ?narrower_uri skos:prefLabel ?narrower_prefLabel . } WHERE { - SELECT * WHERE { - ?uri luc:term ?query ; - a ?type ; - void:inDataset ; - gvp:broaderPreferred+ . # limit results to the "processes and techniques hierarchy name (300053001)" - - ?type rdfs:subClassOf gvp:Subject . - FILTER (?type != gvp:Subject) . - ?uri skosxl:prefLabel ?prefLabel_uri . - ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?prefLabel_uri skosxl:literalForm ?prefLabel . - OPTIONAL { - ?uri skosxl:altLabel ?altLabel_uri . - ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?altLabel_uri skosxl:literalForm ?altLabel . - } - OPTIONAL { - ?uri skos:scopeNote ?scopeNote_uri . - ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) - ?scopeNote_uri rdf:value ?scopeNote . - } - OPTIONAL { - ?uri rdfs:seeAlso ?rdfs_seeAlso - } - OPTIONAL { - ?uri gvp:broaderPreferred ?broader_uri . - ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . - ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . - } - OPTIONAL { - ?uri skos:narrower ?narrower_uri . - ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . - ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . - } - OPTIONAL { - ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. - FILTER(?exactMatch_uri != ?uri) # Exclude self-reference. + { + SELECT * WHERE { + ?uri luc:term ?query ; + a ?type ; + void:inDataset ; + gvp:broaderPreferred+ . # limit results to the "processes and techniques hierarchy name (300053001)" + ?type rdfs:subClassOf gvp:Subject . + FILTER (?type != gvp:Subject) . + ?uri skosxl:prefLabel ?prefLabel_uri . + ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?prefLabel_uri skosxl:literalForm ?prefLabel . } + #LIMIT# + } + OPTIONAL { + ?uri skosxl:altLabel ?altLabel_uri . + ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?altLabel_uri skosxl:literalForm ?altLabel . + } + OPTIONAL { + ?uri skos:scopeNote ?scopeNote_uri . + ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) + ?scopeNote_uri rdf:value ?scopeNote . + } + OPTIONAL { + ?uri rdfs:seeAlso ?rdfs_seeAlso + } + OPTIONAL { + ?uri gvp:broaderPreferred ?broader_uri . + ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . + ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . + } + OPTIONAL { + ?uri skos:narrower ?narrower_uri . + ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . + ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . + } + OPTIONAL { + ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. + FILTER(?exactMatch_uri != ?uri) # Exclude self-reference. } - LIMIT 1000 } diff --git a/packages/network-of-terms-catalog/catalog/queries/search/aat-styles-and-periods.rq b/packages/network-of-terms-catalog/catalog/queries/search/aat-styles-and-periods.rq index 4520a1afb..e83094ab1 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/aat-styles-and-periods.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/aat-styles-and-periods.rq @@ -21,48 +21,47 @@ CONSTRUCT { ?narrower_uri skos:prefLabel ?narrower_prefLabel . } WHERE { - SELECT * WHERE { - ?uri luc:term ?query ; - a ?type ; - void:inDataset . - - # limit results to the "styles and periodes hierarchy name (300015646)" - ?uri gvp:broaderPreferred+ . - - ?type rdfs:subClassOf gvp:Subject . - FILTER (?type != gvp:Subject) . - ?uri skosxl:prefLabel ?prefLabel_uri . - ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?prefLabel_uri skosxl:literalForm ?prefLabel . - OPTIONAL { - ?uri skosxl:altLabel ?altLabel_uri . - ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?altLabel_uri skosxl:literalForm ?altLabel . - } - OPTIONAL { - ?uri skos:scopeNote ?scopeNote_uri . - ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) - ?scopeNote_uri rdf:value ?scopeNote . - } - OPTIONAL { - ?uri rdfs:seeAlso ?rdfs_seeAlso - } - OPTIONAL { - ?uri gvp:broaderPreferred ?broader_uri . - ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . - ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . - } - OPTIONAL { - ?uri skos:narrower ?narrower_uri . - ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . - ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . - } - OPTIONAL { - ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. - FILTER(?exactMatch_uri != ?uri) # Exclude self-reference. + { + SELECT * WHERE { + ?uri luc:term ?query ; + a ?type ; + void:inDataset ; + gvp:broaderPreferred+ . # limit results to the "styles and periodes hierarchy name (300015646)" + ?type rdfs:subClassOf gvp:Subject . + FILTER (?type != gvp:Subject) . + ?uri skosxl:prefLabel ?prefLabel_uri . + ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?prefLabel_uri skosxl:literalForm ?prefLabel . } + #LIMIT# + } + OPTIONAL { + ?uri skosxl:altLabel ?altLabel_uri . + ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?altLabel_uri skosxl:literalForm ?altLabel . + } + OPTIONAL { + ?uri skos:scopeNote ?scopeNote_uri . + ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) + ?scopeNote_uri rdf:value ?scopeNote . + } + OPTIONAL { + ?uri rdfs:seeAlso ?rdfs_seeAlso + } + OPTIONAL { + ?uri gvp:broaderPreferred ?broader_uri . + ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . + ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . + } + OPTIONAL { + ?uri skos:narrower ?narrower_uri . + ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . + ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . + } + OPTIONAL { + ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. + FILTER(?exactMatch_uri != ?uri) # Exclude self-reference. } - LIMIT 1000 } diff --git a/packages/network-of-terms-catalog/catalog/queries/search/aat.rq b/packages/network-of-terms-catalog/catalog/queries/search/aat.rq index 13fde7bda..ab8d6aebc 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/aat.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/aat.rq @@ -22,46 +22,48 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - SELECT * WHERE { - ?uri luc:term ?query ; - a ?type ; - void:inDataset . - ?type rdfs:subClassOf gvp:Subject . - FILTER (?type != gvp:Subject) . - ?uri skosxl:prefLabel ?prefLabel_uri . - ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?prefLabel_uri skosxl:literalForm ?prefLabel . - OPTIONAL { - ?uri skosxl:altLabel ?altLabel_uri . - ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) - ?altLabel_uri skosxl:literalForm ?altLabel . - } - OPTIONAL { - ?uri skos:scopeNote ?scopeNote_uri . - ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) - ?scopeNote_uri rdf:value ?scopeNote . - } - OPTIONAL { - ?uri rdfs:seeAlso ?rdfs_seeAlso - } - OPTIONAL { - ?uri gvp:broaderPreferred ?broader_uri . - ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . - ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . - } - OPTIONAL { - ?uri skos:narrower ?narrower_uri . - ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . - ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . - } - OPTIONAL { - ?uri skos:exactMatch ?exactMatch_uri . - ?exactMatch_uri skosxl:prefLabel ?exactMatch_uri_skosxl . - ?exactMatch_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) - ?exactMatch_uri_skosxl skosxl:literalForm ?exactMatch_prefLabel . + { + SELECT * WHERE { + ?uri luc:term ?query ; + a ?type ; + void:inDataset . + ?type rdfs:subClassOf gvp:Subject . + FILTER (?type != gvp:Subject) . + ?uri skosxl:prefLabel ?prefLabel_uri . + ?prefLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?prefLabel_uri skosxl:literalForm ?prefLabel . } + #LIMIT# + } + OPTIONAL { + ?uri skosxl:altLabel ?altLabel_uri . + ?altLabel_uri dcterms:language aat:300388256 . # Dutch (language) + ?altLabel_uri skosxl:literalForm ?altLabel . + } + OPTIONAL { + ?uri skos:scopeNote ?scopeNote_uri . + ?scopeNote_uri dcterms:language aat:300388256 . # Dutch (language) + ?scopeNote_uri rdf:value ?scopeNote . + } + OPTIONAL { + ?uri rdfs:seeAlso ?rdfs_seeAlso + } + OPTIONAL { + ?uri gvp:broaderPreferred ?broader_uri . + ?broader_uri skosxl:prefLabel ?broader_uri_skosxl . + ?broader_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?broader_uri_skosxl skosxl:literalForm ?broader_prefLabel . + } + OPTIONAL { + ?uri skos:narrower ?narrower_uri . + ?narrower_uri skosxl:prefLabel ?narrower_uri_skosxl . + ?narrower_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?narrower_uri_skosxl skosxl:literalForm ?narrower_prefLabel . + } + OPTIONAL { + ?uri skos:exactMatch ?exactMatch_uri . + ?exactMatch_uri skosxl:prefLabel ?exactMatch_uri_skosxl . + ?exactMatch_uri_skosxl dcterms:language aat:300388256 . # Dutch (language) + ?exactMatch_uri_skosxl skosxl:literalForm ?exactMatch_prefLabel . } - LIMIT 1000 } diff --git a/packages/network-of-terms-catalog/catalog/queries/search/adamlink-adressen.rq b/packages/network-of-terms-catalog/catalog/queries/search/adamlink-adressen.rq index 719cf1949..5103f6380 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/adamlink-adressen.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/adamlink-adressen.rq @@ -19,12 +19,15 @@ CONSTRUCT { } WHERE { GRAPH { - ?uri a hg:Address . - ?uri ?predicate ?label . - - VALUES ?predicate { rdfs:label skos:prefLabel skos:altLabel } - - ?label ?virtuosoQuery . + { + SELECT ?uri WHERE { + ?uri a hg:Address ; + ?predicate ?label . + VALUES ?predicate { rdfs:label skos:prefLabel skos:altLabel } + ?label ?virtuosoQuery . + } + #LIMIT# + } OPTIONAL { ?uri rdfs:label ?prefLabel } OPTIONAL { ?uri skos:altLabel ?altLabel } @@ -34,10 +37,10 @@ WHERE { BIND(CONCAT("Adres afkomstig van ", ?source_name) AS ?scopeNote) } OPTIONAL { ?uri owl:sameAs ?exactMatch_uri } - OPTIONAL { + OPTIONAL { ?exactMatch_uri a bag:Pand ; schema:geoContains ?geo . - ?uri schema:geoContains ?geo . + ?uri schema:geoContains ?geo . } # A historical address is very similar to a bag:Pand OPTIONAL { ?uri schema:geoContains ?geo . @@ -46,4 +49,3 @@ WHERE { } } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/adamlink-straten.rq b/packages/network-of-terms-catalog/catalog/queries/search/adamlink-straten.rq index 3068c440f..52fa49b07 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/adamlink-straten.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/adamlink-straten.rq @@ -12,12 +12,15 @@ CONSTRUCT { } WHERE { GRAPH { - ?uri a hg:Street . - ?uri ?predicate ?label . - - VALUES ?predicate { skos:prefLabel skos:altLabel } - - ?label ?virtuosoQuery . + { + SELECT ?uri WHERE { + ?uri a hg:Street ; + ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + ?label ?virtuosoQuery . + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel } OPTIONAL { ?uri skos:altLabel ?altLabel } @@ -28,4 +31,3 @@ WHERE { OPTIONAL { ?uri owl:sameAs ?exactMatch_uri } # Has no labels. } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/brabantse-gebouwen.rq b/packages/network-of-terms-catalog/catalog/queries/search/brabantse-gebouwen.rq index 22f4f523d..5be35f4ee 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/brabantse-gebouwen.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/brabantse-gebouwen.rq @@ -9,14 +9,19 @@ CONSTRUCT { skos:scopeNote ?schema_description, ?scopeNote . } WHERE { - ?uri a schema:LandmarksOrHistoricalBuildings . - ?uri ?predicate ?label . - VALUES ?predicate { schema:name schema:alternateName skos:hiddenLabel skos:scopeNote} - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT * WHERE { + ?uri a schema:LandmarksOrHistoricalBuildings ; + ?predicate ?label . + VALUES ?predicate { schema:name schema:alternateName skos:hiddenLabel skos:scopeNote} + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } + OPTIONAL { ?uri schema:name ?schema_name } OPTIONAL { ?uri skos:hiddenLabel ?hiddenLabel } OPTIONAL { ?uri skos:scopeNote ?scopeNote} OPTIONAL { ?uri schema:alternateName ?schema_alternateName } OPTIONAL { ?uri schema:description ?schema_description } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/brinkman.rq b/packages/network-of-terms-catalog/catalog/queries/search/brinkman.rq index 85ce76643..bffad125d 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/brinkman.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/brinkman.rq @@ -1,5 +1,6 @@ # Do not remove this prefix - KB data uses old version of SKOS PREFIX skos: +PREFIX bif: CONSTRUCT { ?uri a skos:Concept ; @@ -16,12 +17,17 @@ CONSTRUCT { ?related_uri skos:prefLabel ?related_prefLabel . } WHERE { - ?uri a skos:Concept . - ?uri skos:inScheme . - ?uri ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - FILTER(LANG(?label) = "nl") - ?label ?virtuosoQuery . + { + SELECT ?uri WHERE { + ?uri a skos:Concept ; + skos:inScheme ; + ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + ?label ?virtuosoQuery . + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . @@ -56,4 +62,3 @@ WHERE { } OPTIONAL { ?uri skos:exactMatch ?exactMatch_uri } # Has no labels. } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/cht-materials.rq b/packages/network-of-terms-catalog/catalog/queries/search/cht-materials.rq index edff47089..dc3d2a278 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/cht-materials.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/cht-materials.rq @@ -16,14 +16,17 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - ?uri ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - - # limit results to the narrower terms of the toplevel term 'materialen' - ?uri skos:broader+ . - - FILTER(LANG(?label) = "nl") - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT * WHERE { + ?uri ?predicate ?label ; + # limit results to the narrower terms of the toplevel term 'materialen' + skos:broader+ . + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl") diff --git a/packages/network-of-terms-catalog/catalog/queries/search/cht-styles-and-periods.rq b/packages/network-of-terms-catalog/catalog/queries/search/cht-styles-and-periods.rq index cb940af00..dcb7dcdd8 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/cht-styles-and-periods.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/cht-styles-and-periods.rq @@ -16,14 +16,17 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - ?uri ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - - # limit results to the narrower terms of the toplevel term 'stijlen en periodes' - ?uri skos:broader+ . - - FILTER(LANG(?label) = "nl") - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT * WHERE { + ?uri ?predicate ?label ; + # limit results to the narrower terms of the toplevel term 'stijlen en periodes' + skos:broader+ . + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl") diff --git a/packages/network-of-terms-catalog/catalog/queries/search/cht.rq b/packages/network-of-terms-catalog/catalog/queries/search/cht.rq index d949265f5..07d73e578 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/cht.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/cht.rq @@ -16,10 +16,15 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - ?uri ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - FILTER(LANG(?label) = "nl") - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT * WHERE { + ?uri ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl") @@ -61,4 +66,3 @@ WHERE { } } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/eurovoc.rq b/packages/network-of-terms-catalog/catalog/queries/search/eurovoc.rq index debf59e81..3b72f4050 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/eurovoc.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/eurovoc.rq @@ -15,14 +15,19 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - ?uri a eurovoc:ThesaurusConcept . - ?uri ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - FILTER(LANG(?label) = "nl") - # The http://publications.europa.eu/webapi/rdf/sparql endpoint - # is based on Virtuoso but it looks like fulltext search support - # is not enabled therefore fallback to the standard CONTAINS function - FILTER (CONTAINS(LCASE(STR(?label)),LCASE(?query))) + { + SELECT * WHERE { + ?uri a eurovoc:ThesaurusConcept ; + ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + # The http://publications.europa.eu/webapi/rdf/sparql endpoint + # is based on Virtuoso but it looks like fulltext search support + # is not enabled therefore fallback to the standard CONTAINS function + FILTER (CONTAINS(LCASE(STR(?label)), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl") diff --git a/packages/network-of-terms-catalog/catalog/queries/search/geonames.rq b/packages/network-of-terms-catalog/catalog/queries/search/geonames.rq index 08198c59e..eeefde4c7 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/geonames.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/geonames.rq @@ -13,17 +13,24 @@ CONSTRUCT { ?broader skos:prefLabel ?broader_prefLabel . } WHERE { - (?uri ?score) text:query (gn:name gn:alternateName ?query 100) . - ?uri a gn:Feature ; - gn:featureClass ?featureClass ; - gn:name ?prefLabel ; + { + SELECT ?uri (MAX(?sc) as ?score) WHERE { + (?uri ?sc) text:query (gn:name gn:alternateName ?query) . + ?uri a gn:Feature ; + gn:featureClass ?featureClass ; + # Limit results to places (P), localities (L), administrative levels (A) and water surfaces (H). + VALUES ?featureClass { gn:P gn:L gn:A gn:H } + } + GROUP BY ?uri + ORDER BY DESC(?score) + #LIMIT# + } + + ?uri gn:name ?prefLabel ; gn:countryCode ?countryCode . BIND(CONCAT(?prefLabel," (",UCASE(?countryCode),")") as ?prefLabel_ext) - # Limit results to places (P), localities (L), administrative levels (A) and water surfaces (H). - VALUES ?featureClass { gn:P gn:L gn:A gn:H } - OPTIONAL { ?uri gn:alternateName ?altLabel . FILTER(?altLabel != "") @@ -41,4 +48,3 @@ WHERE { ?uri gn:featureCode/gn:name ?scopeNote . } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/goudatijdmachine-straten.rq b/packages/network-of-terms-catalog/catalog/queries/search/goudatijdmachine-straten.rq index 1948a84f6..91b34c354 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/goudatijdmachine-straten.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/goudatijdmachine-straten.rq @@ -7,6 +7,7 @@ PREFIX luc-index: PREFIX omeka: PREFIX owl: PREFIX rdfs: +PREFIX vrank: CONSTRUCT { ?piduri a skos:Concept ; @@ -14,19 +15,21 @@ CONSTRUCT { skos:altLabel ?altLabel; skos:scopeNote ?scopeNote ; skos:related ?related_uri ; - skos:exactMatch ?exactMatch_uri . + skos:exactMatch ?exactMatch_uri ; + vrank:simpleRank ?score . ?related_uri skos:prefLabel ?related_prefLabel . ?exactMatch_uri skos:prefLabel ?exactMatch_label . } WHERE { ?search a luc-index:straten_index ; luc:query ?query ; + luc:limit ?limit ; luc:entities ?uri . ?uri owl:sameAs ?piduri FILTER(STRSTARTS(STR(?piduri), "https://n2t.net")) - ?uri sdo:name ?prefLabel ; - luc:score ?score . + ?uri sdo:name ?prefLabel . + ?uri luc:score ?score . OPTIONAL { ?uri gtm:genoemdNaar ?genoemdNaar . @@ -52,4 +55,4 @@ CONSTRUCT { ?uri rdfs:seeAlso ?exactMatch_uri . ?exactMatch_uri omeka:label ?exactMatch_label . } -} ORDER BY DESC(?score) LIMIT 100 +} diff --git a/packages/network-of-terms-catalog/catalog/queries/search/gtaa.rq b/packages/network-of-terms-catalog/catalog/queries/search/gtaa.rq index b7e7c2eed..eed42161e 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/gtaa.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/gtaa.rq @@ -20,10 +20,16 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - (?uri ?score) text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?query) . - ?uri skos:inScheme ?datasetUri ; - bengthes:status ?status . - FILTER(?status IN ('approved', 'candidate')) + { + SELECT ?uri (MAX(?sc) as ?score) { + (?uri ?sc) text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?query) . + ?uri skos:inScheme ?datasetUri ; + bengthes:status ?status . + FILTER(?status IN ('approved', 'candidate')) + } + GROUP BY ?uri + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . @@ -62,5 +68,3 @@ WHERE { FILTER(LANG(?exactMatch_prefLabel) = "nl") } } -ORDER BY DESC(?score) -LIMIT 10 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/iconclass.rq b/packages/network-of-terms-catalog/catalog/queries/search/iconclass.rq index bdfb5feb8..63b836b33 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/iconclass.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/iconclass.rq @@ -12,10 +12,14 @@ CONSTRUCT { ?related_uri skos:prefLabel ?related_prefLabel . } WHERE { - ?uri a skos:Concept ; - skos:prefLabel ?prefLabel . - - FILTER(CONTAINS(LCASE(?prefLabel), LCASE(?query))) + { + SELECT * WHERE { + ?uri a skos:Concept ; + skos:prefLabel ?prefLabel . + FILTER(CONTAINS(LCASE(?prefLabel), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:broader ?broader_uri . @@ -30,4 +34,3 @@ WHERE { ?related_uri skos:prefLabel ?related_prefLabel . } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/ied.rq b/packages/network-of-terms-catalog/catalog/queries/search/ied.rq index d0333cab6..811b7cf20 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/ied.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/ied.rq @@ -13,14 +13,19 @@ CONSTRUCT { ?narrower_uri skos:prefLabel ?narrower_prefLabel . } WHERE { - ?uri ?predicate ?label . - # Exclude terms from the 'Technische Lijsten', a concept scheme with terms that should only be used by NOB - FILTER NOT EXISTS { - ?uri skos:inScheme - } - VALUES ?predicate { skos:prefLabel skos:altLabel } - FILTER(LANG(?label) = "nl") - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT * WHERE { + ?uri ?predicate ?label . + # Exclude terms from the 'Technische Lijsten', a concept scheme with terms that should only be used by NOB + FILTER NOT EXISTS { + ?uri skos:inScheme + } + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl" ) @@ -51,4 +56,3 @@ WHERE { ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-klassiekewerken.rq b/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-klassiekewerken.rq index 979617476..c6614b3d5 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-klassiekewerken.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-klassiekewerken.rq @@ -1,3 +1,4 @@ +PREFIX bif: PREFIX rdf: PREFIX rdfs: PREFIX rdaw: @@ -16,12 +17,17 @@ CONSTRUCT { ?narrower_uri skos:prefLabel ?narrower_prefLabel . } WHERE { - ?uri ?predicate ?label. - VALUES ?predicate { rdfs:label rdaw:P10086 rdaw:P10223 rdaw:P10333 rdaw:P10335 rdaw:P10047 } - ?label ?virtuosoQuery . + { + SELECT ?uri WHERE { + ?uri a ; + ?predicate ?label . + VALUES ?predicate { rdfs:label rdaw:P10086 rdaw:P10223 rdaw:P10333 rdaw:P10335 rdaw:P10047 } + ?label ?virtuosoQuery . + } + #LIMIT# + } - ?uri a ; - rdfs:label ?prefLabel . + ?uri rdfs:label ?prefLabel . OPTIONAL { ?uri rdaw:P10086 ?altLabel } # Varianttitel OPTIONAL { ?uri rdaw:P10219 ?eerste_datum } @@ -46,4 +52,4 @@ WHERE { ) AS ?scopeNote ) } -LIMIT 1000 + diff --git a/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-onderwerpen.rq b/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-onderwerpen.rq index 153a759f3..c4f599d35 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-onderwerpen.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-onderwerpen.rq @@ -12,11 +12,16 @@ CONSTRUCT { ?broader_uri skos:prefLabel ?broader_schema_name . } WHERE { - ?uri a skos:Concept ; - ?predicate ?label . - - VALUES ?predicate { schema:name schema:keywords } - ?label ?virtuosoQuery . + { + SELECT DISTINCT ?uri WHERE { + ?uri a skos:Concept ; + som:BASIS "1" . + ?uri ?predicate ?label . + VALUES ?predicate { schema:name schema:keywords } + ?label ?virtuosoQuery . + } + #LIMIT# + } OPTIONAL { ?uri schema:name ?schema_name . @@ -41,7 +46,5 @@ WHERE { ) AS ?scopeNote ) - ?uri som:BASIS "1" . OPTIONAL { ?uri skos:exactMatch ?exactMatch_uri } # Has no labels. } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-personen.rq b/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-personen.rq index 334a1c93e..f8ca0898e 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-personen.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/muziekschatten-personen.rq @@ -29,12 +29,17 @@ CONSTRUCT { skos:exactMatch ?exactMatch_uri . } WHERE { - ?uri a schema:Person . - # Require the presence of this property for quality purposes - ?uri som:NDEREC ?nderec ; - ?predicate ?label . - VALUES ?predicate { schema:name schema:alternateName } - ?label ?virtuosoQuery . + { + SELECT DISTINCT ?uri WHERE { + ?uri a schema:Person . + # Require the presence of this property for quality purposes + ?uri som:NDEREC ?nderec ; + ?predicate ?label . + VALUES ?predicate { schema:name schema:alternateName } + ?label ?virtuosoQuery . + } + #LIMIT# + } OPTIONAL { ?uri schema:name ?schema_name } OPTIONAL { ?uri schema:alternateName ?schema_alternateName } @@ -63,4 +68,4 @@ WHERE { BIND(CONCAT(?name, IF(?dates != "", CONCAT(" (", ?dates, ")"), "")) AS ?prefLabel) OPTIONAL { ?uri owl:sameAs ?exactMatch_uri } # Has no labels. } -LIMIT 1000 + diff --git a/packages/network-of-terms-catalog/catalog/queries/search/mw-genresstijlen.rq b/packages/network-of-terms-catalog/catalog/queries/search/mw-genresstijlen.rq index 75cf6387e..9eed44eb1 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/mw-genresstijlen.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/mw-genresstijlen.rq @@ -14,9 +14,16 @@ CONSTRUCT { ?narrower_uri skos:prefLabel ?narrower_prefLabel . } WHERE { - ?uri a muziekweb:Genre ; - rdfs:label ?rdfs_label . - ?rdfs_label ?virtuosoQuery . + { + SELECT DISTINCT ?uri WHERE { + ?uri a muziekweb:Genre ; + rdfs:label ?rdfs_label . + ?rdfs_label ?virtuosoQuery . + } + #LIMIT# + } + + ?uri rdfs:label ?rdfs_label . OPTIONAL { ?uri skos:broader ?broader_uri . @@ -29,4 +36,4 @@ WHERE { OPTIONAL { ?uri rdfs:comment ?rdfs_comment } OPTIONAL { ?uri owl:sameAs ?exactMatch_uri } # Has no labels. } -LIMIT 1000 + diff --git a/packages/network-of-terms-catalog/catalog/queries/search/mw-personengroepen.rq b/packages/network-of-terms-catalog/catalog/queries/search/mw-personengroepen.rq index 321d33f1e..956d6c676 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/mw-personengroepen.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/mw-personengroepen.rq @@ -12,10 +12,15 @@ CONSTRUCT { skos:exactMatch ?exactMatch_uri . } WHERE { - ?uri a schema:MusicGroup ; - ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - ?label ?virtuosoQuery . + { + SELECT DISTINCT ?uri WHERE { + ?uri a schema:MusicGroup ; + ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + ?label ?virtuosoQuery . + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel } OPTIONAL { ?uri skos:altLabel ?altLabel } @@ -23,4 +28,3 @@ WHERE { OPTIONAL { ?uri schema:description ?schema_description } OPTIONAL { ?uri owl:sameAs ?exactMatch_uri } # Has no labels. } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/nmvw.rq b/packages/network-of-terms-catalog/catalog/queries/search/nmvw.rq index ac1691672..67400fed3 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/nmvw.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/nmvw.rq @@ -1,3 +1,4 @@ +#PREFIX bif: PREFIX skos: CONSTRUCT { @@ -13,9 +14,14 @@ CONSTRUCT { ?narrower_uri skos:prefLabel ?narrower_prefLabel . } WHERE { - ?uri ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - ?label ?virtuosoQuery . + { + SELECT DISTINCT ?uri { + ?uri ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + ?label ?virtuosoQuery + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . @@ -41,4 +47,3 @@ WHERE { ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/nta.rq b/packages/network-of-terms-catalog/catalog/queries/search/nta.rq index 4941854d6..754dbc70a 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/nta.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/nta.rq @@ -13,10 +13,15 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - ?uri schema:mainEntityOfPage/schema:isPartOf ; - ?predicate ?label . - VALUES ?predicate { rdfs:label schema:name schema:alternateName } - ?label ?virtuosoQuery . + { + SELECT DISTINCT ?uri WHERE { + ?uri schema:mainEntityOfPage/schema:isPartOf ; + ?predicate ?label . + VALUES ?predicate { rdfs:label schema:name schema:alternateName } + ?label ?virtuosoQuery . + } + #LIMIT# + } OPTIONAL { ?uri rdfs:label ?rdfs_label } OPTIONAL { ?uri schema:name ?schema_name } @@ -30,4 +35,3 @@ WHERE { } } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/picot.rq b/packages/network-of-terms-catalog/catalog/queries/search/picot.rq index 5888002bd..029809887 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/picot.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/picot.rq @@ -16,12 +16,17 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - ?uri a skos:Concept ; - skos:inScheme ?datasetUri ; - ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - FILTER(LANG(?label) = "nl") - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT DISTINCT ?uri WHERE { + ?uri a skos:Concept ; + skos:inScheme ?datasetUri ; + ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl") @@ -65,4 +70,4 @@ WHERE { } } } -LIMIT 1000 + diff --git a/packages/network-of-terms-catalog/catalog/queries/search/poolparty.rq b/packages/network-of-terms-catalog/catalog/queries/search/poolparty.rq index 555b6b584..a8e6208f1 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/poolparty.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/poolparty.rq @@ -16,11 +16,16 @@ CONSTRUCT { ?exactMatch_uri skos:prefLabel ?exactMatch_prefLabel . } WHERE { - ?uri a skos:Concept ; - ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - FILTER(LANG(?label) = "nl") - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT DISTINCT ?uri WHERE { + ?uri a skos:Concept ; + ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl") @@ -64,4 +69,3 @@ WHERE { } } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/rijksmonumenten.rq b/packages/network-of-terms-catalog/catalog/queries/search/rijksmonumenten.rq index 32b3427f0..9db80801c 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/rijksmonumenten.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/rijksmonumenten.rq @@ -14,9 +14,14 @@ CONSTRUCT { rdfs:seeAlso ?monument_url . } WHERE { - ?uri ?predicate ?label . - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) - VALUES ?predicate { schema:addressLocality schema:identifier schema:address schema:name schema:addressRegion } + { + SELECT ?uri WHERE { + ?uri ?predicate ?label . + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + VALUES ?predicate { schema:addressLocality schema:identifier schema:address schema:name schema:addressRegion } + } + #LIMIT# + } ?uri schema:identifier ?rijksmonumentnummer ; schema:category ?monumentaard ; @@ -56,4 +61,3 @@ WHERE { ) AS ?adres_lang ) } -LIMIT 200 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/rkdartists.rq b/packages/network-of-terms-catalog/catalog/queries/search/rkdartists.rq index 600ef3fe2..afe5f1a20 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/rkdartists.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/rkdartists.rq @@ -10,17 +10,17 @@ CONSTRUCT { rdfs:seeAlso ?seeAlso . } WHERE { - ?uri ?predicate ?label . - ?label ?virtuosoQuery . - VALUES ?predicate { schema:name schema:alternateName } - { - SELECT ?uri + SELECT DISTINCT ?uri (GROUP_CONCAT(DISTINCT ?schema_description; separator="; ") as ?descriptions) (GROUP_CONCAT(DISTINCT ?birthPlace; separator="/") as ?birthPlaces) (GROUP_CONCAT(DISTINCT ?deathPlace; separator="/") as ?deathPlaces) (GROUP_CONCAT(DISTINCT ?additionalType; separator=", ") as ?additionalTypes) WHERE { + ?uri ?predicate ?label . + ?label ?virtuosoQuery . + VALUES ?predicate { schema:name schema:alternateName } + ?uri a ?type . VALUES ?type { schema:Person schema:Organization } @@ -32,7 +32,8 @@ WHERE { OPTIONAL { ?uri schema:additionalType ?additionalType . FILTER(langMatches(lang(?additionalType), "nl"))} - } GROUP BY ?uri + } + #LIMIT# } OPTIONAL { ?uri schema:name ?prefLabel . } @@ -62,4 +63,3 @@ WHERE { BIND(STRAFTER(STR(?uri), "https://data.rkd.nl/artists/") AS ?identifier) BIND(IRI(CONCAT("https://rkd.nl/explore/artists/", ?identifier)) AS ?seeAlso) } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/stcn-drukkers.rq b/packages/network-of-terms-catalog/catalog/queries/search/stcn-drukkers.rq index 81597f53a..52617643c 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/stcn-drukkers.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/stcn-drukkers.rq @@ -12,13 +12,18 @@ CONSTRUCT { skos:exactMatch ?exactMatch_uri . } WHERE { - ?uri schema:mainEntityOfPage/schema:isPartOf ; - schema:additionalType ; # Select printers. - rdfs:label ?rdfs_label . + { + SELECT ?uri ?rdfs_label WHERE { + ?uri schema:mainEntityOfPage/schema:isPartOf ; + schema:additionalType ; # Select printers. + rdfs:label ?rdfs_label . - ?uri ?predicate ?label . - VALUES ?predicate { rdfs:label schema:name schema:alternateName } - ?label ?virtuosoQuery . + ?uri ?predicate ?label . + VALUES ?predicate { rdfs:label schema:name schema:alternateName } + ?label ?virtuosoQuery . + } + #LIMIT# + } # STCN defines multiple URIs for the same printer. # The distinction between these URIs is based on the place where the printer lived and worked. # See for example "Plantijn" @@ -34,4 +39,3 @@ WHERE { ?uri schema:sameAs ?exactMatch_uri . # Has no labels. } } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/uitvoeringsmedium.rq b/packages/network-of-terms-catalog/catalog/queries/search/uitvoeringsmedium.rq index fad0b5404..468cc1ed7 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/uitvoeringsmedium.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/uitvoeringsmedium.rq @@ -11,15 +11,21 @@ CONSTRUCT { ?broader_uri skos:prefLabel ?broader_prefLabel . } WHERE { - ?uri a skos:Concept ; - skos:inScheme som:Uitvoeringsmedium ; - skos:prefLabel ?prefLabel . + { + SELECT ?uri ?prefLabel WHERE { + ?uri a skos:Concept ; + skos:inScheme som:Uitvoeringsmedium ; + skos:prefLabel ?prefLabel . - FILTER(LANG(?prefLabel) = "nl") + FILTER(LANG(?prefLabel) = "nl") - ?uri ?predicate ?label . - VALUES ?predicate { skos:prefLabel skos:altLabel } - ?label ?virtuosoQuery . + ?uri ?predicate ?label . + VALUES ?predicate { skos:prefLabel skos:altLabel } + ?label ?virtuosoQuery . + } + GROUP BY ?uri + #LIMIT# + } OPTIONAL { ?uri skos:scopeNote ?scopeNote @@ -38,4 +44,3 @@ WHERE { OPTIONAL { ?uri skos:exactMatch ?exactMatch_uri } # Has no labels. } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-all.rq b/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-all.rq index 3acb1c252..715d07586 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-all.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-all.rq @@ -1,7 +1,9 @@ PREFIX bd: PREFIX mwapi: +PREFIX rdfs: PREFIX schema: PREFIX skos: +PREFIX vrank: PREFIX wikibase: CONSTRUCT { @@ -11,6 +13,7 @@ CONSTRUCT { ?item skos:prefLabel ?rdfs_label . ?item skos:altLabel ?altLabel . ?item skos:scopeNote ?schema_description . + ?item vrank:simpleRank ?score . } WHERE { SERVICE wikibase:mwapi { @@ -18,7 +21,9 @@ WHERE { bd:serviceParam wikibase:api "EntitySearch" . bd:serviceParam mwapi:language "nl" . bd:serviceParam mwapi:search ?query . + bd:serviceParam wikibase:limit ?limit . ?item wikibase:apiOutputItem mwapi:item . + ?ordinal wikibase:apiOrdinal true. } ?item rdfs:label ?rdfs_label . FILTER(LANG(?rdfs_label) = "nl") @@ -30,5 +35,7 @@ WHERE { ?item schema:description ?schema_description FILTER(LANG(?schema_description) = "nl") } + BIND(-?ordinal AS ?score) } -LIMIT 1000 +ORDER BY ASC(?ordinal) + diff --git a/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-persons.rq b/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-persons.rq index 6e89d4b7e..306d949bd 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-persons.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-persons.rq @@ -3,6 +3,7 @@ PREFIX mwapi: PREFIX rdfs: PREFIX schema: PREFIX skos: +PREFIX vrank: PREFIX wikibase: PREFIX wdt: PREFIX wd: @@ -14,23 +15,35 @@ CONSTRUCT { ?item skos:prefLabel ?prefLabel . ?item skos:altLabel ?altLabel . ?item skos:scopeNote ?description . + ?item vrank:simpleRank ?score . } WHERE { - SERVICE wikibase:mwapi { - bd:serviceParam wikibase:endpoint "www.wikidata.org" . - # Instead of using the "EntitySearch" API we use a more generic text search option - # To avoid noise we will filter the resultset on the occurence of the search string - # in either prefLabel or altLabel - bd:serviceParam wikibase:api "Search" . - bd:serviceParam mwapi:language "nl" . - bd:serviceParam mwapi:srsearch ?query . - ?item wikibase:apiOutputItem mwapi:title . + { + SELECT * WHERE { + SERVICE wikibase:mwapi { + bd:serviceParam wikibase:endpoint "www.wikidata.org" . + # Instead of using the "EntitySearch" API we use a more generic text search option + # To avoid noise we will filter the resultset on the occurence of the search string + # in either prefLabel or altLabel + bd:serviceParam wikibase:api "Search" . + bd:serviceParam mwapi:language "nl" . + + # While Wikidata is no Virtuoso, ?virtuosoQuery works more reliably. + bd:serviceParam mwapi:srsearch ?virtuosoQuery . + ?item wikibase:apiOutputItem mwapi:title . + ?ordinal wikibase:apiOrdinal true. + } + + BIND(-?ordinal AS ?score) + # Only select instances of type "human" + ?item wdt:P31 wd:Q5 ; + rdfs:label ?prefLabel . + FILTER(LANG(?prefLabel) = "nl") + } + ORDER BY ASC(?ordinal) + #LIMIT# } - # Only select instances of type "human" - ?item wdt:P31 wd:Q5 . - ?item rdfs:label ?prefLabel . - FILTER(LANG(?prefLabel) = "nl") OPTIONAL { ?item skos:altLabel ?altLabel . FILTER(LANG(?altLabel) = "nl"||LANG(?altLabel) = "en") @@ -39,7 +52,4 @@ WHERE { ?item schema:description ?description FILTER(LANG(?description) = "nl") } - # limit the result set to matches in the prefLabels or altLabels - FILTER(CONTAINS(LCASE(?prefLabel),LCASE(?query))||CONTAINS(LCASE(?altLabel),LCASE(?query))) } -LIMIT 1000 diff --git a/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-streets.rq b/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-streets.rq index a8374b773..043dcf240 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-streets.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/wikidata-entities-streets.rq @@ -19,6 +19,7 @@ WHERE { bd:serviceParam wikibase:api "Search" . bd:serviceParam mwapi:language "nl" . bd:serviceParam mwapi:srsearch ?query . + bd:serviceParam wikibase:limit ?limit . ?item wikibase:apiOutputItem mwapi:title . } # Use UNION instead of VALUES because the latter doesn't properly restrict results. diff --git a/packages/network-of-terms-catalog/catalog/queries/search/wo2thesaurus.rq b/packages/network-of-terms-catalog/catalog/queries/search/wo2thesaurus.rq index b7ee06f15..a44deb132 100644 --- a/packages/network-of-terms-catalog/catalog/queries/search/wo2thesaurus.rq +++ b/packages/network-of-terms-catalog/catalog/queries/search/wo2thesaurus.rq @@ -13,14 +13,19 @@ CONSTRUCT { ?narrower_uri skos:prefLabel ?narrower_prefLabel . } WHERE { - ?uri ?predicate ?label . - # Exclude terms from the 'Technische Lijsten', a concept scheme with terms that should only be used by NOB - FILTER NOT EXISTS { - ?uri skos:inScheme - } - VALUES ?predicate { skos:prefLabel skos:altLabel } - FILTER(LANG(?label) = "nl") - FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + { + SELECT ?uri WHERE { + ?uri ?predicate ?label . + # Exclude terms from the 'Technische Lijsten', a concept scheme with terms that should only be used by NOB + FILTER NOT EXISTS { + ?uri skos:inScheme + } + VALUES ?predicate { skos:prefLabel skos:altLabel } + FILTER(LANG(?label) = "nl") + FILTER(CONTAINS(LCASE(?label), LCASE(?query))) + } + #LIMIT# + } OPTIONAL { ?uri skos:prefLabel ?prefLabel . FILTER(LANG(?prefLabel) = "nl" ) @@ -51,4 +56,3 @@ WHERE { ?uri skos:exactMatch ?exactMatch_uri . # Has no labels. } } -LIMIT 1000 diff --git a/packages/network-of-terms-cli/src/query.ts b/packages/network-of-terms-cli/src/query.ts index a91f77245..19bdf3777 100644 --- a/packages/network-of-terms-cli/src/query.ts +++ b/packages/network-of-terms-cli/src/query.ts @@ -110,6 +110,7 @@ export class QuerySourcesCommand extends Command { sources, query: flags.query, queryMode: QueryMode[flags.queryMode as keyof typeof QueryMode], + limit: 100, timeoutMs: flags.timeout, }); this.render(results, catalog); diff --git a/packages/network-of-terms-graphql/src/resolvers.ts b/packages/network-of-terms-graphql/src/resolvers.ts index 68b80e2bd..7e2cb9ba5 100644 --- a/packages/network-of-terms-graphql/src/resolvers.ts +++ b/packages/network-of-terms-graphql/src/resolvers.ts @@ -42,6 +42,7 @@ async function queryTerms(object: any, args: any, context: any): Promise { sources: args.sources.map((datasetIri: string) => new IRI(datasetIri)), query: args.query, queryMode: QueryMode[args.queryMode as keyof typeof QueryMode], + limit: args.limit, timeoutMs: args.timeoutMs, }); return resolveTermsResponse(results, context.catalog); diff --git a/packages/network-of-terms-graphql/src/schema.ts b/packages/network-of-terms-graphql/src/schema.ts index e64f3f45e..fb66b5403 100644 --- a/packages/network-of-terms-graphql/src/schema.ts +++ b/packages/network-of-terms-graphql/src/schema.ts @@ -78,6 +78,9 @@ export const schema = ` "The mode in which the literal search query (\`query\`) is interpreted before it is sent to the term sources." queryMode: QueryMode = OPTIMIZED + + "Maximum number of terms to return." + limit: Int = 100, "Timeout period in milliseconds that we wait for sources to respond." timeoutMs: Int = 10000 diff --git a/packages/network-of-terms-query/src/distributions.ts b/packages/network-of-terms-query/src/distributions.ts index 9437b14fb..6343acc84 100644 --- a/packages/network-of-terms-query/src/distributions.ts +++ b/packages/network-of-terms-query/src/distributions.ts @@ -7,34 +7,36 @@ import {Catalog, IRI} from './catalog.js'; import {comunica} from './index.js'; import {clientQueriesCounter} from './instrumentation.js'; -export interface QueryOptions { - source: IRI; +interface BaseQueryOptions { query: string; queryMode: QueryMode; + limit: number; timeoutMs: number; } -const schemaQuery = Joi.object({ - source: Joi.object().required(), - query: Joi.string().required(), - queryMode: Joi.string().required(), - timeoutMs: Joi.number().integer(), -}); +export interface QueryOptions extends BaseQueryOptions { + source: IRI; +} -export interface QueryAllOptions { +export interface QueryAllOptions extends BaseQueryOptions { sources: IRI[]; - query: string; - queryMode: QueryMode; - timeoutMs: number; } -const schemaQueryAll = Joi.object({ - sources: Joi.array().items(Joi.object().required()).min(1).required(), +const schemaBase = Joi.object({ query: Joi.string().required(), queryMode: Joi.string().required(), + limit: Joi.number().integer(), timeoutMs: Joi.number().integer(), }); +const schemaQuery = schemaBase.append({ + source: Joi.object().required(), +}); + +const schemaQueryAll = schemaBase.append({ + sources: Joi.array().items(Joi.object().required()).min(1).required(), +}); + export class DistributionsService { private logger: Pino.Logger; private catalog: Catalog; @@ -67,6 +69,7 @@ export class DistributionsService { args.queryMode, dataset, distribution, + args.limit, args.timeoutMs ); } @@ -82,6 +85,7 @@ export class DistributionsService { source, query: args.query, queryMode: args.queryMode, + limit: args.limit, timeoutMs: args.timeoutMs, }) ); diff --git a/packages/network-of-terms-query/src/query.ts b/packages/network-of-terms-query/src/query.ts index 1dd689110..687b0da23 100644 --- a/packages/network-of-terms-query/src/query.ts +++ b/packages/network-of-terms-query/src/query.ts @@ -57,11 +57,34 @@ export class QueryTermsService { this.logger = options.logger || Pino.pino(); } + /** + * Parameterize the SPARQL query’s limit in two ways: + * - as a pre-bound variable ?limit (for GraphDB’s luc:limit, Wikidata and text:query); + * - by replacing the #LIMIT# placeholder (for LIMIT 123). + */ + parameterizeLimit(args: { + query: string; + bindings: Record; + limit: number; + }): {queryWithLimit: string; bindingsWithLimit: Record} { + return { + queryWithLimit: args.query.replace('#LIMIT#', `LIMIT ${args.limit}`), + bindingsWithLimit: { + ...args.bindings, + limit: dataFactory.literal( + args.limit.toString(), + dataFactory.namedNode('http://www.w3.org/2001/XMLSchema#integer') + ), + }, + }; + } + async search( searchQuery: string, queryMode: QueryMode, dataset: Dataset, distribution: Distribution, + limit: number, timeoutMs: number ): Promise { const bindings = [...queryVariants(searchQuery, queryMode)].reduce( @@ -73,11 +96,18 @@ export class QueryTermsService { ); bindings['datasetUri'] = dataFactory.namedNode(dataset.iri.toString()); + const {queryWithLimit, bindingsWithLimit} = this.parameterizeLimit({ + query: distribution.searchQuery, + bindings, + limit, + }); + return this.run( - distribution.searchQuery, + // For plain SPARQL LIMIT (LIMIT 123) that cannot be pre-bound + queryWithLimit, distribution, timeoutMs, - bindings + bindingsWithLimit ); } diff --git a/packages/network-of-terms-reconciliation/src/query.ts b/packages/network-of-terms-reconciliation/src/query.ts index 27ff1de1d..6b7f284c0 100644 --- a/packages/network-of-terms-reconciliation/src/query.ts +++ b/packages/network-of-terms-reconciliation/src/query.ts @@ -33,6 +33,7 @@ export async function reconciliationQuery( QueryMode.OPTIMIZED, dataset, distribution, + 100, 10000 ); const terms =