Skip to content

Commit

Permalink
Merge branch 'kg-refactor' of https://github.com/biothings/bte_trapi_…
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed May 16, 2024
2 parents 7ca41aa + 505922a commit c342603
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MetaKG from '@biothings-explorer/smartapi-kg';
import MetaKG, { SmartAPIQueryResult } from '@biothings-explorer/smartapi-kg';
import path from 'path';
import QueryGraph from './query_graph';
import KnowledgeGraph from './graph/knowledge_graph';
Expand Down Expand Up @@ -73,14 +73,21 @@ export default class TRAPIQueryHandler {

async findUnregisteredAPIs() {
const configListAPIs = this.options.apiList['include'];
const smartapiRegistry = await fs.readFile(this.path, { encoding: 'utf8' });

let smartapiRegistry: SmartAPIQueryResult;
if (this.options.smartapi) {
smartapiRegistry = this.options.smartapi;
} else {
const file = await fs.readFile(this.path, "utf-8");
smartapiRegistry = JSON.parse(file);
}

const smartapiIds: string[] = [];
const inforesIds: string[] = [];
const unregisteredAPIs: string[] = [];

// TODO typing for smartapiRegistration
JSON.parse(smartapiRegistry).hits.forEach((smartapiRegistration) => {
smartapiRegistry.hits.forEach((smartapiRegistration) => {
smartapiIds.push(smartapiRegistration._id);
inforesIds.push(smartapiRegistration.info?.['x-translator']?.infores);
});
Expand All @@ -96,14 +103,23 @@ export default class TRAPIQueryHandler {
return unregisteredAPIs;
}

_loadMetaKG(): MetaKG {
const metaKG = new MetaKG(this.path, this.predicatePath);
async _loadMetaKG(): Promise<MetaKG> {
debug(
`Query options are: ${JSON.stringify({
...this.options,
schema: this.options.schema ? this.options.schema.info.version : 'not included',
metakg: "",
smartapi: ""
})}`,
);

if (this.options.metakg) {
const metaKG = new MetaKG(undefined, undefined, (this.options as any).metakg);
metaKG.filterKG(this.options);
return metaKG;
}

const metaKG = new MetaKG(this.path, this.predicatePath);
debug(`SmartAPI Specs read from path: ${this.path}`);
metaKG.constructMetaKGSync(this.includeReasoner, this.options);
return metaKG;
Expand Down Expand Up @@ -629,7 +645,7 @@ export default class TRAPIQueryHandler {
const span1 = Telemetry.startSpan({ description: 'loadMetaKG' });

debug('Start to load metakg.');
const metaKG = this._loadMetaKG();
const metaKG = await this._loadMetaKG();
if (!metaKG.ops.length) {
let error: string;
if (this.options.smartAPIID) {
Expand Down

0 comments on commit c342603

Please sign in to comment.