7:- use_module(library(mcintyre)). 8
9:- if(current_predicate(use_rendering/1)). 10:- use_rendering(c3). 11:- endif. 12:- mc. 13:- begin_lpad. 53
55
57s(W,Num,np(N,NN),det(D,DD),n(M,MM),v(V,VV)) :-
58 split(W,W1,W2),
59 np(W1,Num,np(N,NI),det(D,DI),n(M,MI),v(V,VI)),
60 vp(W2,Num,np(NI,NN),det(DI,DD),n(MI,MM),v(VI,VV)).
61
62% np(Num) -> 0.4:: det(sg),n(sg) | 0.4:: n(pl) | 0.2::det(pl),n(pl)
630.4::np_to(N,sg_dn); 0.4::np_to(N,pl_n); 0.2::np_to(N,pl_dn).
65np(W,sg,np(N,NN),det(D,DD),n(M,MM),v(V,VV)) :-
66 np_to(N,sg_dn),
67 NI is N+1,
68 split(W,W1,W2),
69 det(W1,sg,np(NI,N1),det(D,D1),n(M,M1),v(V,V1)),
70 n(W2,sg,np(N1,NN),det(D1,DD),n(M1,MM),v(V1,VV)).
71np(W,pl,np(N,NN),det(D,DD),n(M,MM),v(V,VV)) :-
72 np_to(N,pl_n),
73 NI is N+1,
74 n(W,pl,np(NI,NN),det(D,DD),n(M,MM),v(V,VV)).
75np(W,pl,np(N,NN),det(D,DD),n(M,MM),v(V,VV)) :-
76 np_to(N,pl_dn),
77 NI is N+1,
78 split(W,W1,W2),
79 det(W1,pl,np(NI,N1),det(D,D1),n(M,M1),v(V,V1)),
80 n(W2,pl,np(N1,NN),det(D1,DD),n(M1,MM),v(V1,VV)).
81
83vp(W,Num,np(N,NN),det(D,DD),n(M,MM),v(V,VV)) :-
84 split(W,W1,W2),
85 v(W1,Num,np(N,NI),det(D,DI),n(M,MI),v(V,VI)),
86 np(W2,_,np(NI,NN),det(DI,DD),n(MI,MM),v(VI,VV)).
87
88% det(Num) -> 1/3 the(pl) | 1/3 the(sg) | 1/3 a(sg)
89% det_to(N,the_pl):1/3; det_to(N,the_sg):1/3; det_to(N,a_sg):1/3.
901/3::det_to(N,the_pl); 1/3::det_to(N,the_sg); 1/3::det_to(N,a_sg).
91det([the],pl,np(N,N),det(D,DD),n(M,M),v(V,V)) :-
92 det_to(D,the_pl), DD is D+1.
93det([the],sg,np(N,N),det(D,DD),n(M,M),v(V,V)) :-
94 det_to(D,the_sg), DD is D+1.
95det([a],sg,np(N,N),det(D,DD),n(M,M),v(V,V)) :-
96 det_to(D,a_sg), DD is D+1.
97
98% n(Num) -> 0.25 cat(sg) | 0.15 mouse(sg) | 0.1 dog(sg) | 0.25 cats(pl) | 0.15 mice(pl) | 0.1 dogs(pl)
990.25::n_to(N,cat_sg); 0.15::n_to(N, mouse_sg) ; 0.1::n_to(N, dog_sg) ; 0.25::n_to(N, cats_pl) ; 0.15::n_to(N, mice_pl) ; 0.1::n_to(N, dogs_pl).
103n([cat],sg,np(N,N),det(D,D),n(M,MM),v(V,V)) :-
104 n_to(M,cat_sg), MM is M+1.
105n([mouse],sg,np(N,N),det(D,D),n(M,MM),v(V,V)) :-
106 n_to(M,mouse_sg), MM is M+1.
107n([dog],sg,np(N,N),det(D,D),n(M,MM),v(V,V)) :-
108 n_to(M,dog_sg), MM is M+1.
109n([cats],pl,np(N,N),det(D,D),n(M,MM),v(V,V)) :-
110 n_to(M,cats_pl), MM is M+1.
111n([mice],pl,np(N,N),det(D,D),n(M,MM),v(V,V)) :-
112 n_to(M,mice_pl), MM is M+1.
113n([dogs],pl,np(N,N),det(D,D),n(M,MM),v(V,V)) :-
114 n_to(M,dogs_pl), MM is M+1.
115
116% v(Num) -> 0.35 chases(sg) | 0.15 sees(sg) | 0.2 chase(pl) | 0.3 see(pl)
1170.35::v_to(N, chases_sg) ; 0.15::v_to(N, sees_sg) ; 0.2::v_to(N, chase_pl) ; 0.3::v_to(N, see_pl).
119v([chases],sg,np(N,N),det(D,D),n(M,M),v(V,VV)) :-
120 v_to(V,chases_sg), VV is V+1.
121v([sees],sg,np(N,N),det(D,D),n(M,M),v(V,VV)) :-
122 v_to(V,sees_sg), VV is V+1.
123v([chase],pl,np(N,N),det(D,D),n(M,M),v(V,VV)) :-
124 v_to(V,chase_pl), VV is V+1.
125v([see],pl,np(N,N),det(D,D),n(M,M),v(V,VV)) :-
126 v_to(V,see_pl), VV is V+1.
127
129word(L) :- s(L,_Num,np(0,_),det(0,_),n(0,_),v(0,_)).
130
133split([A,B|C],[A],[B|C]).
134split([A,B|C],[A|D],E) :-
135 split([B|C],D,E).
136
139query(X):-X=[_,_,_,_,_],word(X).
140query(X):-X=[_,_,_,_],word(X).
141query(X):-X=[_,_,_],word(X).
142evidence(is_word).
143
146is_word :- word([_,_,_]).
147is_word :- word([_,_,_,_]).
148is_word :- word([_,_,_,_,_]).
149
150:- end_lpad.
?-
mc_sample(is_word,1000,P)
. % the probability of getting a word of length 3/4/5 % Expected result 0.067222?-
mc_mh_sample_arg(word([A,B,C]),word([_,_,_]),10,[A,B,C],V,[lag(1)])
. % take 10 samples of 3 token words given that the length of the word is 3?-
mc_mh_sample_arg(word([A,B,C]),word([_,_,_]),10,[A,B,C],V,[lag(1)])
,argbar(V,C)
. % take 10 samples of 3 token words given that the length of the word is 3 % and draw a bar chart of the results?-
mc_mh_sample_arg(query(X),is_word,10,X,V,[lag(1)])
. % take 10 samples of 3, 4 or 5 token words given that the length of the word is % 3, 5 or 5?-
mc_gibbs_sample(word([mice,see,cats]),word([mice,_,_]),1000,V,[lag(1)])
.*/