S.I/Lisp/

_?_is_the_1_of_2.




A1="Women is the plural of woman."
A2="Up is the opposite of down."
A3="Cain is the brother of Abel."

=_?_is_the_1_of_2.("plural", "woman", A1:A3)
-> "Women"

=_?_is_the_1_of_2.("opposite", "down", A1:A3)
-> "Up"

=_?_is_the_1_of_2.("brother", "Abel", A1:A3)
-> "Cain"
        



DEFINE(
    _?_is_the_1_of_2.,
    LAMBDA(
        _1,
        _2,
        knowledgebase,
        LET(
            predicate,
                FORMAT(
                    " is the {1} of {2}.",
                    _1,
                    _2),
            knowledgecolumn,
                TOCOL(knowledgebase),
            matches,
                FILTER(
                    knowledgecolumn,
                    ENDSWITH?(
                        knowledgecolumn,
                        predicate)),
            IF(
                ISERROR(matches),
                FALSE,
                TRIMALL(
                    REGEXEXTRACT(
                        matches,
                        FORMAT(
                            "^(.+) is the {1} of {2}\.$",
                            _1,
                            _2),
                        2))))))
        



Help us optimize this function