2015-06-17 81 views
0

我的代碼片段如下所示。做了很多繁瑣的跟蹤後,我已經達到了一個點,我認爲這是這是我的問題的根源在外部模塊,如links_of_actorfindall不會被調用,但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').

+1

如果'links_of_actor/2'正在被呼叫,但'的findall/3'沒有被從'links_of_actor/2'子句,則稱爲這意味着演員的'一個(A)'或'WP (A,WT)'總是失敗。這並不是說他們中的一個總是失敗,但這意味着每次*調用'links_of_actor/2'時,其中一個失敗。問題陳述中沒有足夠的信息來確定爲什麼這些失敗。 – lurker

+0

@lurker我剛使用了guitracer,發現我的問題在**編輯**上面失敗的地方 –

+1

請不要在註釋中放置代碼。編輯你的問題,並在那裏添加代碼,格式正確。看起來'wp(A,WT)'可能會失敗。 – lurker

回答

2

使用these definitions,誤差可以通過在這些目標前添加@必須成功本地化。

... 
wp(Q,WT):- 
    @wp_query2URL(Q,URL), 
    @http_get(URL,R,[]), 
    @atom_json_term(R,RR,[]), 
    @wt_get(RR,WT0), 
    ... 
2

嗯,你嘗試看看,如果你給http_open的URL實際上是有效的?你總是可以從頂層的測試,如果你能http_open的網址:

 
?- use_module(library(http/http_client)). 
true. 

?- http_open("stackoverflow.com", R, []). 
R = % a lot of stuff 
+0

剛剛嘗試過'wp_query2URL('Billy Bob Thornton',URL).'並得到了答案:'URL ='http://en.wikipedia.org/w/api.php?format=json&action=query&titles=Billy%20Bob %20Thornton&prop = revisions&rvprop = content&rawcontinue'.'這很有趣,因爲在我的Firefox上,實際的網頁以「https://en.wikipedia.org/?title = Billy_Bob_Thornton」出現。 ' –

+0

當我試圖做一個'http_get(URL,R,[])'它出現爲false。 –