Skip to content

Commit dc48864

Browse files
authored
Merge pull request #189 from biothings/source-urls
Support `source_record_urls`
2 parents 1bd30c5 + da17df0 commit dc48864

File tree

14 files changed

+45
-180
lines changed

14 files changed

+45
-180
lines changed

src/cache_handler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import chunker from 'stream-chunker';
99
import { Readable, Transform } from 'stream';
1010
import { Record, RecordPackage } from '@biothings-explorer/api-response-transform';
1111
import { threadId } from 'worker_threads';
12-
import MetaKG from '../../smartapi-kg/built';
12+
import MetaKG from '@biothings-explorer/smartapi-kg';
1313
import QEdge from './query_edge';
1414
import { QueryHandlerOptions } from '@biothings-explorer/types';
1515

@@ -113,7 +113,7 @@ export default class CacheHandler {
113113
}
114114

115115
async categorizeEdges(qEdges: QEdge[]): Promise<{ cachedRecords: Record[]; nonCachedQEdges: QEdge[] }> {
116-
if (this.cacheEnabled === false || process.env.INTERNAL_DISABLE_REDIS === "true") {
116+
if (this.cacheEnabled === false || process.env.INTERNAL_DISABLE_REDIS === 'true') {
117117
return {
118118
cachedRecords: [],
119119
nonCachedQEdges: qEdges,
@@ -210,7 +210,7 @@ export default class CacheHandler {
210210
}
211211

212212
async cacheEdges(queryRecords: Record[]): Promise<void> {
213-
if (this.cacheEnabled === false || process.env.INTERNAL_DISABLE_REDIS === "true") {
213+
if (this.cacheEnabled === false || process.env.INTERNAL_DISABLE_REDIS === 'true') {
214214
if (global.parentPort) {
215215
global.parentPort.postMessage({ threadId, cacheDone: true });
216216
}
@@ -257,8 +257,8 @@ export default class CacheHandler {
257257
resolve();
258258
});
259259
});
260-
if (process.env.QEDGE_CACHE_TIME_S !== "0") {
261-
await redisClient.client.expireTimeout(redisID, process.env.QEDGE_CACHE_TIME_S || 1800);
260+
if (process.env.QEDGE_CACHE_TIME_S !== '0') {
261+
await redisClient.client.expireTimeout(redisID, process.env.QEDGE_CACHE_TIME_S || 1800);
262262
}
263263
} catch (error) {
264264
failedHashes.push(hash);

src/graph/graph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import Debug from 'debug';
44
import { LogEntry, StampedLog } from '@biothings-explorer/utils';
55
import KGNode from './kg_node';
66
import KGEdge from './kg_edge';
7-
import { Record } from '../../../api-response-transform/built';
8-
import { TrapiAuxiliaryGraph, TrapiResult } from '../types';
7+
import { Record } from '@biothings-explorer/api-response-transform';
8+
import { TrapiAuxiliaryGraph, TrapiResult } from '@biothings-explorer/types';
99
import KnowledgeGraph from './knowledge_graph';
1010
const debug = Debug('bte:biothings-explorer-trapi:Graph');
1111

src/graph/kg_edge.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ProvenanceChainItem } from '@biothings-explorer/api-response-transform';
2-
import { TrapiAttribute } from '../types';
1+
import { TrapiSource } from '@biothings-explorer/types';
2+
import { TrapiAttribute } from '@biothings-explorer/types';
33

44
export interface KGEdgeInfo {
55
object: string;
@@ -20,6 +20,7 @@ export default class KGEdge {
2020
resource_id: string;
2121
resource_role: string;
2222
upstream_resource_ids?: Set<string>;
23+
source_record_urls?: Set<string>;
2324
};
2425
};
2526
};
@@ -68,7 +69,7 @@ export default class KGEdge {
6869
});
6970
}
7071

71-
addSource(source: ProvenanceChainItem | ProvenanceChainItem[]): void {
72+
addSource(source: TrapiSource | TrapiSource[]): void {
7273
if (typeof source === 'undefined') {
7374
return;
7475
}
@@ -77,19 +78,26 @@ export default class KGEdge {
7778
}
7879
source.forEach((item) => {
7980
if (!this.sources[item.resource_id]) this.sources[item.resource_id] = {};
81+
if (item.upstream_resource_ids && !Array.isArray(item.upstream_resource_ids)) {
82+
item.upstream_resource_ids = [item.upstream_resource_ids];
83+
}
84+
if (item.source_record_urls && !Array.isArray(item.source_record_urls)) {
85+
item.source_record_urls = [item.source_record_urls];
86+
}
8087
if (!this.sources[item.resource_id][item.resource_role]) {
8188
this.sources[item.resource_id][item.resource_role] = {
8289
resource_id: item.resource_id,
8390
resource_role: item.resource_role,
8491
upstream_resource_ids: item.upstream_resource_ids ? new Set(item.upstream_resource_ids) : undefined,
92+
source_record_urls: item.source_record_urls ? new Set(item.source_record_urls) : undefined,
8593
};
8694
}
87-
if (item.upstream_resource_ids && !Array.isArray(item.upstream_resource_ids)) {
88-
item.upstream_resource_ids = [item.upstream_resource_ids];
89-
}
9095
item.upstream_resource_ids?.forEach((upstream) =>
9196
this.sources[item.resource_id][item.resource_role].upstream_resource_ids.add(upstream),
9297
);
98+
item.source_record_urls?.forEach((url) =>
99+
this.sources[item.resource_id][item.resource_role].source_record_urls.add(url),
100+
);
93101
});
94102
}
95103

src/graph/kg_node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TrapiAttribute } from '../types';
1+
import { TrapiAttribute } from '@biothings-explorer/types';
22

33
export interface KGNodeInfo {
44
label: string;

src/graph/knowledge_graph.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TrapiKGNodes,
1010
TrapiQualifier,
1111
TrapiSource,
12-
} from '../types';
12+
} from '@biothings-explorer/types';
1313
import KGNode from './kg_node';
1414
import KGEdge from './kg_edge';
1515
import { BTEGraphUpdate } from './graph';
@@ -142,6 +142,7 @@ export default class KnowledgeGraph {
142142
const trapiSource: TrapiSource = {
143143
...sourceObj,
144144
upstream_resource_ids: sourceObj.upstream_resource_ids ? [...sourceObj.upstream_resource_ids] : undefined,
145+
source_record_urls: sourceObj.source_record_urls ? [...sourceObj.source_record_urls] : undefined,
145146
};
146147
sources.push(trapiSource);
147148
});

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
TrapiQueryGraph,
2525
TrapiResponse,
2626
TrapiResult,
27-
} from './types';
27+
} from '@biothings-explorer/types';
2828
import { QueryHandlerOptions } from '@biothings-explorer/types';
2929
import BTEGraph from './graph/graph';
3030
import QEdge from './query_edge';

