diff --git a/src/inferred_mode/inferred_mode.js b/src/inferred_mode/inferred_mode.js index e4a5aef9..241270ce 100644 --- a/src/inferred_mode/inferred_mode.js +++ b/src/inferred_mode/inferred_mode.js @@ -482,7 +482,10 @@ module.exports = class InferredQueryHandler { let scoredResults = 0; let unscoredResults = 0; combinedResponse.message.results.forEach((result) => { - if (result.score > 0.1) { + const scoreFromEdges = Object.values(result.edge_bindings).reduce((count, qEdge_bindings) => { + return count + qEdge_bindings.length; + }, 0); + if (result.score > scoreFromEdges) { scoredResults += 1; } else { unscoredResults += 1; diff --git a/src/query_results.js b/src/query_results.js index ef54edaa..b84cf651 100644 --- a/src/query_results.js +++ b/src/query_results.js @@ -399,11 +399,12 @@ module.exports = class TrapiResultsAssembler { this._results = consolidatedSolutions.map((consolidatedSolution) => { // TODO: replace with better score implementation later - const result = {node_bindings: {}, edge_bindings: {}, score: calculateScore(consolidatedSolution, scoreCombos)}; - if (result.score === 0.1) { - resultsWithoutScore++; - } else { + const { score, scoredByNGD } = calculateScore(consolidatedSolution, scoreCombos); + const result = {node_bindings: {}, edge_bindings: {}, score: score}; + if (scoredByNGD) { resultsWithScore++; + } else { + resultsWithoutScore++; } if (!shouldScore) delete result.score; diff --git a/src/score.js b/src/score.js index 8464a4ad..cf7ebd4f 100644 --- a/src/score.js +++ b/src/score.js @@ -87,17 +87,19 @@ async function getScores (recordsByQEdgeID) { //addition of scores function calculateScore(comboInfo, scoreCombos) { - let score = 0.1; - + let score = 0; + let scoredByNGD = false; Object.keys(comboInfo).forEach((edgeKey) => { + score += 0.1 * comboInfo[edgeKey].recordHashes.size; for (const combo of scoreCombos) { if (comboInfo[edgeKey].inputUMLS?.includes(combo.umls[0]) && comboInfo[edgeKey].outputUMLS?.includes(combo.umls[1])) { score += 1/combo.ngd; + scoredByNGD = true; } } }) - return score; + return { score, scoredByNGD }; } module.exports.getScores = getScores;