Skip to content

Commit

Permalink
feat: support source_record_urls
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Apr 11, 2024
1 parent 1838d58 commit da17df0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/graph/kg_edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class KGEdge {
resource_id: string;
resource_role: string;
upstream_resource_ids?: Set<string>;
source_record_urls?: Set<string>;
};
};
};
Expand Down Expand Up @@ -77,19 +78,26 @@ export default class KGEdge {
}
source.forEach((item) => {
if (!this.sources[item.resource_id]) this.sources[item.resource_id] = {};
if (item.upstream_resource_ids && !Array.isArray(item.upstream_resource_ids)) {
item.upstream_resource_ids = [item.upstream_resource_ids];
}
if (item.source_record_urls && !Array.isArray(item.source_record_urls)) {
item.source_record_urls = [item.source_record_urls];
}
if (!this.sources[item.resource_id][item.resource_role]) {
this.sources[item.resource_id][item.resource_role] = {
resource_id: item.resource_id,
resource_role: item.resource_role,
upstream_resource_ids: item.upstream_resource_ids ? new Set(item.upstream_resource_ids) : undefined,
source_record_urls: item.source_record_urls ? new Set(item.source_record_urls) : undefined,
};
}
if (item.upstream_resource_ids && !Array.isArray(item.upstream_resource_ids)) {
item.upstream_resource_ids = [item.upstream_resource_ids];
}
item.upstream_resource_ids?.forEach((upstream) =>
this.sources[item.resource_id][item.resource_role].upstream_resource_ids.add(upstream),
);
item.source_record_urls?.forEach((url) =>
this.sources[item.resource_id][item.resource_role].source_record_urls.add(url),
);
});
}

Expand Down
1 change: 1 addition & 0 deletions src/graph/knowledge_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default class KnowledgeGraph {
const trapiSource: TrapiSource = {
...sourceObj,
upstream_resource_ids: sourceObj.upstream_resource_ids ? [...sourceObj.upstream_resource_ids] : undefined,
source_record_urls: sourceObj.source_record_urls ? [...sourceObj.source_record_urls] : undefined,
};
sources.push(trapiSource);
});
Expand Down

0 comments on commit da17df0

Please sign in to comment.