-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCOM.hs
executable file
·97 lines (75 loc) · 2.61 KB
/
TCOM.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module TCOM where
import Data.List
import FSynF
import Model
allNum, noNum :: Int -> Int -> Bool
allNum = \ m n -> m == 0
noNum = \ m n -> n == 0
atleastNum, atmostNum :: Int -> Int -> Int -> Bool
atleastNum k = \ m n -> n >= k
atmostNum k = \ m n -> n <= k
atleast2butnotall :: Int -> Int -> Bool
atleast2butnotall = \ m n -> m > 0 && n >= 2
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 f (x,y,z) = f x y z
rel3 :: Entity -> Entity -> Entity -> Bool
rel3 D x y = love x y
rel3 E x y = not (love x y)
rel3 _ _ _ = False
intSent :: Sent -> Bool
intSent (Sent np vp) = (intNP np) (intVP vp)
intNP :: NP -> (Entity -> Bool) -> Bool
intNP SnowWhite = \ p -> p snowWhite
intNP Alice = \ p -> p alice
intNP Dorothy = \ p -> p dorothy
intNP Goldilocks = \ p -> p goldilocks
intNP LittleMook = \ p -> p littleMook
intNP Atreyu = \ p -> p atreyu
intNP (NP1 det cn) = (intDET det) (intCN cn)
intNP (NP2 det rcn) = (intDET det) (intRCN rcn)
intVP :: VP -> Entity -> Bool
intVP Laughed = \ x -> laugh x
intVP Cheered = \ x -> cheer x
intVP Shuddered = \ x -> shudder x
intVP (VP1 tv np) =
\ subj -> intNP np (\ obj -> intTV tv subj obj)
intVP (VP2 dv np1 np2) =
\ subj -> intNP np1 (\ iobj -> intNP np2 (\ dobj ->
intDV dv subj iobj dobj))
intTV :: TV -> Entity -> Entity -> Bool
intTV Loved = \ x y -> love x y
intTV Admired = \ x y -> admire x y
intTV Helped = \ x y -> help x y
intTV Defeated = \ x y -> defeat x y
intDV :: DV -> Entity -> Entity -> Entity -> Bool
intDV Gave = \ x y z -> give x y z
intCN :: CN -> Entity -> Bool
intCN Girl = \ x -> girl x
intCN Boy = \ x -> boy x
intCN Princess = \ x -> princess x
intCN Dwarf = \ x -> dwarf x
intCN Giant = \ x -> giant x
intCN Wizard = \ x -> wizard x
intCN Sword = \ x -> sword x
intCN Dagger = \ x -> dagger x
intDET :: DET ->
(Entity -> Bool) -> (Entity -> Bool) -> Bool
intDET Some p q = any q (filter p entities)
intDET Every p q = all q (filter p entities)
intDET The p q = singleton plist && q (head plist)
where
plist = filter p entities
singleton [x] = True
singleton _ = False
intDET No p q = not (intDET Some p q)
intDET Most p q = length pqlist > length (plist \\ qlist)
where
plist = filter p entities
qlist = filter q entities
pqlist = filter q plist
intRCN :: RCN -> Entity -> Bool
intRCN (RCN1 cn _ vp) =
\ e -> ((intCN cn e) && (intVP vp e))
intRCN (RCN2 cn _ np tv) =
\ e -> ((intCN cn e) &&
(intNP np (\ subj -> (intTV tv subj e))))