Skip to content

Commit ec8ba3f

Browse files
committed
Add hw-9
1 parent 7553487 commit ec8ba3f

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

hw-9/Hector_Reyes_pl9.pl

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Homework: NLP
3+
-------------------------------------
4+
Course: Programming Languages
5+
Teacher: Gilberto Echeverría Furió
6+
Author: Héctor Alexis Reyes Manrique (A01339607)
7+
Date: November 30th, 2020
8+
*/
9+
10+
11+
/*
12+
Dictionary
13+
----------
14+
*/
15+
16+
% Articles
17+
18+
article(art(el), sin, mas, L0, L) :- terminal(el, L0, L).
19+
article(art(la), sin, fem, L0, L) :- terminal(la, L0, L).
20+
article(art(los), plu, mas, L0, L) :- terminal(los, L0, L).
21+
article(art(las), plu, fem, L0, L) :- terminal(las, L0, L).
22+
article(art(ellos), plu, mas, L0, L) :- terminal(ellos, L0, L).
23+
article(art(ellas), plu, fem, L0, L) :- terminal(ellas, L0, L).
24+
article(art(un), sin, mas, L0, L) :- terminal(un, L0, L).
25+
article(art(una), sin, fem, L0, L) :- terminal(una, L0, L).
26+
article(art(unos), plu, mas, L0, L) :- terminal(unos, L0, L).
27+
article(art(unas), plu, fem, L0, L) :- terminal(unas, L0, L).
28+
article(art(mi), sin, _, L0, L) :- terminal(mi, L0, L).
29+
article(art(mis), plu, _, L0, L) :- terminal(mis, L0, L).
30+
31+
% Nouns
32+
33+
noun(nou(estudiante), sin, _, L0, L) :- terminal(estudiante, L0, L).
34+
noun(nou(estudiantes), plu, _, L0, L) :- terminal(estudiantes, L0, L).
35+
noun(nou(clase), sin, fem, L0, L) :- terminal(clase, L0, L).
36+
noun(nou(clases), plu, fem, L0, L) :- terminal(clases, L0, L).
37+
noun(nou(alumno), sin, mas, L0, L) :- terminal(alumno, L0, L).
38+
noun(nou(alumnos), plu, mas, L0, L) :- terminal(alumnos, L0, L).
39+
noun(nou(alumna), sin, fem, L0, L) :- terminal(alumna, L0, L).
40+
noun(nou(alumnas), plu, fem, L0, L) :- terminal(alumnas, L0, L).
41+
noun(nou(niño), sin, mas, L0, L) :- terminal(niño, L0, L).
42+
noun(nou(niños), plu, mas, L0, L) :- terminal(niños, L0, L).
43+
noun(nou(niña), sin, fem, L0, L) :- terminal(niña, L0, L).
44+
noun(nou(niñas), plu, fem, L0, L) :- terminal(niñas, L0, L).
45+
noun(nou(pelota), sin, fem, L0, L) :- terminal(pelota, L0, L).
46+
noun(nou(pelotas), plu, fem, L0, L) :- terminal(pelotas, L0, L).
47+
noun(nou(bici), sin, fem, L0, L) :- terminal(bici, L0, L).
48+
49+
% Verbs
50+
51+
verb(v(asiste), sin, transitive, L0, L) :- terminal(asiste, L0, L).
52+
verb(v(asisten), plu, transitive, L0, L) :- terminal(asisten, L0, L).
53+
verb(v(escucha), sin, _, L0, L) :- terminal(escucha, L0, L).
54+
verb(v(escuchan), plu, _, L0, L) :- terminal(escuchan, L0, L).
55+
verb(v(rie), sin, intransitive, L0, L) :- terminal(rie, L0, L).
56+
verb(v(rien), plu, intransitive, L0, L) :- terminal(rien, L0, L).
57+
verb(v(corre), sin, intransitive, L0, L) :- terminal(corre, L0, L).
58+
verb(v(corren), plu, intransitive, L0, L) :- terminal(corren, L0, L).
59+
verb(v(lanza), sin, transitive, L0, L) :- terminal(lanza, L0, L).
60+
verb(v(lanzan), plu, transitive, L0, L) :- terminal(lanzan, L0, L).
61+
verb(v(monta), sin, transitive, L0, L) :- terminal(monta, L0, L).
62+
verb(v(montan), plu, transitive, L0, L) :- terminal(montan, L0, L).
63+
64+
% Adjectives
65+
66+
adjective(adj(grande), sin, _, L0, L) :- terminal(grande, L0, L).
67+
adjective(adj(grandes), sin, _, L0, L) :- terminal(grandes, L0, L).
68+
adjective(adj(pequeña), sin, fem, L0, L) :- terminal(pequeña, L0, L).
69+
adjective(adj(pequeñas), plu, fem, L0, L) :- terminal(pequeñas, L0, L).
70+
adjective(adj(roja), sin, fem, L0, L) :- terminal(roja, L0, L).
71+
adjective(adj(rojas), plu, fem, L0, L) :- terminal(rojas, L0, L).
72+
73+
74+
/*
75+
Terminal
76+
--------
77+
*/
78+
79+
terminal(Word, [Word|Rest], Rest).
80+
81+
82+
/*
83+
Predicates
84+
--------
85+
*/
86+
87+
sentence(sen(Subject, Predicate), L0, L) :-
88+
subject(Subject, Number, L0, L1),
89+
predicate(Predicate, Number, L1, L), !.
90+
91+
subject(subj(Article, Noun), Number, L0, L) :-
92+
article(Article, Number, Gender, L0, L1),
93+
noun(Noun, Number, Gender, L1, L), !.
94+
95+
subject(subj(Article, Noun, Adjective), Number, L0, L) :-
96+
article(Article, Number, Gender, L0, L1),
97+
noun(Noun, Number, Gender, L1, L2),
98+
adjective(Adjective, Number, Gender, L2, L), !.
99+
100+
predicate(pred(Verb), Number, L0, L) :-
101+
verb(Verb, Number, intransitive, L0, L), !.
102+
103+
predicate(pred(Verb, DirectObject), Number, L0, L) :-
104+
verb(Verb, Number, _, L0, L1),
105+
subject(DirectObject, _, L1, L), !.

