Search code examples
dictionaryprologmember

Prolog: Check if dictionary has special member


Based on my question here I have following prolog code:

:-op(900, xfy, →).
:-op(900, xfy, ⟷).
    
find_axioms(Specific, BaseSet, Fullfill) :-
        findall(X, 
                ( member(X, Specific), 
                  member(X, BaseSet) ), 
                Fullfill).

My input

find_axioms([(peter → anna), (peter → peter)], [(A → A), (B → A) ⟷ (A → B)], Z).

gives:

Z = [peter→peter].

My aim now is to generalize it in that way, BaseSet is some dictionary. Means all the axioms alrady have names as keys. So:

find_axioms([(peter → anna), (peter → peter)], axioms{'axiom1':(A → A), 'axiom2':(B → A) ⟷ (A → B)}, Z).

would get

Z = axioms{'axiom1':(peter l peter)}

What is the best way to do that?


Solution

  • I found some solution.

    :-op(900, xfy, →).
    :-op(900, xfy, ⟷).
        
    find_axioms(Specific, BaseSet, Fullfill) :-
            findall(X, 
                    ( member(X, Specific), 
                      member(X, BaseSet) ), 
                    Fullfill).
    
    find_axioms_pair(Specific, BaseSet, Fullfill) :-
        pairs_values(BaseSet, BaseSet_Values),
        find_axioms(Specific, BaseSet_Values, Fullfill_Values),
        pairs_values(Fullfill, Fullfill_Values),
        subset(Fullfill, BaseSet).
    
    find_axioms_dict(Specific, BaseSet, Fullfill) :-
        dict_pairs(BaseSet, _, BaseSet_Pairs),
        find_axioms_pair(Specific, BaseSet_Pairs, Fullfill_Pairs),
        dict_pairs(Fullfill, useable_axioms, Fullfill_Pairs).