Skip to content

Instantly share code, notes, and snippets.

@vineckb
Last active April 25, 2023 20:38
Show Gist options
  • Select an option

  • Save vineckb/0b431cf9879fda023548e169a1302592 to your computer and use it in GitHub Desktop.

Select an option

Save vineckb/0b431cf9879fda023548e169a1302592 to your computer and use it in GitHub Desktop.
const SYNONYMS = [
['rate', 'ratings'],
['approval', 'popularity'],
];
const QUERIES = [
['obama approval ratings', 'obama popularity rate'],
['obama approval rates', 'obama popularity ratings'],
['obama approval rate', 'popularity ratings obama'],
];
const isSynonym = (a, b) =>
SYNONYMS.reduce((acc, [sA, sB]) => {
if (acc) return acc;
if (a == sA) {
return b == sB;
}
if (b == sA) {
return a == sB;
}
return acc;
}, false);
QUERIES.map(([a, b]) => {
const bList = b.split(' ');
return a
.split(' ')
.map((word, index) => {
if (word === bList[index]) return true;
return isSynonym(word, bList[index]);
})
.reduce((acc, curr) => acc && curr, true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment