Skip to content

Commit 5d86bc7

Browse files
author
Ian
committed
Create eeg.pl
There are six predicates which must be defined at run time. This can be done using the command structure: :-dynamic Name/Arity where Name is the predicate and Arity is the variables of the predication. For example, predicate(X,Y) is Name "predicate" and has an Arity of 2 (X,Y). The command would then be: :- dynamic predicate/2 This is incomplete, however, and requires the use of the "assert" function of prolog, which is done by using the "assert/1" command. Thus the full command structure for defining a dynamic run time predication is done by the following: :- dynamic l:grab/2. This must be typed for each of the six predicates: l:grab/2 l:letter/2 l:noun_p/0 l:prep_p/0 l:verb_p/0 l:word/4 Once done, the algorithms will compile without error, and work more efficiently.
1 parent b691d4d commit 5d86bc7

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

eeg.pl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
l:sentence:-read(49).
2+
l:sentence-->(l:noun_p,l:verb_p);((l:noun_p),(l:prep_p),(l:word));((l:verb),(l:noun_p),(l:prep_p),(l:word)).
3+
l:sentence(Number)-->l:noun_p(Number),l:verb_p(Number).
4+
l:sentence:-((idea);(question;command)),((l:noun_p),l:prep_p,l:verb_p).
5+
l:word(Char|((Char,String);Rest))-->l:letter(Char|String,Char),l:grab_l((Char|Rest,Rest),(Char|String,String)),form_w(Char|String,String).
6+
l:verb_p-->l:verb,l:noun_p.
7+
l:verb_p(Number)-->l:verb(Number),l:noun_p(Number).
8+
l:noun_p-->(l:determiner->l:noun).
9+
l:noun_p(Number)-->l:determiner(Number),l:noun(Number).
10+
l:determiner-->[a];[the].
11+
l:noun-->([name];[person]);[place];[thing];[idea].
12+
l:noun_pr-->[name],[place],[thing].
13+
l:noun(singular)-->(l:determiner->[a]).
14+
l:noun(plural)-->(l:determiner(the)).
15+
l:verb-->[action];[state];[being].
16+
l:prep_p-->l:prep,((l:noun_p);(l:noun);(l:prep,l:noun_pr)).
17+
l:prep-->[in];[to];[with];[into];[by].
18+
l:grab_l(Char|String,String)-->form_w(Char|String,String).
19+
l:grab_l(X,Y)-->form_w(X|Y,Y).
20+
l:output(Answer):-l:output(Answer),write(Answer).
21+
l:output(_):-question,call(l:sentence).
22+
l:verb_p(Number):-l:noun_p(Number).
23+
l:noun_p(Number):-l:verb_p(Number).
24+
l:determiner(X,Y,Z):-write(X;Y;Z).
25+
l:verb(X,Y,Z):-write(X;Y;Z).
26+
l:word(X,Y):-l:letter(Y|X,Y).
27+
l:letter(Y,X,Z,P):-l:grab_l(Y|X,X);l:grab_l(X|Z,Z);l:grab_l(Z|P,P).
28+
form_w(Char|String,String)-->l:word(Char|String,String),l:sentence(String).
29+
idea:-information;question;command.
30+
information:-l:sentence.
31+
question:-l:output(answer).
32+
command:-l:sentence,task.
33+
task:-objective(task);command.
34+
objective(X):-input(X=task).
35+
input(Wordlist):-getsentence(Wordlist).
36+
input(P):-(P:Q),display(Q).
37+
input(_):-assert((_)).
38+
getsentence(Wordlist):-get0(Char),getrest(Char,Wordlist).
39+
getrest(46,[]):-!.
40+
getrest(32,Wordlist):-!,getsentence(Wordlist).
41+
getrest(Letter,[Word|Wordlist]):-getletters(Letter,Letters,Nextchar),name(Word,Letters),getrest(Nextchar,Wordlist).
42+
getletters(46,[],46):-!.
43+
getletters(32,[],32):-!.
44+
getletters(Let,[Let|Letters],Nextchar):-get0(Char),getletters(Char,Letters,Nextchar).
45+
:-op(1200,xfy,(-:-)).
46+
copy_list([X|Y]-:-[X|Z]):-copy_list(Y-:-Z),tell([a]).
47+
options:-write('Your Choice is either 1 or 2, enter 1 for sentence forms and 2 to stream input in english'),nl,options_display(49),options_choose(49),nl.
48+
options_display(49):-sentence.
49+
options_display(49):-get(49),nl.
50+
options_choose(49):-read(49)->l:sentence,display(l:sentence),options_choose_aux(49,50,Input,(read(Input))).
51+
options_choose_aux(First,Last,Result,Char):-Char>=First,Char=<Last,!,options_select(First,Char,Result).
52+
options_choose_aux(First,Last,Result,_):-put(7),put(13),options,nl,display(First),nl,display(Last),nl,display(Result).
53+
options_select(First,Char,Result):-NewFirst is First+1,options_select(NewFirst,Char,Result).
54+
sentence:-copy_list(idea-:-command).
55+
copy_list([]-:-[]).
56+
display(options):-start.
57+
start:-(options->options_display(49)).
58+
sentence:-l:sentence.

0 commit comments

Comments
 (0)