Skip to content

Commit be01271

Browse files
authored
Merge pull request #13 from psychoinformatics-de/shor
Support the correct nodeKind determination for a limited `sh:or` scenario
2 parents be0108b + 4c9b163 commit be01271

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shacl-tulip",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"type": "module",
55
"main": "./src/index.js",
66
"module": "./src/index.js",

public/tests/mockShapes.ttl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,19 @@ dlsocial:Person a sh:NodeShape ;
166166
sh:maxCount 1 ;
167167
sh:nodeKind sh:IRI ;
168168
sh:order 2 ;
169-
sh:path dlspatial:at_location ] ;
169+
sh:path dlspatial:at_location ],
170+
[ sh:description "The type of person, which is one of two classes: a 'Parent' or a 'Child'" ;
171+
sh:maxCount 1 ;
172+
sh:minCount 1 ;
173+
sh:or ( [ sh:class ex:Parent ] [ sh:class ex:Child ] ) ;
174+
sh:order 1 ;
175+
sh:path dlthings:person_type ],
176+
[ sh:description "The organization that the Person belongs to" ;
177+
sh:maxCount 1 ;
178+
sh:minCount 1 ;
179+
sh:or ( [ sh:class ex:Organization ] [ sh:nodeKind sh:Literal ; sh:datatype xsd:string ] ) ;
180+
sh:order 1 ;
181+
sh:path dlthings:belongs_to ] ;
170182
sh:targetClass dlsocial:Person .
171183

172184

src/classes/ShapesDataset.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ export class ShapesDataset extends RdfDataset {
145145
// Assume Literal nodekind for any arrays
146146
console.log(`\t- NodeKind not found for property shape: ${property_uri}; found 'sh:in'. Setting to default literal`)
147147
nodeFunc = literal
148+
} else if (
149+
propertyShape.hasOwnProperty(SHACL.or.value) &&
150+
Array.isArray(propertyShape[SHACL.or.value]) &&
151+
propertyShape[SHACL.or.value].every(obj => obj.hasOwnProperty(SHACL.class.value))
152+
) {
153+
// This is a temporary solution to exactly match the property values entered using `shacl-vue`'s `ShaclORClassEditor`
154+
// A future replacement should account for a generic `sh:or`
155+
console.log(`\t- NodeKind not found for property shape: ${property_uri}; found 'sh:or' with every element containing 'sh:class'. Setting to namedNode`)
156+
nodeFunc = namedNode
148157
}
149158
else {
150159
console.log(`\t- NodeKind not found for property shape: ${property_uri}. Setting to default literal`)

tests/ShapesDataset.test.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect, beforeEach} from 'vitest';
22
import { ShapesDataset } from '@/classes/ShapesDataset';
3-
import { DataFactory } from 'n3';
4-
const { literal, blankNode } = DataFactory;
3+
import { DataFactory, NamedNode } from 'n3';
4+
const { literal, blankNode, namedNode } = DataFactory;
55
import httpServer from 'http-server';
66
let server;
77
const PORT = 8082;
@@ -28,7 +28,7 @@ describe('ShapesDataset', () => {
2828
await new Promise(resolve => dataset.addEventListener('graphLoaded', resolve));
2929
expect(dataset.data.graphLoaded).toBe(true);
3030
expect(dataset.data.prefixesLoaded).toBe(true);
31-
expect(dataset.data.graph.size).toBe(318); // number of quads in the mockShapes.ttl file
31+
expect(dataset.data.graph.size).toBe(345); // number of quads in the mockShapes.ttl file
3232
// Test content of all loaded variables
3333
expect(dataset.data.nodeShapeNames).toEqual(
3434
{
@@ -76,23 +76,39 @@ describe('ShapesDataset', () => {
7676
}
7777
)
7878
// Test getPropertyNodeKind
79-
80-
// expect(getPropertyNodeKind(class_uri, property_uri, id_uri))
79+
// Test literal nodekind
8180
var nk1 = dataset.getPropertyNodeKind(
8281
'https://concepts.datalad.org/s/social/unreleased/Person',
8382
'https://concepts.datalad.org/s/social/unreleased/honorific_name_prefix',
8483
'https://concepts.datalad.org/s/things/v1/id'
8584
)
86-
8785
expect(nk1[0]).toBeTypeOf('function')
8886
expect(nk1[0]).toEqual(literal)
87+
// Test blankNode
8988
var nk2 = dataset.getPropertyNodeKind(
9089
'https://concepts.datalad.org/s/social/unreleased/Person',
9190
'https://concepts.datalad.org/s/things/v1/attributes',
9291
'https://concepts.datalad.org/s/things/v1/id'
9392
)
9493
expect(nk2[0]).toBeTypeOf('function')
9594
expect(nk2[0]).toEqual(blankNode)
95+
// Test sh:or with ALL elements in array containing sh:class
96+
var nk3 = dataset.getPropertyNodeKind(
97+
'https://concepts.datalad.org/s/social/unreleased/Person',
98+
'https://concepts.datalad.org/s/things/v1/person_type',
99+
'https://concepts.datalad.org/s/things/v1/id'
100+
)
101+
expect(nk3[0]).toBeTypeOf('function')
102+
expect(nk3[0]).toEqual(namedNode)
103+
// Test sh:or with NOT all elements in array containing sh:class
104+
var nk4 = dataset.getPropertyNodeKind(
105+
'https://concepts.datalad.org/s/social/unreleased/Person',
106+
'https://concepts.datalad.org/s/things/v1/belongs_to',
107+
'https://concepts.datalad.org/s/things/v1/id'
108+
)
109+
expect(nk4[0]).toBeTypeOf('function')
110+
expect(nk4[0]).toEqual(literal)
111+
96112
server.close();
97113
});
98114

0 commit comments

Comments
 (0)