【问题标题】:Prolog: Check if dictionary has special memberProlog:检查字典是否有特殊成员
【发布时间】:2022-01-22 19:18:49
【问题描述】:

根据我的问题here 我有以下序言代码:

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

我的意见

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

给予:

Z = [peter→peter].

我现在的目标是以这种方式概括它,BaseSet 是一些字典。意味着所有公理都有名称作为键。所以:

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

会得到

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

最好的方法是什么?

【问题讨论】:

    标签: dictionary prolog member


    【解决方案1】:

    我找到了一些解决方案。

    :-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).
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 2015-11-04
      • 2020-03-15
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 2010-12-20
      相关资源
      最近更新 更多