swi-prolog

How to disable character codes 178 (0xB2) (²) , 179 (0xB3) (³), and 185 (0xB9) (¹) as digits?

梦想的初衷 提交于 2020-01-04 02:40:32
问题 With SWI-Prolog when generating digits using code_type(X,digit). the result is the expected ASCII character codes and 178 (0xB2) ² 179 (0xB3) ³ 185 (0xB9) ¹ e.g. code_type(X,digit). X = 48 ; X = 49 ; X = 50 ; X = 51 ; X = 52 ; X = 53 ; X = 54 ; X = 55 ; X = 56 ; X = 57 ; X = 178 ; X = 179 ; X = 185 ; false. How can I disable or change the functionality so that characters other than 0-9 are not a digit? Obviously I can write a different routine, but I am wondering if there is not some option

Stream reasoning / Reactive programming in prolog?

给你一囗甜甜゛ 提交于 2020-01-01 05:26:13
问题 I was wondering if you know of any way to use prolog for stream processing, that is, some kind of reactive programming, or at least to let a query run on a knowledge base that is continuously updated (effectively a stream), and continuously output the output of the reasoning? Anything implemented in the popular "prologs", such as SWI-prolog? 回答1: You can use Logtalk's support for event-driven programming to define monitors that watch for knowledge base update events and react accordingly. You

aggregate/3 in swi-prolog

≡放荡痞女 提交于 2019-12-30 08:14:56
问题 I need to count all X , that some_predicate(X) and there really a lot of such X . What is the best way to do that? First clue is to find it all, accumulate to a list and return it length. countAllStuff( X ) :- findall( Y , permutation( [1,2,3,4,5,6,7,8,9,10], Y ) , List ), length( List, X ). ( permutation/2 is only example showing that there are many variants and it's bad way to collect it all) Obviously, I have stack-overflow. ?- countAllStuff( X ). ERROR: Out of global stack Than, I'm

aggregate/3 in swi-prolog

江枫思渺然 提交于 2019-12-30 08:14:09
问题 I need to count all X , that some_predicate(X) and there really a lot of such X . What is the best way to do that? First clue is to find it all, accumulate to a list and return it length. countAllStuff( X ) :- findall( Y , permutation( [1,2,3,4,5,6,7,8,9,10], Y ) , List ), length( List, X ). ( permutation/2 is only example showing that there are many variants and it's bad way to collect it all) Obviously, I have stack-overflow. ?- countAllStuff( X ). ERROR: Out of global stack Than, I'm

Why is this prolog query both true and false?

旧时模样 提交于 2019-12-30 01:36:10
问题 My SWI-Prolog knowledge base contains the following two facts: f(a,b). f(a,c). Now if I pose the query ?- f(a,c). true. But ?- f(a,b). true ; false. Why is f(a,b) both true and false? This also happens when there are three facts in the KB. If I append f(a,d). to the KB, then f(a,d) is true (only), but f(a,b) and f(a,c) are both true and false. What's going on, and what can I do so that Prolog answers (only) true to these queries? 回答1: (Note: this answer is somewhat of a guess) Consider how

How to get a value from a field in a Json string in Prolog?

会有一股神秘感。 提交于 2019-12-25 08:37:24
问题 I am working on a Prolog project that can answer questions about Movies and Series from the omdb api. I use this to return the complete Json string with information of a Movie or Series: 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:

How do I turn off SWI-Prolog flags?

可紊 提交于 2019-12-25 01:39:18
问题 I'm not sure if flags is the appropriate term, but is there anyway to configure a swi-prolog program to not output true or false on the completion of a query, and instead simply print out another statement determined in the program? 回答1: There is a facility for customising this kind of behaviour, but it can get quite involved. I have not played with it myself but looking at the manual and Prolog boot files might help you. Prolog has a "top level", which is a bit of Prolog code that controls

How to echo the true/false value Prolog returns after a query

对着背影说爱祢 提交于 2019-12-24 20:04:42
问题 I 'd like to pose a question. I tried to connect php with SWI-Prolog using the exec function and my effort was succeful. I have managed to query prolog via php and I was able to echo Prolog's answer. What I want to do but can't figure how to accomplish it, is to echo the true/false prolog returns. Lets assume I have a simple knowledge_base.pl file with these facts and rules: girl(erin). boy(john). likes(erin,reading). likes(john,reading). hangs_out_with(erin,X) :- likes(X,reading), boy(X),

How can I make a bar chart (bar graph) in Prolog GUI (XPCE) programming?

纵饮孤独 提交于 2019-12-24 17:09:58
问题 I'm trying to make a barchart by using XPCE in Proglog libraries. Though I found some materials but I cannot execute it right away. The code is as below. barchart :- barchart(vertical). barchart(HV) :- new(W, picture), active_classes(Classes), length(Classes, N), required_scale(Classes, Scale), send(W, display, new(BC, bar_chart(HV, 0, Scale, 200, N))), forall(member(class(Name, Created, Freed), Classes), send(BC, append, bar_group(Name, bar(created, Created, green), bar(freed, Freed, red))))

SWI Prolog CLP(FD) scheduling

巧了我就是萌 提交于 2019-12-24 13:26:32
问题 I am solving a scheduling task in SWI Prolog using the CLPFD library. Since it is the first time I solve something more serious than was the sendmory I probably need some good advices from more experienced users. Let me briefly describe the domain/the task. Domain I have a "calendar" for a month. Everyday there are 2 for the whole day, 2 for the whole night (long 12h service). There are also, only Mon-Fri 10 more workers for 8 hours (short service). The domain constraints are, obviously: