Hello,
Since a couple of weeks we are learning prolog on school. Now our excercise is to create a chatbot and use an api. I choose to use an api of the NS(public transport in the netherlands). Now i wrote a little bit of prolog to get the data and read it out. Now i want to print all destinations, but i cant work it out.
This is my json: { "links": { "disruptions": { "uri": "/api/v2/disruptions?station - Pastebin.com
:- use_module(library('http/http_client')).
:- use_module(library('http/json')).
:- use_module(library('http/http_open')).
% Get the departure data of ns api on the selected trainstation
data_departures(CityCode, Data) :-
First = 'https://ns-api.nl/reisinfo/api/v2/departures?maxJourneys=25&lang=nl&station=',
Second = CityCode,
atomic_concat(First, Second, HREF),
setup_call_cleanup(
http_open(HREF, In, [request_header('Accept'='application/json'), request_header('x-api-key'='secret')]),
json_read_dict(In, Data),
close(In)
).
departure_stations(Data, Test, Dest) :-
Payload = Data.get(payload),
Test = Payload.get(source),
Departures = Payload.get(departures),
Dest = Departures.get(destination).
And my error:
?- data_departures('LW', X), departure_stations(X, Y, Z).
ERROR: Type error: `atom' expected, found `get(destination)' (a compound)
ERROR: In:
ERROR: [12] throw(error(type_error(atom,...),_4428))
ERROR: [10] '$dicts':'.'('<garbage_collected>','<garbage_collected>',_4468) at c:/program files/swipl/boot/dicts.pl:46
ERROR: [9] departure_stations('<garbage_collected>','<garbage_collected>',_4496) at c:/users/wesley/google drive/jaar 3 - ase minor/kunstmatige intelligentie/eindopdracht_chatbot/test.pl:20
ERROR: [7] <user>
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
?-
Can someone help or give me a tip in the right way so i can work it out.
Thanks in advance,
Greetings Wesley