Skip to content

Commit

Permalink
clownface debug logTable
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofstetter Benjamin (extern) committed Nov 15, 2024
1 parent d6f2376 commit 612aaa3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ export abstract class ClownfaceObject {
return [...predicateSet];
}

static logNodeAsTable(node: GraphPointer) {
const spo = [...node.dataset.match(node.term)].map(quad => {
return {
subject: quad.subject.value,
predicate: quad.predicate.value,
object: quad.object.value,
}
});
console.table(spo);
}

protected readonly _node: GraphPointer;

/**
Expand Down Expand Up @@ -53,14 +64,7 @@ export abstract class ClownfaceObject {
* This is a debug function to log this node to the console as a table.
*/
logTable() {
const spo = [...this._node.dataset.match(rdfEnvironment.namedNode(this.iri))].map(quad => {
return {
subject: quad.subject.value,
predicate: quad.predicate.value,
object: quad.object.value,
}
});
console.table(spo);
return ClownfaceObject.logNodeAsTable(this._node);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class AggregateService {
outLinks.push(...links);
});


const inLinks: ICompositionToNodeLink[] = [];
const inLinkFactory = new IncomingCompositionToNodeLinkFactory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ export interface ICompositionToNodeLink {
}

export class CompositionToNodeLink extends ClownfaceObject implements ICompositionToNodeLink {
private _sourceComposition: Composition | null | undefined = undefined;
private _targetComposition: Composition | null | undefined = undefined;
#sourceComposition: Composition | null | undefined = undefined;
#targetComposition: Composition | null | undefined = undefined;

private _sourceNodeIri: string | null | undefined = undefined;
private _targetNodeIri: string | null | undefined = undefined;

private _label: string | null = null;
#sourceNodeIri: string | null | undefined = undefined;
#targetNodeIri: string | null | undefined = undefined;
#label: string | null = null;


constructor(node: GraphPointer) {
Expand All @@ -36,21 +35,21 @@ export class CompositionToNodeLink extends ClownfaceObject implements ICompositi
* @readonly
*/
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) {
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;
}

/**
Expand All @@ -60,42 +59,42 @@ export class CompositionToNodeLink extends ClownfaceObject implements ICompositi
* @readonly
*/
get targetComposition(): Composition | null {
if (this._targetComposition === undefined) {
if (this.#targetComposition === undefined) {
const targetCompositions = this._node.out(blueprint.targetNamedNode).has(rdf.typeNamedNode, blueprint.CompositionNamedNode).map(p => new Composition(p));

if (targetCompositions.length === 0) {
this._targetComposition = null;
this.#targetComposition = null;
} else {
if (targetCompositions.length > 1) {
console.warn(`AggregateLink has more than one Composition <${this._node.value}>. Using the first one.`);
}
this._targetComposition = targetCompositions[0];
this.#targetComposition = targetCompositions[0];
}
}

return this._targetComposition;
return this.#targetComposition;
}

/**
* The label of the link. If the link is incomming the label is showing the bp:inverseLabel.
* The label of the link. If the link is incoming the label is showing the bp:inverseLabel.
* This is done while fetching the data (SPARQL construct).
*
* @readonly
*/
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;
}

/**
Expand Down Expand Up @@ -123,18 +122,18 @@ export class CompositionToNodeLink extends ClownfaceObject implements ICompositi
* @readonly
*/
get sourceNodeIri(): string | null {
if (this._sourceNodeIri === undefined) {
if (this.#sourceNodeIri === undefined) {
const sourceIris = this._node.out(blueprint.sourceNamedNode).values;
if (sourceIris.length === 0) {
this._sourceNodeIri = null;
this.#sourceNodeIri = null;
} else {
if (sourceIris.length > 1) {
console.warn(`AggregateLink has more than one sourceNodeIri: ${sourceIris}. Using the first one.`);
}
this._sourceNodeIri = sourceIris[0];
this.#sourceNodeIri = sourceIris[0];
}
}
return this._sourceNodeIri;
return this.#sourceNodeIri;
}

/**
Expand All @@ -143,18 +142,18 @@ export class CompositionToNodeLink extends ClownfaceObject implements ICompositi
* @readonly
*/
get targetNodeIri(): string | null {
if (this._targetNodeIri === undefined) {
if (this.#targetNodeIri === undefined) {
const targetIris = this._node.out(blueprint.targetNamedNode).values;
if (targetIris.length === 0) {
this._targetNodeIri = null;
this.#targetNodeIri = null;
} else {
if (targetIris.length > 1) {
console.warn(`AggregateLink has more than one targetNodeIri: ${targetIris}. Using the first one.`);
}
this._targetNodeIri = targetIris[0];
this.#targetNodeIri = targetIris[0];
}
}
return this._targetNodeIri;
return this.#targetNodeIri;
}

invert(): ICompositionToNodeLink {
Expand Down

0 comments on commit 612aaa3

Please sign in to comment.