diff --git a/src/components/descriptors/OcDescriptorResource/OcDescriptorResource.vue b/src/components/descriptors/OcDescriptorResource/OcDescriptorResource.vue index 588892123aefb93cf8502457fb922dc8572990b6..6bf16b0d791bc0f34d32c674160347be63461e9f 100644 --- a/src/components/descriptors/OcDescriptorResource/OcDescriptorResource.vue +++ b/src/components/descriptors/OcDescriptorResource/OcDescriptorResource.vue @@ -10,7 +10,7 @@ :href="shareLink" /> <Button - v-if="resource?.identifier && can('read', community) && can('update', resource)" + v-if="resource?.identifier && can('read', community) && can('update', resource) && router.hasRoute(updateRoute.name)" size="small" :as="OcLink" :to="updateRoute" diff --git a/src/sparql/agents.ts b/src/sparql/agents.ts index 538eda1dd614f0148816c2d76c51cf63961ef8c5..fb36d81407cd18c345e39a6b16d179bddf985540 100644 --- a/src/sparql/agents.ts +++ b/src/sparql/agents.ts @@ -8,10 +8,9 @@ export const queryPersons = async (query: string, auth?: Credentials) => { FROM <https://www.irit.fr/opencommon/agents> WHERE { ?person a foaf:Person; - foaf:familyName ?familyName; - foaf:firstName ?firstName; - ?p ?o. - FILTER (regex(?familyName, "${query}", "i") || regex(?firstName, "${query}", "i")) + foaf:familyName|foaf:firstName ?name; + ?p ?o. + FILTER (regex(?name, "${query}", "i")) } `, { @@ -54,8 +53,8 @@ export const queryOrganizations = async (query: string, auth?: Credentials) => { FROM <https://www.irit.fr/opencommon/agents> WHERE { ?organization a foaf:Organization; - foaf:name ?name; - ?p ?o. + foaf:name ?name; + ?p ?o. FILTER regex(?name, "${query}", "i") } `, diff --git a/src/sparql/catalog.ts b/src/sparql/catalog.ts index 2508a2e98c6aa07bb60264efac74a050c3422982..ff5af15782155b8d5177e47214fc49713873a6a7 100644 --- a/src/sparql/catalog.ts +++ b/src/sparql/catalog.ts @@ -32,17 +32,19 @@ export const getCatalogSummary = async (identifier: string, auth?: Credentials) oct:graph ?g. } WHERE { - VALUES ?p { - rdf:type - dct:title - dct:description - dcat:catalog - } - ?catalog a dcat:Catalog; - ?p ?o. GRAPH ?g { - ?catalog dct:identifier ?identifier + ?catalog a dcat:Catalog; + dct:identifier ?identifier. FILTER (STR(?identifier) = "${identifier}") + + VALUES ?p { + rdf:type + dct:title + dct:description + dcat:catalog + } + + ?catalog ?p ?o. } } `, @@ -74,10 +76,16 @@ export const getCatalogSummaryFromUri = async (uri: string, auth?: Credentials) oct:graph ?g. } WHERE { - <${uri}> a dcat:Catalog; - ?p ?o. GRAPH ?g { - <${uri}> dct:identifier ?identifier + <${uri}> a dcat:Catalog. + VALUES ?p { + dct:identifier + rdf:type + dct:title + dct:description + dcat:catalog + } + <${uri}> ?p ?o. } } `, @@ -107,14 +115,20 @@ export const getCatalogSummaryFromParentUri = async (uri: string, auth?: Credent ` CONSTRUCT { ?node ?p ?o; - oct:graph ?g. + oct:graph ?g. } WHERE { <${uri}> a dcat:Catalog; dcat:catalog ?node. - ?node ?p ?o. GRAPH ?g { - ?node dct:identifier ?identifier + VALUES ?p { + dct:identifier + rdf:type + dct:title + dct:description + dcat:catalog + } + ?node ?p ?o. } } `, @@ -137,14 +151,21 @@ export const getCatalogSummaryFromChildUri = async (uri: string, auth?: Credenti ` CONSTRUCT { ?node ?p ?o; - oct:graph ?g. + oct:graph ?g. } WHERE { ?node a dcat:Catalog; - dcat:catalog <${uri}>. - ?node ?p ?o. + dcat:catalog <${uri}>. + GRAPH ?g { - ?node dct:identifier ?identifier + VALUES ?p { + dct:identifier + rdf:type + dct:title + dct:description + dcat:catalog + } + ?node ?p ?o. } } `, @@ -301,15 +322,15 @@ export async function getCatalog(identifier: string, auth?: Credentials): Promis ` CONSTRUCT { ?catalog ?p ?o; - oct:graph ?g. + oct:graph ?g. } WHERE { - ?catalog a dcat:Catalog; - ?p ?o. - ?catalog dct:identifier ?identifier. - FILTER (str(?identifier) = "${identifier}"). GRAPH ?g { - ?node dct:identifier ?identifier + ?catalog a dcat:Catalog; + dct:identifier ?identifier. + FILTER (str(?identifier) = "${identifier}") + + ?catalog ?p ?o. } } `, diff --git a/src/sparql/communities.ts b/src/sparql/communities.ts index a2185979b701aa762d4e9ba699d0a9281942a374..19655ab00eb0000b36c3b247777988097618a9dc 100644 --- a/src/sparql/communities.ts +++ b/src/sparql/communities.ts @@ -44,7 +44,7 @@ export const getCommunityList = async (auth?: Credentials) => { ` CONSTRUCT { ?space ?p ?o. } WHERE { - ?space a oct:Space; + ?space a oct:Community; ?p ?o. } `, diff --git a/src/sparql/distribution.ts b/src/sparql/distribution.ts index 2f850d0da85d2b0343d114c829e1d115cdea4e2b..4ead4c6b03b90e2b8b848e0a5a355d02e0fb541a 100644 --- a/src/sparql/distribution.ts +++ b/src/sparql/distribution.ts @@ -14,6 +14,7 @@ import { executeSparqlConstruct } from './sparql' import { resourceContext } from './resource' +import { ContextDefinition } from 'jsonld' export async function insertDistribution( distribution: Partial<OcDistribution>, @@ -124,104 +125,74 @@ export async function getDistribution( identifier: string, auth?: Credentials ): Promise<OcDistribution> { - /** - * First, get the @id of the catalog - * to better filtering requests. - */ - const distributionIdResponse = await executeSparqlConstruct<OcDistribution>( - ` - CONSTRUCT { - ?distribution ?p ?o. - ?distribution oct:graph ?g. - } - WHERE { - ?distribution ?p ?o; - a dcat:Distribution. - GRAPH ?g { - ?distribution dct:identifier ?identifier. - } - FILTER (str(?identifier) = "${identifier}"). + const context: ContextDefinition = { + ...resourceContext, + accessURL: { '@id': 'http://www.w3.org/ns/dcat#accessURL', '@type': '@id' }, + license: { '@id': 'http://purl.org/dc/terms/license', '@type': '@id' }, + type: { '@id': 'http://purl.org/dc/terms/type', '@type': '@id' }, + accessRights: { '@id': 'http://purl.org/dc/terms/accessRights', '@type': '@id' }, + format: { '@id': 'http://purl.org/dc/terms/format', '@type': '@id' }, + label: { + '@id': 'http://www.w3.org/2004/02/skos/core#label', + '@container': '@language' + }, + prefLabel: { + '@id': 'http://www.w3.org/2004/02/skos/core#prefLabel', + '@container': '@language' } - - `, - { - auth, - context: { - ...resourceContext, - accessURL: { '@id': 'http://www.w3.org/ns/dcat#accessURL', '@type': '@id' }, - license: { '@id': 'http://purl.org/dc/terms/license', '@type': '@id' }, - type: { '@id': 'http://purl.org/dc/terms/type', '@type': '@id' }, - accessRights: { '@id': 'http://purl.org/dc/terms/accessRights', '@type': '@id' }, - format: { '@id': 'http://purl.org/dc/terms/format', '@type': '@id' } + } + + const frame = { + '@context': context, + '@type': [ + 'http://www.w3.org/ns/dcat#Distribution', + ], + contains: { + accessRights: { + '@embed': '@always', + }, + type: { + '@embed': '@always' + }, + format: { + '@embed': '@always' + }, + license: { + '@embed': '@always' } } - ) - const distribution = distributionIdResponse?.[0] - const distributionUri = distribution['@id'] + } - /** - * access rights, License, type, access URL and format - */ - const distributionRelatedResponse = await executeSparqlConstruct<OcConcept>( + const distributionResponse = await executeSparqlConstruct<OcDistribution>( ` CONSTRUCT { - ?accessRights ?p1 ?o1. - ?license ?p2 ?o2. - ?type ?p3 ?o3. - ?format ?p5 ?o5. + ?distribution ?p ?o. + ?distribution oct:graph ?g. + ?o2 ?p3 ?o3. } WHERE { - OPTIONAL { - <${distributionUri}> dct:accessRights ?accessRights. - ?accessRights ?p1 ?o1. - } - OPTIONAL { - <${distributionUri}> dct:license ?license. - ?license ?p2 ?o2. - } - OPTIONAL { - <${distributionUri}> dct:type ?type. - ?type ?p3 ?o3. - } - OPTIONAL { - <${distributionUri}> dct:format ?format. - ?format ?p5 ?o5. + GRAPH ?g { + ?distribution a dcat:Distribution; + dct:identifier ?identifier. + FILTER (str(?identifier) = "${identifier}") } + + ?distribution ?p ?o. + + VALUES ?p2 { dct:accessRights dct:license dct:type dct:format } + ?distribution ?p2 ?o2. + ?o2 ?p3 ?o3. } `, { auth, - context: { - ...resourceContext, - label: { - '@id': 'http://www.w3.org/2004/02/skos/core#label', - '@container': '@language' - }, - prefLabel: { - '@id': 'http://www.w3.org/2004/02/skos/core#prefLabel', - '@container': '@language' - } - } + context: context, + frame: frame } ) + const distribution = distributionResponse?.[0] - const distributionResponse = await Promise.all([ - distributionRelatedResponse // 0 - ]) - - distribution.license = distributionResponse[0].find( - (d) => d['@id'] === (distribution.license as unknown as string) - ) - distribution.type = distributionResponse[0].find( - (d) => d['@id'] === (distribution.type as unknown as string) - ) - distribution.accessRights = distributionResponse[0].find( - (d) => d['@id'] === (distribution.accessRights as unknown as string) - ) - distribution.format = distributionResponse[0].find( - (d) => d['@id'] === (distribution.format as unknown as string) - ) return distribution } diff --git a/src/sparql/resource.ts b/src/sparql/resource.ts index b2092c8c028649467327a51a88cae63dec5ddaf7..8aa36dbd0e3104d33a4fc3e406ee4b49ef42cabf 100644 --- a/src/sparql/resource.ts +++ b/src/sparql/resource.ts @@ -41,15 +41,13 @@ export async function getResource(identifier: string, auth?: Credentials): Promi ` CONSTRUCT { ?resource ?p ?o. - ?resource oct:graph ?g. + oct:graph ?g. } WHERE { - ?resource ?p ?o. - ?resource dct:identifier ?id. - filter (STR(?id) = "${identifier}") - GRAPH ?g { - ?resource dct:identifier ?id + ?resource dct:identifier ?id. + FILTER (STR(?id) = "${identifier}") + ?resource ?p ?o. } } `, diff --git a/src/sparql/search.ts b/src/sparql/search.ts index c0807945a651c0c22d7bdc034e03acf77d71f2ca..a189450b6344b56eb388d0ea704957ce8e2535f2 100644 --- a/src/sparql/search.ts +++ b/src/sparql/search.ts @@ -153,29 +153,32 @@ export const getSearchResults = async (resourceUriList: string[], auth?: Credent } WHERE { VALUES ?s { ${formattedUris} } - VALUES ?p { - rdf:type - dct:title - dct:description - dcat:version - dcat:catalog - dcat:dataset - dcat:distribution + GRAPH ?g { + ?s dct:identifier ?identifier. + + VALUES ?p { + rdf:type + dct:title + dct:description + dcat:version + dcat:catalog + dcat:dataset + dcat:distribution + } + ?s ?p ?o. } - ?s ?p ?o. OPTIONAL { ?s dct:creator ?creator. VALUES ?p2 { foaf:name foaf:givenName foaf:familyName foaf:firstName } ?creator ?p2 ?o2. } OPTIONAL { - ?parentCatalog dcat:dataset|dcat:catalog ?s. + VALUES ?parentLink { dcat:dataset dcat:catalog } + ?parentCatalog a dcat:Catalog; + ?parentLink ?s. VALUES ?pparentCatalog { dct:identifier dct:title } ?parentCatalog ?pparentCatalog ?oparentCatalog. } - GRAPH ?g { - ?s dct:identifier ?identifier. - } } `, { diff --git a/src/sparql/service.ts b/src/sparql/service.ts index cb4b1f721d68c6e82bd54013da5a5498835b2541..a4ce6d69a53f4f5798bc2ca72f83e0de6fc41293 100644 --- a/src/sparql/service.ts +++ b/src/sparql/service.ts @@ -1,8 +1,8 @@ -import type { Credentials, OcService, OcJsonLdDocument } from "@/declarations" +import type { Credentials, OcService } from "@/declarations" import { executeSparqlConstruct } from "./sparql" import type { ContextDefinition } from "jsonld" -const sereviceContext: ContextDefinition = { +const serviceContext: ContextDefinition = { "identifier": { "@id": "http://purl.org/dc/terms/identifier", "@type": "http://www.w3.org/2000/01/rdf-schema#Literal" @@ -13,21 +13,21 @@ const sereviceContext: ContextDefinition = { }, } -export const queryService = async (query: string, locale: string, auth?: Credentials): Promise<OcJsonLdDocument<OcService>> => { +export const queryService = async (query: string, locale: string, auth?: Credentials): Promise<OcService[]> => { return executeSparqlConstruct<OcService>( ` CONSTRUCT {?s ?p ?o.} WHERE { ?s a dcat:DataService; - dct:title ?title; - ?p ?o. - FILTER regex(?title, "${query}", "i"). - FILTER(LANG(?title) = "${locale}" || LANG(?title) = ""). + dct:title ?title. + FILTER regex(?title, "${query}", "i") + FILTER(LANG(?title) = "${locale}" || LANG(?title) = "") + ?s ?p ?o. } `, { auth: auth, - context: sereviceContext + context: serviceContext } ) } \ No newline at end of file diff --git a/src/sparql/tree.ts b/src/sparql/tree.ts index 5c12524a2e31e712370c1771c8749fab2fdf9240..680064645d1b2139a83b1cc637b09baa81c4ba47 100644 --- a/src/sparql/tree.ts +++ b/src/sparql/tree.ts @@ -59,26 +59,30 @@ export const getTreeNodesFromParentNodeURI = async (parentNodeUri: string, auth? return await executeSparqlConstruct<OcTreeNode>( ` - CONSTRUCT { + CONSTRUCT { + <${parentNodeUri}> ?p ?o. + ?node ?p2 ?o2. + ?node oct:graph ?g. + } + WHERE { + { + VALUES ?p { dcat:catalog dcat:dataset dcat:distribution dct:title dct:identifier rdf:type } <${parentNodeUri}> ?p ?o. - ?node ?p2 ?o2. - ?node oct:graph ?g. - } - WHERE { - VALUES ?p { dcat:catalog dcat:dataset dcat:distribution dct:title dct:identifier rdf:type } - VALUES ?p2 { dcat:catalog dcat:dataset dcat:distribution dct:title dct:identifier rdf:type } - <${parentNodeUri}> ?p ?o. - <${parentNodeUri}> (dcat:catalog|dcat:dataset|dcat:distribution){0,1} ?node. - ?node ?p2 ?o2 + } UNION { + VALUES ?p2 { dcat:catalog dcat:dataset dcat:distribution dct:title dct:identifier rdf:type } + <${parentNodeUri}> (dcat:catalog|dcat:dataset|dcat:distribution){0,1} ?node. + ?node ?p2 ?o2 . GRAPH ?g { - ?node dct:identifier ?id + ?node dct:identifier ?id } } + } `, { context, auth, - frame + frame, + withoutContext: true } ) } @@ -137,7 +141,6 @@ export const getUrisBetweenHomeAndResource = async ( VALUES ?p3 { dct:identifier rdf:type } VALUES ?p4 { dct:identifier rdf:type } ?child ?p ?o. - ?subchild dcat:dataset ?dataset. ?subchild ?p2 ?o2. ?dataset ?p3 ?o3. ?distribution ?p4 ?o4. @@ -161,7 +164,6 @@ export const getUrisBetweenHomeAndResource = async ( VALUES ?p2 { dct:identifier rdf:type } VALUES ?p3 { dct:identifier rdf:type } ?child ?p ?o. - ?subchild dcat:dataset ?dataset. ?subchild ?p2 ?o2. ?dataset ?p3 ?o3. ` @@ -194,7 +196,8 @@ export const getUrisBetweenHomeAndResource = async ( `, { context, - auth + auth, + withoutContext: true } ) } diff --git a/src/sparql/vocabularies.ts b/src/sparql/vocabularies.ts index 2390646363e2d04915791b7b62b45a709e8d93e7..29a6be9298aa538950f0f7b62f24a96f5e41a6fe 100644 --- a/src/sparql/vocabularies.ts +++ b/src/sparql/vocabularies.ts @@ -40,8 +40,8 @@ export const getVocabularyList = (scheme: string, auth?: Credentials) => { CONSTRUCT {?s skos:prefLabel ?label.} WHERE { ?s a skos:Concept; - skos:prefLabel ?label; - skos:inScheme <${scheme}>. + skos:prefLabel ?label; + skos:inScheme <${scheme}>. } `, { @@ -74,8 +74,9 @@ export const queryVocabulary = ( CONSTRUCT {?s skos:prefLabel ?label.} WHERE { ?s a skos:Concept; - skos:prefLabel ?label; - skos:inScheme <${scheme}>. + skos:inScheme <${scheme}>; + skos:prefLabel ?label. + FILTER regex(?label, "${query}", "i"). FILTER(LANG(?label) = "${locale}" || LANG(?title) = ""). } @@ -96,9 +97,9 @@ export const getConceptChildren = (scheme: string, parentTerm?: string, auth?: C } WHERE { ?s a skos:Concept; - skos:prefLabel ?label; - skos:broader|^skos:narrower <${parentTerm}>; - skos:inScheme <${scheme}>. + skos:prefLabel ?label; + skos:broader|^skos:narrower <${parentTerm}>; + skos:inScheme <${scheme}>. OPTIONAL { ?s skos:narrower|^skos:broader ?narrower } @@ -120,8 +121,8 @@ export const getVocabularyRootConcepts = async (scheme: string, auth?: Credentia } WHERE { ?s a skos:Concept; - skos:prefLabel ?label; - skos:topConceptOf|^skos:hasTopConcept <${scheme}>. + skos:topConceptOf|^skos:hasTopConcept <${scheme}>; + skos:prefLabel ?label. OPTIONAL { ?s skos:narrower|^skos:broader ?narrower } @@ -163,18 +164,18 @@ export const getLocaleList = () => { return executeSparqlConstruct<OcLocale>( ` CONSTRUCT { - ?s ?p ?o. + ?s skos:prefLabel ?prefLabel. ?s <http://publications.europa.eu/ontology/authority/legacy-code> ?codeValue. } WHERE { ?s a skos:Concept; - ?p ?o; - <http://publications.europa.eu/ontology/authority/op-mapped-code> ?code; - skos:inScheme <http://publications.europa.eu/resource/authority/language>. - FILTER(?p in (skos:prefLabel)) + skos:inScheme <http://publications.europa.eu/resource/authority/language>; + <http://publications.europa.eu/ontology/authority/op-mapped-code> ?code; + skos:prefLabel ?prefLabel. + ?code ?p2 ?o2; - dc:source 'iso-639-1'; - <http://publications.europa.eu/ontology/authority/legacy-code> ?codeValue. + dc:source 'iso-639-1'; + <http://publications.europa.eu/ontology/authority/legacy-code> ?codeValue. } `, { @@ -204,9 +205,9 @@ export const getLicenseList = () => { } WHERE { ?s a skos:Concept; - skos:prefLabel ?prefLabel; - skos:altLabel ?altLabel; - skos:inScheme <http://publications.europa.eu/resource/authority/licence>. + skos:inScheme <http://publications.europa.eu/resource/authority/licence>; + skos:prefLabel ?prefLabel; + skos:altLabel ?altLabel. } `, {