Skip to content

Commit

Permalink
Merge pull request #48 from zazuko/use-path-strategy
Browse files Browse the repository at this point in the history
Use path strategy
  • Loading branch information
BenjaminHofstetter authored Nov 18, 2024
2 parents cb98b58 + 82a75bc commit 658f905
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { shacl } from '@blueprint/ontology';
*/
export class UiLinkMetadata extends ClownfaceObject {

private _destination: string | null = null;
private _source: string | null = null;
private _path: MultiPointer | null = null;
private _label: string | null = null;
#destination: string | null = null;
#source: string | null = null;
#path: MultiPointer | null = null;
#label: string | null = null;

constructor(node: GraphPointer) {
super(node);
Expand All @@ -24,16 +24,16 @@ export class UiLinkMetadata extends ClownfaceObject {
* @link shacl:class
*/
public get destination(): string {
if (this._destination === null) {
if (this.#destination === null) {
const destinationNodeIris = this._node.out(shacl.classNamedNode).values;
if (destinationNodeIris.length === 0) {
console.warn(`UiLinkMetadata.destination is undefined for ${this._node.value}.`);
} else if (destinationNodeIris.length > 1) {
console.warn(`UiLinkMetadata.destination has multiple values for ${this._node.value}. Using the first one.`);
}
this._destination = destinationNodeIris[0] ?? '';
this.#destination = destinationNodeIris[0] ?? '';
}
return this._destination;
return this.#destination;
}

/**
Expand All @@ -43,16 +43,16 @@ export class UiLinkMetadata extends ClownfaceObject {
* @link shacl:targetClass
*/
public get source(): string {
if (this._source === null) {
if (this.#source === null) {
const sourceNodeIris = this._node.out(shacl.targetClassNamedNode).values;
if (sourceNodeIris.length === 0) {
console.warn(`UiLinkMetadata.source is undefined for ${this._node.value}.`);
} else if (sourceNodeIris.length > 1) {
console.warn(`UiLinkMetadata.source has multiple values for ${this._node.value}. Using the first one.`);
}
this._source = sourceNodeIris[0] ?? '';
this.#source = sourceNodeIris[0] ?? '';
}
return this._source;
return this.#source;
}

/**
Expand All @@ -62,16 +62,16 @@ export class UiLinkMetadata extends ClownfaceObject {
* @link shacl:path
*/
public get path(): MultiPointer {
if (this._path === null) {
if (this.#path === null) {
const pathNode = this._node.out(shacl.pathNamedNode);
if (pathNode.values.length === 0) {
console.warn(`UiLinkMetadata.path is undefined for ${this._node.value}.`);
} else if (pathNode.values.length > 1) {
console.warn(`UiLinkMetadata.path has multiple values for ${this._node.value}. Using the first one.`);
}
this._path = pathNode.toArray()[0];
this.#path = pathNode.toArray()[0];
}
return this._path;
return this.#path;
}

/**
Expand All @@ -81,20 +81,20 @@ export class UiLinkMetadata extends ClownfaceObject {
* @link shacl:name
*/
public get label(): string {
if (this._label === null) {
if (this.#label === null) {
const labels = this._node.out(shacl.nameNamedNode).values;
if (labels.length === 0) {
console.warn(`UiLinkMetadata.label is undefined for ${this._node.value}. Using an empty string.`);
this._label = '';
return this._label;
this.#label = '';
return this.#label;
} else if (labels.length > 1) {
console.warn(`UiLinkMetadata.label has multiple values for ${this._node.value}. Joining them with a space.`);
this._label = labels.join(' ');
this.#label = labels.join(' ');
} else {
this._label = labels[0];
this.#label = labels[0];
}
}
return this._label;
return this.#label;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,63 @@ export interface ICompositionToCompositionLink {

export class CompositionToCompositionLink extends ClownfaceObject implements ICompositionToCompositionLink {

private _sourceComposition: Composition | null | undefined = undefined;
private _targetComposition: Composition | null | undefined = undefined;
private _label: string | null = null;
#sourceComposition: Composition | null | undefined = undefined;
#targetComposition: Composition | null | undefined = undefined;
#label: string | null = null;


constructor(node: GraphPointer) {
super(node);
}

get sourceComposition(): Composition | null {
if (this._sourceComposition === undefined) {
if (this.#sourceComposition === undefined) {

const sourceCompositions = this._node.out(shacl.targetClassNamedNode).map(p => new Composition(p));

if (sourceCompositions.length === 0) {
console.warn(`AggregateLink has no sourceIri: ${this._node.value}`);
this._sourceComposition = null;
this.#sourceComposition = null;
} else {
if (sourceCompositions.length > 1) {
console.warn(`AggregateLink has more than one source composition: ${this._node.value}. Using the first one.`);
}
this._sourceComposition = sourceCompositions[0];
this.#sourceComposition = sourceCompositions[0];
}
}
return this._sourceComposition;
return this.#sourceComposition;
}

get targetComposition(): Composition | null {
if (this._targetComposition === undefined) {
if (this.#targetComposition === undefined) {
const targetCompositions = this._node.out(blueprint.targetNamedNode).map(n => new Composition(n));
if (targetCompositions.length === 0) {
console.warn(`AggregateLink has no sourceIri: ${this._node.value}`);
this._targetComposition = null;
this.#targetComposition = null;
} else {
if (targetCompositions.length > 1) {
console.warn(`AggregateLink has more than one target compositions: ${this._node.value}. Using the first one.`);
}
this._targetComposition = targetCompositions[0];
this.#targetComposition = targetCompositions[0];
}
}
return this._targetComposition;
return this.#targetComposition;
}

get label(): string {
if (this._label === null) {
if (this.#label === null) {
const labels = this._node.out(rdfs.labelNamedNode).values;
if (labels.length === 0) {
console.warn(`AggregateLink has no label: ${this._node.value}. Using "" as label.`);
this._label = '';
this.#label = '';
} else {
if (labels.length > 1) {
console.warn(`AggregateLink has more than one label: ${labels}. Joining them with a space.`);
}
this._label = labels.join(' ');
this.#label = labels.join(' ');
}
}
return this._label;
return this.#label;
}

get path(): PathDefinition[][] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { PathDefinition } from "../path-definition";
import { Composition } from "../composition";
import { OutgoingPathFactory } from "projects/blueprint/src/app/shared/sparql/path/factory/outgoing-path-factory";


export interface ICompositionToNodeLink {
iri: string;
sourceComposition: Composition | null;
Expand Down Expand Up @@ -106,10 +105,20 @@ export class CompositionToNodeLink extends ClownfaceObject implements ICompositi
const path = this._node.out(shacl.propertyNamedNode).map(p => {
const targetClass = p.out(shacl.targetClassNamedNode).values[0];
const shClass = p.out(shacl.classNamedNode).values[0];
const cfPath = p.out(shacl.pathNamedNode).toArray()[0];

const pathFactory = new OutgoingPathFactory();
const path = pathFactory.createPath(cfPath);
return [new PathDefinition(targetClass, shClass, path.toPathFragments())];

const pathStrategy = p.out(shacl.pathNamedNode).map(p => pathFactory.createPath(p));

if (pathStrategy.length === 0) {
console.warn(`AggregateLink has no path: ${this._node.value}. Using empty path.`);
return [];
}
if (pathStrategy.length > 1) {
console.warn(`AggregateLink has more than one path: ${pathStrategy}. Using the first one.`);
}

return [new PathDefinition(targetClass, shClass, pathStrategy[0].toPathFragments())];

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,60 @@ import { ClownfaceObject } from '@blueprint/model/clownface-object/clownface-obj

export class HierarchyNode extends ClownfaceObject {

#_children: HierarchyNode[] | null = null;
#_targetClass: string | null = null;
#_label: string | null = null;
#_classLabel: string | null = null;
#_parent: HierarchyNode | null | undefined = undefined;
#children: HierarchyNode[] | null = null;
#targetClass: string | null = null;
#label: string | null = null;
#classLabel: string | null = null;
#parent: HierarchyNode | null | undefined = undefined;

constructor(cfNode: GraphPointer) {
super(cfNode);
}

get label(): string {
if (this.#_label === null) {
this.#_label = this._node.out(rdfs.labelNamedNode).value ?? '';
if (this.#label === null) {
this.#label = this._node.out(rdfs.labelNamedNode).value ?? '';
}
return this.#_label;
return this.#label;
}

get children(): HierarchyNode[] {
if (this.#_children === null) {
this.#_children = this._node.out(shacl.propertyNamedNode).out(shacl.nodeNamedNode).map(childNode => new HierarchyNode(childNode));
if (this.#children === null) {
this.#children = this._node.out(shacl.propertyNamedNode).out(shacl.nodeNamedNode).map(childNode => new HierarchyNode(childNode));
}
return this.#_children;
return this.#children;
}

get targetClass(): string {
if (this.#_targetClass === null) {
if (this.#targetClass === null) {
const targetClasses = this._node.out(shacl.targetClassNamedNode).values;
if (targetClasses.length === 0) {
console.warn(`No targetClass found for node ${this.iri}. Use an empty string.`);
this.#_targetClass = '';
this.#targetClass = '';
} else {
if (targetClasses.length > 1) {
console.warn(`Expected exactly one targetClass for node ${this.iri}. Found ${targetClasses.length}. Use the first one.`);
}
this.#_targetClass = targetClasses[0];
this.#targetClass = targetClasses[0];
}
}
return this.#_targetClass;
return this.#targetClass;
}

get classLabel(): string {
if (this.#_classLabel === null) {
if (this.#classLabel === null) {
const classLabels = this._node.out(shacl.targetClassNamedNode).in(shacl.targetNodeNamedNode).out(rdfs.labelNamedNode).values;
if (classLabels.length === 0) {
console.warn(`No classLabel found for node ${this.iri}. Use an empty string.`);
this.#_classLabel = '';
this.#classLabel = '';
} else {
if (classLabels.length > 1) {
console.warn(`Expected exactly one classLabel for node ${this.iri}. Found ${classLabels.length}. Use the first one.`);
}
this.#_classLabel = classLabels[0];
this.#classLabel = classLabels[0];
}
}
return this.#_classLabel;
return this.#classLabel;
}

get pathToParent(): string | null {
Expand Down Expand Up @@ -100,6 +100,7 @@ export class HierarchyNode extends ClownfaceObject {
return '';
}


if (path.term.termType === 'BlankNode') {
const inverse = path.out(shacl.inversePathNamedNode);
if (inverse.values.length === 1) {
Expand All @@ -117,18 +118,20 @@ export class HierarchyNode extends ClownfaceObject {


get parent(): HierarchyNode | null {
if (this.#_parent === undefined) {
if (this.#parent === undefined) {
const parent = this._node.in(shacl.nodeNamedNode).in(shacl.propertyNamedNode);
if (parent.values.length === 0) {
this.#_parent = null;
this.#parent = null;
} else {
if (parent.values.length > 1) {
console.warn(`Expected exactly one parent for node ${this.iri}. Found ${parent.values.length}. Use the first one.`);
}
this.#_parent = new HierarchyNode(parent.toArray()[0]);
this.#parent = new HierarchyNode(parent.toArray()[0]);
}
}
return this.#_parent;
return this.#parent;
}



}
Loading

0 comments on commit 658f905

Please sign in to comment.