我的代碼片段如下所示。做了很多繁瑣的跟蹤後,我已經達到了一個點,我認爲這是這是我的問題的根源在外部模塊,如links_of_actor
的findall
不會被調用,但links_of_actor
本身被調用。如果需要的話,我會非常感謝任何能夠幫助的人,並且可以澄清/添加更多我的代碼到這個問題。我不確定爲什麼'find_identity(X)'返回false [代碼如下]
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
後,我hav e發現該程序在http_get(URL,R,[])
的wp(Q,WT)
謂詞中失敗。但是,我仍然不確定爲什麼這不起作用 - 可能是因爲我的互聯網?
爲了澄清,謂詞actor在我的文件中定義爲:actor('Billy Bob Thornton').
等,鏈接如下:link('Barack Obama').
。
如果'links_of_actor/2'正在被呼叫,但'的findall/3'沒有被從'links_of_actor/2'子句,則稱爲這意味着演員的'一個(A)'或'WP (A,WT)'總是失敗。這並不是說他們中的一個總是失敗,但這意味着每次*調用'links_of_actor/2'時,其中一個失敗。問題陳述中沒有足夠的信息來確定爲什麼這些失敗。 – lurker
@lurker我剛使用了guitracer,發現我的問題在**編輯**上面失敗的地方 –
請不要在註釋中放置代碼。編輯你的問題,並在那裏添加代碼,格式正確。看起來'wp(A,WT)'可能會失敗。 – lurker