I am working on a Prolog project that can answer questions about Movies and Series from the omdb api.
我正在开发一个Prolog项目,可以从omdb api回答关于电影和系列的问题。
I use this to return the complete Json string with information of a Movie or Series:
我使用它来返回包含电影或系列信息的完整Json字符串:
findMovie(X,Json):-
atomic_list_concat(X, ',', Atom),
uri_query_components(QS, [t=Atom]) %t is the title of the movie
format(atom(HREF),'http://www.omdbapi.com/?~s',[QS]),
http_get(HREF,Json, []),
write(Json).
If I search for example on: "Fantastic Beasts", write(Json) will print the following in the console:
如果我搜索“Fantastic Beasts”的例子,写(Json)将在控制台中打印以下内容:
{"Title":"Fantastic Beasts and Where to Find Them",
"Year":"2016",
"Rated":"PG-13",
"Released":" 2016",
"Runtime":"133 min",
"Genre":"Adventure, Family, Fantasy",
"Director":"David Yates","WriJ.K. Rowling",
"Actors":"Eddie Redmayne, Sam Redford, Scott Goldman, Tim Bentinck",
"Plot":"Thetures of writer Newt Scamander in New York's secret community of witches and wizards seventy before Harry Potter reads his book in school.",
"Language":"English",
"Country":"UK, USA","Awards":"1 nomination.",
"Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMjMxOTM1OTI4MV5BBnXkFtZTgwODE5OTYxMDI@._V1_SX300.jpg",
"Metascore":"66",
"imdbRating":"7.9",
"imdbVotes":"75,816bID":"tt3183660",
"Type":"movie",
"Response":"True"}
How can I return a value? For example: the value of "Year" which is 2016. I've read some things about converting the Json string to a Prolog format but I couldn't figure it out.
我怎样才能返回一个值?例如:2016年的“年份”的值。我已经阅读了一些关于将Json字符串转换为Prolog格式的内容,但我无法弄明白。
1 个解决方案
#1
0
I found the solution for this.
我找到了解决方案。
findMovie(X,Json):-
Field = 'Year',
atomic_list_concat(X, ',', Atom),
uri_query_components(QS, [t=Atom]) %t is the title of the movie
format(atom(HREF),'http://www.omdbapi.com/?~s',[QS]),
http_get(HREF,json(Json), []), %json(Json) converts it to Prolog terms.
member(Field=Result,Json), %Result will get the value of 'Year'
write(Result).
#1
0
I found the solution for this.
我找到了解决方案。
findMovie(X,Json):-
Field = 'Year',
atomic_list_concat(X, ',', Atom),
uri_query_components(QS, [t=Atom]) %t is the title of the movie
format(atom(HREF),'http://www.omdbapi.com/?~s',[QS]),
http_get(HREF,json(Json), []), %json(Json) converts it to Prolog terms.
member(Field=Result,Json), %Result will get the value of 'Year'
write(Result).