hw-9/hw_9_test.plt

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Unit tests for factorial functions
3+
4+
Gilberto Echeverria
5+
10/11/2020
6+
*/
7+
8+
% Indicate the name for the tests
9+
:- begin_tests(list_functions).
10+
% Import the knowledge base
11+
:- include("Hector_Reyes_pl9").
12+
13+
% Function 'sentence'
14+
% Detection of invalid sentences
15+
test(invalid_structure, [fail]) :-
16+
sentence(_, ['niño', 'corre'], _).
17+
test(invalid_structure, [fail]) :-
18+
sentence(_, ['el', 'corre', 'niño'], _).
19+
test(missmatched_article_gender, [fail]) :-
20+
sentence(_, ['el', 'niña', 'corre'], _).
21+
test(missmatched_article_number, [fail]) :-
22+
sentence(_, ['el', 'niños', 'corre'], _).
23+
test(missmatched_article_gender, [fail]) :-
24+
sentence(_, ['el', 'niño', 'lanza', 'el', 'pelota'], _).
25+
test(missmatched_article_number, [fail]) :-
26+
sentence(_, ['el', 'niño', 'lanza', 'las', 'pelota'], _).
27+
test(missmatched_verb_number, [fail]) :-
28+
sentence(_, ['el', 'niño', 'corren'], _).
29+
test(missmatched_verb_number, [fail]) :-
30+
sentence(_, ['los', 'niños', 'corre'], _).
31+
test(missmatched_adjective_gender, [fail]) :-
32+
sentence(_, ['el', 'niño', 'pequeña', 'corren'], _).
33+
test(missmatched_adjective_number, [fail]) :-
34+
sentence(_, ['los', 'niños', 'grande', 'corre'], _).
35+
36+
% Recognition of valid sentences
37+
test(intransitive_verb) :-
38+
sentence(sen(subj(art(el), nou(niño)), pred(v(corre))), ['el', 'niño', 'corre'], []).
39+
test(intransitive_verb_plural_subject) :-
40+
sentence(sen(subj(art(los), nou(niños)), pred(v(corren))), ['los', 'niños', 'corren'], []).
41+
test(transitive_verb) :-
42+
sentence(sen(subj(art(el), nou(niño)), pred(v(lanza), subj(art(la), nou(pelota)))), ['el', 'niño', 'lanza', 'la', 'pelota'], []).
43+
test(transitive_verb_plural_subject) :-
44+
sentence(sen(subj(art(los), nou(niños)), pred(v(lanzan), subj(art(la), nou(pelota)))), ['los', 'niños', 'lanzan', 'la', 'pelota'], []).
45+
test(adjectives) :-
46+
sentence(sen(subj(art(el), nou(niño), adj(grande)), pred(v(lanza), subj(art(las), nou(pelotas), adj(pequeñas)))), ['el', 'niño', 'grande', 'lanza', 'las', 'pelotas', 'pequeñas'], []).
47+
test(adjectives) :-
48+
sentence(sen(subj(art(el), nou(niño), adj(grande)), pred(v(lanza), subj(art(las), nou(pelotas), adj(rojas)))), ['el', 'niño', 'grande', 'lanza', 'las', 'pelotas', 'rojas'], []).
49+
test(adjectives) :-
50+
sentence(sen(subj(art(el), nou(niño), adj(grande)), pred(v(lanza), subj(art(la), nou(pelota), adj(roja)))), ['el', 'niño', 'grande', 'lanza', 'la', 'pelota', 'roja'], []).
51+
52+
:- end_tests(list_functions).

0 commit comments

Comments
 (0)