prolog

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

泪湿孤枕 提交于 2019-12-20 12:35:58
问题 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

Comparing SQL and Prolog

老子叫甜甜 提交于 2019-12-20 08:17:08
问题 I've started learning Prolog and wondering about the theoretical difference from the SQL language. For example: both are declarative languages both support a fact-driven knowledge database both support question-styled data-retrieving both support functional dependencies Any more common points? Any notable differences? 回答1: Most of the (earlier) answers here are a reflection of the fact that most people do not know what SQL is (its an implementation of Relational Calculus) or what that means

Print a value from a fact in Prolog?

断了今生、忘了曾经 提交于 2019-12-20 07:25:26
问题 Let's say I have these facts: champion(Real_Madrid). second_place(Atl). How do I print the "Real_Madrid" string value from a query in Prolog so I can say for example: Champions(Something). Real_Madrid Any way to do that? 回答1: In Prolog, atoms need quotes if they start by an upper-case letter so that they're not confused with variables. Here, you could write: champion('Real Madrid'). second_place('Atl'). Then the simple query: ?- champion(Something). would print the required bindings:

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

坚强是说给别人听的谎言 提交于 2019-12-20 07:18:10
问题 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

Aggregate solution over multiple facts

半城伤御伤魂 提交于 2019-12-20 06:29:04
问题 Trying to create a predicate ( timePeriod/2 ) that calculates the time period between two dates for a specific fact. I've managed to do this by myself, but face issues when 'other answers' exist in the same list (i.e. easier to explain with examples). I have the following knowledge-base facts; popStar('Jackson',1987,1991). popStar('Jackson',1992,1996). popStar('Michaels',1996,2000). popStar('Newcastle',2000,2007). popStar('Bowie',2008,2010). And the following function, calculates the time

Prolog - How to make a variable list out of a given list from input file?

久未见 提交于 2019-12-20 06:27:37
问题 I have a input predicate will read the file as a list: input(Filename,List). The list then will be in the format of ["_","_","_",9,"_","_"] "_" is literally the character underscore "_" here, not a wild card. The question is how can I write a predicate pred(List,List2) then transform all the "_" into variables but keep 9 still at the same position? So If I type in input(Filename,List),pred(List,X). I will get something like X = [_G1426, _G1429, _G1432, 9, _G1438, _G1441]. I know if I define a

How to write a cmp_list/3 function in Prolog?

家住魔仙堡 提交于 2019-12-20 06:03:01
问题 Write a predicate cmp_list/3 , the first 2 arguments are 2 lists, and the last one is Comparison which means ge , lt , le , or gt . ge : greater or equal lt : less than le : less or equal gt : greater than the output should be like this: the first two lists represent a version of a software, and the function is used to compare two versions of a software to see which one is newer: ?- cmp_list([2,3,4], [2,3,5], C). C = lt ; C = le . ?- cmp_list([1,2,3,4], [1,1,8], C). C = gt ; C = ge . 回答1:

how do you print stars n amount of times on multiple lines using prolog

懵懂的女人 提交于 2019-12-20 05:55:57
问题 i need to print stars '*' n amount of time 回答1: Very simple solution: star(0). star(N):- N > 0, foreach(between(1,N,_),write('*')),nl, N1 is N-1, star(N1). ?- star(3). *** ** * true false One of the problem in your code is that if you call star with N-1 , at the next iteration N will be unified with N-1 (as you write it, it does not performs the arithmetic operation). Instead you should do N1 is N-1 and then call star with N-1 . Then there are other problems... Look at my code to have an idea

Prolog if-statement

久未见 提交于 2019-12-20 05:55:24
问题 I'm trying to implement a predicate that works as follows: pred :- % do this always % if-statement %do this only, when if-statement is true % do this also always, independent if if-statement where true or false. I need this functionality for a program, which has optionality a gui (XPCE) or not. You can call it with start(true) % with gui or start(false) % without gui Because I don't want to write two different predicates with the same logic, but one time with gui and another time without, I

truthtable split in prolog

℡╲_俬逩灬. 提交于 2019-12-20 05:51:23
问题 Hello stackoverflow community so I am trying to compute this output A B and(A,B) or(A,and(A,B)) true true true true true true false false false false true false false false false false however my code gives me error when I consult it here is my code :- use_module(library(apply)). and(A,B) :- A, B. or(A,_) :- A. or(_,B) :- B. equ(A,B) :- or(and(A,B), and(not(A),not(B))). xor(A,B) :- not(equ(A,B)). nor(A,B) :- not(or(A,B)). nand(A,B) :- not(and(A,B)). impl(A,B) :- or(not(A),B). :- op(900, fy