├── LPN 01 Exercises.docx ├── LPN 02 Exercises.docx ├── LPN 03 Exercises.docx ├── LPN 03 Practical.docx ├── LPN 04 Exercises.docx ├── LPN 04 Practical.docx ├── LPN 05 Exercises.docx ├── LPN 05 Practical.docx ├── LPN 06 Exercises.docx ├── LPN 06 Practical.docx ├── LPN 07 Exercises.docx ├── LPN 07 Practical.docx ├── LPN 08 Exercises.docx ├── LPN 08 Practical.docx ├── LPN 09 Exercises.docx ├── LPN 09 Practical.docx ├── LPN 10 Exercises.docx ├── LPN 10 Practical.docx ├── LPN 11 Exercises.docx ├── LPN 11 Practical.docx ├── LPN 12 Practical ├── dcg.pl ├── input.txt ├── lpn12.pl └── pretty.pl └── README.md /LPN 01 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 01 Exercises.docx -------------------------------------------------------------------------------- /LPN 02 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 02 Exercises.docx -------------------------------------------------------------------------------- /LPN 03 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 03 Exercises.docx -------------------------------------------------------------------------------- /LPN 03 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 03 Practical.docx -------------------------------------------------------------------------------- /LPN 04 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 04 Exercises.docx -------------------------------------------------------------------------------- /LPN 04 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 04 Practical.docx -------------------------------------------------------------------------------- /LPN 05 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 05 Exercises.docx -------------------------------------------------------------------------------- /LPN 05 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 05 Practical.docx -------------------------------------------------------------------------------- /LPN 06 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 06 Exercises.docx -------------------------------------------------------------------------------- /LPN 06 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 06 Practical.docx -------------------------------------------------------------------------------- /LPN 07 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 07 Exercises.docx -------------------------------------------------------------------------------- /LPN 07 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 07 Practical.docx -------------------------------------------------------------------------------- /LPN 08 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 08 Exercises.docx -------------------------------------------------------------------------------- /LPN 08 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 08 Practical.docx -------------------------------------------------------------------------------- /LPN 09 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 09 Exercises.docx -------------------------------------------------------------------------------- /LPN 09 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 09 Practical.docx -------------------------------------------------------------------------------- /LPN 10 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 10 Exercises.docx -------------------------------------------------------------------------------- /LPN 10 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 10 Practical.docx -------------------------------------------------------------------------------- /LPN 11 Exercises.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 11 Exercises.docx -------------------------------------------------------------------------------- /LPN 11 Practical.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tboronczyk/LearnPrologNow/6e786ee29feb2f78479594d7aa8e5fd2953d5d36/LPN 11 Practical.docx -------------------------------------------------------------------------------- /LPN 12 Practical/dcg.pl: -------------------------------------------------------------------------------- 1 | :- module(dcg,[s/3]). 2 | 3 | s(s(NP,VP)) --> np(NP,X,Y,subject), vp(VP,X,Y). 4 | 5 | np(np(DET,NBAR,PP),X,Y,_) --> det(DET,X), nbar(NBAR,X,Y), pp(PP). 6 | np(np(DET,NBAR),X,Y,_) --> det(DET,X), nbar(NBAR,X,Y). 7 | np(np(PRO),X,Y,Z) --> pro(PRO,X,Y,Z). 8 | 9 | vp(vp(V),X,Y) --> v(V,X,Y). 10 | vp(vp(V,NP),X,Y) --> v(V,X,Y), np(NP,_,_,object). 11 | 12 | nbar(nbar(JP),X,3) --> jp(JP,X). 13 | 14 | pp(pp(PREP,NP)) --> prep(PREP), np(NP,_,_,object). 15 | 16 | jp(N,X) --> n(N,X). 17 | jp(jp(ADJ,JP),X) --> adj(ADJ), jp(JP,X). 18 | 19 | det(det(DET),X) --> [DET], {lex(DET,det,X)}. 20 | 21 | pro(pro(PRO),X,Y,Z) --> [PRO], {lex(PRO,pro,X,Y,Z)}. 22 | 23 | v(v(V),X,Y) --> [V], {lex(V,v,X,Y)}. 24 | 25 | prep(prep(PREP)) --> [PREP], {lex(PREP,prep)}. 26 | 27 | n(n(N),X) --> [N], {lex(N,n,X)}. 28 | 29 | adj(adj(ADJ)) --> [ADJ], {lex(ADJ,adj)}. 30 | 31 | lex(i,pro,singular,1,subject). 32 | lex(you,pro,singular,2,subject). 33 | lex(he,pro,singular,3,subject). 34 | lex(she,pro,singular,3,subject). 35 | lex(it,pro,singular,3,subject). 36 | 37 | lex(we,pro,plural,1,subject). 38 | lex(you,pro,plural,2,subject). 39 | lex(they,pro,plural,3,subject). 40 | 41 | lex(me,pro,singular,1,object). 42 | lex(you,pro,singular,2,object). 43 | lex(him,pro,singular,3,object). 44 | lex(her,pro,singular,3,object). 45 | lex(it,pro,singular,3,object). 46 | 47 | lex(us,pro,plural,1,object). 48 | lex(you,pro,plural,2,object). 49 | lex(them,pro,plural,3,object). 50 | 51 | lex(shoot,v,singular,1). 52 | lex(shoot,v,singular,2). 53 | lex(shoots,v,singular,3). 54 | 55 | lex(shoot,v,plural,_). 56 | 57 | lex(the,det,_). 58 | lex(a,det,singular). 59 | 60 | lex(man,n,singular). 61 | lex(woman,n,singular). 62 | lex(table,n,singular). 63 | lex(cow,n,singular). 64 | lex(shower,n,singular). 65 | 66 | lex(men,n,plural). 67 | lex(women,n,plural). 68 | 69 | lex(on,prep). 70 | lex(under,prep). 71 | 72 | lex(small,adj). 73 | lex(frightened,adj). 74 | lex(big,adj). 75 | lex(fat,adj). 76 | -------------------------------------------------------------------------------- /LPN 12 Practical/input.txt: -------------------------------------------------------------------------------- 1 | [the, cow, under, the, table, shoots]. 2 | [a, dead, woman, likes, he]. 3 | -------------------------------------------------------------------------------- /LPN 12 Practical/lpn12.pl: -------------------------------------------------------------------------------- 1 | :- ensure_loaded([dcg,pretty]). 2 | 3 | test(InFile,OutFile) :- 4 | open(InFile,read,In), 5 | open(OutFile,write,Out), 6 | read(In,S), 7 | parse_sentence(S,In,Out), 8 | close(In), 9 | close(Out). 10 | 11 | parse_sentence(end_of_file,_,_) :- !. 12 | parse_sentence(S,In,Out) :- 13 | write(Out,S), nl(Out), 14 | nl(Out), 15 | s(Tree,S,[]), 16 | pptree(Out,Tree), nl(Out), 17 | nl(Out), nl(Out), 18 | read(In,NewS), 19 | parse_sentence(NewS,In,Out). 20 | parse_sentence(_,In,Out) :- 21 | write(Out,'no'), nl(Out), 22 | nl(Out), nl(Out), 23 | read(In,S), 24 | parse_sentence(S,In,Out). 25 | -------------------------------------------------------------------------------- /LPN 12 Practical/pretty.pl: -------------------------------------------------------------------------------- 1 | :- module(pretty,[pptree/2]). 2 | 3 | pptree(OS,s(NP,VP)) :- 4 | write(OS,'s('), nl(OS), 5 | tab(OS,4), pptree(OS,NP,4), nl(OS), 6 | tab(OS,4), pptree(OS,VP,4), 7 | write(OS,')'). 8 | 9 | pptree(OS,det(DET)) :- 10 | write(OS,'det('), 11 | write(OS,DET), 12 | write(OS,')'). 13 | 14 | pptree(OS,pro(PRO)) :- 15 | write(OS,'pro('), 16 | write(OS,PRO), 17 | write(OS,')'). 18 | 19 | pptree(OS,v(V)) :- 20 | write(OS,'v('), 21 | write(OS,V), 22 | write(OS,')'). 23 | 24 | pptree(OS,prep(PREP)) :- 25 | write(OS,'prep('), 26 | write(OS,PREP), 27 | write(OS,')'). 28 | 29 | pptree(OS,adj(ADJ)) :- 30 | write(OS,'adj('), 31 | write(OS,ADJ), 32 | write(OS,')'). 33 | 34 | pptree(OS,n(N),_) :- 35 | write(OS,'n('), 36 | write(OS,N), 37 | write(OS,')'). 38 | 39 | pptree(OS,np(DET,NBAR,PP),I) :- 40 | Indent is I+4, 41 | write(OS,'np('), nl(OS), 42 | tab(OS,Indent), pptree(OS,DET), nl(OS), 43 | tab(OS,Indent), pptree(OS,NBAR,Indent), nl(OS), 44 | tab(OS,Indent), pptree(OS,PP,Indent), 45 | write(OS,')'). 46 | 47 | pptree(OS,np(DET,NBAR),I) :- 48 | Indent is I+4, 49 | write(OS,'np('), nl(OS), 50 | tab(OS,Indent), pptree(OS,DET), nl(OS), 51 | tab(OS,Indent), pptree(OS,NBAR,Indent), 52 | write(OS,')'). 53 | 54 | pptree(OS,np(PRO),I) :- 55 | Indent is I+4, 56 | write(OS,'np('), nl(OS), 57 | tab(OS,Indent), pptree(OS,PRO), 58 | write(OS,')'). 59 | 60 | pptree(OS,vp(V),I) :- 61 | Indent is I+4, 62 | write(OS,'vp('), nl(OS), 63 | tab(OS,Indent), pptree(OS,V), 64 | write(OS,')'). 65 | 66 | pptree(OS,vp(V,NP),I) :- 67 | Indent is I+4, 68 | write(OS,'vp('), nl(OS), 69 | tab(OS,Indent), pptree(OS,V), nl(OS), 70 | tab(OS,Indent), pptree(OS,NP,Indent), 71 | write(OS,')'). 72 | 73 | pptree(OS,nbar(JP),I) :- 74 | Indent is I+4, 75 | write(OS,'nbar('), nl(OS), 76 | tab(OS,Indent), pptree(OS,JP,Indent), 77 | write(OS,')'). 78 | 79 | pptree(OS,pp(PREP,NP),I) :- 80 | Indent is I+4, 81 | write(OS,'pp('), nl(OS), 82 | tab(OS,Indent), pptree(OS,PREP), nl(OS), 83 | tab(OS,Indent), pptree(OS,NP,Indent), 84 | write(OS,')'). 85 | 86 | pptree(OS,jp(ADJ,JP),I) :- 87 | Indent is I+4, 88 | write(OS,'jp('), nl(OS), 89 | tab(OS,Indent), pptree(OS,ADJ), nl(OS), 90 | tab(OS,Indent), pptree(OS,JP,Indent), 91 | write(OS,')'). 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # My answers for Learn Prolog Now! 2 | 3 | At first I put my answers to the Learn Prolog Now! exercises in a zip file 4 | and linked it from my blog... but then I thought, "Hey I'll put them on 5 | GitHub!" 6 | --------------------------------------------------------------------------------