Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property query proposal. See #6. #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { renderHook, waitFor } from '@testing-library/react';
import { fromJS } from 'immutable';
import { describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { useOntoScore } from './use-onto-score';
import * as useSparqlQueryImport from './use-sparql';
import * as configuration from '../../configuration';

describe('useOntoScore', () => {
beforeEach(() => {
vi.spyOn(configuration, 'useConfiguration').mockReturnValue({
sparqlUrl: 'https://virtuoso-dev-external-service-ndc-dev.apps.cloudpub.testedev.istat.it/sparql',
});
});

afterEach(() => {
vi.restoreAllMocks();
});

it('should return 0 without jsonldcontext', async () => {
vi.spyOn(useSparqlQueryImport, 'useSparqlQuery').mockReturnValue({
status: 'idle',
Expand Down Expand Up @@ -110,4 +121,18 @@ describe('useOntoScore', () => {
},
);
});

it('should check real values for https://w3id.org/italia/social-security/onto/contributions/retribuzioneOrariaEffettiva', async () => {
const jsonldContext = fromJS({
retribuzioneOrariaEffettiva:
'https://w3id.org/italia/social-security/onto/contributions/retribuzioneOrariaEffettiva',
});
const { result } = renderHook(() => useOntoScore(jsonldContext, [['retribuzioneOrariaEffettiva']]));
await waitFor(() => expect(result.current.status).toBe('fulfilled'));
expect(result.current.data).toEqual({
rawPropertiesCount: 1,
semanticPropertiesCount: 1,
score: 1,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export function useOntoScore(
SELECT (COUNT(DISTINCT ?fieldUri) as ?count) WHERE {
VALUES ?fieldUri { ${resolvedProperties.unknown.map((propertyName) => `<${propertyName}>`).join(' ')} }

?fieldUri
rdfs:range ?class
.
FILTER EXISTS {
?fieldUri rdf:type ?validType .
FILTER(?validType IN (rdf:Property, owl:ObjectProperty, owl:DatatypeProperty, owl:FunctionalProperty))
}
}
`,
{ skip: skipQuery },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { renderHook, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import * as configuration from '../../configuration';
import { useRDFPropertyResolver } from './use-rdf-ontologies-resolver';

describe('useRDFOntologiesResolver', () => {
beforeEach(() => {
vi.spyOn(configuration, 'useConfiguration').mockReturnValue({
sparqlUrl: 'https://virtuoso-dev-external-service-ndc-dev.apps.cloudpub.testedev.istat.it/sparql',
});
});

describe('useRDFPropertyResolver', () => {
it('should check real values for https://w3id.org/italia/onto/CPV/taxCode', async () => {
const ontologicalProperty = 'https://w3id.org/italia/onto/CPV/taxCode';
const { result } = renderHook(() => useRDFPropertyResolver(ontologicalProperty));
await waitFor(() => expect(result.current.status).toBe('fulfilled'));
expect(result.current.data).toEqual({
controlledVocabulary: undefined,
ontologicalClass: 'https://w3id.org/italia/onto/CPV/Person',
ontologicalProperty,
ontologicalPropertyComment: 'The tax code of a person.',
ontologicalType: 'http://www.w3.org/2000/01/rdf-schema#Literal',
});
});

it('should check real values for https://w3id.org/italia/social-security/onto/contributions/retribuzioneOrariaEffettiva', async () => {
const ontologicalProperty =
'https://w3id.org/italia/social-security/onto/contributions/retribuzioneOrariaEffettiva';
const { result } = renderHook(() => useRDFPropertyResolver(ontologicalProperty));
await waitFor(() => expect(result.current.status).toBe('fulfilled'));
expect(result.current.data).toEqual({
controlledVocabulary: undefined,
ontologicalClass: 'https://w3id.org/italia/social-security/onto/contributions/LavoratoreDomestico',
ontologicalProperty,
ontologicalPropertyComment:
'It is the hourly wage stipulated in the Employment Contract. The minimum hourly wage allowed must not be lower than that established by the regulations of the current year. It may vary in the field of the employment relationship giving rise to different role -playing requests for the same person.',
ontologicalType: undefined,
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,38 @@ export function useRDFPropertyResolver(fieldUri: string | undefined): AsyncState
`
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>


SELECT DISTINCT * WHERE {
SELECT DISTINCT
?fieldUri
?domain
?class
?comment
?controlledVocabulary
WHERE {
VALUES ?fieldUri { <${fieldUri}> }

?fieldUri
rdfs:domain ?domain ;
rdfs:range ?class
.
FILTER EXISTS {
?fieldUri rdf:type ?validType .
FILTER(?validType IN (rdf:Property, owl:ObjectProperty, owl:DatatypeProperty, owl:FunctionalProperty))
}

OPTIONAL {
?fieldUri
rdfs:comment ?comment
.
FILTER(lang(?comment) = 'en')
?fieldUri rdfs:domain ?domain .
}

OPTIONAL {
?class
<https://w3id.org/italia/onto/l0/controlledVocabulary> ?controlledVocabulary
.
?fieldUri rdfs:range ?class .

OPTIONAL {
?class
<https://w3id.org/italia/onto/l0/controlledVocabulary> ?controlledVocabulary
.
}
}

OPTIONAL {
?fieldUri rdfs:comment ?comment .
FILTER(lang(?comment) = 'en')
}
}
`,
{ skip: !fieldUri },
Expand Down
Loading