Given
[
["hahaha", "hehehe", "hihihi", "huhuhu"],
["hehe","hehehe","hihi","hihihi"],
["huhuhu","juju","jejejjo"],
["zxcvzxcv","zevaerva","53qgaSD","zvxzr","hahaha"]
]
find subsets of elements in each array , eg take the first one
["hahaha", "hehehe", "hihihi", "huhuhu"],
that make it uniquely identifiable in all of the arrays. Eg
["hahaha","huhuhu"]
["hehehe","huhuhu"]
would uniquely identify the first array
["hahaha", "hehehe", "hihihi", "huhuhu"],
I have been thinking about this problem for a long time, and it is somewhat akin to LCM, but I guess instead of least common, we would look for the least uncommon elements? Wonder if there is a term in computer science for this problem.
My first approach is generating all variations like this for each array (source https://stackoverflow.com/questions/43241174/javascript-generating-all-combinations-of-elements-in-a-single-array-in-pairs)
variations = current_array.reduce(
(acc, v, i) =>
acc.concat(
example.wrong.strings[example.error_position]
.slice(i + 1)
.map(w => [v, w])
),
[]
);
and looping through with every generated versions the main array of arrays and throwing away subsets that match more than one.
This approach does not seem to scale when arrays have many elements, eg 10+, with thousands of such arrays.
I originally posted this question at Stackoverflow but unsure which site would be a better match.
Big picture: I have been running an online grammar checker for 7 years now at https://proofreadbot.com and started collecting good - bad pair of sentences. Now, if each word is represented as an array with features (eg the sentence pairs "I am like you." "I am liked you."
can be represented as an array of arrays like so
[
"I",
"noun",
"personal pronoun",
"first_person",
"sentence_start",
"preceded_by_verb",
"preceded_by_present_tense"
],
[
"am",
"verb",
"present_tense",
"preceded_by_noun",
"preceded_by_first_person",
], [
"like",
"adverb",
"preceded_by_present_tense",
"preceded_by_verb",
"preceded_by_first_person",
],
...
[
"liked",
"verb",
"past_tense",
"preceded_by_noun",
"preceded_by_first_person",
"contains_error"],
)
Then, I would like to focus on finding the words that have the error. Hope that makes sense. By the way, the first answer by Doc Brown seems great, will give it a shot.
Given hundreds of good pad sentence pairs, there are plenty of items where a subset is tested giving high confidence.
I would guess such an algorithm could be useful for searching through DNA as well and identifying unique strings etc.