0

Why maplist applies only on the first list of list-of-lists ?

 %% given K:V match return V2 specified by K2
 kv2kv(K:V,ResK,HL,Res) :- writeln(HL), member(K:V, HL), member(ResK:Res, HL).

 find(K:V, FSL, S) :- maplist(kv2kv(K:V,word),FSL, S).

example :

?- fs7(L).
L = [[word:we,pos:pron,dep:nsubj],[word:are,pos:aux,dep:root],[word:about,pos:adj,dep:acomp],[word:to,pos:part,dep:aux],[word:finish,pos:verb,dep:xcomp],[word:the,pos:det,dep:det],[word:game,pos:noun,dep:dobj]].

?- fs7(L),find(dep:root,L,R).
[word:we,pos:pron,dep:nsubj]
false.

As a quick question the kv2kv clause uses two member-queries, i suppose it checks the list twice is there a better solution.

false
  • 10,264
  • 13
  • 101
  • 209
sten
  • 7,028
  • 9
  • 41
  • 63

2 Answers2

2

You are essentially asking why a particular goal fails. Here is a generalization of your program that still fails. It should now be obvious what the reason is. Any further generalization will make this program succeed. And therefore, you need to change something in the remaining visible part.

:- op(950, fy, *).

* _G_0.   % serves to generalize goals away

fs7(L) :-
    L = [[word:_/*we*/, pos:_/*pron*/, dep:nsubj]
        | _/* [word:are,pos:aux,dep:root],
              [word:about,pos:adj,dep:acomp],
              [word:to,pos:part,dep:aux],
              [word:finish,pos:verb,dep:xcomp],
              [word:the,pos:det,dep:det],
              [word:game,pos:noun,dep:dobj] */
        ].



%% given K:V match return V2 specified by K2
kv2kv(K:V,ResK,HL,Res) :-
    * writeln(HL),
    member(K:V, HL),
    * member(ResK:Res, HL).

find(K:V, FSL, S) :-
    maplist(kv2kv(K:V,_/*word*/),FSL, S).

?- fs7(L),find(dep:root,L,R).
   false.
false
  • 10,264
  • 13
  • 101
  • 209
  • i found out that maplist fails if the goal fails... and it fails on the first elem ... i was thinking in functional lang terms – sten Jul 26 '21 at 19:33
0

this solved it :

 kv2kv(K:V,K2:V2,HL) :- member(Lst,HL), member(K:V,Lst), member(K2:V2,Lst).

ex:

fs58(L),kv2kv(dep:root,word:R,L).
sten
  • 7,028
  • 9
  • 41
  • 63