diff --git a/src/graph/kg_edge.ts b/src/graph/kg_edge.ts index 797c82f..baee66e 100644 --- a/src/graph/kg_edge.ts +++ b/src/graph/kg_edge.ts @@ -120,7 +120,8 @@ export default class KGEdge { addAdditionalAttributes(name: string, value: string | string[] | TrapiAttribute[]): void { // special handling for full edge attributes if (name === 'edge-attributes') { - this.attributes[name] = value as TrapiAttribute[]; + if (this.attributes[name]) this.attributes[name] = [...this.attributes[name], ...value as TrapiAttribute[]]; + else this.attributes[name] = value as TrapiAttribute[]; return; } diff --git a/src/graph/knowledge_graph.ts b/src/graph/knowledge_graph.ts index 9aa4b2d..b6d6818 100644 --- a/src/graph/knowledge_graph.ts +++ b/src/graph/knowledge_graph.ts @@ -166,9 +166,35 @@ export default class KnowledgeGraph { }); //handle TRAPI APIs (Situation A of https://github.com/biothings/BioThings_Explorer_TRAPI/issues/208) and APIs that define 'edge-atributes' in x-bte + const seenPmids = new Set(); kgEdge.attributes['edge-attributes']?.forEach((attribute) => { + // Do not add multiple SemmedDB sentences/other "supporting study results" from the same publication + if (attribute.attribute_type_id === "biolink:has_supporting_study_result" && attribute?.attributes?.find((attr) => attr.attribute_type_id === "biolink:publications")) { + const publication = attribute.attributes.find((attr) => attr.attribute_type_id === "biolink:publications").value; + // publication has been seen or cap reached + if (seenPmids.has(publication) || seenPmids.size >= 50) { + seenPmids.add(publication); + return; + } + seenPmids.add(publication); + } + attributes.push(attribute); }); + + // update evidence count after PMIDs have been merged (for SemmedDB) + if (seenPmids.size != 0) { + const evidenceAttr = attributes.find(attr => attr.attribute_type_id === 'biolink:evidence_count'); + if (evidenceAttr) { + evidenceAttr.value = seenPmids.size; + } else { + attributes.push({ + attribute_type_id: 'biolink:evidence_count', + value: seenPmids.size, + }); + } + } + return attributes; }