Skip to content

Commit

Permalink
Fix #643
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed Oct 14, 2024
1 parent 17b4133 commit 9098ae1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
20 changes: 7 additions & 13 deletions src/sparnatural/spec-providers/shacl/SHACLSpecificationEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ export class SHACLSpecificationEntity extends SHACLSpecificationEntry implements
propShapes
.forEach(ps => {
let prop = new SHACLSpecificationProperty(ps, this.provider, this.store, this.lang);
if(!prop.isDeactivated()) {
let pRange = prop.getRange();
if(pRange.indexOf(range) > -1) {
items.push(ps);
}
let pRange = prop.getRange();
if(pRange.indexOf(range) > -1) {
items.push(ps);
}
});

Expand Down Expand Up @@ -147,18 +145,15 @@ export class SHACLSpecificationEntity extends SHACLSpecificationEntry implements
getConnectedEntities(): string[] {
var items: string[] = [];

// read all sh:property
// let propShapes = this._readAsResource(factory.namedNode(this.uri), SH.PROPERTY);
// read all properties that make sense for Sparnatural
let propShapes = this.getProperties();

propShapes
.forEach(ps => {
// read the property
let prop = new SHACLSpecificationProperty(ps, this.provider, this.store, this.lang);
if(!prop.isDeactivated()) {
// and then read their ranges
items.push(...prop.getRange());
}
// and then read their ranges
items.push(...prop.getRange());
});

// dedup
Expand Down Expand Up @@ -242,8 +237,7 @@ export class SHACLSpecificationEntity extends SHACLSpecificationEntry implements

propShapes
.forEach(ps => {
let prop = new SHACLSpecificationProperty(ps, this.provider, this.store, this.lang);
if(!prop.isDeactivated()) {
if(SHACLSpecificationProperty.isSparnaturalSHACLSpecificationProperty(ps, this.store)) {
items.push(ps);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ export class SHACLSpecificationProperty extends SHACLSpecificationEntry implemen
super(uri, provider, n3store, lang);
}

/**
* Tests whether the provided property shape URI will be turned into a Sparnatural property
* @param propertyShapeUri
* @param n3store
* @returns false if the property is deactivated, or it is on rdf:type, or it has an sh:hasValue
*/
static isSparnaturalSHACLSpecificationProperty(propertyShapeUri:string, n3store: RdfStore):boolean {
let graph = new StoreModel(n3store);
return (
!graph.hasTriple(factory.namedNode(propertyShapeUri), SH.DEACTIVATED, factory.literal("true", XSD.BOOLEAN))
&&
!graph.hasTriple(factory.namedNode(propertyShapeUri), SH.PATH, RDF.TYPE)
&&
!graph.hasTriple(factory.namedNode(propertyShapeUri), SH.HAS_VALUE, null)
);
}

getLabel(): string {
// first try to read an sh:name
let label = this.graph.readSinglePropertyInLang(factory.namedNode(this.uri), SH.NAME, this.lang)?.value;
Expand Down Expand Up @@ -349,7 +366,7 @@ export class SHACLSpecificationProperty extends SHACLSpecificationEntry implemen
null
).forEach((q:Quad) => {
n3store.getQuads(
quad.object,
q.subject,
RDF.TYPE,
SH.NODE_SHAPE,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const SH = {
DATATYPE: factory.namedNode(SH_NAMESPACE + "datatype") as NamedNode,
DEACTIVATED: factory.namedNode(SH_NAMESPACE + "deactivated") as NamedNode,
DESCRIPTION: factory.namedNode(SH_NAMESPACE + "description") as NamedNode,
HAS_VALUE: factory.namedNode(SH_NAMESPACE + "hasValue") as NamedNode,
IN: factory.namedNode(SH_NAMESPACE + "in") as NamedNode,
INVERSE_PATH: factory.namedNode(SH_NAMESPACE + "inversePath") as NamedNode,
IRI: factory.namedNode(SH_NAMESPACE + "IRI") as NamedNode,
Expand Down Expand Up @@ -390,7 +391,7 @@ export class SHACLSpecificationProvider extends BaseRDFReader implements ISparna
return !that.graph.hasTriple(node, SH.DEACTIVATED, factory.literal("true", XSD.BOOLEAN))
});

// remove from the initial list the NodeShapes that are connected to only deactivated properties
// remove from the initial list the NodeShapes that are connected to only properties that Sparnatural will not use
// by checking the lenght of the list of properties we can make sure of that
dedupNodeShapes = dedupNodeShapes.filter(node => {
return (this.getEntity(node.value) as SHACLSpecificationEntity).getProperties().length > 0;
Expand Down

0 comments on commit 9098ae1

Please sign in to comment.