Skip to content

Commit

Permalink
feat: qualifier-filter for creative mode template matching
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Dec 14, 2022
1 parent 32b6bc1 commit 7af3960
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
33 changes: 23 additions & 10 deletions src/inferred_mode/inferred_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,31 @@ module.exports = class InferredQueryHandler {
const expandedObject = qObject.categories.reduce((arr, objectCategory) => {
return utils.getUnique([...arr, ...biolink.getDescendantClasses(utils.removeBioLinkPrefix(objectCategory))]);
}, []);
const qualifierConstraints = (qEdge.qualifier_constraints || []).map((qualifierSetObj) => {
return Object.fromEntries(
qualifierSetObj.qualifier_set.map(({ qualifier_type_id, qualifier_value }) => [
qualifier_type_id.replace('biolink:', ''),
qualifier_value.replace('biolink:', ''),
]),
);
});
if (qualifierConstraints.length === 0) qualifierConstraints.push({});
const lookupObjects = expandedSubject.reduce((arr, subjectCategory) => {
let templates = expandedObject.reduce((arr2, objectCategory) => {
return [
...arr2,
...expandedPredicates.map((predicate) => {
return {
subject: utils.removeBioLinkPrefix(subjectCategory),
object: utils.removeBioLinkPrefix(objectCategory),
predicate: utils.removeBioLinkPrefix(predicate),
};
}),
];
let templates2 = qualifierConstraints.reduce((arr3, qualifierSet) => {
return [
...arr3,
...expandedPredicates.map((predicate) => {
return {
subject: utils.removeBioLinkPrefix(subjectCategory),
object: utils.removeBioLinkPrefix(objectCategory),
predicate: utils.removeBioLinkPrefix(predicate),
qualifiers: qualifierSet,
};
}),
];
}, []);
return [...arr2, ...templates2];
}, []);
return [...arr, ...templates];
}, []);
Expand Down
5 changes: 4 additions & 1 deletion src/inferred_mode/template_lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ exports.getTemplates = async (lookups) => {
return (
group.subject.includes(lookup.subject) &&
group.object.includes(lookup.object) &&
group.predicate.includes(lookup.predicate)
group.predicate.includes(lookup.predicate) &&
Object.entries(lookup.qualifiers || {}).every(([qualifierType, qualifierValue]) => {
return (group.qualifiers || {})[qualifierType] && group.qualifiers[qualifierType] === qualifierValue;
})
);
});

Expand Down

0 comments on commit 7af3960

Please sign in to comment.