---
# System prepended metadata

title: TP Prolog - s09 - ISC IL 3a
tags: [prolog]

---

###### tags: `prolog`

# TP Prolog - s09 - ISC IL 3a
## Baudin Valentin et Braillard Simon

## Exercice 1
```prolog=
determiner( _Num)    --> [W], {member(W, [the, my])}.
determiner(singular) --> [W], {member(W, [a, this])}.
determiner(plural)   --> [W], {member(W, [those, many])}.

noun(singular)       --> [W], {member(W, [cat, mouse, dog])}.
noun(plural)         --> [W], {member(W, [cats, mice, dogs])}.

verb(plural)         --> [W], {member(W, [eat,  follow ])}.
verb(singular)       --> [W], {member(W, [eats, follows])}.

adjective            --> [W], {member(W, [red, pretty, old])}.

conjonction          --> [W], {member(W, [and])}.

sentence --> complexeNounPhrase(Num), verbPhrase(Num).

nounPhrase(Num) --> determiner(Num), noun(Num).
nounPhrase(Num) --> noun(Num).

nounPhrase(Num) --> determiner(Num), adjectiveNounPhrase, noun(Num).
nounPhrase(Num) --> adjectiveNounPhrase, noun(Num).

adjectiveNounPhrase --> adjective, adjectiveNounPhrase.
adjectiveNounPhrase --> adjective.

complexeNounPhrase(Num) --> nounPhrase(Num).
complexeNounPhrase(plural) --> nounPhrase(_Num1), conjonction,
                                        complexeNounPhrase(_Num2).

verbPhrase(Num) --> verb(Num).
verbPhrase(Num) --> verb(Num), complexeNounPhrase(_Num1).
```

### Output
```
| ?- > ex1_test.
Trying some sentences...
Trying several adjectives...
Trying a wrong sentence...
Test OK

true ? > 


yes
| ?- 
```

## Exercice 2
```prolog=
determiner(X, _Num)    --> [W], {member(W, [the, my])}, {X = det(W)}.
determiner(X, singular) --> [W], {member(W, [a, this])}, {X = det(W)}.
determiner(X, plural)   --> [W], {member(W, [those, many])}, {X = det(W)}.

noun(X, singular)   --> [W], {member(W, [cat, mouse, dog])}, {X = noun(W)}.
noun(X, plural)     --> [W], {member(W, [cats, mice, dogs])}, {X = noun(W)}.

verb(X, plural)     --> [W], {member(W, [eat,  follow ])}, {X = verb(W)}.
verb(X, singular)   --> [W], {member(W, [eats, follows])}, {X = verb(W)}.

sentence(X) --> nounPhrase(X1, Num), verbPhrase(X2, Num), {X = s(X1,X2)}.

nounPhrase(X, Num) --> determiner(X1, Num), noun(X2, Num), {X = np(X1,X2)}.
nounPhrase(X, Num) --> noun(X1, Num), {X = np(X1)}.

verbPhrase(X, Num) --> verb(X1, Num), {X = vp(X1)}.
verbPhrase(X, Num) --> verb(X1, Num), nounPhrase(X2, _Num1),
                                                    {X = vp(X1,X2)}.
```
### Output
```
| ?- > ex2_test .
Test passed successfully

true ? > 


(1 ms) yes
```

## Exercice 3

```prolog=
pronominalQuestion([Num1, V, Num2]) --> auxiliary(Num1), pronoun(Num1,
            subject), verb(V, plural), pronoun(Num2, object), [?].
pronominalQuestion([Num, V]) -->  auxiliary(Num), pronoun(Num, subject),
            verb(V, plural), [?].
```

### Output

```
| ?- > ex3_test.
[the,cat,eats,a,mouse]	[does,it,eat,it,?]
[cats,follow,mice]	[do,they,follow,them,?]
[a,cat,eats,mice]	[does,it,eat,them,?]
[my,cats,eat,the,mouse]	[do,they,eat,it,?]
[my,cats,eat]	[do,they,eat,?]
[a,cat,eat,a,cat]	is not considered valid...
18 accepted pronominal questions, expected 18
Test passed successfully

yes
| ?- | ?- > ex3_test.
[the,cat,eats,a,mouse]	[does,it,eat,it,?]
[cats,follow,mice]	[do,they,follow,them,?]
[a,cat,eats,mice]	[does,it,eat,them,?]
[my,cats,eat,the,mouse]	[do,they,eat,it,?]
[my,cats,eat]	[do,they,eat,?]
[a,cat,eat,a,cat]	is not considered valid...
18 accepted pronominal questions, expected 18
Test passed successfully

yes
| ?- 
```

## Exercice 4 

```prolog=
xxx(X) --> digit(D), [hundred], restxxx(R), { D1 is D*100, X is D1+R }.
xxx(X) --> xx(X).
restxxx(X) --> [and], xx(X).
restxxx(0) --> [].
xx(X) --> digit(X).
xx(X) --> teen(X).
xx(X) --> tens(T), restxx(R), { X is T+R }.
restxx(R) --> digit(R).
restxx(0) --> [].

wordNumber(X) --> [zero], { X is 0 }.
wordNumber(X) --> xxx(X).
```

### Output
```
> ex4_test.
Trying some number sentences...
Trying a wrong number sentence...
Trying to count all number sentences...
1000 accepted numbers, should be 1000
Test OK

true ? > 


yes
| ?- > 
```

### Expliquer le comportement du programme si on demande la conversion dans l'autre sens
Le langage que nous avons décrit est fini (on peut aller au maximum jusqu'à 999). Par conséquent le moteur prolog essaie toutes les solutions et trouve donc le résultat attendu.