Skip to content

Commit

Permalink
fix: fix qualifier array or string
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Dec 5, 2023
1 parent 4ea2f9e commit 7c60594
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,15 @@ export class Record {
const reversedQualifiers = Object.fromEntries(
Object.entries(reversedAPIEdge.qualifiers).map(([qualifierType, qualifier]) => {
let newQualifierType: string = qualifierType;
let newQualifier: string = qualifier;
let newQualifier: string | string[] = qualifier;
if (qualifierType.includes("predicate")) {
newQualifier = `biolink:${this.qEdge.getReversedPredicate(qualifier.replace("biolink:", ""))}`;
if (Array.isArray(qualifier)) {
newQualifier = qualifier.map(
(str: string) => `biolink:${this.qEdge.getReversedPredicate(str.replace("biolink:", ""))}`,
);
} else {
newQualifier = `biolink:${this.qEdge.getReversedPredicate(qualifier.replace("biolink:", ""))}`;
}
}
if (qualifierType.includes("subject")) {
newQualifierType = qualifierType.replace("subject", "object");
Expand Down Expand Up @@ -230,9 +236,9 @@ export class Record {
getHashedEdgeRepresentation(): string {
return hash(
record.subject.semanticType +
record.predicate +
record.object.semanticType +
(record.subject.equivalentCuries || record.object.equivalentCuries),
record.predicate +
record.object.semanticType +
(record.subject.equivalentCuries || record.object.equivalentCuries),
);
},
};
Expand All @@ -243,10 +249,10 @@ export class Record {
predicate: record.predicate?.replace("biolink:", ""),
qualifiers: record.qualifiers
? Object.fromEntries(
Object.entries(record.qualifiers).map(([qualifierType, qualifier]: [string, string]) => {
return [qualifierType.replace("biolink:", ""), qualifier];
}),
)
Object.entries(record.qualifiers).map(([qualifierType, qualifier]: [string, string]) => {
return [qualifierType.replace("biolink:", ""), qualifier];
}),
)
: undefined,
api_name: record.api,
source: record.metaEdgeSource,
Expand Down Expand Up @@ -346,11 +352,11 @@ export class Record {
_getFlattenedEdgeAttributes(attributes: EdgeAttribute[]): EdgeAttribute[] {
return attributes
? attributes.reduce((arr: EdgeAttribute[], attribute: EdgeAttribute) => {
attribute.attributes
? arr.push(attribute, ...this._getFlattenedEdgeAttributes(attribute.attributes))
: arr.push(attribute);
return arr;
}, [])
attribute.attributes
? arr.push(attribute, ...this._getFlattenedEdgeAttributes(attribute.attributes))
: arr.push(attribute);
return arr;
}, [])
: [];
}

Expand Down Expand Up @@ -396,7 +402,11 @@ export class Record {
const newQualifierType = `biolink:${qualifierType.replace("biolink:", "")}`;
let newQualifier = qualifier;
if (qualifierType.includes("predicate")) {
newQualifier = `biolink:${qualifier.replace("biolink:", "")}`;
if (Array.isArray(qualifier)) {
newQualifier = qualifier.map(str => `biolink:${str.replace("biolink", "")}`);
} else {
newQualifier = `biolink:${qualifier.replace("biolink:", "")}`;
}
}
return [newQualifierType, newQualifier];
}),
Expand Down Expand Up @@ -586,7 +596,7 @@ export interface NodeNormalizerResultObj {
}

export interface BulkQualifiers {
[qualifierTypeID: string]: string; // qualifierValue
[qualifierTypeID: string]: string | string[]; // qualifierValue
}

export interface ProvenanceChainItem {
Expand Down

0 comments on commit 7c60594

Please sign in to comment.