我不确定为什么 'find_identity(X)' 返回为 false [下面的代码]
I am not sure as to why 'find_identity(X)' is returning as false [Code Below]
我的代码片段如下所示。在进行了大量繁琐的跟踪之后,我认为是外部模块是问题的根源,因为 links_of_actor
中的 findall
永远不会被调用,但是 links_of_actor
本身被调用。如果需要,我将非常感谢任何可以提供帮助并且可以 clarify/add 我的更多代码来解决这个问题的人。
find_identity(A) :-
all_actor_links(ALs),
find_identity(ALs,[],A).
find_identity([a(A,_)],_,A).
find_identity(ALs,Ms,A) :-
agent_ask_oracle(oscar,o(1),link,L),
( memberchk(L,Ms) -> find_identity(ALs,Ms,A)
; otherwise -> purge_actors(ALs,L,NewALs),
find_identity(NewALs,[L|Ms],A)
).
links_of_actor(A,Ls) :-
actor(A),
wp(A,WT),
findall(L,wt_link(WT,L),Ls1),
findall(L,link(L),Ls2),
intersection(Ls1,Ls2,Ls).
actor_links(A,a(A,Ls)) :-
links_of_actor(A,Ls).
all_actor_links(ALs) :-
findall(A,actor(A),As),
maplist(actor_links,As,ALs).
---------------------------------------- -------------- 支持功能------------------------------------ --------------
% wp(Q,WT) <- issue query Q to Wikipedia and return the page in wikitext format
wp(Q,WT):-
wp_cache(Q,WT),!.
wp(Q,WT):-
wp_query2URL(Q,URL),
http_get(URL,R,[]),
atom_json_term(R,RR,[]),
wt_get(RR,WT0),
( atomic_list_concat1(_L,'#REDIRECT',WT0) -> wt_link(WT0,QQ),wp(QQ,WT)
; otherwise -> WT=WT0
),
assert(wp_cache(Q,WT)).
---------------------------------------- - - - - - - - - - - 编辑 - - - - - - - - - - - - - - - ----------------------------------
在使用 prolog 提供的 guitracer
后,我发现程序在 wp(Q,WT)
谓词的 http_get(URL,R,[])
处失败。但是,我仍然不确定为什么这不起作用 - 可能是因为我的互联网?
澄清一下,谓词参与者在我的文件中定义:actor('Billy Bob Thornton').
等等,链接也是如此:link('Barack Obama').
.
那么,您是否尝试查看您给 http_open
的 URL 是否真的有效?如果可以 http_open
和 URL:
,您始终可以从顶层进行测试
?- use_module(library(http/http_client)).
true.
?- http_open("whosebug.com", R, []).
R = % a lot of stuff
使用 ,可以通过在 必须成功 的目标前添加 @
来定位错误。
...
wp(Q,WT):-
@wp_query2URL(Q,URL),
@http_get(URL,R,[]),
@atom_json_term(R,RR,[]),
@wt_get(RR,WT0),
...
我的代码片段如下所示。在进行了大量繁琐的跟踪之后,我认为是外部模块是问题的根源,因为 links_of_actor
中的 findall
永远不会被调用,但是 links_of_actor
本身被调用。如果需要,我将非常感谢任何可以提供帮助并且可以 clarify/add 我的更多代码来解决这个问题的人。
find_identity(A) :-
all_actor_links(ALs),
find_identity(ALs,[],A).
find_identity([a(A,_)],_,A).
find_identity(ALs,Ms,A) :-
agent_ask_oracle(oscar,o(1),link,L),
( memberchk(L,Ms) -> find_identity(ALs,Ms,A)
; otherwise -> purge_actors(ALs,L,NewALs),
find_identity(NewALs,[L|Ms],A)
).
links_of_actor(A,Ls) :-
actor(A),
wp(A,WT),
findall(L,wt_link(WT,L),Ls1),
findall(L,link(L),Ls2),
intersection(Ls1,Ls2,Ls).
actor_links(A,a(A,Ls)) :-
links_of_actor(A,Ls).
all_actor_links(ALs) :-
findall(A,actor(A),As),
maplist(actor_links,As,ALs).
---------------------------------------- -------------- 支持功能------------------------------------ --------------
% wp(Q,WT) <- issue query Q to Wikipedia and return the page in wikitext format
wp(Q,WT):-
wp_cache(Q,WT),!.
wp(Q,WT):-
wp_query2URL(Q,URL),
http_get(URL,R,[]),
atom_json_term(R,RR,[]),
wt_get(RR,WT0),
( atomic_list_concat1(_L,'#REDIRECT',WT0) -> wt_link(WT0,QQ),wp(QQ,WT)
; otherwise -> WT=WT0
),
assert(wp_cache(Q,WT)).
---------------------------------------- - - - - - - - - - - 编辑 - - - - - - - - - - - - - - - ----------------------------------
在使用 prolog 提供的 guitracer
后,我发现程序在 wp(Q,WT)
谓词的 http_get(URL,R,[])
处失败。但是,我仍然不确定为什么这不起作用 - 可能是因为我的互联网?
澄清一下,谓词参与者在我的文件中定义:actor('Billy Bob Thornton').
等等,链接也是如此:link('Barack Obama').
.
那么,您是否尝试查看您给 http_open
的 URL 是否真的有效?如果可以 http_open
和 URL:
?- use_module(library(http/http_client)). true. ?- http_open("whosebug.com", R, []). R = % a lot of stuff
使用 @
来定位错误。
...
wp(Q,WT):-
@wp_query2URL(Q,URL),
@http_get(URL,R,[]),
@atom_json_term(R,RR,[]),
@wt_get(RR,WT0),
...