Closed megoth-capgemini closed 1 year ago
Interesting. Could you paste the contents of the generated *.context.ts
and the *.typings.ts
files associated with your ShEx shape?
Sure, the contents of app.context.ts
:
import { ContextDefinition } from "jsonld";
/**
* =============================================================================
* appContext: JSONLD Context for app
* =============================================================================
*/
export const appContext: ContextDefinition = {
type: {
"@id": "@type",
"@container": "@set",
},
Document: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Document",
vocabulary: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#vocabulary",
"@type": "@id",
"@container": "@set",
},
Vocabulary:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Vocabulary",
name: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name",
"@type": "http://www.w3.org/2001/XMLSchema#string",
"@container": "@set",
},
path: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path",
"@type": "@id",
"@container": "@set",
},
law: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#law",
"@type": "@id",
},
Law: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Law",
};
And the contents of app.typings.ts
:
import { ContextDefinition } from "jsonld";
/**
* =============================================================================
* Typescript Typings for app
* =============================================================================
*/
/**
* DocumentShape Type
*/
export interface DocumentShape {
"@id"?: string;
"@context"?: ContextDefinition;
type: {
"@id": "Document";
};
vocabulary?: VocabularyShape[];
law: LawShape;
}
/**
* LawShape Type
*/
export interface LawShape {
"@id"?: string;
"@context"?: ContextDefinition;
type: {
"@id": "Law";
};
name: string;
path: {
"@id": string;
};
}
/**
* VocabularyShape Type
*/
export interface VocabularyShape {
"@id"?: string;
"@context"?: ContextDefinition;
type: {
"@id": "Vocabulary";
};
name: string;
path: {
"@id": string;
};
}
Something that sticks out to me is the use of "@container": "@set"
in app.context.ts
, which is not present when the predicates aren't reused across multiple shapes.
Right, I expect this is a bug. Could you also send the contents of app.schema.ts
?
The contents of app.schema.ts
:
import { Schema } from "shexj";
/**
* =============================================================================
* appSchema: ShexJ Schema for app
* =============================================================================
*/
export const appSchema: Schema = {
type: "Schema",
shapes: [
{
id: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#DocumentShape",
type: "ShapeDecl",
shapeExpr: {
type: "Shape",
expression: {
type: "EachOf",
expressions: [
{
type: "TripleConstraint",
predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
valueExpr: {
type: "NodeConstraint",
values: [
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Document",
],
},
},
{
type: "TripleConstraint",
predicate:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#vocabulary",
valueExpr:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#VocabularyShape",
min: 0,
max: -1,
},
{
type: "TripleConstraint",
predicate:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#law",
valueExpr:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#LawShape",
},
],
},
},
},
{
id: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#LawShape",
type: "ShapeDecl",
shapeExpr: {
type: "Shape",
expression: {
type: "EachOf",
expressions: [
{
type: "TripleConstraint",
predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
valueExpr: {
type: "NodeConstraint",
values: [
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Law",
],
},
},
{
type: "TripleConstraint",
predicate:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name",
valueExpr: {
type: "NodeConstraint",
datatype: "http://www.w3.org/2001/XMLSchema#string",
},
},
{
type: "TripleConstraint",
predicate:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path",
valueExpr: {
type: "NodeConstraint",
nodeKind: "iri",
},
},
],
},
},
},
{
id: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#VocabularyShape",
type: "ShapeDecl",
shapeExpr: {
type: "Shape",
expression: {
type: "EachOf",
expressions: [
{
type: "TripleConstraint",
predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
valueExpr: {
type: "NodeConstraint",
values: [
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Vocabulary",
],
},
},
{
type: "TripleConstraint",
predicate:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name",
valueExpr: {
type: "NodeConstraint",
datatype: "http://www.w3.org/2001/XMLSchema#string",
},
},
{
type: "TripleConstraint",
predicate:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path",
valueExpr: {
type: "NodeConstraint",
nodeKind: "iri",
},
},
],
},
},
},
],
};
Thank you so much for looking into it ^_^
Yep, this is definitely a bug. I'll take a look into it tomorrow.
Hey, I looked into it and I wasn't able to replicate the issue. Pasting your ShEx in, I see the following:
import {ContextDefinition} from "jsonld"
export interface DocumentShape {
"@id"?: string;
"@context"?: ContextDefinition;
type: {
"@id": "Document";
};
vocabulary?: (VocabularyShape)[];
law: LawShape;
}
export interface LawShape {
"@id"?: string;
"@context"?: ContextDefinition;
type: {
"@id": "Law";
};
name: string;
path: {
"@id": string;
};
}
export interface VocabularyShape {
"@id"?: string;
"@context"?: ContextDefinition;
type: {
"@id": "Vocabulary";
};
name: string;
path: {
"@id": string;
};
}
The cardinality on name
and path
seem correct. Are you using the most recent version of LDO?
I was using an older version of LDO (ldo@0.0.12, ldo-cli@2.0.0), and have now upgraded to latest (ldo@1.0.1, ldo-cli@3.0.1), but I'm still having some problems.
The cardinality looks correct, but the problem is in the context I think:
import { ContextDefinition } from "jsonld";
/**
* =============================================================================
* appContext: JSONLD Context for app
* =============================================================================
*/
export const appContext: ContextDefinition = {
type: {
"@id": "@type",
"@container": "@set",
},
Document: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Document",
vocabulary: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#vocabulary",
"@type": "@id",
"@container": "@set",
},
Vocabulary:
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Vocabulary",
name: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name",
"@type": "http://www.w3.org/2001/XMLSchema#string",
"@container": "@set",
},
path: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path",
"@type": "@id",
"@container": "@set",
},
law: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#law",
"@type": "@id",
},
Law: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Law",
};
When I console.log or debug vocab.path
in my code, it seems to referring to an array, and if I do console.log("TEST", vocab?.path.map((p) => p["@id"]))
it outputs an array with one element, i.e. the value that I'm expecting. So it seems to setting the data as an array, instead of the value itself.
A weird thing now though, is that it only seems to be affecting .path
, i.e. .name
is working as expected.
Ah, yep. Sorry I missed that. Looking into it now.
Welp, this bug is going to require a slight re-architecture. So, in the meantime removing the "@container: @set" from your context manually is going to be the best bet.
I'll let you know when this is fixed.
Closed in favor of https://github.com/o-development/ldo/issues/22
I'm not 100% sure if this is a bug, but I tried to simplify an ontology by reusing some predicates, which seemingly leeds to LDO not loading data properly.
The original ontology:
The original shape:
I wanted to simplify these by combining
app:lawName
andapp:vocabName
intoapp:name
, andapp:lawPath
andapp:vocabPath
intoapp:path
. For reference, these are the changed files:The ontology:
The shape:
As I understand it, these shouldn't have any changes except needing to change
.vocabName
and.lawName
to.name
and.vocabPath
and.lawPath
into.path
in my code. But for some reason, the code that previously worked,vocab?.vocabPath?.["@id"]
, now needs to bevocab?.vocabPath[0]?.["@id"]
.Again, I'm not sure if this is a bug, or if I've misunderstood something, but thought I should create a bug issue to let you know in case it is actually a bug.