swi-prolog

read line to atomic list in prolog

馋奶兔 提交于 2019-12-04 09:28:52
I need to read any line (from user_input) into an atomic list, e.g.: Example line, which contains any ASCII chars. into: [Example,'line,',which,contains,any,ASCII,'chars.'] what I've got so far: read_line_to_codes(user_input, Input), atom_codes(IA,Input), atomic_list_concat(AlistI,' ',IA). but that only works w/ single words, because of atom_codes. read/2 also complains about spaces, so is there any way to do this? oh and maybe then splitting at comma into 2d-lists, appending the dot/exclamationmark/questionmark, e.g.: [[Example,line],[which,contains,any,ASCII,chars],'.'] btw: that's SWI

Example how to use predsort(:Compare, +List, -Sorted) in prolog

梦想的初衷 提交于 2019-12-04 09:18:27
I want to order a custom list. The list I want to order will be in this form... [n(_,2,_),n(_,1,_),n(_,3,_)] I have wrote a comparator cheaper(n(_,C1,_),n(_,C2,_)) :- C1>C2. How do I use this with predsort. I wrote a sorting algorithm using bubble sort, but I have very large lists so it very slow. Is it possible to do predsort(cheaper, [n(_,2,_),n(_,1,_),n(_,3,_)] , X). Thank you :) Try this : cheaper(>, n(_,C1,_),n(_,C2,_)) :- C1>C2. cheaper(<, n(_,C1,_),n(_,C2,_)) :- C1<C2. cheaper(=, n(_,C1,_),n(_,C2,_)) :- C1=C2. Be aware that predsort works like sort, there are no doubles ! If you want to

How to query RDF/OWL using SWI-Prolog's Semantic Web Library?

爷,独闯天下 提交于 2019-12-03 03:52:25
How can I use the SWI-Prolog Semantic Web Library to make a query into the OWL/RDF file and extract some information? The OWL/RDF file is having information about all the Debian packages so I need to make the query in order to find package dependencies. For Example: The OWL file is structured as follows: package: A Depends: package: B pacakge: C How can I load a OWL/RDF file into a Prolog script and what is the syntax to make a query within the Prolog script such that I put A as a parameter and the script outputs B and C? This is how you load the semweb library: ?- use_module(library(semweb

SwiPICs.dll PlEngine.Initialize FileNotFoundException

我只是一个虾纸丫 提交于 2019-12-02 12:03:41
问题 For educational purposes, one of our college subjects requires a project that integrates any instance of Prolog with any other GUI supportive language. I went with C# as I have the most experience with it. I'm trying to learn by example of my fellow college colleagues from higher years. They gave me their repos to download their code and to see how it all comes together. And this is where the problems started. No matter what I do, what tutorial I follow, what tips from other sources I apply,

Using aleph with SWI-prolog: source_sink `library(aleph)' does not exist

寵の児 提交于 2019-12-02 08:16:50
I’m trying to work Aleph with Swi-prolog. When I ran my program I got the error here. What can I do to import the library(aleph)?By the way, I have already downloaded Aleph.pl for my program. Here is my test program, I know there must be something wrong with the library aleph. :- use_module(library(aleph)). :- aleph. I got the error: ERROR: c:/users/mac/desktop/swi-prolog/aleph draft/1.pl:1: source_sink `library(aleph)' does not exist Warning: c:/users/mac/desktop/swi-prolog/aleph draft/1.pl:1: Goal (directive) failed: user:use_module(library(aleph)) ERROR: c:/users/mac/desktop/swi-prolog

Generating subsets using length/2 and ord_subset/2

十年热恋 提交于 2019-12-02 05:08:17
I am a beginner in prolog. I tried this in swipl interpreter: ?- length(Lists, 3), ord_subset(Lists, [1, 2, 3, 4]). false. expecting to get all length-3 lists that are subsets of [1, 2, 3, 4] like [1, 2, 3] or [1, 2, 4]. Why do i get false? Notice: both length and ord_subset are builtin functions (or whatever they are called) in SWI-Prolog. You don't get a solution because the ord_subset/2 predicate only checks if a list is a subset of another list; it does not generate subsets. Here is one simplistic way to define a predicate that does what you seem to be after: subset_set([], _). subset_set(

SwiPICs.dll PlEngine.Initialize FileNotFoundException

血红的双手。 提交于 2019-12-02 03:53:16
For educational purposes, one of our college subjects requires a project that integrates any instance of Prolog with any other GUI supportive language. I went with C# as I have the most experience with it. I'm trying to learn by example of my fellow college colleagues from higher years. They gave me their repos to download their code and to see how it all comes together. And this is where the problems started. No matter what I do, what tutorial I follow, what tips from other sources I apply, the error will not change: FileNotFoundException was unhandled: An unhandled exception of type 'System

aggregate/3 in swi-prolog

帅比萌擦擦* 提交于 2019-12-01 03:39:18
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 trying to replace findall to setof and nothing changes. At last, I've founded aggregate (clickable)

Verifying a signature chain SWI-Prolog

放肆的年华 提交于 2019-12-01 00:07:24
This question is related to Opening and checking a Pem file in SWI-Prolog Once I have downloaded and opened the certificates how do I verify the signature chain? I have: :-use_module(library(http/http_client)). url('https://s3.amazonaws.com/echo.api/echo-api-cert-4.pem'). url_data1(Url,Certs):- http_open(Url,Stream,[]), all_certs(Stream,Certs), forall(member(C,Certs),my_validate(C)), close(Stream). all_certs(Stream,[C1|Certs]):- catch(load_certificate(Stream,C1),_,fail), all_certs(Stream,Certs),!. all_certs(_Stream,[]). my_validate(C):- memberchk(to_be_signed(Signed),C), memberchk(key(Key),C),

Why is this prolog query both true and false?

那年仲夏 提交于 2019-11-30 06:13:00
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? (Note: this answer is somewhat of a guess) Consider how Prolog determines whether f(a,c) is true or not. It checks the first rule, f(a,b) , and doesn't find a match,