src/inferred_mode/inferred_mode.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import biolink from '../biolink';
66
import { getTemplates, MatchedTemplate, TemplateLookup } from './template_lookup';
77
import { scaled_sigmoid, inverse_scaled_sigmoid } from '../results_assembly/score';
88
import TRAPIQueryHandler from '../index';
9-
import { QueryHandlerOptions } from '@biothings-explorer/types';
109
import {
11-
CompactQualifiers,
10+
QueryHandlerOptions,
1211
TrapiAuxGraphCollection,
1312
TrapiEdgeBinding,
1413
TrapiKnowledgeGraph,
@@ -17,7 +16,8 @@ import {
1716
TrapiQueryGraph,
1817
TrapiResponse,
1918
TrapiResult,
20-
} from '../types';
19+
} from '@biothings-explorer/types';
20+
import { CompactQualifiers } from '../index';
2121
const debug = Debug('bte:biothings-explorer-trapi:inferred-mode');
2222

2323
export interface CombinedResponse {
@@ -390,9 +390,9 @@ export default class InferredQueryHandler {
390390
if (typeof combinedResponse.message.results[resultID].analyses[0].score !== 'undefined') {
391391
combinedResponse.message.results[resultID].analyses[0].score = resScore
392392
? scaled_sigmoid(
393-
inverse_scaled_sigmoid(combinedResponse.message.results[resultID].analyses[0].score) +
394-
inverse_scaled_sigmoid(resScore),
395-
)
393+
inverse_scaled_sigmoid(combinedResponse.message.results[resultID].analyses[0].score) +
394+
inverse_scaled_sigmoid(resScore),
395+
)
396396
: combinedResponse.message.results[resultID].analyses[0].score;
397397
} else {
398398
combinedResponse.message.results[resultID].analyses[0].score = resScore;
@@ -560,9 +560,11 @@ export default class InferredQueryHandler {
560560
const message = [
561561
`Addition of ${creativeLimitHit} results from Template ${i + 1}`,
562562
Object.keys(combinedResponse.message.results).length === this.CREATIVE_LIMIT ? ' meets ' : ' exceeds ',
563-
`creative result maximum of ${this.CREATIVE_LIMIT} (reaching ${Object.keys(combinedResponse.message.results).length
563+
`creative result maximum of ${this.CREATIVE_LIMIT} (reaching ${
564+
Object.keys(combinedResponse.message.results).length
564565
} merged). `,
565-
`Response will be truncated to top-scoring ${this.CREATIVE_LIMIT} results. Skipping remaining ${subQueries.length - (i + 1)
566+
`Response will be truncated to top-scoring ${this.CREATIVE_LIMIT} results. Skipping remaining ${
567+
subQueries.length - (i + 1)
566568
} `,
567569
subQueries.length - (i + 1) === 1 ? `template.` : `templates.`,
568570
].join('');
@@ -587,8 +589,9 @@ export default class InferredQueryHandler {
587589
const total =
588590
Object.values(mergedResultsCount).reduce((sum, count) => sum + count, 0) +
589591
Object.keys(mergedResultsCount).length;
590-
const message = `Merging Summary: (${total}) inferred-template results were merged into (${Object.keys(mergedResultsCount).length
591-
}) final results, reducing result count by (${total - Object.keys(mergedResultsCount).length})`;
592+
const message = `Merging Summary: (${total}) inferred-template results were merged into (${
593+
Object.keys(mergedResultsCount).length
594+
}) final results, reducing result count by (${total - Object.keys(mergedResultsCount).length})`;
592595
debug(message);
593596
combinedResponse.logs.push(new LogEntry('INFO', null, message).getLog());
594597
}

src/inferred_mode/template_lookup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import async from 'async';
5-
import { TrapiQueryGraph, CompactQualifiers } from '../types';
5+
import { TrapiQueryGraph } from '@biothings-explorer/types';
6+
import { CompactQualifiers } from '../types';
67

78
export interface TemplateLookup {
89
subject: string;

src/query_edge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Record, RecordNode, FrozenRecord } from '@biothings-explorer/api-respon
66
import QNode from './query_node';
77
import { QNodeInfo } from './query_node';
88
import { LogEntry, StampedLog } from '@biothings-explorer/utils';
9-
import { TrapiAttributeConstraint, TrapiQualifierConstraint } from './types';
9+
import { TrapiAttributeConstraint, TrapiQualifierConstraint } from '@biothings-explorer/types';
1010

1111
const debug = Debug('bte:biothings-explorer-trapi:QEdge');
1212

src/query_graph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import biolink from './biolink';
77
import { resolveSRI } from 'biomedical_id_resolver';
88
import _ from 'lodash';
99
import * as utils from './utils';
10-
import { TrapiQueryGraph } from './types';
10+
import { TrapiQueryGraph } from '@biothings-explorer/types';
1111

1212
const debug = Debug('bte:biothings-explorer-trapi:query_graph');
1313

0 commit comments

Comments
 (0)