0

Snippets of my code are shown below. After doing a lot of cumbersome tracing, I have reached a point where I think it's the external modules which are the source of my problem, as the findall in links_of_actor never gets called, but links_of_actor itself gets called. I would be very grateful to anyone who can help and can clarify/add more of my code to this question if needed.

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

----------------------------------------------------- Support Functions ---------------------------------------------------

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

------------------------------------------------------------ Edit ----------------------------------------------------------------

After using the guitracer that is available with prolog, I have found that the program fails at http_get(URL,R,[]) in the wp(Q,WT) predicate. However, I am still not sure as to why this isn't working - Could it be possibly because of my internet?

To clarify, the predicate actor is defined in my file: actor('Billy Bob Thornton'). etc. and so are the links : link('Barack Obama')..

false
  • 10,264
  • 13
  • 101
  • 209
SDG
  • 2,260
  • 8
  • 35
  • 77
  • 1
    If `links_of_actor/2` is being called, but the `findall/3` is not being called from the `links_of_actor/2` clause, then that means one of `actor(A)` or `wp(A, WT)` are always failing. That's not to say just one of them always fails, but it means that on *every* call to `links_of_actor/2`, one of them fails. There's not enough information in your problem statement to determine why either of those would fail. – lurker Jun 17 '15 at 21:08
  • @lurker I just used the guitracer and found out where my question is failing in the **Edit** above – SDG Jun 17 '15 at 21:32
  • 1
    Please don't put code in comments. Edit your question and add the code there, properly formatted. It would seem that `wp(A, WT)` is likely failing. – lurker Jun 17 '15 at 23:09
  • @lurker but there are no apparent reasons why wp(A, WT) should fail. I have also moved my code to the question itself. – SDG Jun 17 '15 at 23:49
  • @SharanDuggirala: (Meta) Please leave out the tag swi-prolog, unless you are talking about something specific to SWI. Think of it: People use the tags to search, and if they find only random general questions, that's no help to them. – false Jun 18 '15 at 14:19
  • @false I wasn't aware of the source of the problem when I wrote this question. I'll remove it now. – SDG Jun 18 '15 at 14:48

2 Answers2

2

Well, did you try to see if the URL you gave to http_open is actually valid? You can always test from the top-level if you can http_open an URL:

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

?- http_open("stackoverflow.com", R, []).
R = % a lot of stuff
  • just tried `wp_query2URL('Billy Bob Thornton',URL).` and got the answer: `URL = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles=Billy%20Bob%20Thornton&prop=revisions&rvprop=content&rawcontinue'.` This is interesting as the actual web page is coming up as `https://en.wikipedia.org/?title=Billy_Bob_Thornton` on my Firefox. ` – SDG Jun 18 '15 at 13:58
  • and when I try to do a `http_get(URL,R,[])` it comes up as false. – SDG Jun 18 '15 at 14:15
2

Using these definitions, the error can be localized by adding a @ in front of those goals that have to succeed.

...
wp(Q,WT):-
    @wp_query2URL(Q,URL),
    @http_get(URL,R,[]),
    @atom_json_term(R,RR,[]),
    @wt_get(RR,WT0),
    ...
Community
  • 1
  • 1
false
  • 10,264
  • 13
  • 101
  • 209