Skip to content

Commit

Permalink
fix: 0.1 score per edge and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Feb 1, 2023
1 parent 20c64e8 commit e81dee9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/inferred_mode/inferred_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/query_results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e81dee9

Please sign in to comment.