diff --git a/README.md b/README.md index 65ef371..7d60a3b 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -Probablity questions solver powered with Problog Engine +Probablity questions solver powered with Problog Engine diff --git a/probE/1.pl b/probE/1.pl index 3155bda..1cb4b26 100644 --- a/probE/1.pl +++ b/probE/1.pl @@ -1,25 +1,25 @@ -P_Student_success :: student_roll(L, P_Student_success, P_Student_fail, D, success); P_Student_fail :: student_roll(L, P_Student_success, P_Student_fail, D, fail) :- student(L, P_Student_success, P_Student_fail, D). - -student(f, 0.2, 0.8, D ) :- between(1, 1, D). -student(f, 0.25, 0.75, D ) :- between(1, 1, D). -student(f, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 1, D). - -alias_Z(Z1) :- student_roll(f, 0.3333333333333333, 0.6666666666666666, 1, Z1 ) . -alias_X(X1) :- student_roll(f, 0.2, 0.8, 1, X1 ) . -alias_Y(Y1) :- student_roll(f, 0.25, 0.75, 1, Y1 ) . - -q(8250) :- alias_Z(Z1), alias_X(X1), alias_Y(Y1), ( count([X1 , Y1 , Z1],success, C7470) , C7470 >= 2 ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - +P_Student_success :: student_roll(L, P_Student_success, P_Student_fail, D, success); P_Student_fail :: student_roll(L, P_Student_success, P_Student_fail, D, fail) :- student(L, P_Student_success, P_Student_fail, D). + +student(f, 0.2, 0.8, D ) :- between(1, 1, D). +student(f, 0.25, 0.75, D ) :- between(1, 1, D). +student(f, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 1, D). + +alias_Z(Z1) :- student_roll(f, 0.3333333333333333, 0.6666666666666666, 1, Z1 ) . +alias_X(X1) :- student_roll(f, 0.2, 0.8, 1, X1 ) . +alias_Y(Y1) :- student_roll(f, 0.25, 0.75, 1, Y1 ) . + +q(8250) :- alias_Z(Z1), alias_X(X1), alias_Y(Y1), ( count([X1 , Y1 , Z1],success, C7470) , C7470 >= 2 ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + query(q(_)). \ No newline at end of file diff --git a/probE/1.pq b/probE/1.pq index c250c5d..c7171e9 100644 --- a/probE/1.pq +++ b/probE/1.pq @@ -1,17 +1,17 @@ -# The probability of success of three students X, Y and Z in the one examination -# are 1/5, 1/4 and 1/3 respectively. Find the probability of success of at least two. - -entity student[S,F]( -S :: success; F :: fail -) - -X = student(1/5,4/5){1}.roll() -Y = student(1/4,3/4){1}.roll() -Z = student(1/3,2/3){1}.roll() - - -probability( equalAtleast( 2, [ X | Y | Z ] , success)) -# entity student[S](S :: success; 1-S::fail) - - -# correct ans: 1/6 = 0.16666667 +# The probability of success of three students X, Y and Z in the one examination +# are 1/5, 1/4 and 1/3 respectively. Find the probability of success of at least two. + +entity student[S,F]( +S :: success; F :: fail +) + +X = student(1/5,4/5){1}.roll() +Y = student(1/4,3/4){1}.roll() +Z = student(1/3,2/3){1}.roll() + + +probability( equalAtleast( 2, [ X | Y | Z ] , success)) +# entity student[S](S :: success; 1-S::fail) + + +# correct ans: 1/6 = 0.16666667 diff --git a/probE/10.pl b/probE/10.pl index 15b58ae..b340076 100644 --- a/probE/10.pl +++ b/probE/10.pl @@ -1,17 +1,17 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). -P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). - -dice(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, D ) :- between(1, 2, D). - -alias_X(X1, X2) :- dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 1, X1 ), dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 2, X2 ) . - -q(4631) :- alias_X(X1, X2), ( \+ ( ( X1 + X2 =:= 8 ) , ( count([X1, X2],1, C3689) , C3689 = 2 ) ) ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). +P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). + +dice(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, D ) :- between(1, 2, D). + +alias_X(X1, X2) :- dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 1, X1 ), dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 2, X2 ) . + +q(4631) :- alias_X(X1, X2), ( \+ ( ( X1 + X2 =:= 8 ) , ( count([X1, X2],1, C3689) , C3689 = 2 ) ) ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + query(q(_)). \ No newline at end of file diff --git a/probE/10.pq b/probE/10.pq index f2bb048..adc94ef 100644 --- a/probE/10.pq +++ b/probE/10.pq @@ -1,2 +1,2 @@ -X = dice{2}.roll() -probability( not ((X[1] + X[2] == 8) and equalAll(X,1) ) ) +X = dice{2}.roll() +probability( not ((X[1] + X[2] == 8) and equalAll(X,1) ) ) diff --git a/probE/2.pl b/probE/2.pl index 6435a27..dc83463 100644 --- a/probE/2.pl +++ b/probE/2.pl @@ -1,25 +1,25 @@ -P_Student_1 :: student_roll(L, P_Student_1, P_Student_2, D, 1); P_Student_2 :: student_roll(L, P_Student_1, P_Student_2, D, 2) :- student(L, P_Student_1, P_Student_2, D). - -student(f, 0.2, 0.8, D ) :- between(1, 3, D). -student(f, 0.25, 0.75, D ) :- between(1, 2, D). -student(f, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 1, D). - -alias_Z(Z1) :- student_roll(f, 0.3333333333333333, 0.6666666666666666, 1, Z1 ) . -alias_Y(Y1, Y2) :- student_roll(f, 0.25, 0.75, 1, Y1 ), student_roll(f, 0.25, 0.75, 2, Y2 ) . -alias_X(X1, X2, X3) :- student_roll(f, 0.2, 0.8, 1, X1 ), student_roll(f, 0.2, 0.8, 2, X2 ), student_roll(f, 0.2, 0.8, 3, X3 ) . - -q(2658) :- alias_Z(Z1), alias_Y(Y1, Y2), alias_X(X1, X2, X3), ( ( ( count([X1, X2, X3 , Y1, Y2 , Z1],1, C1839) , C1839 >= 2 ) ; ( count([X1, X2, X3],2, C3482) , C3482 =< 2 ) ) , ( ( ( X1 + Y2 + Z1 ) / 2 ) + 3 =:= 5 ) ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - -query(q(_)). +P_Student_1 :: student_roll(L, P_Student_1, P_Student_2, D, 1); P_Student_2 :: student_roll(L, P_Student_1, P_Student_2, D, 2) :- student(L, P_Student_1, P_Student_2, D). + +student(f, 0.2, 0.8, D ) :- between(1, 3, D). +student(f, 0.25, 0.75, D ) :- between(1, 2, D). +student(f, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 1, D). + +alias_Z(Z1) :- student_roll(f, 0.3333333333333333, 0.6666666666666666, 1, Z1 ) . +alias_Y(Y1, Y2) :- student_roll(f, 0.25, 0.75, 1, Y1 ), student_roll(f, 0.25, 0.75, 2, Y2 ) . +alias_X(X1, X2, X3) :- student_roll(f, 0.2, 0.8, 1, X1 ), student_roll(f, 0.2, 0.8, 2, X2 ), student_roll(f, 0.2, 0.8, 3, X3 ) . + +q(2658) :- alias_Z(Z1), alias_Y(Y1, Y2), alias_X(X1, X2, X3), ( ( ( count([X1, X2, X3 , Y1, Y2 , Z1],1, C1839) , C1839 >= 2 ) ; ( count([X1, X2, X3],2, C3482) , C3482 =< 2 ) ) , ( ( ( X1 + Y2 + Z1 ) / 2 ) + 3 =:= 5 ) ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + +query(q(_)). diff --git a/probE/2.pq b/probE/2.pq index 4606d12..65f60cd 100644 --- a/probE/2.pq +++ b/probE/2.pq @@ -1,11 +1,11 @@ - -entity student(1/2 :: 1; 1/2 :: 2) - -X = student(1/5,4/5){3}.roll() -Y = student(1/4,3/4){2}.roll() -Z = student(1/3,2/3){1}.roll() - -probability( - ( equalAtleast( 2, [ X | Y | Z ] , 1) or equalAtmost( 2, X , 2) ) - and (( X[1] + Y[2] + Z[1] ) / 2) + 3 == 5 -) + +entity student(1/2 :: 1; 1/2 :: 2) + +X = student(1/5,4/5){3}.roll() +Y = student(1/4,3/4){2}.roll() +Z = student(1/3,2/3){1}.roll() + +probability( + ( equalAtleast( 2, [ X | Y | Z ] , 1) or equalAtmost( 2, X , 2) ) + and (( X[1] + Y[2] + Z[1] ) / 2) + 3 == 5 +) diff --git a/probE/3.pl b/probE/3.pl index db32b72..8e79645 100644 --- a/probE/3.pl +++ b/probE/3.pl @@ -1,20 +1,20 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, D, 3) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, D). - -dice(f, 0.5, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 5, D). - -alias_Y(Y1, Y2, Y3, Y4, Y5) :- dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 1, Y1 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 2, Y2 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 3, Y3 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 4, Y4 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 5, Y5 ) . - - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, D, 3) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, D). + +dice(f, 0.5, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 5, D). + +alias_Y(Y1, Y2, Y3, Y4, Y5) :- dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 1, Y1 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 2, Y2 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 3, Y3 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 4, Y4 ), dice_roll(f, 0.5, 0.3333333333333333, 0.6666666666666666, 5, Y5 ) . + + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + query(q(_)). \ No newline at end of file diff --git a/probE/3.pq b/probE/3.pq index 0e25f92..497deb3 100644 --- a/probE/3.pq +++ b/probE/3.pq @@ -1,4 +1,4 @@ -entity dice(1;2;3) - -X = dice(1/2,1/3,2/3){5} -Y = X.roll() +entity dice(1;2;3) + +X = dice(1/2,1/3,2/3){5} +Y = X.roll() diff --git a/probE/4.pl b/probE/4.pl index c2b53c4..c3dc010 100644 --- a/probE/4.pl +++ b/probE/4.pl @@ -1,20 +1,20 @@ -P_Student_solve :: student_roll(L, P_Student_solve, P_Student_fail, D, solve); P_Student_fail :: student_roll(L, P_Student_solve, P_Student_fail, D, fail) :- student(L, P_Student_solve, P_Student_fail, D). - -student(f, 0.5, 0.5, D ) :- between(1, 1, D). -student(f, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 1, D). -student(f, 0.25, 0.75, D ) :- between(1, 1, D). - -alias_C(C1) :- student_roll(f, 0.25, 0.75, 1, C1 ) . -alias_B(B1) :- student_roll(f, 0.3333333333333333, 0.6666666666666666, 1, B1 ) . -alias_A(A1) :- student_roll(f, 0.5, 0.5, 1, A1 ) . - -q(4873) :- alias_C(C1), alias_B(B1), alias_A(A1), ( count([A1 , B1 , C1],solve, C7636) , C7636 >= 1 ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - +P_Student_solve :: student_roll(L, P_Student_solve, P_Student_fail, D, solve); P_Student_fail :: student_roll(L, P_Student_solve, P_Student_fail, D, fail) :- student(L, P_Student_solve, P_Student_fail, D). + +student(f, 0.5, 0.5, D ) :- between(1, 1, D). +student(f, 0.3333333333333333, 0.6666666666666666, D ) :- between(1, 1, D). +student(f, 0.25, 0.75, D ) :- between(1, 1, D). + +alias_C(C1) :- student_roll(f, 0.25, 0.75, 1, C1 ) . +alias_B(B1) :- student_roll(f, 0.3333333333333333, 0.6666666666666666, 1, B1 ) . +alias_A(A1) :- student_roll(f, 0.5, 0.5, 1, A1 ) . + +q(4873) :- alias_C(C1), alias_B(B1), alias_A(A1), ( count([A1 , B1 , C1],solve, C7636) , C7636 >= 1 ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + query(q(_)). \ No newline at end of file diff --git a/probE/4.pq b/probE/4.pq index 3868147..3dd1839 100644 --- a/probE/4.pq +++ b/probE/4.pq @@ -1,5 +1,5 @@ -entity student(solve;fail) -A = student(1/2,1/2){1}.roll() -B = student(1/3,2/3){1}.roll() -C = student(1/4,3/4){1}.roll() -probability( equalAtleast(1,[A|B|C], solve) ) +entity student(solve;fail) +A = student(1/2,1/2){1}.roll() +B = student(1/3,2/3){1}.roll() +C = student(1/4,3/4){1}.roll() +probability( equalAtleast(1,[A|B|C], solve) ) diff --git a/probE/5.pl b/probE/5.pl index c7e4443..a6ed3e4 100644 --- a/probE/5.pl +++ b/probE/5.pl @@ -1,18 +1,18 @@ -P_Interview_s :: interview_roll(L, P_Interview_s, P_Interview_ns, D, s); P_Interview_ns :: interview_roll(L, P_Interview_s, P_Interview_ns, D, ns) :- interview(L, P_Interview_s, P_Interview_ns, D). - -interview(f, 0.14285714285714285, 0.8571428571428571, D ) :- between(1, 1, D). -interview(f, 0.2, 0.8, D ) :- between(1, 1, D). - -alias_Hus(Hus1) :- interview_roll(f, 0.14285714285714285, 0.8571428571428571, 1, Hus1 ) . -alias_Wife(Wife1) :- interview_roll(f, 0.2, 0.8, 1, Wife1 ) . - -q(2463) :- alias_Hus(Hus1), alias_Wife(Wife1), ( count([Hus1 , Wife1],s, C4617) , C4617 = 1 ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - +P_Interview_s :: interview_roll(L, P_Interview_s, P_Interview_ns, D, s); P_Interview_ns :: interview_roll(L, P_Interview_s, P_Interview_ns, D, ns) :- interview(L, P_Interview_s, P_Interview_ns, D). + +interview(f, 0.14285714285714285, 0.8571428571428571, D ) :- between(1, 1, D). +interview(f, 0.2, 0.8, D ) :- between(1, 1, D). + +alias_Hus(Hus1) :- interview_roll(f, 0.14285714285714285, 0.8571428571428571, 1, Hus1 ) . +alias_Wife(Wife1) :- interview_roll(f, 0.2, 0.8, 1, Wife1 ) . + +q(2463) :- alias_Hus(Hus1), alias_Wife(Wife1), ( count([Hus1 , Wife1],s, C4617) , C4617 = 1 ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + query(q(_)). \ No newline at end of file diff --git a/probE/5.pq b/probE/5.pq index f85a836..920d2db 100644 --- a/probE/5.pq +++ b/probE/5.pq @@ -1,4 +1,4 @@ -entity interview(s;ns) -Hus = interview(1/7,6/7){1}.roll() -Wife = interview(1/5,4/5){1}.roll() -probability(equalFew(1,[Hus|Wife],s)) +entity interview(s;ns) +Hus = interview(1/7,6/7){1}.roll() +Wife = interview(1/5,4/5){1}.roll() +probability(equalFew(1,[Hus|Wife],s)) diff --git a/probE/6.pl b/probE/6.pl index 631be5d..7369649 100644 --- a/probE/6.pl +++ b/probE/6.pl @@ -1,16 +1,19 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). - -dice(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, D ) :- between(1, 2, D). - -alias_X(X1, X2) :- dice_roll(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 1, X1 ), dice_roll(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 2, X2 ) . - -q(8404) :- ( ( X1 + X2 / 4 =:= 1 ) ; ( X1 + X2 / 4 =:= 2 ) ; ( X1 + X2 / 4 =:= 3 ) ; ( X1 + X2 / 6 =:= 2 ) ; ( X1 + X2 / 6 =:= 1 ) ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). +P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). + +dice(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, D ) :- between(1, 2, D). +dice(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, D ) :- between(1, 3, D). + +alias_X(X1, X2) :- dice_roll(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 1, X1 ), dice_roll(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 2, X2 ) . +alias_Y(Y1, Y2, Y3) :- dice_roll(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 1, Y1 ), dice_roll(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 2, Y2 ), dice_roll(f, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 0.16666666666666666, 3, Y3 ) . + +q(1558) :- alias_Y(Y1, Y2, Y3), alias_X(X1, X2), ( X1+ X2 + Y2 =:= 4 ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + query(q(_)). \ No newline at end of file diff --git a/probE/6.pq b/probE/6.pq index 5b33c2c..052a8e6 100644 --- a/probE/6.pq +++ b/probE/6.pq @@ -1,3 +1,4 @@ -entity dice(1;2;3;4;5;6) -X = dice(1/6,1/6,1/6,1/6,1/6,1/6){2}.roll() -probability((X[1]+ X[2] / 4 == 1 ) or (X[1]+ X[2] / 4 == 2 ) or (X[1]+ X[2] / 4 == 3 ) or (X[1]+ X[2] / 6 == 2 ) or (X[1]+ X[2] / 6 == 1 ) ) +entity dice(1;2;3;4;5;6) +X = dice(1/6,1/6,1/6,1/6,1/6,1/6){2}.roll() +Y = dice(1/6,1/6,1/6,1/6,1/6,1/6){3}.roll() +probability( sum( (X[1:2]|Y[2]),4) ) \ No newline at end of file diff --git a/probE/7.pl b/probE/7.pl index 95967e8..adb3871 100644 --- a/probE/7.pl +++ b/probE/7.pl @@ -1,16 +1,16 @@ -P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). - -coin(f, 0.5, 0.5, D ) :- between(1, 3, D). - -alias_X(X1, X2, X3) :- coin_roll(f, 0.5, 0.5, 1, X1 ), coin_roll(f, 0.5, 0.5, 2, X2 ), coin_roll(f, 0.5, 0.5, 3, X3 ) . - -q(3882) :- alias_X(X1, X2, X3), ( count([X1, X2, X3],head, C4910) , C4910 =< 2 ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - +P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). + +coin(f, 0.5, 0.5, D ) :- between(1, 3, D). + +alias_X(X1, X2, X3) :- coin_roll(f, 0.5, 0.5, 1, X1 ), coin_roll(f, 0.5, 0.5, 2, X2 ), coin_roll(f, 0.5, 0.5, 3, X3 ) . + +q(3882) :- alias_X(X1, X2, X3), ( count([X1, X2, X3],head, C4910) , C4910 =< 2 ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + query(q(_)). \ No newline at end of file diff --git a/probE/7.pq b/probE/7.pq index 8faf1d7..883c692 100644 --- a/probE/7.pq +++ b/probE/7.pq @@ -1,3 +1,3 @@ -entity coin(head;tail) -X = coin(0.5,0.5){3}.roll() -probability(equalAtmost(2,X,head)) +entity coin(head;tail) +X = coin(0.5,0.5){3}.roll() +probability(equalAtmost(2,X,head)) diff --git a/probE/8.pl b/probE/8.pl index 23ed1b8..5fcaafb 100644 --- a/probE/8.pl +++ b/probE/8.pl @@ -1,20 +1,20 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). -P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). - -dice(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, D ) :- between(1, 2, D). -coin(empty, 0.5, 0.5, D ) :- between(1, 2, D). - -alias_Y(Y1, Y2) :- coin_roll(empty, 0.5, 0.5, 1, Y1 ), coin_roll(empty, 0.5, 0.5, 2, Y2 ) . -alias_X(X1, X2) :- dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 1, X1 ), dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 2, X2 ) . - -q(6830) :- alias_X(X1, X2), ( ( X1 + X2 > 7 ) ; ( count([X1, X2],6, C6488) , C6488 = 2 ) ) . -q(4044) :- alias_Y(Y1, Y2), ( count([Y1, Y2],head, C4230) , C4230 = 2 ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). +P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). + +dice(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, D ) :- between(1, 2, D). +coin(empty, 0.5, 0.5, D ) :- between(1, 2, D). + +alias_X(X1, X2) :- dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 1, X1 ), dice_roll(empty, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 0.16666666666, 2, X2 ) . +alias_Y(Y1, Y2) :- coin_roll(empty, 0.5, 0.5, 1, Y1 ), coin_roll(empty, 0.5, 0.5, 2, Y2 ) . + +q(1520) :- alias_X(X1, X2), ( ( X1 + X2 > 7 ) ; ( count([X1, X2],6, C9661) , C9661 = 2 ) ) . +q(2391) :- alias_Y(Y1, Y2), ( count([Y1, Y2],head, C5565) , C5565 = 2 ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + query(q(_)). \ No newline at end of file diff --git a/probE/8.pq b/probE/8.pq index 00196b2..216ba08 100644 --- a/probE/8.pq +++ b/probE/8.pq @@ -1,5 +1,5 @@ -X = dice{2}.roll() -probability(X[1] + X[2] > 7 or equalAll(X,6)) - -Y = coin{2}.roll() -probability(equalAll(Y,head)) +X = dice{2}.roll() +probability(X[1] + X[2] > 7 or equalAll(X,6)) + +Y = coin{2}.roll() +probability(equalAll(Y,head)) diff --git a/probE/9.pl b/probE/9.pl index f822851..b3d6cee 100644 --- a/probE/9.pl +++ b/probE/9.pl @@ -1,18 +1,18 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). -P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). -P_Apply_ho :: apply_roll(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D, ho); P_Apply_ht :: apply_roll(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D, ht); P_Apply_hth :: apply_roll(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D, hth) :- apply(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D). - -apply(f, 0.5, 0.16666666666666666, 0.3333333333333333, D ) :- between(1, 3, D). - -alias_H(H1, H2, H3) :- apply_roll(f, 0.5, 0.16666666666666666, 0.3333333333333333, 1, H1 ), apply_roll(f, 0.5, 0.16666666666666666, 0.3333333333333333, 2, H2 ), apply_roll(f, 0.5, 0.16666666666666666, 0.3333333333333333, 3, H3 ) . - -q(6893) :- alias_H(H1, H2, H3), ( ( count([H1, H2, H3],ho, C1535) , C1535 = 3 ) ; ( count([H1, H2, H3],ht, C6285) , C6285 = 3 ) ; ( count([H1, H2, H3],hth, C3553) , C3553 = 3 ) ) . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - +P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). +P_Apply_ho :: apply_roll(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D, ho); P_Apply_ht :: apply_roll(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D, ht); P_Apply_hth :: apply_roll(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D, hth) :- apply(L, P_Apply_ho, P_Apply_ht, P_Apply_hth, D). + +apply(f, 0.5, 0.16666666666666666, 0.3333333333333333, D ) :- between(1, 3, D). + +alias_H(H1, H2, H3) :- apply_roll(f, 0.5, 0.16666666666666666, 0.3333333333333333, 1, H1 ), apply_roll(f, 0.5, 0.16666666666666666, 0.3333333333333333, 2, H2 ), apply_roll(f, 0.5, 0.16666666666666666, 0.3333333333333333, 3, H3 ) . + +q(7920) :- alias_H(H1, H2, H3), ( ( count([H1, H2, H3],ho, C1410) , C1410 = 3 ) ; ( count([H1, H2, H3],ht, C1498) , C1498 = 3 ) ; ( count([H1, H2, H3],hth, C4155) , C4155 = 3 ) ) . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + query(q(_)). \ No newline at end of file diff --git a/probE/9.pq b/probE/9.pq index 63f1f0b..34d98f4 100644 --- a/probE/9.pq +++ b/probE/9.pq @@ -1,4 +1,4 @@ -entity apply( 1/3 :: ho; 1/3 :: ht; 1/3 :: hth) -K = apply(1/2,1/6,2/6){3} -H = K.roll() -probability(equalAll(H,ho) or equalAll(H,ht) or equalAll(H,hth)) +entity apply( 1/3 :: ho; 1/3 :: ht; 1/3 :: hth) +K = apply(1/2,1/6,2/6){3} +H = K.roll() +probability(equalAll(H,ho) or equalAll(H,ht) or equalAll(H,hth)) diff --git a/probE/baised_dice.pl b/probE/baised_dice.pl index f3f11cd..b54aa1c 100644 --- a/probE/baised_dice.pl +++ b/probE/baised_dice.pl @@ -1,8 +1,8 @@ -coin(fair,0.5, D) :- between(1,2,D). -coin(b1,0.7,1). - -H::flip(F, D, 1); T::flip(F, D, 0) :- coin(F, H ,D), T is 1 - H. - -q :- flip(fair,1,X), flip(fair,2,Y),flip(b1,1,Z), (X+Y+Z =:= 2;X+Y+Z =:= 1;X+Y+Z =:= 0). - -query(q). +coin(fair,0.5, D) :- between(1,2,D). +coin(b1,0.7,1). + +H::flip(F, D, 1); T::flip(F, D, 0) :- coin(F, H ,D), T is 1 - H. + +q :- flip(fair,1,X), flip(fair,2,Y),flip(b1,1,Z), (X+Y+Z =:= 2;X+Y+Z =:= 1;X+Y+Z =:= 0). + +query(q). diff --git a/probE/c2.pl b/probE/c2.pl index 1a82864..4224bc1 100644 --- a/probE/c2.pl +++ b/probE/c2.pl @@ -1,34 +1,34 @@ -:- use_module(library(lists)). - -dice(f,D) :- between(1,6,D). - -1/6::die(F,D, one); 1/6::die(F,D, two); 1/6::die(F,D, three); -1/6::die(F,D, 4); 1/6::die(F,D, 5); 1/6::die(F,D, 6) :- dice(F,D). - -% -% p(E,C) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), count([X,Y,Z,X1],E,C) . -% -% q :- C = 1 ,p(three,C). -% query(q). -% query(p(three,C)). - -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - - -rolld(X,Y,Z,X1) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1). - -% p(E,C) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1] , countall(L,E,C). - -q(equalAtmost_1_X_3) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1] , countall(L,E,C), ((C >= 1, E = three )) . -q(equalAtmost_1_X_4) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1] , countall(L,E,C), ((C >= 1, E = three )) . - - -query(q(_)). -% query(p(three,)). +:- use_module(library(lists)). + +dice(f,D) :- between(1,6,D). + +1/6::die(F,D, one); 1/6::die(F,D, two); 1/6::die(F,D, three); +1/6::die(F,D, 4); 1/6::die(F,D, 5); 1/6::die(F,D, 6) :- dice(F,D). + +% +% p(E,C) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), count([X,Y,Z,X1],E,C) . +% +% q :- C = 1 ,p(three,C). +% query(q). +% query(p(three,C)). + +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + + +rolld(X,Y,Z,X1) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1). + +% p(E,C) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1] , countall(L,E,C). + +q(equalAtmost_1_X_3) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1] , countall(L,E,C), ((C >= 1, E = three )) . +q(equalAtmost_1_X_4) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1] , countall(L,E,C), ((C >= 1, E = three )) . + + +query(q(_)). +% query(p(three,)). diff --git a/probE/count.pl b/probE/count.pl index acc7d29..41f6b3e 100644 --- a/probE/count.pl +++ b/probE/count.pl @@ -1,68 +1,68 @@ -% Your model here - - -:- use_module(library(lists)). - - -dice(f,probab,D) :- between(1,6,D). -1/6::die(F,D, one); 1/6::die(F,D, two); 1/6::die(F,D, three); -1/6::die(F,D, 4); 1/6::die(F,D, 5); 1/6::die(F,D, 6) :- dice(F,P,D). - -% -% p(E,C) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), count([X,Y,Z,X1],E,C) . -% -% q :- C = 1 ,p(three,C). -% query(q). -% query(p(three,C)). - -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - - -p(M) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), member(M,[X,Y,Z,X1]), count([X,Y,Z,X1],E,C) . -query(p(_)). - -% query(countall([1,2,3,4,5,6,7,7,8,8,8,8,9,gdgh,dsgsgf],X,C)). - - - -% Your model here - - -:- use_module(library(lists)). - - -dice(f,probab,D) :- between(1,6,D). -1/6::die(F,D, one); 1/6::die(F,D, two); 1/6::die(F,D, three); -1/6::die(F,D, 4); 1/6::die(F,D, 5); 1/6::die(F,D, 6) :- dice(F,P,D). - -% -% p(E,C) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), count([X,Y,Z,X1],E,C) . -% -% q :- C = 1 ,p(three,C). -% query(q). -% query(p(three,C)). - -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). -rolld(X,Y,Z,X1) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1). - -cond :- rolld(X,Y,Z,X1) , L = , count(L,4,1). - -evidence( cond,true). -p(M,C) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1], member(M,L), C=1. -query(p(_,_)). - -% query(countall([1,2,3,4,5,6,7,7,8,8,8,8,9,gdgh,dsgsgf],X,C)). +% Your model here + + +:- use_module(library(lists)). + + +dice(f,probab,D) :- between(1,6,D). +1/6::die(F,D, one); 1/6::die(F,D, two); 1/6::die(F,D, three); +1/6::die(F,D, 4); 1/6::die(F,D, 5); 1/6::die(F,D, 6) :- dice(F,P,D). + +% +% p(E,C) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), count([X,Y,Z,X1],E,C) . +% +% q :- C = 1 ,p(three,C). +% query(q). +% query(p(three,C)). + +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + + +p(M) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), member(M,[X,Y,Z,X1]), count([X,Y,Z,X1],E,C) . +query(p(_)). + +% query(countall([1,2,3,4,5,6,7,7,8,8,8,8,9,gdgh,dsgsgf],X,C)). + + + +% Your model here + + +:- use_module(library(lists)). + + +dice(f,probab,D) :- between(1,6,D). +1/6::die(F,D, one); 1/6::die(F,D, two); 1/6::die(F,D, three); +1/6::die(F,D, 4); 1/6::die(F,D, 5); 1/6::die(F,D, 6) :- dice(F,P,D). + +% +% p(E,C) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1), count([X,Y,Z,X1],E,C) . +% +% q :- C = 1 ,p(three,C). +% query(q). +% query(p(three,C)). + +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). +rolld(X,Y,Z,X1) :- die(f,1,X),die(f,2,Y),die(f,3,Z),die(f,1,X1). + +cond :- rolld(X,Y,Z,X1) , L = , count(L,4,1). + +evidence( cond,true). +p(M,C) :- rolld(X,Y,Z,X1) , L = [X,Y,Z,X1], member(M,L), C=1. +query(p(_,_)). + +% query(countall([1,2,3,4,5,6,7,7,8,8,8,8,9,gdgh,dsgsgf],X,C)). diff --git a/probE/problog.pl b/probE/problog.pl index fe6acab..83117ea 100644 --- a/probE/problog.pl +++ b/probE/problog.pl @@ -1,21 +1,21 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). - -dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 3, D). - -alias_Y(Y1, Y2, Y3) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ) . - -q(equalAtmost_2_Y_4) :- alias_Y(Y1, Y2, Y3) , L = [Y1, Y2, Y3], countall(L, E, C) , E = 4 , C =< 2 . - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). + +dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 3, D). + +alias_Y(Y1, Y2, Y3) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ) . + +q(equalAtmost_2_Y_4) :- alias_Y(Y1, Y2, Y3) , L = [Y1, Y2, Y3], countall(L, E, C) , E = 4 , C =< 2 . + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + query(q(_)). \ No newline at end of file diff --git a/probE/probq.pl b/probE/probq.pl index aad573f..7512d49 100644 --- a/probE/probq.pl +++ b/probE/probq.pl @@ -1,54 +1,54 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). -P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). - -dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 3, D). -coin(f, 0.5, 0.5, D ) :- between(1, 4, D). -coin(u, 0.7, 0.029411764705882353, D ) :- between(1, 4, D). - -alias_Y(Y1, Y2, Y3) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ) . -alias_X(X1, X2, X3, X4) :- coin_roll(f, 0.5, 0.5, 1, X1 ), coin_roll(f, 0.5, 0.5, 2, X2 ), coin_roll(f, 0.5, 0.5, 3, X3 ), coin_roll(f, 0.5, 0.5, 4, X4 ) . -alias_T(T1, T2, T3, T4) :- coin_roll(u, 0.7, 0.029411764705882353, 1, T1 ), coin_roll(u, 0.7, 0.029411764705882353, 2, T2 ), coin_roll(u, 0.7, 0.029411764705882353, 3, T3 ), coin_roll(u, 0.7, 0.029411764705882353, 4, T4 ) . - - - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - -query(q(_)). - - -% Your model here -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). -P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). - -dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 3, D). -coin(f, 0.5, 0.5, D ) :- between(1, 4, D). -coin(u, 0.7, 0.029411764705882353, D ) :- between(1, 4, D). - -alias_Y(Y1, Y2, Y3) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ) . -alias_X(X1, X2, X3, X4) :- coin_roll(f, 0.5, 0.5, 1, X1 ), coin_roll(f, 0.5, 0.5, 2, X2 ), coin_roll(f, 0.5, 0.5, 3, X3 ), coin_roll(f, 0.5, 0.5, 4, X4 ) . -alias_T(T1, T2, T3, T4) :- coin_roll(u, 0.7, 0.029411764705882353, 1, T1 ), coin_roll(u, 0.7, 0.029411764705882353, 2, T2 ), coin_roll(u, 0.7, 0.029411764705882353, 3, T3 ), coin_roll(u, 0.7, 0.029411764705882353, 4, T4 ) . - - -q(bdjf) :- alias_Y(Y1,Y2,Y3) , alias_T(T1, T2, T3, T4), L = [Y1,Y2,T1, T2, T3, T4], countall(L,E,C), ((E = 1, C = 2);(E = head, C=3)). - - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -countall(List,X,C) :- - sort(List,List1), - member(X,List1), - count(List,X,C). - -query(q(_)). +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). +P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). + +dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 3, D). +coin(f, 0.5, 0.5, D ) :- between(1, 4, D). +coin(u, 0.7, 0.029411764705882353, D ) :- between(1, 4, D). + +alias_Y(Y1, Y2, Y3) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ) . +alias_X(X1, X2, X3, X4) :- coin_roll(f, 0.5, 0.5, 1, X1 ), coin_roll(f, 0.5, 0.5, 2, X2 ), coin_roll(f, 0.5, 0.5, 3, X3 ), coin_roll(f, 0.5, 0.5, 4, X4 ) . +alias_T(T1, T2, T3, T4) :- coin_roll(u, 0.7, 0.029411764705882353, 1, T1 ), coin_roll(u, 0.7, 0.029411764705882353, 2, T2 ), coin_roll(u, 0.7, 0.029411764705882353, 3, T3 ), coin_roll(u, 0.7, 0.029411764705882353, 4, T4 ) . + + + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + +query(q(_)). + + +% Your model here +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). +P_Coin_head :: coin_roll(L, P_Coin_head, P_Coin_tail, D, head); P_Coin_tail :: coin_roll(L, P_Coin_head, P_Coin_tail, D, tail) :- coin(L, P_Coin_head, P_Coin_tail, D). + +dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 3, D). +coin(f, 0.5, 0.5, D ) :- between(1, 4, D). +coin(u, 0.7, 0.029411764705882353, D ) :- between(1, 4, D). + +alias_Y(Y1, Y2, Y3) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ) . +alias_X(X1, X2, X3, X4) :- coin_roll(f, 0.5, 0.5, 1, X1 ), coin_roll(f, 0.5, 0.5, 2, X2 ), coin_roll(f, 0.5, 0.5, 3, X3 ), coin_roll(f, 0.5, 0.5, 4, X4 ) . +alias_T(T1, T2, T3, T4) :- coin_roll(u, 0.7, 0.029411764705882353, 1, T1 ), coin_roll(u, 0.7, 0.029411764705882353, 2, T2 ), coin_roll(u, 0.7, 0.029411764705882353, 3, T3 ), coin_roll(u, 0.7, 0.029411764705882353, 4, T4 ) . + + +q(bdjf) :- alias_Y(Y1,Y2,Y3) , alias_T(T1, T2, T3, T4), L = [Y1,Y2,T1, T2, T3, T4], countall(L,E,C), ((E = 1, C = 2);(E = head, C=3)). + + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +countall(List,X,C) :- + sort(List,List1), + member(X,List1), + count(List,X,C). + +query(q(_)). diff --git a/probE/probq.pq b/probE/probq.pq index ce75d88..7e11e22 100644 --- a/probE/probq.pq +++ b/probE/probq.pq @@ -1,12 +1,12 @@ -entity dice[O,T,Th,F,Fv,S](O::1;T::2;Th::3;F::4;F::5;S::6) - -Y = dice(0.1666,0.0666,0.0666,0.3666,0.0666,0.2666 | unfair){3}.roll() - -entity coin[H,T](H::head;T::tail) - -X = coin(1/2,0.5 | f ){4}.roll() -T = coin(0.7,1/34 | u ){4}.roll() - -probability( equalAtmost(5,X,tail)) -probability( equalAtmost(5,T,tail)) -probability( equalAll(Y,4)) +entity dice[O,T,Th,F,Fv,S](O::1;T::2;Th::3;F::4;F::5;S::6) + +Y = dice(0.1666,0.0666,0.0666,0.3666,0.0666,0.2666 | unfair){3}.roll() + +entity coin[H,T](H::head;T::tail) + +X = coin(1/2,0.5 | f ){4}.roll() +T = coin(0.7,1/34 | u ){4}.roll() + +probability( equalAtmost(5,X,tail)) +probability( equalAtmost(5,T,tail)) +probability( equalAll(Y,4)) diff --git a/probE/sum.pq b/probE/sum.pq new file mode 100644 index 0000000..e5395b7 --- /dev/null +++ b/probE/sum.pq @@ -0,0 +1,5 @@ +entity coin(1;0) +X = coin(0.6,0.4){1}.roll() +Y = coin(0.6,0.4){1}.roll() +Z = coin(0.6,0.4){1}.roll() +probability(sum(X|Y|Z,0)) \ No newline at end of file diff --git a/probE/test.pl b/probE/test.pl index 4a58771..44c80b7 100644 --- a/probE/test.pl +++ b/probE/test.pl @@ -1,8 +1,8 @@ -P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). -dice(fair, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, D ) :- between(1, 2, D). -alias_X(X1, X2) :- dice_roll(fair, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 1, X1 ), dice_roll(fair, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 2, X2 ) . -dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 16, D). -alias_Y(Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 4, Y4 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 5, Y5 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 6, Y6 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 7, Y7 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 8, Y8 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 9, Y9 ). - -q :- alias_X(X1, X2),alias_Y(Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9), X1 - X2 =:= 2, Y1 =:= 5 . -query(q). +P_Dice_1 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 1); P_Dice_2 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 2); P_Dice_3 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 3); P_Dice_4 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 4); P_Dice_5 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 5); P_Dice_6 :: dice_roll(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D, 6) :- dice(L, P_Dice_1, P_Dice_2, P_Dice_3, P_Dice_4, P_Dice_5, P_Dice_6, D). +dice(fair, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, D ) :- between(1, 2, D). +alias_X(X1, X2) :- dice_roll(fair, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 1, X1 ), dice_roll(fair, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 2, X2 ) . +dice(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, D ) :- between(1, 16, D). +alias_Y(Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9) :- dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 1, Y1 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 2, Y2 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 3, Y3 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 4, Y4 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 5, Y5 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 6, Y6 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 7, Y7 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 8, Y8 ), dice_roll(unfair, 0.1666, 0.0666, 0.0666, 0.3666, 0.0666, 0.2666, 9, Y9 ). + +q :- alias_X(X1, X2),alias_Y(Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9), X1 - X2 =:= 2, Y1 =:= 5 . +query(q). diff --git a/probQlexer/__pycache__/__init__.cpython-36.pyc b/probQlexer/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..63ac197 Binary files /dev/null and b/probQlexer/__pycache__/__init__.cpython-36.pyc differ diff --git a/probQlexer/__pycache__/lexer.cpython-36.pyc b/probQlexer/__pycache__/lexer.cpython-36.pyc new file mode 100644 index 0000000..478e3d9 Binary files /dev/null and b/probQlexer/__pycache__/lexer.cpython-36.pyc differ diff --git a/probQlexer/lexer.py b/probQlexer/lexer.py index 839bb66..fb37828 100644 --- a/probQlexer/lexer.py +++ b/probQlexer/lexer.py @@ -1,150 +1,186 @@ -import ply.lex as lex - - -# List of token names. -tokens = [ - 'IDEN', - 'ALIAS', - 'COMMENT', - 'ASSIGNMENT', - 'COMMA', - 'DOT', - 'SEMICOLON', - 'COLON', - 'BAR', - 'DOUBLECOLON', - 'LEFTSQRBRACKET', - 'RIGHTSQRBRACKET', - 'LEFTSMALLBRACKET', - 'RIGHTSMALLBRACKET', - 'LEFTCURLYBRACE', - 'RIGHTCURLYBRACE', - - 'NUMBER', - 'EQUAL', - 'NOTEQUAL', - 'GREATEREQUAL', - 'GREATER', - 'LESSEQUAL', - 'LESS', - - 'FRACTION', - 'FLOAT', - 'PLUS', - 'MINUS', - 'TIMES', - 'DIVIDE' -] - -# reserved words. -reserved = { - 'bucket':'BUCKET', - 'entity' : 'ENTITY', - 'roll' : 'ROLL', - 'flag': 'FLAG', - 'pick' : 'PICK', - 'probability' : 'QUERY', - 'evidence' : 'EVIDENCE', - 'equalAtmost' : 'EQUALATMOST', - 'equalAtleast' : 'EQUALATLEAST', - 'equalFew' : 'EQUALFEW', - 'equalAll' : 'EQUALALL', - 'equalAny' : 'EQUALANY', - 'and' : 'AND', - 'or' : 'OR', - 'not' : 'NOT' -} - -tokens = tokens + list(reserved.values()) - - -# Regular expression rules for simple tokens -t_ASSIGNMENT = r'=' -t_COMMA = r',' -t_DOT = r'\.' -t_SEMICOLON = r';' -t_DOUBLECOLON = r'::' -t_COLON = r':' -t_BAR = r'\|' -t_LEFTSQRBRACKET = r'\[' -t_RIGHTSQRBRACKET = r'\]' -t_LEFTSMALLBRACKET = r'\(' -t_RIGHTSMALLBRACKET = r'\)' -t_LEFTCURLYBRACE = r'\{' -t_RIGHTCURLYBRACE = r'\}' - - -t_NOTEQUAL = r'!=' -t_EQUAL = r'==' -t_GREATEREQUAL = r'>=' -t_GREATER = r'>' -t_LESSEQUAL = r'<=' -t_LESS = r'<' - - -t_PLUS = r'\+' -t_MINUS = r'\-' -t_TIMES = r'\*' -t_DIVIDE = r'\/' -# A regular expression rule with some action code -# Note addition of self parameter since we're in a class - -def t_FLOAT(t): - r'(-)?(\d+\.\d+)' - return t - -def t_FRACTION(t): - r'[1-9][0-9]*\/[1-9][0-9]*' - t.type = 'FLOAT' - f = str(t.value) - num,den = f.split( '/' ) - result = int(num)/float(den) - t.value = str(result) - return t - -def t_NUMBER(t): - r'\d+' - t.value = int(t.value) - return t - -def t_IDEN(t): - r'[a-z]([a-zA-Z_0-9áéíóúñÁÉÍÓÚÑ]*[áéíóúñÁÉÍÓÚÑa-zA-Z])?' - t.type = reserved.get(t.value,'IDEN') - return t - -def t_ALIAS(t): - r'[A-Z]([a-zA-Z_0-9áéíóúñÁÉÍÓÚÑ]*[áéíóúñÁÉÍÓÚÑa-zA-Z])?' - t.type = reserved.get(t.value,'ALIAS') - return t - - -# comment -def t_COMMENT(t): - r'\#.*' - pass - -# Define a rule so we can track line numbers -def t_newline(t): - r'\n+' - t.lexer.lineno += len(t.value) - -# A string containing ignored characters (spaces and tabs) -t_ignore = ' \t' - -# Error handling rule -def t_error(t): - print("Illegal character '%s'" % t.value[0]) - t.lexer.skip(1) - -# Test it output -def test(data): - lex.input(data) - while True: - tok = lex.token() - if not tok: - break - print(tok.type + ' => \' ' + str(tok.value) + ' \'') - - -# Build the lexer -lexer = lex.lex(debug = 0) +import ply.lex as lex + + +# List of token names. +tokens = [ + 'IDEN', + 'ALIAS', + 'E_ACTION', + 'B_ACTION', + 'COMMENT', + 'ASSIGNMENT', + 'COMMA', + 'DOT', + 'SEMICOLON', + 'COLON', + 'BAR', + 'DOUBLECOLON', + 'LEFTSQRBRACKET', + 'RIGHTSQRBRACKET', + 'LEFTSMALLBRACKET', + 'RIGHTSMALLBRACKET', + 'LEFTCURLYBRACE', + 'RIGHTCURLYBRACE', + + 'NUMBER', + 'EQUAL', + 'NOTEQUAL', + 'GREATEREQUAL', + 'GREATER', + 'LESSEQUAL', + 'LESS', + + 'SUM', + 'SUMATMOST', + 'SUMATLEAST', + + 'MOD', + 'MODATMOST', + 'MODATLEAST', + + 'FRACTION', + 'FLOAT', + 'PLUS', + 'MINUS', + 'TIMES', + 'DIVIDE' +] + +# reserved words. +reserved = { + 'bucket':'BUCKET', + 'entity' : 'ENTITY', + 'roll' : 'ROLL', + 'flag': 'FLAG', + 'action' : 'ACTION', + 'pick' : 'PICK', + 'probability' : 'QUERY', + 'evidence' : 'EVIDENCE', + 'equal' : 'EQUAL', + 'equalAtmost' : 'EQUALATMOST', + 'equalAtleast' : 'EQUALATLEAST', + 'equalFew' : 'EQUALFEW', + 'equalAll' : 'EQUALALL', + 'equalAny' : 'EQUALANY', + 'sum' : 'SUM', + 'sumAtMost' : 'SUMATMOST', + 'sumAtLeast' : 'SUMATLEAST', + 'mod' : 'MOD', + 'modAtMost' : 'MODATMOST', + 'modAtLeast' : 'MODATLEAST', + 'and' : 'AND', + 'or' : 'OR', + 'not' : 'NOT', + 'odd' : 'ODD', + 'even' : 'EVEN' +} + +tokens = tokens + list(reserved.values()) + + +# Regular expression rules for simple tokens +t_ASSIGNMENT = r'=' +t_COMMA = r',' +t_DOT = r'\.' +t_SEMICOLON = r';' +t_DOUBLECOLON = r'::' +t_COLON = r':' +t_BAR = r'\|' +t_LEFTSQRBRACKET = r'\[' +t_RIGHTSQRBRACKET = r'\]' +t_LEFTSMALLBRACKET = r'\(' +t_RIGHTSMALLBRACKET = r'\)' +t_LEFTCURLYBRACE = r'\{' +t_RIGHTCURLYBRACE = r'\}' + + +t_NOTEQUAL = r'!=' +t_EQUAL = r'==' +t_GREATEREQUAL = r'>=' +t_GREATER = r'>' +t_LESSEQUAL = r'<=' +t_LESS = r'<' + + +t_PLUS = r'\+' +t_MINUS = r'\-' +t_TIMES = r'\*' +t_DIVIDE = r'\/' +# A regular expression rule with some action code +# Note addition of self parameter since we're in a class + +def t_FLOAT(t): + r'(-)?(\d+\.\d+)' + return t + +def t_FRACTION(t): + r'[1-9][0-9]*\/[1-9][0-9]*' + t.type = 'FLOAT' + f = str(t.value) + num,den = f.split( '/' ) + result = int(num)/float(den) + t.value = str(result) + return t + +def t_NUMBER(t): + r'\d+' + t.value = int(t.value) + return t + +def t_IDEN(t): + r'[a-z]([a-zA-Z_0-9áéíóúñÁÉÍÓÚÑ]*[áéíóúñÁÉÍÓÚÑa-zA-Z])?' + t.type = reserved.get(t.value,'IDEN') + return t + +def t_ALIAS(t): + r'[A-Z]([a-zA-Z_0-9áéíóúñÁÉÍÓÚÑ]*[áéíóúñÁÉÍÓÚÑa-zA-Z])?' + t.type = reserved.get(t.value,'ALIAS') + return t + + +# comment +def t_COMMENT(t): + r'\#.*' + pass + +# Define a rule so we can track line numbers +def t_newline(t): + r'\n+' + t.lexer.lineno += len(t.value) + +# A string containing ignored characters (spaces and tabs) +t_ignore = ' \t' + +# Error handling rule +def t_error(t): + print("Illegal character '%s'" % t.value[0]) + t.lexer.skip(1) + +# Test it output +def test(data): + lex.input(data) + while True: + tok = lex.token() + if not tok: + break + print(tok.type + ' => \' ' + str(tok.value) + ' \'') + + +# Build the lexer +lex.lex(debug = 0) +#for testing purpose +""" +source = ''' +bucket pocket( coin{2},coin(0.6){1} ) + +X = pocket.pick(1) + +Y = X.flip() + +evidence( Y.equal(head) ) + +Probability ( equal(X, coin(0.6) ) +''' + +#test(source) +""" \ No newline at end of file diff --git a/probQparser/__pycache__/__init__.cpython-36.pyc b/probQparser/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..1fc6a40 Binary files /dev/null and b/probQparser/__pycache__/__init__.cpython-36.pyc differ diff --git a/probQparser/__pycache__/parser.cpython-36.pyc b/probQparser/__pycache__/parser.cpython-36.pyc new file mode 100644 index 0000000..1a55909 Binary files /dev/null and b/probQparser/__pycache__/parser.cpython-36.pyc differ diff --git a/probQparser/__pycache__/parsetab.cpython-36.pyc b/probQparser/__pycache__/parsetab.cpython-36.pyc new file mode 100644 index 0000000..d053f3b Binary files /dev/null and b/probQparser/__pycache__/parsetab.cpython-36.pyc differ diff --git a/probQparser/parser.out b/probQparser/parser.out new file mode 100644 index 0000000..701a072 --- /dev/null +++ b/probQparser/parser.out @@ -0,0 +1,2394 @@ +Created by PLY version 3.10 (http://www.dabeaz.com/ply) + +Unused terminals: + + E_ACTION + B_ACTION + COMMENT + FRACTION + BUCKET + FLAG + ACTION + PICK + EVIDENCE + ODD + EVEN + +Grammar + +Rule 0 S' -> program +Rule 1 program -> program statement +Rule 2 program -> statement +Rule 3 statement -> entity_def +Rule 4 statement -> entity_initialize_wrap +Rule 5 statement -> entity_action +Rule 6 statement -> query_wrap +Rule 7 empty -> +Rule 8 entity_def -> ENTITY IDEN ed_feature +Rule 9 ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET +Rule 10 ed_feature_inner -> entity_prop_prob +Rule 11 entity_prop_prob -> entity_prop_prob SEMICOLON entity_prop_prob_atom +Rule 12 entity_prop_prob -> entity_prop_prob_atom +Rule 13 entity_prop_prob_atom -> IDEN +Rule 14 entity_prop_prob_atom -> NUMBER +Rule 15 entity_prop_prob_atom -> NUMBER DOUBLECOLON IDEN +Rule 16 entity_prop_prob_atom -> NUMBER DOUBLECOLON NUMBER +Rule 17 entity_prop_prob_atom -> FLOAT DOUBLECOLON IDEN +Rule 18 entity_prop_prob_atom -> FLOAT DOUBLECOLON NUMBER +Rule 19 entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize +Rule 20 entity_initialize -> IDEN ei_params ei_number +Rule 21 ei_params -> LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET +Rule 22 ei_params -> empty +Rule 23 float_list -> float_list COMMA FLOAT +Rule 24 float_list -> float_list COMMA NUMBER +Rule 25 float_list -> FLOAT +Rule 26 float_list -> NUMBER +Rule 27 ei_flag_option -> BAR IDEN +Rule 28 ei_flag_option -> empty +Rule 29 ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE +Rule 30 entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET +Rule 31 entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET +Rule 32 option_number -> NUMBER +Rule 33 option_number -> empty +Rule 34 query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET +Rule 35 q_expr -> q_term_list OR q_term +Rule 36 q_expr -> q_term +Rule 37 q_term -> q_factor_list AND q_factor +Rule 38 q_term -> q_factor +Rule 39 q_term_list -> q_term_list OR q_term +Rule 40 q_term_list -> q_term +Rule 41 q_factor -> q_atom +Rule 42 q_factor -> NOT q_factor +Rule 43 q_factor -> LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET +Rule 44 q_factor_list -> q_factor_list AND q_factor +Rule 45 q_factor_list -> q_factor +Rule 46 q_atom -> q_equal_atom_3 +Rule 47 q_atom -> q_equal_atom_2 +Rule 48 q_atom -> q_sum_atom +Rule 49 q_atom -> me_atom +Rule 50 q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET +Rule 51 q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET +Rule 52 q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET +Rule 53 q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET +Rule 54 q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap +Rule 55 q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom +Rule 56 q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET +Rule 57 q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET +Rule 58 q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET +Rule 59 q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET +Rule 60 q_sum -> SUM +Rule 61 q_sum -> SUMATLEAST +Rule 62 q_sum -> SUMATMOST +Rule 63 q_iden_3 -> EQUALATMOST +Rule 64 q_iden_3 -> EQUALATLEAST +Rule 65 q_iden_3 -> EQUALFEW +Rule 66 q_iden_2 -> EQUALALL +Rule 67 q_iden_2 -> EQUALANY +Rule 68 q_alias_concat_wrap -> alias_slice +Rule 69 q_alias_concat_wrap -> LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET +Rule 70 q_alias_concat -> q_alias_concat BAR alias_slice +Rule 71 q_alias_concat -> alias_slice +Rule 72 alias_slice -> ALIAS +Rule 73 alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET +Rule 74 me_atom -> a_expression_atom +Rule 75 a_expression_atom -> a_expression EQUAL a_expression +Rule 76 a_expression_atom -> a_expression NOTEQUAL a_expression +Rule 77 a_expression_atom -> a_expression GREATEREQUAL a_expression +Rule 78 a_expression_atom -> a_expression GREATER a_expression +Rule 79 a_expression_atom -> a_expression LESSEQUAL a_expression +Rule 80 a_expression_atom -> a_expression LESS a_expression +Rule 81 a_expression -> a_expression PLUS a_term +Rule 82 a_expression -> a_expression MINUS a_term +Rule 83 a_expression -> a_term +Rule 84 a_term -> a_term TIMES a_factor +Rule 85 a_term -> a_term DIVIDE a_factor +Rule 86 a_term -> a_factor +Rule 87 a_factor -> NUMBER +Rule 88 a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET +Rule 89 a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + +Terminals, with rules where they appear + +ACTION : +ALIAS : 19 30 30 31 56 57 72 73 88 +AND : 37 44 +ASSIGNMENT : 19 30 31 +BAR : 27 53 54 70 +BUCKET : +B_ACTION : +COLON : 57 73 +COMMA : 23 24 50 50 51 51 52 58 59 +COMMENT : +DIVIDE : 85 +DOT : 30 31 +DOUBLECOLON : 15 16 17 18 +ENTITY : 8 +EQUAL : 75 +EQUALALL : 66 +EQUALANY : 67 +EQUALATLEAST : 64 +EQUALATMOST : 63 +EQUALFEW : 65 +EVEN : +EVIDENCE : +E_ACTION : +FLAG : +FLOAT : 17 18 23 25 +FRACTION : +GREATER : 78 +GREATEREQUAL : 77 +IDEN : 8 13 15 17 20 27 50 58 +LEFTCURLYBRACE : 29 +LEFTSMALLBRACKET : 9 21 30 31 34 43 50 51 52 53 58 59 89 +LEFTSQRBRACKET : 56 57 69 73 88 +LESS : 80 +LESSEQUAL : 79 +MINUS : 82 +NOT : 42 +NOTEQUAL : 76 +NUMBER : 14 15 16 16 18 24 26 29 32 50 51 51 52 56 57 57 59 73 73 87 88 +ODD : +OR : 35 39 +PICK : +PLUS : 81 +QUERY : 34 +RIGHTCURLYBRACE : 29 +RIGHTSMALLBRACKET : 9 21 30 31 34 43 50 51 52 53 58 59 89 +RIGHTSQRBRACKET : 56 57 69 73 88 +ROLL : 30 31 +SEMICOLON : 11 +SUM : 60 +SUMATLEAST : 61 +SUMATMOST : 62 +TIMES : 84 +error : + +Nonterminals, with rules where they appear + +a_expression : 75 75 76 76 77 77 78 78 79 79 80 80 81 82 89 +a_expression_atom : 74 +a_factor : 84 85 86 +a_term : 81 82 83 84 85 +alias_slice : 68 70 71 +ed_feature : 8 +ed_feature_inner : 9 +ei_flag_option : 21 +ei_number : 20 +ei_params : 20 +empty : 22 28 33 +entity_action : 5 +entity_def : 3 +entity_initialize : 19 31 +entity_initialize_wrap : 4 +entity_prop_prob : 10 11 +entity_prop_prob_atom : 11 12 +float_list : 21 23 24 +me_atom : 49 +option_number : 30 31 +program : 1 0 +q_alias_concat : 69 70 +q_alias_concat_wrap : 50 51 58 59 +q_alias_sum_concat_wrap : 52 53 54 +q_alias_sum_concat_wrap_atom : 53 54 55 +q_atom : 41 +q_equal_atom_2 : 47 +q_equal_atom_3 : 46 +q_expr : 34 43 +q_factor : 37 38 42 44 45 +q_factor_list : 37 44 +q_iden_2 : 58 59 +q_iden_3 : 50 51 +q_sum : 52 +q_sum_atom : 48 +q_term : 35 36 39 40 +q_term_list : 35 39 +query_wrap : 6 +statement : 1 2 + +Parsing method: LALR + +state 0 + + (0) S' -> . program + (1) program -> . program statement + (2) program -> . statement + (3) statement -> . entity_def + (4) statement -> . entity_initialize_wrap + (5) statement -> . entity_action + (6) statement -> . query_wrap + (8) entity_def -> . ENTITY IDEN ed_feature + (19) entity_initialize_wrap -> . ALIAS ASSIGNMENT entity_initialize + (30) entity_action -> . ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + (31) entity_action -> . ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + (34) query_wrap -> . QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + + ENTITY shift and go to state 7 + ALIAS shift and go to state 8 + QUERY shift and go to state 9 + + program shift and go to state 1 + statement shift and go to state 2 + entity_def shift and go to state 3 + entity_initialize_wrap shift and go to state 4 + entity_action shift and go to state 5 + query_wrap shift and go to state 6 + +state 1 + + (0) S' -> program . + (1) program -> program . statement + (3) statement -> . entity_def + (4) statement -> . entity_initialize_wrap + (5) statement -> . entity_action + (6) statement -> . query_wrap + (8) entity_def -> . ENTITY IDEN ed_feature + (19) entity_initialize_wrap -> . ALIAS ASSIGNMENT entity_initialize + (30) entity_action -> . ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + (31) entity_action -> . ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + (34) query_wrap -> . QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + + ENTITY shift and go to state 7 + ALIAS shift and go to state 8 + QUERY shift and go to state 9 + + statement shift and go to state 10 + entity_def shift and go to state 3 + entity_initialize_wrap shift and go to state 4 + entity_action shift and go to state 5 + query_wrap shift and go to state 6 + +state 2 + + (2) program -> statement . + + ENTITY reduce using rule 2 (program -> statement .) + ALIAS reduce using rule 2 (program -> statement .) + QUERY reduce using rule 2 (program -> statement .) + $end reduce using rule 2 (program -> statement .) + + +state 3 + + (3) statement -> entity_def . + + ENTITY reduce using rule 3 (statement -> entity_def .) + ALIAS reduce using rule 3 (statement -> entity_def .) + QUERY reduce using rule 3 (statement -> entity_def .) + $end reduce using rule 3 (statement -> entity_def .) + + +state 4 + + (4) statement -> entity_initialize_wrap . + + ENTITY reduce using rule 4 (statement -> entity_initialize_wrap .) + ALIAS reduce using rule 4 (statement -> entity_initialize_wrap .) + QUERY reduce using rule 4 (statement -> entity_initialize_wrap .) + $end reduce using rule 4 (statement -> entity_initialize_wrap .) + + +state 5 + + (5) statement -> entity_action . + + ENTITY reduce using rule 5 (statement -> entity_action .) + ALIAS reduce using rule 5 (statement -> entity_action .) + QUERY reduce using rule 5 (statement -> entity_action .) + $end reduce using rule 5 (statement -> entity_action .) + + +state 6 + + (6) statement -> query_wrap . + + ENTITY reduce using rule 6 (statement -> query_wrap .) + ALIAS reduce using rule 6 (statement -> query_wrap .) + QUERY reduce using rule 6 (statement -> query_wrap .) + $end reduce using rule 6 (statement -> query_wrap .) + + +state 7 + + (8) entity_def -> ENTITY . IDEN ed_feature + + IDEN shift and go to state 11 + + +state 8 + + (19) entity_initialize_wrap -> ALIAS . ASSIGNMENT entity_initialize + (30) entity_action -> ALIAS . ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + (31) entity_action -> ALIAS . ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + ASSIGNMENT shift and go to state 12 + + +state 9 + + (34) query_wrap -> QUERY . LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + + LEFTSMALLBRACKET shift and go to state 13 + + +state 10 + + (1) program -> program statement . + + ENTITY reduce using rule 1 (program -> program statement .) + ALIAS reduce using rule 1 (program -> program statement .) + QUERY reduce using rule 1 (program -> program statement .) + $end reduce using rule 1 (program -> program statement .) + + +state 11 + + (8) entity_def -> ENTITY IDEN . ed_feature + (9) ed_feature -> . LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET + + LEFTSMALLBRACKET shift and go to state 15 + + ed_feature shift and go to state 14 + +state 12 + + (19) entity_initialize_wrap -> ALIAS ASSIGNMENT . entity_initialize + (30) entity_action -> ALIAS ASSIGNMENT . ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + (31) entity_action -> ALIAS ASSIGNMENT . entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + (20) entity_initialize -> . IDEN ei_params ei_number + + ALIAS shift and go to state 16 + IDEN shift and go to state 18 + + entity_initialize shift and go to state 17 + +state 13 + + (34) query_wrap -> QUERY LEFTSMALLBRACKET . q_expr RIGHTSMALLBRACKET + (35) q_expr -> . q_term_list OR q_term + (36) q_expr -> . q_term + (39) q_term_list -> . q_term_list OR q_term + (40) q_term_list -> . q_term + (37) q_term -> . q_factor_list AND q_factor + (38) q_term -> . q_factor + (44) q_factor_list -> . q_factor_list AND q_factor + (45) q_factor_list -> . q_factor + (41) q_factor -> . q_atom + (42) q_factor -> . NOT q_factor + (43) q_factor -> . LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + (46) q_atom -> . q_equal_atom_3 + (47) q_atom -> . q_equal_atom_2 + (48) q_atom -> . q_sum_atom + (49) q_atom -> . me_atom + (50) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (58) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (52) q_sum_atom -> . q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (74) me_atom -> . a_expression_atom + (63) q_iden_3 -> . EQUALATMOST + (64) q_iden_3 -> . EQUALATLEAST + (65) q_iden_3 -> . EQUALFEW + (66) q_iden_2 -> . EQUALALL + (67) q_iden_2 -> . EQUALANY + (60) q_sum -> . SUM + (61) q_sum -> . SUMATLEAST + (62) q_sum -> . SUMATMOST + (75) a_expression_atom -> . a_expression EQUAL a_expression + (76) a_expression_atom -> . a_expression NOTEQUAL a_expression + (77) a_expression_atom -> . a_expression GREATEREQUAL a_expression + (78) a_expression_atom -> . a_expression GREATER a_expression + (79) a_expression_atom -> . a_expression LESSEQUAL a_expression + (80) a_expression_atom -> . a_expression LESS a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NOT shift and go to state 26 + LEFTSMALLBRACKET shift and go to state 19 + EQUALATMOST shift and go to state 36 + EQUALATLEAST shift and go to state 37 + EQUALFEW shift and go to state 38 + EQUALALL shift and go to state 39 + EQUALANY shift and go to state 40 + SUM shift and go to state 41 + SUMATLEAST shift and go to state 42 + SUMATMOST shift and go to state 43 + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + + q_expr shift and go to state 20 + q_term_list shift and go to state 21 + q_term shift and go to state 22 + q_factor_list shift and go to state 23 + q_factor shift and go to state 24 + q_atom shift and go to state 25 + q_equal_atom_3 shift and go to state 27 + q_equal_atom_2 shift and go to state 28 + q_sum_atom shift and go to state 29 + me_atom shift and go to state 30 + q_iden_3 shift and go to state 31 + q_iden_2 shift and go to state 33 + q_sum shift and go to state 34 + a_expression_atom shift and go to state 35 + a_expression shift and go to state 44 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 14 + + (8) entity_def -> ENTITY IDEN ed_feature . + + ENTITY reduce using rule 8 (entity_def -> ENTITY IDEN ed_feature .) + ALIAS reduce using rule 8 (entity_def -> ENTITY IDEN ed_feature .) + QUERY reduce using rule 8 (entity_def -> ENTITY IDEN ed_feature .) + $end reduce using rule 8 (entity_def -> ENTITY IDEN ed_feature .) + + +state 15 + + (9) ed_feature -> LEFTSMALLBRACKET . ed_feature_inner RIGHTSMALLBRACKET + (10) ed_feature_inner -> . entity_prop_prob + (11) entity_prop_prob -> . entity_prop_prob SEMICOLON entity_prop_prob_atom + (12) entity_prop_prob -> . entity_prop_prob_atom + (13) entity_prop_prob_atom -> . IDEN + (14) entity_prop_prob_atom -> . NUMBER + (15) entity_prop_prob_atom -> . NUMBER DOUBLECOLON IDEN + (16) entity_prop_prob_atom -> . NUMBER DOUBLECOLON NUMBER + (17) entity_prop_prob_atom -> . FLOAT DOUBLECOLON IDEN + (18) entity_prop_prob_atom -> . FLOAT DOUBLECOLON NUMBER + + IDEN shift and go to state 51 + NUMBER shift and go to state 52 + FLOAT shift and go to state 53 + + ed_feature_inner shift and go to state 48 + entity_prop_prob shift and go to state 49 + entity_prop_prob_atom shift and go to state 50 + +state 16 + + (30) entity_action -> ALIAS ASSIGNMENT ALIAS . DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + DOT shift and go to state 54 + + +state 17 + + (19) entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize . + (31) entity_action -> ALIAS ASSIGNMENT entity_initialize . DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + ENTITY reduce using rule 19 (entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize .) + ALIAS reduce using rule 19 (entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize .) + QUERY reduce using rule 19 (entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize .) + $end reduce using rule 19 (entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize .) + DOT shift and go to state 55 + + +state 18 + + (20) entity_initialize -> IDEN . ei_params ei_number + (21) ei_params -> . LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET + (22) ei_params -> . empty + (7) empty -> . + + LEFTSMALLBRACKET shift and go to state 57 + LEFTCURLYBRACE reduce using rule 7 (empty -> .) + + ei_params shift and go to state 56 + empty shift and go to state 58 + +state 19 + + (43) q_factor -> LEFTSMALLBRACKET . q_expr RIGHTSMALLBRACKET + (89) a_factor -> LEFTSMALLBRACKET . a_expression RIGHTSMALLBRACKET + (35) q_expr -> . q_term_list OR q_term + (36) q_expr -> . q_term + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (39) q_term_list -> . q_term_list OR q_term + (40) q_term_list -> . q_term + (37) q_term -> . q_factor_list AND q_factor + (38) q_term -> . q_factor + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (44) q_factor_list -> . q_factor_list AND q_factor + (45) q_factor_list -> . q_factor + (41) q_factor -> . q_atom + (42) q_factor -> . NOT q_factor + (43) q_factor -> . LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + (46) q_atom -> . q_equal_atom_3 + (47) q_atom -> . q_equal_atom_2 + (48) q_atom -> . q_sum_atom + (49) q_atom -> . me_atom + (50) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (58) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (52) q_sum_atom -> . q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (74) me_atom -> . a_expression_atom + (63) q_iden_3 -> . EQUALATMOST + (64) q_iden_3 -> . EQUALATLEAST + (65) q_iden_3 -> . EQUALFEW + (66) q_iden_2 -> . EQUALALL + (67) q_iden_2 -> . EQUALANY + (60) q_sum -> . SUM + (61) q_sum -> . SUMATLEAST + (62) q_sum -> . SUMATMOST + (75) a_expression_atom -> . a_expression EQUAL a_expression + (76) a_expression_atom -> . a_expression NOTEQUAL a_expression + (77) a_expression_atom -> . a_expression GREATEREQUAL a_expression + (78) a_expression_atom -> . a_expression GREATER a_expression + (79) a_expression_atom -> . a_expression LESSEQUAL a_expression + (80) a_expression_atom -> . a_expression LESS a_expression + + NOT shift and go to state 26 + LEFTSMALLBRACKET shift and go to state 19 + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + EQUALATMOST shift and go to state 36 + EQUALATLEAST shift and go to state 37 + EQUALFEW shift and go to state 38 + EQUALALL shift and go to state 39 + EQUALANY shift and go to state 40 + SUM shift and go to state 41 + SUMATLEAST shift and go to state 42 + SUMATMOST shift and go to state 43 + + q_expr shift and go to state 59 + a_expression shift and go to state 60 + q_term_list shift and go to state 21 + q_term shift and go to state 22 + a_term shift and go to state 45 + q_factor_list shift and go to state 23 + q_factor shift and go to state 24 + a_factor shift and go to state 46 + q_atom shift and go to state 25 + q_equal_atom_3 shift and go to state 27 + q_equal_atom_2 shift and go to state 28 + q_sum_atom shift and go to state 29 + me_atom shift and go to state 30 + q_iden_3 shift and go to state 31 + q_iden_2 shift and go to state 33 + q_sum shift and go to state 34 + a_expression_atom shift and go to state 35 + +state 20 + + (34) query_wrap -> QUERY LEFTSMALLBRACKET q_expr . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 61 + + +state 21 + + (35) q_expr -> q_term_list . OR q_term + (39) q_term_list -> q_term_list . OR q_term + + OR shift and go to state 62 + + +state 22 + + (36) q_expr -> q_term . + (40) q_term_list -> q_term . + + RIGHTSMALLBRACKET reduce using rule 36 (q_expr -> q_term .) + OR reduce using rule 40 (q_term_list -> q_term .) + + +state 23 + + (37) q_term -> q_factor_list . AND q_factor + (44) q_factor_list -> q_factor_list . AND q_factor + + AND shift and go to state 63 + + +state 24 + + (38) q_term -> q_factor . + (45) q_factor_list -> q_factor . + + RIGHTSMALLBRACKET reduce using rule 38 (q_term -> q_factor .) + OR reduce using rule 38 (q_term -> q_factor .) + AND reduce using rule 45 (q_factor_list -> q_factor .) + + +state 25 + + (41) q_factor -> q_atom . + + RIGHTSMALLBRACKET reduce using rule 41 (q_factor -> q_atom .) + OR reduce using rule 41 (q_factor -> q_atom .) + AND reduce using rule 41 (q_factor -> q_atom .) + + +state 26 + + (42) q_factor -> NOT . q_factor + (41) q_factor -> . q_atom + (42) q_factor -> . NOT q_factor + (43) q_factor -> . LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + (46) q_atom -> . q_equal_atom_3 + (47) q_atom -> . q_equal_atom_2 + (48) q_atom -> . q_sum_atom + (49) q_atom -> . me_atom + (50) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (58) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (52) q_sum_atom -> . q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (74) me_atom -> . a_expression_atom + (63) q_iden_3 -> . EQUALATMOST + (64) q_iden_3 -> . EQUALATLEAST + (65) q_iden_3 -> . EQUALFEW + (66) q_iden_2 -> . EQUALALL + (67) q_iden_2 -> . EQUALANY + (60) q_sum -> . SUM + (61) q_sum -> . SUMATLEAST + (62) q_sum -> . SUMATMOST + (75) a_expression_atom -> . a_expression EQUAL a_expression + (76) a_expression_atom -> . a_expression NOTEQUAL a_expression + (77) a_expression_atom -> . a_expression GREATEREQUAL a_expression + (78) a_expression_atom -> . a_expression GREATER a_expression + (79) a_expression_atom -> . a_expression LESSEQUAL a_expression + (80) a_expression_atom -> . a_expression LESS a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NOT shift and go to state 26 + LEFTSMALLBRACKET shift and go to state 19 + EQUALATMOST shift and go to state 36 + EQUALATLEAST shift and go to state 37 + EQUALFEW shift and go to state 38 + EQUALALL shift and go to state 39 + EQUALANY shift and go to state 40 + SUM shift and go to state 41 + SUMATLEAST shift and go to state 42 + SUMATMOST shift and go to state 43 + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + + q_factor shift and go to state 64 + q_atom shift and go to state 25 + q_equal_atom_3 shift and go to state 27 + q_equal_atom_2 shift and go to state 28 + q_sum_atom shift and go to state 29 + me_atom shift and go to state 30 + q_iden_3 shift and go to state 31 + q_iden_2 shift and go to state 33 + q_sum shift and go to state 34 + a_expression_atom shift and go to state 35 + a_expression shift and go to state 44 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 27 + + (46) q_atom -> q_equal_atom_3 . + + RIGHTSMALLBRACKET reduce using rule 46 (q_atom -> q_equal_atom_3 .) + OR reduce using rule 46 (q_atom -> q_equal_atom_3 .) + AND reduce using rule 46 (q_atom -> q_equal_atom_3 .) + + +state 28 + + (47) q_atom -> q_equal_atom_2 . + + RIGHTSMALLBRACKET reduce using rule 47 (q_atom -> q_equal_atom_2 .) + OR reduce using rule 47 (q_atom -> q_equal_atom_2 .) + AND reduce using rule 47 (q_atom -> q_equal_atom_2 .) + + +state 29 + + (48) q_atom -> q_sum_atom . + + RIGHTSMALLBRACKET reduce using rule 48 (q_atom -> q_sum_atom .) + OR reduce using rule 48 (q_atom -> q_sum_atom .) + AND reduce using rule 48 (q_atom -> q_sum_atom .) + + +state 30 + + (49) q_atom -> me_atom . + + RIGHTSMALLBRACKET reduce using rule 49 (q_atom -> me_atom .) + OR reduce using rule 49 (q_atom -> me_atom .) + AND reduce using rule 49 (q_atom -> me_atom .) + + +state 31 + + (50) q_equal_atom_3 -> q_iden_3 . LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> q_iden_3 . LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + + LEFTSMALLBRACKET shift and go to state 65 + + +state 32 + + (87) a_factor -> NUMBER . + + TIMES reduce using rule 87 (a_factor -> NUMBER .) + DIVIDE reduce using rule 87 (a_factor -> NUMBER .) + EQUAL reduce using rule 87 (a_factor -> NUMBER .) + NOTEQUAL reduce using rule 87 (a_factor -> NUMBER .) + GREATEREQUAL reduce using rule 87 (a_factor -> NUMBER .) + GREATER reduce using rule 87 (a_factor -> NUMBER .) + LESSEQUAL reduce using rule 87 (a_factor -> NUMBER .) + LESS reduce using rule 87 (a_factor -> NUMBER .) + PLUS reduce using rule 87 (a_factor -> NUMBER .) + MINUS reduce using rule 87 (a_factor -> NUMBER .) + RIGHTSMALLBRACKET reduce using rule 87 (a_factor -> NUMBER .) + OR reduce using rule 87 (a_factor -> NUMBER .) + AND reduce using rule 87 (a_factor -> NUMBER .) + + +state 33 + + (58) q_equal_atom_2 -> q_iden_2 . LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> q_iden_2 . LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + + LEFTSMALLBRACKET shift and go to state 66 + + +state 34 + + (52) q_sum_atom -> q_sum . LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + + LEFTSMALLBRACKET shift and go to state 67 + + +state 35 + + (74) me_atom -> a_expression_atom . + + RIGHTSMALLBRACKET reduce using rule 74 (me_atom -> a_expression_atom .) + OR reduce using rule 74 (me_atom -> a_expression_atom .) + AND reduce using rule 74 (me_atom -> a_expression_atom .) + + +state 36 + + (63) q_iden_3 -> EQUALATMOST . + + LEFTSMALLBRACKET reduce using rule 63 (q_iden_3 -> EQUALATMOST .) + + +state 37 + + (64) q_iden_3 -> EQUALATLEAST . + + LEFTSMALLBRACKET reduce using rule 64 (q_iden_3 -> EQUALATLEAST .) + + +state 38 + + (65) q_iden_3 -> EQUALFEW . + + LEFTSMALLBRACKET reduce using rule 65 (q_iden_3 -> EQUALFEW .) + + +state 39 + + (66) q_iden_2 -> EQUALALL . + + LEFTSMALLBRACKET reduce using rule 66 (q_iden_2 -> EQUALALL .) + + +state 40 + + (67) q_iden_2 -> EQUALANY . + + LEFTSMALLBRACKET reduce using rule 67 (q_iden_2 -> EQUALANY .) + + +state 41 + + (60) q_sum -> SUM . + + LEFTSMALLBRACKET reduce using rule 60 (q_sum -> SUM .) + + +state 42 + + (61) q_sum -> SUMATLEAST . + + LEFTSMALLBRACKET reduce using rule 61 (q_sum -> SUMATLEAST .) + + +state 43 + + (62) q_sum -> SUMATMOST . + + LEFTSMALLBRACKET reduce using rule 62 (q_sum -> SUMATMOST .) + + +state 44 + + (75) a_expression_atom -> a_expression . EQUAL a_expression + (76) a_expression_atom -> a_expression . NOTEQUAL a_expression + (77) a_expression_atom -> a_expression . GREATEREQUAL a_expression + (78) a_expression_atom -> a_expression . GREATER a_expression + (79) a_expression_atom -> a_expression . LESSEQUAL a_expression + (80) a_expression_atom -> a_expression . LESS a_expression + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + EQUAL shift and go to state 68 + NOTEQUAL shift and go to state 69 + GREATEREQUAL shift and go to state 70 + GREATER shift and go to state 71 + LESSEQUAL shift and go to state 72 + LESS shift and go to state 73 + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 45 + + (83) a_expression -> a_term . + (84) a_term -> a_term . TIMES a_factor + (85) a_term -> a_term . DIVIDE a_factor + + EQUAL reduce using rule 83 (a_expression -> a_term .) + NOTEQUAL reduce using rule 83 (a_expression -> a_term .) + GREATEREQUAL reduce using rule 83 (a_expression -> a_term .) + GREATER reduce using rule 83 (a_expression -> a_term .) + LESSEQUAL reduce using rule 83 (a_expression -> a_term .) + LESS reduce using rule 83 (a_expression -> a_term .) + PLUS reduce using rule 83 (a_expression -> a_term .) + MINUS reduce using rule 83 (a_expression -> a_term .) + RIGHTSMALLBRACKET reduce using rule 83 (a_expression -> a_term .) + OR reduce using rule 83 (a_expression -> a_term .) + AND reduce using rule 83 (a_expression -> a_term .) + TIMES shift and go to state 76 + DIVIDE shift and go to state 77 + + +state 46 + + (86) a_term -> a_factor . + + TIMES reduce using rule 86 (a_term -> a_factor .) + DIVIDE reduce using rule 86 (a_term -> a_factor .) + EQUAL reduce using rule 86 (a_term -> a_factor .) + NOTEQUAL reduce using rule 86 (a_term -> a_factor .) + GREATEREQUAL reduce using rule 86 (a_term -> a_factor .) + GREATER reduce using rule 86 (a_term -> a_factor .) + LESSEQUAL reduce using rule 86 (a_term -> a_factor .) + LESS reduce using rule 86 (a_term -> a_factor .) + PLUS reduce using rule 86 (a_term -> a_factor .) + MINUS reduce using rule 86 (a_term -> a_factor .) + RIGHTSMALLBRACKET reduce using rule 86 (a_term -> a_factor .) + OR reduce using rule 86 (a_term -> a_factor .) + AND reduce using rule 86 (a_term -> a_factor .) + + +state 47 + + (88) a_factor -> ALIAS . LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + + LEFTSQRBRACKET shift and go to state 78 + + +state 48 + + (9) ed_feature -> LEFTSMALLBRACKET ed_feature_inner . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 79 + + +state 49 + + (10) ed_feature_inner -> entity_prop_prob . + (11) entity_prop_prob -> entity_prop_prob . SEMICOLON entity_prop_prob_atom + + RIGHTSMALLBRACKET reduce using rule 10 (ed_feature_inner -> entity_prop_prob .) + SEMICOLON shift and go to state 80 + + +state 50 + + (12) entity_prop_prob -> entity_prop_prob_atom . + + SEMICOLON reduce using rule 12 (entity_prop_prob -> entity_prop_prob_atom .) + RIGHTSMALLBRACKET reduce using rule 12 (entity_prop_prob -> entity_prop_prob_atom .) + + +state 51 + + (13) entity_prop_prob_atom -> IDEN . + + SEMICOLON reduce using rule 13 (entity_prop_prob_atom -> IDEN .) + RIGHTSMALLBRACKET reduce using rule 13 (entity_prop_prob_atom -> IDEN .) + + +state 52 + + (14) entity_prop_prob_atom -> NUMBER . + (15) entity_prop_prob_atom -> NUMBER . DOUBLECOLON IDEN + (16) entity_prop_prob_atom -> NUMBER . DOUBLECOLON NUMBER + + SEMICOLON reduce using rule 14 (entity_prop_prob_atom -> NUMBER .) + RIGHTSMALLBRACKET reduce using rule 14 (entity_prop_prob_atom -> NUMBER .) + DOUBLECOLON shift and go to state 81 + + +state 53 + + (17) entity_prop_prob_atom -> FLOAT . DOUBLECOLON IDEN + (18) entity_prop_prob_atom -> FLOAT . DOUBLECOLON NUMBER + + DOUBLECOLON shift and go to state 82 + + +state 54 + + (30) entity_action -> ALIAS ASSIGNMENT ALIAS DOT . ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + ROLL shift and go to state 83 + + +state 55 + + (31) entity_action -> ALIAS ASSIGNMENT entity_initialize DOT . ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + ROLL shift and go to state 84 + + +state 56 + + (20) entity_initialize -> IDEN ei_params . ei_number + (29) ei_number -> . LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE + + LEFTCURLYBRACE shift and go to state 86 + + ei_number shift and go to state 85 + +state 57 + + (21) ei_params -> LEFTSMALLBRACKET . float_list ei_flag_option RIGHTSMALLBRACKET + (23) float_list -> . float_list COMMA FLOAT + (24) float_list -> . float_list COMMA NUMBER + (25) float_list -> . FLOAT + (26) float_list -> . NUMBER + + FLOAT shift and go to state 88 + NUMBER shift and go to state 89 + + float_list shift and go to state 87 + +state 58 + + (22) ei_params -> empty . + + LEFTCURLYBRACE reduce using rule 22 (ei_params -> empty .) + + +state 59 + + (43) q_factor -> LEFTSMALLBRACKET q_expr . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 90 + + +state 60 + + (89) a_factor -> LEFTSMALLBRACKET a_expression . RIGHTSMALLBRACKET + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + (75) a_expression_atom -> a_expression . EQUAL a_expression + (76) a_expression_atom -> a_expression . NOTEQUAL a_expression + (77) a_expression_atom -> a_expression . GREATEREQUAL a_expression + (78) a_expression_atom -> a_expression . GREATER a_expression + (79) a_expression_atom -> a_expression . LESSEQUAL a_expression + (80) a_expression_atom -> a_expression . LESS a_expression + + RIGHTSMALLBRACKET shift and go to state 91 + PLUS shift and go to state 74 + MINUS shift and go to state 75 + EQUAL shift and go to state 68 + NOTEQUAL shift and go to state 69 + GREATEREQUAL shift and go to state 70 + GREATER shift and go to state 71 + LESSEQUAL shift and go to state 72 + LESS shift and go to state 73 + + +state 61 + + (34) query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET . + + ENTITY reduce using rule 34 (query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET .) + ALIAS reduce using rule 34 (query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET .) + QUERY reduce using rule 34 (query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET .) + $end reduce using rule 34 (query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET .) + + +state 62 + + (35) q_expr -> q_term_list OR . q_term + (39) q_term_list -> q_term_list OR . q_term + (37) q_term -> . q_factor_list AND q_factor + (38) q_term -> . q_factor + (44) q_factor_list -> . q_factor_list AND q_factor + (45) q_factor_list -> . q_factor + (41) q_factor -> . q_atom + (42) q_factor -> . NOT q_factor + (43) q_factor -> . LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + (46) q_atom -> . q_equal_atom_3 + (47) q_atom -> . q_equal_atom_2 + (48) q_atom -> . q_sum_atom + (49) q_atom -> . me_atom + (50) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (58) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (52) q_sum_atom -> . q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (74) me_atom -> . a_expression_atom + (63) q_iden_3 -> . EQUALATMOST + (64) q_iden_3 -> . EQUALATLEAST + (65) q_iden_3 -> . EQUALFEW + (66) q_iden_2 -> . EQUALALL + (67) q_iden_2 -> . EQUALANY + (60) q_sum -> . SUM + (61) q_sum -> . SUMATLEAST + (62) q_sum -> . SUMATMOST + (75) a_expression_atom -> . a_expression EQUAL a_expression + (76) a_expression_atom -> . a_expression NOTEQUAL a_expression + (77) a_expression_atom -> . a_expression GREATEREQUAL a_expression + (78) a_expression_atom -> . a_expression GREATER a_expression + (79) a_expression_atom -> . a_expression LESSEQUAL a_expression + (80) a_expression_atom -> . a_expression LESS a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NOT shift and go to state 26 + LEFTSMALLBRACKET shift and go to state 19 + EQUALATMOST shift and go to state 36 + EQUALATLEAST shift and go to state 37 + EQUALFEW shift and go to state 38 + EQUALALL shift and go to state 39 + EQUALANY shift and go to state 40 + SUM shift and go to state 41 + SUMATLEAST shift and go to state 42 + SUMATMOST shift and go to state 43 + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + + q_term shift and go to state 92 + q_factor_list shift and go to state 23 + q_factor shift and go to state 24 + q_atom shift and go to state 25 + q_equal_atom_3 shift and go to state 27 + q_equal_atom_2 shift and go to state 28 + q_sum_atom shift and go to state 29 + me_atom shift and go to state 30 + q_iden_3 shift and go to state 31 + q_iden_2 shift and go to state 33 + q_sum shift and go to state 34 + a_expression_atom shift and go to state 35 + a_expression shift and go to state 44 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 63 + + (37) q_term -> q_factor_list AND . q_factor + (44) q_factor_list -> q_factor_list AND . q_factor + (41) q_factor -> . q_atom + (42) q_factor -> . NOT q_factor + (43) q_factor -> . LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET + (46) q_atom -> . q_equal_atom_3 + (47) q_atom -> . q_equal_atom_2 + (48) q_atom -> . q_sum_atom + (49) q_atom -> . me_atom + (50) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> . q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (58) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> . q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (52) q_sum_atom -> . q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (74) me_atom -> . a_expression_atom + (63) q_iden_3 -> . EQUALATMOST + (64) q_iden_3 -> . EQUALATLEAST + (65) q_iden_3 -> . EQUALFEW + (66) q_iden_2 -> . EQUALALL + (67) q_iden_2 -> . EQUALANY + (60) q_sum -> . SUM + (61) q_sum -> . SUMATLEAST + (62) q_sum -> . SUMATMOST + (75) a_expression_atom -> . a_expression EQUAL a_expression + (76) a_expression_atom -> . a_expression NOTEQUAL a_expression + (77) a_expression_atom -> . a_expression GREATEREQUAL a_expression + (78) a_expression_atom -> . a_expression GREATER a_expression + (79) a_expression_atom -> . a_expression LESSEQUAL a_expression + (80) a_expression_atom -> . a_expression LESS a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NOT shift and go to state 26 + LEFTSMALLBRACKET shift and go to state 19 + EQUALATMOST shift and go to state 36 + EQUALATLEAST shift and go to state 37 + EQUALFEW shift and go to state 38 + EQUALALL shift and go to state 39 + EQUALANY shift and go to state 40 + SUM shift and go to state 41 + SUMATLEAST shift and go to state 42 + SUMATMOST shift and go to state 43 + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + + q_factor shift and go to state 93 + q_atom shift and go to state 25 + q_equal_atom_3 shift and go to state 27 + q_equal_atom_2 shift and go to state 28 + q_sum_atom shift and go to state 29 + me_atom shift and go to state 30 + q_iden_3 shift and go to state 31 + q_iden_2 shift and go to state 33 + q_sum shift and go to state 34 + a_expression_atom shift and go to state 35 + a_expression shift and go to state 44 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 64 + + (42) q_factor -> NOT q_factor . + + RIGHTSMALLBRACKET reduce using rule 42 (q_factor -> NOT q_factor .) + OR reduce using rule 42 (q_factor -> NOT q_factor .) + AND reduce using rule 42 (q_factor -> NOT q_factor .) + + +state 65 + + (50) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET . NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET . NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + + NUMBER shift and go to state 94 + + +state 66 + + (58) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET . q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET . q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (68) q_alias_concat_wrap -> . alias_slice + (69) q_alias_concat_wrap -> . LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET + (72) alias_slice -> . ALIAS + (73) alias_slice -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + LEFTSQRBRACKET shift and go to state 97 + ALIAS shift and go to state 98 + + q_alias_concat_wrap shift and go to state 95 + alias_slice shift and go to state 96 + +state 67 + + (52) q_sum_atom -> q_sum LEFTSMALLBRACKET . q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (53) q_alias_sum_concat_wrap -> . LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET + (54) q_alias_sum_concat_wrap -> . q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap + (55) q_alias_sum_concat_wrap -> . q_alias_sum_concat_wrap_atom + (56) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (57) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + LEFTSMALLBRACKET shift and go to state 99 + ALIAS shift and go to state 102 + + q_alias_sum_concat_wrap shift and go to state 100 + q_alias_sum_concat_wrap_atom shift and go to state 101 + +state 68 + + (75) a_expression_atom -> a_expression EQUAL . a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_expression shift and go to state 103 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 69 + + (76) a_expression_atom -> a_expression NOTEQUAL . a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_expression shift and go to state 105 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 70 + + (77) a_expression_atom -> a_expression GREATEREQUAL . a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_expression shift and go to state 106 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 71 + + (78) a_expression_atom -> a_expression GREATER . a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_expression shift and go to state 107 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 72 + + (79) a_expression_atom -> a_expression LESSEQUAL . a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_expression shift and go to state 108 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 73 + + (80) a_expression_atom -> a_expression LESS . a_expression + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_expression shift and go to state 109 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 74 + + (81) a_expression -> a_expression PLUS . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_term shift and go to state 110 + a_factor shift and go to state 46 + +state 75 + + (82) a_expression -> a_expression MINUS . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_term shift and go to state 111 + a_factor shift and go to state 46 + +state 76 + + (84) a_term -> a_term TIMES . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_factor shift and go to state 112 + +state 77 + + (85) a_term -> a_term DIVIDE . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_factor shift and go to state 113 + +state 78 + + (88) a_factor -> ALIAS LEFTSQRBRACKET . NUMBER RIGHTSQRBRACKET + + NUMBER shift and go to state 114 + + +state 79 + + (9) ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET . + + ENTITY reduce using rule 9 (ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET .) + ALIAS reduce using rule 9 (ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET .) + QUERY reduce using rule 9 (ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET .) + $end reduce using rule 9 (ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET .) + + +state 80 + + (11) entity_prop_prob -> entity_prop_prob SEMICOLON . entity_prop_prob_atom + (13) entity_prop_prob_atom -> . IDEN + (14) entity_prop_prob_atom -> . NUMBER + (15) entity_prop_prob_atom -> . NUMBER DOUBLECOLON IDEN + (16) entity_prop_prob_atom -> . NUMBER DOUBLECOLON NUMBER + (17) entity_prop_prob_atom -> . FLOAT DOUBLECOLON IDEN + (18) entity_prop_prob_atom -> . FLOAT DOUBLECOLON NUMBER + + IDEN shift and go to state 51 + NUMBER shift and go to state 52 + FLOAT shift and go to state 53 + + entity_prop_prob_atom shift and go to state 115 + +state 81 + + (15) entity_prop_prob_atom -> NUMBER DOUBLECOLON . IDEN + (16) entity_prop_prob_atom -> NUMBER DOUBLECOLON . NUMBER + + IDEN shift and go to state 117 + NUMBER shift and go to state 116 + + +state 82 + + (17) entity_prop_prob_atom -> FLOAT DOUBLECOLON . IDEN + (18) entity_prop_prob_atom -> FLOAT DOUBLECOLON . NUMBER + + IDEN shift and go to state 118 + NUMBER shift and go to state 119 + + +state 83 + + (30) entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL . LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + LEFTSMALLBRACKET shift and go to state 120 + + +state 84 + + (31) entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL . LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + LEFTSMALLBRACKET shift and go to state 121 + + +state 85 + + (20) entity_initialize -> IDEN ei_params ei_number . + + DOT reduce using rule 20 (entity_initialize -> IDEN ei_params ei_number .) + ENTITY reduce using rule 20 (entity_initialize -> IDEN ei_params ei_number .) + ALIAS reduce using rule 20 (entity_initialize -> IDEN ei_params ei_number .) + QUERY reduce using rule 20 (entity_initialize -> IDEN ei_params ei_number .) + $end reduce using rule 20 (entity_initialize -> IDEN ei_params ei_number .) + + +state 86 + + (29) ei_number -> LEFTCURLYBRACE . NUMBER RIGHTCURLYBRACE + + NUMBER shift and go to state 122 + + +state 87 + + (21) ei_params -> LEFTSMALLBRACKET float_list . ei_flag_option RIGHTSMALLBRACKET + (23) float_list -> float_list . COMMA FLOAT + (24) float_list -> float_list . COMMA NUMBER + (27) ei_flag_option -> . BAR IDEN + (28) ei_flag_option -> . empty + (7) empty -> . + + COMMA shift and go to state 124 + BAR shift and go to state 125 + RIGHTSMALLBRACKET reduce using rule 7 (empty -> .) + + ei_flag_option shift and go to state 123 + empty shift and go to state 126 + +state 88 + + (25) float_list -> FLOAT . + + COMMA reduce using rule 25 (float_list -> FLOAT .) + BAR reduce using rule 25 (float_list -> FLOAT .) + RIGHTSMALLBRACKET reduce using rule 25 (float_list -> FLOAT .) + + +state 89 + + (26) float_list -> NUMBER . + + COMMA reduce using rule 26 (float_list -> NUMBER .) + BAR reduce using rule 26 (float_list -> NUMBER .) + RIGHTSMALLBRACKET reduce using rule 26 (float_list -> NUMBER .) + + +state 90 + + (43) q_factor -> LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET . + + RIGHTSMALLBRACKET reduce using rule 43 (q_factor -> LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET .) + OR reduce using rule 43 (q_factor -> LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET .) + AND reduce using rule 43 (q_factor -> LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET .) + + +state 91 + + (89) a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET . + + TIMES reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + DIVIDE reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + EQUAL reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + NOTEQUAL reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + GREATEREQUAL reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + GREATER reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + LESSEQUAL reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + LESS reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + PLUS reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + MINUS reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + RIGHTSMALLBRACKET reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + OR reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + AND reduce using rule 89 (a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET .) + + +state 92 + + (35) q_expr -> q_term_list OR q_term . + (39) q_term_list -> q_term_list OR q_term . + + RIGHTSMALLBRACKET reduce using rule 35 (q_expr -> q_term_list OR q_term .) + OR reduce using rule 39 (q_term_list -> q_term_list OR q_term .) + + +state 93 + + (37) q_term -> q_factor_list AND q_factor . + (44) q_factor_list -> q_factor_list AND q_factor . + + RIGHTSMALLBRACKET reduce using rule 37 (q_term -> q_factor_list AND q_factor .) + OR reduce using rule 37 (q_term -> q_factor_list AND q_factor .) + AND reduce using rule 44 (q_factor_list -> q_factor_list AND q_factor .) + + +state 94 + + (50) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER . COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER . COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + + COMMA shift and go to state 127 + + +state 95 + + (58) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap . COMMA IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap . COMMA NUMBER RIGHTSMALLBRACKET + + COMMA shift and go to state 128 + + +state 96 + + (68) q_alias_concat_wrap -> alias_slice . + + COMMA reduce using rule 68 (q_alias_concat_wrap -> alias_slice .) + + +state 97 + + (69) q_alias_concat_wrap -> LEFTSQRBRACKET . q_alias_concat RIGHTSQRBRACKET + (70) q_alias_concat -> . q_alias_concat BAR alias_slice + (71) q_alias_concat -> . alias_slice + (72) alias_slice -> . ALIAS + (73) alias_slice -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + ALIAS shift and go to state 98 + + q_alias_concat shift and go to state 129 + alias_slice shift and go to state 130 + +state 98 + + (72) alias_slice -> ALIAS . + (73) alias_slice -> ALIAS . LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + COMMA reduce using rule 72 (alias_slice -> ALIAS .) + RIGHTSQRBRACKET reduce using rule 72 (alias_slice -> ALIAS .) + BAR reduce using rule 72 (alias_slice -> ALIAS .) + LEFTSQRBRACKET shift and go to state 131 + + +state 99 + + (53) q_alias_sum_concat_wrap -> LEFTSMALLBRACKET . q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET + (56) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (57) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + ALIAS shift and go to state 102 + + q_alias_sum_concat_wrap_atom shift and go to state 132 + +state 100 + + (52) q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap . COMMA NUMBER RIGHTSMALLBRACKET + + COMMA shift and go to state 133 + + +state 101 + + (54) q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom . BAR q_alias_sum_concat_wrap + (55) q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom . + + BAR shift and go to state 134 + COMMA reduce using rule 55 (q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom .) + RIGHTSMALLBRACKET reduce using rule 55 (q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom .) + + +state 102 + + (56) q_alias_sum_concat_wrap_atom -> ALIAS . LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (57) q_alias_sum_concat_wrap_atom -> ALIAS . LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + LEFTSQRBRACKET shift and go to state 135 + + +state 103 + + (75) a_expression_atom -> a_expression EQUAL a_expression . + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + RIGHTSMALLBRACKET reduce using rule 75 (a_expression_atom -> a_expression EQUAL a_expression .) + OR reduce using rule 75 (a_expression_atom -> a_expression EQUAL a_expression .) + AND reduce using rule 75 (a_expression_atom -> a_expression EQUAL a_expression .) + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 104 + + (89) a_factor -> LEFTSMALLBRACKET . a_expression RIGHTSMALLBRACKET + (81) a_expression -> . a_expression PLUS a_term + (82) a_expression -> . a_expression MINUS a_term + (83) a_expression -> . a_term + (84) a_term -> . a_term TIMES a_factor + (85) a_term -> . a_term DIVIDE a_factor + (86) a_term -> . a_factor + (87) a_factor -> . NUMBER + (88) a_factor -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (89) a_factor -> . LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET + + NUMBER shift and go to state 32 + ALIAS shift and go to state 47 + LEFTSMALLBRACKET shift and go to state 104 + + a_expression shift and go to state 136 + a_term shift and go to state 45 + a_factor shift and go to state 46 + +state 105 + + (76) a_expression_atom -> a_expression NOTEQUAL a_expression . + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + RIGHTSMALLBRACKET reduce using rule 76 (a_expression_atom -> a_expression NOTEQUAL a_expression .) + OR reduce using rule 76 (a_expression_atom -> a_expression NOTEQUAL a_expression .) + AND reduce using rule 76 (a_expression_atom -> a_expression NOTEQUAL a_expression .) + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 106 + + (77) a_expression_atom -> a_expression GREATEREQUAL a_expression . + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + RIGHTSMALLBRACKET reduce using rule 77 (a_expression_atom -> a_expression GREATEREQUAL a_expression .) + OR reduce using rule 77 (a_expression_atom -> a_expression GREATEREQUAL a_expression .) + AND reduce using rule 77 (a_expression_atom -> a_expression GREATEREQUAL a_expression .) + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 107 + + (78) a_expression_atom -> a_expression GREATER a_expression . + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + RIGHTSMALLBRACKET reduce using rule 78 (a_expression_atom -> a_expression GREATER a_expression .) + OR reduce using rule 78 (a_expression_atom -> a_expression GREATER a_expression .) + AND reduce using rule 78 (a_expression_atom -> a_expression GREATER a_expression .) + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 108 + + (79) a_expression_atom -> a_expression LESSEQUAL a_expression . + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + RIGHTSMALLBRACKET reduce using rule 79 (a_expression_atom -> a_expression LESSEQUAL a_expression .) + OR reduce using rule 79 (a_expression_atom -> a_expression LESSEQUAL a_expression .) + AND reduce using rule 79 (a_expression_atom -> a_expression LESSEQUAL a_expression .) + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 109 + + (80) a_expression_atom -> a_expression LESS a_expression . + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + RIGHTSMALLBRACKET reduce using rule 80 (a_expression_atom -> a_expression LESS a_expression .) + OR reduce using rule 80 (a_expression_atom -> a_expression LESS a_expression .) + AND reduce using rule 80 (a_expression_atom -> a_expression LESS a_expression .) + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 110 + + (81) a_expression -> a_expression PLUS a_term . + (84) a_term -> a_term . TIMES a_factor + (85) a_term -> a_term . DIVIDE a_factor + + EQUAL reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + NOTEQUAL reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + GREATEREQUAL reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + GREATER reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + LESSEQUAL reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + LESS reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + PLUS reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + MINUS reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + RIGHTSMALLBRACKET reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + OR reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + AND reduce using rule 81 (a_expression -> a_expression PLUS a_term .) + TIMES shift and go to state 76 + DIVIDE shift and go to state 77 + + +state 111 + + (82) a_expression -> a_expression MINUS a_term . + (84) a_term -> a_term . TIMES a_factor + (85) a_term -> a_term . DIVIDE a_factor + + EQUAL reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + NOTEQUAL reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + GREATEREQUAL reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + GREATER reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + LESSEQUAL reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + LESS reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + PLUS reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + MINUS reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + RIGHTSMALLBRACKET reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + OR reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + AND reduce using rule 82 (a_expression -> a_expression MINUS a_term .) + TIMES shift and go to state 76 + DIVIDE shift and go to state 77 + + +state 112 + + (84) a_term -> a_term TIMES a_factor . + + TIMES reduce using rule 84 (a_term -> a_term TIMES a_factor .) + DIVIDE reduce using rule 84 (a_term -> a_term TIMES a_factor .) + EQUAL reduce using rule 84 (a_term -> a_term TIMES a_factor .) + NOTEQUAL reduce using rule 84 (a_term -> a_term TIMES a_factor .) + GREATEREQUAL reduce using rule 84 (a_term -> a_term TIMES a_factor .) + GREATER reduce using rule 84 (a_term -> a_term TIMES a_factor .) + LESSEQUAL reduce using rule 84 (a_term -> a_term TIMES a_factor .) + LESS reduce using rule 84 (a_term -> a_term TIMES a_factor .) + PLUS reduce using rule 84 (a_term -> a_term TIMES a_factor .) + MINUS reduce using rule 84 (a_term -> a_term TIMES a_factor .) + RIGHTSMALLBRACKET reduce using rule 84 (a_term -> a_term TIMES a_factor .) + OR reduce using rule 84 (a_term -> a_term TIMES a_factor .) + AND reduce using rule 84 (a_term -> a_term TIMES a_factor .) + + +state 113 + + (85) a_term -> a_term DIVIDE a_factor . + + TIMES reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + DIVIDE reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + EQUAL reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + NOTEQUAL reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + GREATEREQUAL reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + GREATER reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + LESSEQUAL reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + LESS reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + PLUS reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + MINUS reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + RIGHTSMALLBRACKET reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + OR reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + AND reduce using rule 85 (a_term -> a_term DIVIDE a_factor .) + + +state 114 + + (88) a_factor -> ALIAS LEFTSQRBRACKET NUMBER . RIGHTSQRBRACKET + + RIGHTSQRBRACKET shift and go to state 137 + + +state 115 + + (11) entity_prop_prob -> entity_prop_prob SEMICOLON entity_prop_prob_atom . + + SEMICOLON reduce using rule 11 (entity_prop_prob -> entity_prop_prob SEMICOLON entity_prop_prob_atom .) + RIGHTSMALLBRACKET reduce using rule 11 (entity_prop_prob -> entity_prop_prob SEMICOLON entity_prop_prob_atom .) + + +state 116 + + (16) entity_prop_prob_atom -> NUMBER DOUBLECOLON NUMBER . + + SEMICOLON reduce using rule 16 (entity_prop_prob_atom -> NUMBER DOUBLECOLON NUMBER .) + RIGHTSMALLBRACKET reduce using rule 16 (entity_prop_prob_atom -> NUMBER DOUBLECOLON NUMBER .) + + +state 117 + + (15) entity_prop_prob_atom -> NUMBER DOUBLECOLON IDEN . + + SEMICOLON reduce using rule 15 (entity_prop_prob_atom -> NUMBER DOUBLECOLON IDEN .) + RIGHTSMALLBRACKET reduce using rule 15 (entity_prop_prob_atom -> NUMBER DOUBLECOLON IDEN .) + + +state 118 + + (17) entity_prop_prob_atom -> FLOAT DOUBLECOLON IDEN . + + SEMICOLON reduce using rule 17 (entity_prop_prob_atom -> FLOAT DOUBLECOLON IDEN .) + RIGHTSMALLBRACKET reduce using rule 17 (entity_prop_prob_atom -> FLOAT DOUBLECOLON IDEN .) + + +state 119 + + (18) entity_prop_prob_atom -> FLOAT DOUBLECOLON NUMBER . + + SEMICOLON reduce using rule 18 (entity_prop_prob_atom -> FLOAT DOUBLECOLON NUMBER .) + RIGHTSMALLBRACKET reduce using rule 18 (entity_prop_prob_atom -> FLOAT DOUBLECOLON NUMBER .) + + +state 120 + + (30) entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET . option_number RIGHTSMALLBRACKET + (32) option_number -> . NUMBER + (33) option_number -> . empty + (7) empty -> . + + NUMBER shift and go to state 139 + RIGHTSMALLBRACKET reduce using rule 7 (empty -> .) + + option_number shift and go to state 138 + empty shift and go to state 140 + +state 121 + + (31) entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET . option_number RIGHTSMALLBRACKET + (32) option_number -> . NUMBER + (33) option_number -> . empty + (7) empty -> . + + NUMBER shift and go to state 139 + RIGHTSMALLBRACKET reduce using rule 7 (empty -> .) + + option_number shift and go to state 141 + empty shift and go to state 140 + +state 122 + + (29) ei_number -> LEFTCURLYBRACE NUMBER . RIGHTCURLYBRACE + + RIGHTCURLYBRACE shift and go to state 142 + + +state 123 + + (21) ei_params -> LEFTSMALLBRACKET float_list ei_flag_option . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 143 + + +state 124 + + (23) float_list -> float_list COMMA . FLOAT + (24) float_list -> float_list COMMA . NUMBER + + FLOAT shift and go to state 144 + NUMBER shift and go to state 145 + + +state 125 + + (27) ei_flag_option -> BAR . IDEN + + IDEN shift and go to state 146 + + +state 126 + + (28) ei_flag_option -> empty . + + RIGHTSMALLBRACKET reduce using rule 28 (ei_flag_option -> empty .) + + +state 127 + + (50) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA . q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA . q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + (68) q_alias_concat_wrap -> . alias_slice + (69) q_alias_concat_wrap -> . LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET + (72) alias_slice -> . ALIAS + (73) alias_slice -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + LEFTSQRBRACKET shift and go to state 97 + ALIAS shift and go to state 98 + + q_alias_concat_wrap shift and go to state 147 + alias_slice shift and go to state 96 + +state 128 + + (58) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA . IDEN RIGHTSMALLBRACKET + (59) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA . NUMBER RIGHTSMALLBRACKET + + IDEN shift and go to state 148 + NUMBER shift and go to state 149 + + +state 129 + + (69) q_alias_concat_wrap -> LEFTSQRBRACKET q_alias_concat . RIGHTSQRBRACKET + (70) q_alias_concat -> q_alias_concat . BAR alias_slice + + RIGHTSQRBRACKET shift and go to state 150 + BAR shift and go to state 151 + + +state 130 + + (71) q_alias_concat -> alias_slice . + + RIGHTSQRBRACKET reduce using rule 71 (q_alias_concat -> alias_slice .) + BAR reduce using rule 71 (q_alias_concat -> alias_slice .) + + +state 131 + + (73) alias_slice -> ALIAS LEFTSQRBRACKET . NUMBER COLON NUMBER RIGHTSQRBRACKET + + NUMBER shift and go to state 152 + + +state 132 + + (53) q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom . BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET + + BAR shift and go to state 153 + + +state 133 + + (52) q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA . NUMBER RIGHTSMALLBRACKET + + NUMBER shift and go to state 154 + + +state 134 + + (54) q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom BAR . q_alias_sum_concat_wrap + (53) q_alias_sum_concat_wrap -> . LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET + (54) q_alias_sum_concat_wrap -> . q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap + (55) q_alias_sum_concat_wrap -> . q_alias_sum_concat_wrap_atom + (56) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (57) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + LEFTSMALLBRACKET shift and go to state 99 + ALIAS shift and go to state 102 + + q_alias_sum_concat_wrap_atom shift and go to state 101 + q_alias_sum_concat_wrap shift and go to state 155 + +state 135 + + (56) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET . NUMBER RIGHTSQRBRACKET + (57) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET . NUMBER COLON NUMBER RIGHTSQRBRACKET + + NUMBER shift and go to state 156 + + +state 136 + + (89) a_factor -> LEFTSMALLBRACKET a_expression . RIGHTSMALLBRACKET + (81) a_expression -> a_expression . PLUS a_term + (82) a_expression -> a_expression . MINUS a_term + + RIGHTSMALLBRACKET shift and go to state 91 + PLUS shift and go to state 74 + MINUS shift and go to state 75 + + +state 137 + + (88) a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET . + + TIMES reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + DIVIDE reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + EQUAL reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + NOTEQUAL reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + GREATEREQUAL reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + GREATER reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + LESSEQUAL reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + LESS reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + PLUS reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + MINUS reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + RIGHTSMALLBRACKET reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + OR reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + AND reduce using rule 88 (a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + + +state 138 + + (30) entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 157 + + +state 139 + + (32) option_number -> NUMBER . + + RIGHTSMALLBRACKET reduce using rule 32 (option_number -> NUMBER .) + + +state 140 + + (33) option_number -> empty . + + RIGHTSMALLBRACKET reduce using rule 33 (option_number -> empty .) + + +state 141 + + (31) entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 158 + + +state 142 + + (29) ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE . + + DOT reduce using rule 29 (ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE .) + ENTITY reduce using rule 29 (ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE .) + ALIAS reduce using rule 29 (ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE .) + QUERY reduce using rule 29 (ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE .) + $end reduce using rule 29 (ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE .) + + +state 143 + + (21) ei_params -> LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET . + + LEFTCURLYBRACE reduce using rule 21 (ei_params -> LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET .) + + +state 144 + + (23) float_list -> float_list COMMA FLOAT . + + COMMA reduce using rule 23 (float_list -> float_list COMMA FLOAT .) + BAR reduce using rule 23 (float_list -> float_list COMMA FLOAT .) + RIGHTSMALLBRACKET reduce using rule 23 (float_list -> float_list COMMA FLOAT .) + + +state 145 + + (24) float_list -> float_list COMMA NUMBER . + + COMMA reduce using rule 24 (float_list -> float_list COMMA NUMBER .) + BAR reduce using rule 24 (float_list -> float_list COMMA NUMBER .) + RIGHTSMALLBRACKET reduce using rule 24 (float_list -> float_list COMMA NUMBER .) + + +state 146 + + (27) ei_flag_option -> BAR IDEN . + + RIGHTSMALLBRACKET reduce using rule 27 (ei_flag_option -> BAR IDEN .) + + +state 147 + + (50) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap . COMMA IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap . COMMA NUMBER RIGHTSMALLBRACKET + + COMMA shift and go to state 159 + + +state 148 + + (58) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 160 + + +state 149 + + (59) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 161 + + +state 150 + + (69) q_alias_concat_wrap -> LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET . + + COMMA reduce using rule 69 (q_alias_concat_wrap -> LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET .) + + +state 151 + + (70) q_alias_concat -> q_alias_concat BAR . alias_slice + (72) alias_slice -> . ALIAS + (73) alias_slice -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + ALIAS shift and go to state 98 + + alias_slice shift and go to state 162 + +state 152 + + (73) alias_slice -> ALIAS LEFTSQRBRACKET NUMBER . COLON NUMBER RIGHTSQRBRACKET + + COLON shift and go to state 163 + + +state 153 + + (53) q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR . q_alias_sum_concat_wrap RIGHTSMALLBRACKET + (53) q_alias_sum_concat_wrap -> . LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET + (54) q_alias_sum_concat_wrap -> . q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap + (55) q_alias_sum_concat_wrap -> . q_alias_sum_concat_wrap_atom + (56) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + (57) q_alias_sum_concat_wrap_atom -> . ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + + LEFTSMALLBRACKET shift and go to state 99 + ALIAS shift and go to state 102 + + q_alias_sum_concat_wrap_atom shift and go to state 101 + q_alias_sum_concat_wrap shift and go to state 164 + +state 154 + + (52) q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 165 + + +state 155 + + (54) q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap . + + COMMA reduce using rule 54 (q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap .) + RIGHTSMALLBRACKET reduce using rule 54 (q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap .) + + +state 156 + + (56) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER . RIGHTSQRBRACKET + (57) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER . COLON NUMBER RIGHTSQRBRACKET + + RIGHTSQRBRACKET shift and go to state 166 + COLON shift and go to state 167 + + +state 157 + + (30) entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET . + + ENTITY reduce using rule 30 (entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + ALIAS reduce using rule 30 (entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + QUERY reduce using rule 30 (entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + $end reduce using rule 30 (entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + + +state 158 + + (31) entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET . + + ENTITY reduce using rule 31 (entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + ALIAS reduce using rule 31 (entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + QUERY reduce using rule 31 (entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + $end reduce using rule 31 (entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET .) + + +state 159 + + (50) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA . IDEN RIGHTSMALLBRACKET + (51) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA . NUMBER RIGHTSMALLBRACKET + + IDEN shift and go to state 169 + NUMBER shift and go to state 168 + + +state 160 + + (58) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET . + + RIGHTSMALLBRACKET reduce using rule 58 (q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET .) + OR reduce using rule 58 (q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET .) + AND reduce using rule 58 (q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET .) + + +state 161 + + (59) q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET . + + RIGHTSMALLBRACKET reduce using rule 59 (q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + OR reduce using rule 59 (q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + AND reduce using rule 59 (q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + + +state 162 + + (70) q_alias_concat -> q_alias_concat BAR alias_slice . + + RIGHTSQRBRACKET reduce using rule 70 (q_alias_concat -> q_alias_concat BAR alias_slice .) + BAR reduce using rule 70 (q_alias_concat -> q_alias_concat BAR alias_slice .) + + +state 163 + + (73) alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON . NUMBER RIGHTSQRBRACKET + + NUMBER shift and go to state 170 + + +state 164 + + (53) q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 171 + + +state 165 + + (52) q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET . + + RIGHTSMALLBRACKET reduce using rule 52 (q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + OR reduce using rule 52 (q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + AND reduce using rule 52 (q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + + +state 166 + + (56) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET . + + BAR reduce using rule 56 (q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + COMMA reduce using rule 56 (q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + RIGHTSMALLBRACKET reduce using rule 56 (q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET .) + + +state 167 + + (57) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON . NUMBER RIGHTSQRBRACKET + + NUMBER shift and go to state 172 + + +state 168 + + (51) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 173 + + +state 169 + + (50) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN . RIGHTSMALLBRACKET + + RIGHTSMALLBRACKET shift and go to state 174 + + +state 170 + + (73) alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER . RIGHTSQRBRACKET + + RIGHTSQRBRACKET shift and go to state 175 + + +state 171 + + (53) q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET . + + COMMA reduce using rule 53 (q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET .) + RIGHTSMALLBRACKET reduce using rule 53 (q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET .) + + +state 172 + + (57) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER . RIGHTSQRBRACKET + + RIGHTSQRBRACKET shift and go to state 176 + + +state 173 + + (51) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET . + + RIGHTSMALLBRACKET reduce using rule 51 (q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + OR reduce using rule 51 (q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + AND reduce using rule 51 (q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET .) + + +state 174 + + (50) q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET . + + RIGHTSMALLBRACKET reduce using rule 50 (q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET .) + OR reduce using rule 50 (q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET .) + AND reduce using rule 50 (q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET .) + + +state 175 + + (73) alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET . + + COMMA reduce using rule 73 (alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET .) + RIGHTSQRBRACKET reduce using rule 73 (alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET .) + BAR reduce using rule 73 (alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET .) + + +state 176 + + (57) q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET . + + BAR reduce using rule 57 (q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET .) + COMMA reduce using rule 57 (q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET .) + RIGHTSMALLBRACKET reduce using rule 57 (q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET .) + diff --git a/probQparser/parser.py b/probQparser/parser.py index 76e3dbb..a232e5a 100644 --- a/probQparser/parser.py +++ b/probQparser/parser.py @@ -1,514 +1,586 @@ -from ply import yacc -import os,sys,time - -from collections import OrderedDict as odict -from probQlexer.lexer import lexer -from probQlexer.lexer import tokens as lexTokens -from probQsolver.solver import blackbox , QNode - -tokens = lexTokens - -solver = blackbox() - -precedence = ( - ('left', 'PLUS', 'MINUS'), - ('left', 'AND', 'OR', 'NOT') - -) - -# A BASIC program is a series of statements. We represent the program as a -# dictionary of tuples indexed by line number. - -_entity = { - 'dice' : {'entity': 'dice' , 'feature' : odict([(1,0.16666666666),(2,0.16666666666),(3,0.16666666666),(4,0.16666666666),(5,0.16666666666),(6,0.16666666666)]), - 'p_default': [0.16666666666,0.16666666666,0.16666666666,0.16666666666,0.16666666666,0.16666666666] }, - 'coin' : {'entity': 'coin' , 'feature' : odict([('head',0.5),('tail',0.5)]), - 'p_default': [0.5,0.5] } -} -_alias = {} - - -def p_program(p): - '''program : program statement ''' - p[1] += [p[2]] - p[0] = p[1] - -def p_program_single(p): - '''program : statement ''' - p[0] = [ p[1] ] - - -# Format of all BASIC statements. - -def p_statement_entity_def(p): - '''statement : entity_def ''' - p[0] = p[1] - -def p_statement_entity_initialize(p): - ''' statement : entity_initialize_wrap ''' - p[0] = p[1] - -def p_statement_entity_assignment(p): - ''' statement : entity_action ''' - p[0] = p[1] - -def p_statement_query(p): - ''' statement : query_wrap ''' - p[0] = p[1] - - -################################################################################ -############################ HELPERS ##################################### -################################################################################ - -def p_empty(p): - 'empty :' - pass - - -################################################################################ -############################ ENTITY DEF ##################################### -################################################################################ -# entity coin[H,T](H::head;T::tail) -# entity coin[H=0.5,T=0.5](H::head;T::tail) -# -def p_entity_def(p): - ''' entity_def : ENTITY IDEN ed_feature ''' - feature = p[3]['feature'] - default = [] - for key, value in feature.items(): - default.append(value) - - p[0] = {'entity': p[2], 'feature' : p[3]['feature'],'p_default': default } - if float(p[3]['sum']) > 1: - print("WARNING: Sum of probability greater than one! ", p.lineno(3)) - if p[2] in _entity: - print("This entity is already defined, this will be rejected") - else: - solver.add_enitity(p[0]) - _entity[p[2]] = p[0] - - -# ############ -------------------------------------------------------------- -# -# def p_ed_params(p): -# ''' ed_params : LEFTSQRBRACKET alias_list RIGHTSQRBRACKET ''' -# p[0] = p[2] -# -# def p_alias_list(p): -# ''' alias_list : alias_list COMMA ALIAS ASSIGNMENT FLOAT -# | alias_list COMMA ALIAS -# ''' -# size = len(p) -# if size == 6: -# ne = { p[3]:p[5] } -# p[0] = { **p[1], **ne } -# elif size == 4: -# ne = { p[3]: 0.0 } -# p[0] = { **p[1], **ne } -# -# -# def p_alias_list_single(p): -# ''' alias_list : ALIAS ASSIGNMENT FLOAT -# | ALIAS -# ''' -# if len(p) == 4: -# p[0] = { p[1] : p[3]} -# elif len(p) == 2: -# p[0] = { p[1] : 0.0 } -# -# ############ --------------------------------------------------------------- - -def p_ed_feature(p): - ''' ed_feature : LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET''' - p[0] = p[2] - -def p_ed_feature_inner(p): - ''' ed_feature_inner : entity_prop_prob ''' - p[0] = p[1] - -def p_entity_prop_prob(p): - ''' entity_prop_prob : entity_prop_prob SEMICOLON entity_prop_prob_atom ''' - p[1]['feature'].update(p[3]['feature']) - p[1]['sum'] = float(p[1]['sum']) + float(p[3]['sum']) - p[0] = p[1] - -def p_entity_prop_prob_single(p): - ''' entity_prop_prob : entity_prop_prob_atom ''' - p[0] = p[1] - -def p_entity_prop_prob_atom(p): - ''' entity_prop_prob_atom : IDEN - | NUMBER - ''' - p[0] = { 'feature' : odict([(p[1],0)]) , 'sum' : 0 } - -def p_entity_prop_prob_atom_n(p): - ''' entity_prop_prob_atom : NUMBER DOUBLECOLON IDEN - | NUMBER DOUBLECOLON NUMBER - ''' - p[0] = { 'feature' : odict([(p[3],p[1])]), 'sum' : p[1] } - -def p_entity_prop_prob_atom_f(p): - ''' entity_prop_prob_atom : FLOAT DOUBLECOLON IDEN - | FLOAT DOUBLECOLON NUMBER - ''' - p[0] = { 'feature' : odict([(p[3],p[1])]), 'sum' : p[1] } - - -################################################################################ -############################ ENTITY Initialize ############################## -################################################################################ -def p_entity_initialize_wrap(p): - ''' entity_initialize_wrap : ALIAS ASSIGNMENT entity_initialize ''' - alias = {'id': p[1], 'type' : 'entity_instance', 'instance': p[3]} - if p[1] in _alias: - print("Alias already exist", p.lineno(1)) - else: - solver.add_entity_instance(p[3]) - _alias[p[1]] = alias - -def p_entity_initialize(p): - ''' entity_initialize : IDEN ei_params ei_number ''' - if p[1] in _entity: - entity = _entity[p[1]] - e_p_length = len(entity['p_default']) - if p[2]['flag'] == 'empty': - e_param = entity['p_default'] - elif len(p[2]['params'])== e_p_length: - e_param = p[2]['params'] - else: - print("Pass all the required parameters") - - p[0] = {'entity': p[1], 'label': p[2]['flag'], 'params': e_param , 'count' : p[3] } - - else: - print(_entity) - print("entity not defined") - -def p_ei_params(p): - ''' ei_params : LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET ''' - p[0] = {'flag' : p[3], 'params': p[2]} - -def p_ei_params_empty(p): - ''' ei_params : empty ''' - p[0] = {'flag':'empty', 'params' : [] } - -def p_float_list(p): - ''' float_list : float_list COMMA FLOAT - | float_list COMMA NUMBER - ''' - p[1] += [p[3]] - p[0] = p[1] - -def p_float_list_single(p): - ''' float_list : FLOAT - | NUMBER - ''' - p[0] = [ p[1] ] - -def p_ei_flag(p): - ''' ei_flag_option : BAR IDEN - | empty - ''' - if len(p) == 3: - p[0] = p[2] - else: - p[0] = "f" - -def p_ei_number(p): - ''' ei_number : LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE ''' - p[0] = p[2] - -################################################################################ -############################ ENTITY Action ############################## -################################################################################ -def p_entity_action(p): - ''' entity_action : ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET - ''' - if p[1] in _alias: - print("Alias already exist", p.lineno(1)) - else: - if p[3] in _alias and _alias[p[3]]['type'] == 'entity_instance': - entity_instance = _alias[p[3]]['instance'] - - entity_action = {'action_alias' : p[1], 'entity_instance': entity_instance } - action_return = solver.add_entity_action(entity_action) - - _alias[p[1]] = { 'id':p[1],'type':'entity_action','return' : action_return, - 'length' : entity_instance['count'],'instance': entity_instance} - else: - print("wrong alias",p.lineno(3)) - - -def p_entity_action_e(p): - ''' entity_action : ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET ''' - if p[1] in _alias: - print("Alias already exist", p.lineno(1)) - else: - entity_instance = p[3] - solver.add_entity_instance(p[3]) - - entity_action = {'action_alias' : p[1], 'entity_instance': entity_instance } - action_return = solver.add_entity_action(entity_action) - - _alias[p[1]] = { 'id':p[1],'type':'entity_action','return' : action_return, - 'length' : entity_instance['count'],'instance': entity_instance} - -def p_option_number(p): - ''' option_number : NUMBER ''' - p[0] = p[1] - -def p_option_number_wo(p): - ''' option_number : empty ''' - p[0] = 1 - - -################################################################################ -############################ Probability QUERY ########################### -################################################################################ - - -def p_query_wrap(p): - ''' query_wrap : QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET ''' - solver.add_query(p[3]) - - - #in_order(p[3]) - p[0] = p[3] - -################################################################################ - -def p_q_expr(p): - ''' q_expr : q_term_list OR q_term ''' - root = QNode("or","or") - for e_ch in p[1]: - root.add_child(e_ch) - root.add_child(p[3]) - p[0] = root - -def p_q_expr_s(p): - ''' q_expr : q_term ''' - p[0] = p[1] - -def p_q_term(p): - ''' q_term : q_factor_list AND q_factor ''' - root = QNode("and","and") - for e_ch in p[1]: - root.add_child(e_ch) - root.add_child(p[3]) - p[0] = root - -def p_q_term_s(p): - ''' q_term : q_factor ''' - p[0] = p[1] - -def p_q_term_list(p): - ''' q_term_list : q_term_list OR q_term ''' - p[0] = p[1] + [p[3]] - -def p_q_term_list_s(p): - ''' q_term_list : q_term ''' - - p[0] = [p[1]] - -def p_q_factor_a(p): - ''' q_factor : q_atom ''' - p[0] = p[1] - -def p_q_factor_n(p): - ''' q_factor : NOT q_factor ''' - root = QNode("not","not") - root.add_child(p[2]) - p[0] = root - -def p_q_factor_e(p): - ''' q_factor : LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET ''' - p[0] = p[2] - -def p_q_factor_list(p): - ''' q_factor_list : q_factor_list AND q_factor ''' - p[0] = p[1] + [p[3]] - -def p_q_factor_list_s(p): - ''' q_factor_list : q_factor ''' - p[0] = [p[1]] - - -def p_q_atom(p): - ''' q_atom : q_equal_atom_3 - | q_equal_atom_2 - | me_atom - ''' - p[0] = QNode("q_atom", p[1]) - -################################ Keep adding new atom here #################### - - -def p_q_equal_atom3(p): - ''' q_equal_atom_3 : q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET - | q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET - ''' - - query_atom = {'construct' : p[1],'params_count' : 3 ,'number':p[3] , 'equal' : p[7], - 'alias_list' : p[5]['alias_list'], - 'list' : p[5]['list'] , - 'list_len' : p[5]['list_len'] - } - p[0] = {'type': 'nl', 'body' :query_atom} - -def p_q_equal_atom2(p): - ''' q_equal_atom_2 : q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET - | q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET - ''' - query_atom = {'construct' : p[1],'params_count' : 2 ,'number': 0 , 'equal' : p[5], - 'alias_list' : p[3]['alias_list'], - 'list' : p[3]['list'] , - 'list_len' : p[3]['list_len'] - } - p[0] = {'type': 'nl', 'body' :query_atom} - - -def p_query_iden_3(p): - ''' q_iden_3 : EQUALATMOST - | EQUALATLEAST - | EQUALFEW ''' - p[0] = p[1] - -def p_query_iden_2(p): - ''' q_iden_2 : EQUALALL - | EQUALANY ''' - p[0] = p[1] - - -def p_q_alias_concat_wrap(p): - ''' q_alias_concat_wrap : alias_slice - | LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET - ''' - size = len(p) - if size == 4: - p[0] = p[2] - elif size == 2: - p[0] = {'list': p[1]['list'], 'alias_list' : [p[1]['name']], 'list_len' : p[1]['len'] } - - -def p_q_alias_concat(p): - ''' q_alias_concat : q_alias_concat BAR alias_slice - | alias_slice - ''' - size = len(p) - if size == 4: - l = p[1]['list'] + ' , ' + p[3]['list'] - a_list = p[1]['alias_list'] + [p[3]['name']] - a_len = p[1]['list_len'] + p[3]['len'] - p[0] = {'list': l , 'alias_list' : a_list, 'list_len': a_len } - - elif size == 2: - p[0] = {'list': p[1]['list'], 'alias_list' : [p[1]['name']], 'list_len' : p[1]['len'] } - - -def p_alias_slice(p): - ''' alias_slice : ALIAS - | ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET''' - alias = _alias[p[1]] - a_name = str(p[1]) - if len(p) == 2: - res = '' - a_len = alias['length'] - for i in range(1, a_len+1 ): - res = res + a_name + str(i) + ', ' - if len(p) == 7: - res = '' - a_len = int(p[5]) - int(p[3]) + 1 - for i in range(p[3], p[5] ): - res = res + a_name + str(i) + ', ' - - res = res.strip(', ') - p[0] = {'list' : res, 'name' : a_name, 'len' : a_len } - -############################### ME :- constructer :- me_atom ################ -def p_me_atom(p): - ''' me_atom : a_expression_atom ''' - res = {'type' : 'me', 'body': p[1]} - p[0] = res - -############################### ME :- a_expression_atom ######################## -def p_a_expr_atom_e(p): - ''' a_expression_atom : a_expression EQUAL a_expression ''' - p[0] = p[1] + ' =:= ' + p[3] - -def p_a_expr_atom_ne(p): - ''' a_expression_atom : a_expression NOTEQUAL a_expression ''' - p[0] = p[1] + ' =\= ' + p[3] - -def p_a_expr_atom_ge(p): - ''' a_expression_atom : a_expression GREATEREQUAL a_expression ''' - p[0] = p[1] + ' >= ' + p[3] - -def p_a_expr_atom_g(p): - ''' a_expression_atom : a_expression GREATER a_expression ''' - p[0] = p[1] + ' > ' + p[3] -def p_a_expr_atom_le(p): - ''' a_expression_atom : a_expression LESSEQUAL a_expression ''' - p[0] = p[1] + ' =< ' + p[3] - -def p_a_expr_atom_l(p): - ''' a_expression_atom : a_expression LESS a_expression ''' - p[0] = p[1] + ' < ' + p[3] - -def p_a_expression_plus(p): - 'a_expression : a_expression PLUS a_term' - p[0] = str(p[1]) + ' + ' + str(p[3]) - -def p_a_expression_minus(p): - 'a_expression : a_expression MINUS a_term' - p[0] = str(p[1]) + ' - ' + str(p[3]) - -def p_a_expression_term(p): - 'a_expression : a_term' - p[0] = str(p[1]) - -def p_term_times(p): - 'a_term : a_term TIMES a_factor' - p[0] = str(p[1]) + ' * ' + str(p[3]) - -def p_term_div(p): - 'a_term : a_term DIVIDE a_factor' - p[0] = str(p[1]) + ' / ' + str(p[3]) - -def p_term_factor(p): - 'a_term : a_factor' - p[0] = p[1] - -def p_factor_num(p): - ''' a_factor : NUMBER - | ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET - ''' - if len(p) == 2: - p[0] = str(p[1]) - if len(p) == 5: - p[0] = str(p[1]) + str(p[3]) - -def p_factor_expr(p): - 'a_factor : LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET' - p[0] = '( ' + str(p[2]) + ' )' - - -############################### ME END ######################################## - - -def p_error(p): - print("Syntax error in input!", p) - - -def getSolver(data, debug=0): - probQparser = yacc.yacc() - probQparser.error = 0 - # declare pre-existing stuffs - for key,value in _entity.items(): - solver.add_enitity(value) - - # start parsing with lexer from probQlexer - p = probQparser.parse(data,lexer = lexer,debug=debug ) - - return solver +from ply import yacc +import probQlexer.lexer as lexer +from collections import OrderedDict as odict +from probQsolver.solver import blackbox , QNode +import os +import sys +import time + +tokens = lexer.tokens + +solver = blackbox() + +precedence = ( + ('left', 'PLUS', 'MINUS'), + ('left', 'NOT', 'AND', 'OR') + +) + +# A BASIC program is a series of statements. We represent the program as a +# dictionary of tuples indexed by line number. + +_entity = { + 'dice' : {'entity': 'dice' , 'feature' : odict([(1,0.16666666666),(2,0.16666666666),(3,0.16666666666),(4,0.16666666666),(5,0.16666666666),(6,0.16666666666)]), + 'p_default': [0.16666666666,0.16666666666,0.16666666666,0.16666666666,0.16666666666,0.16666666666] }, + 'coin' : {'entity': 'coin' , 'feature' : odict([('head',0.5),('tail',0.5)]), + 'p_default': [0.5,0.5] } +} +_alias = {} + +_entity_def_list = [] #initialising lists + +for key,value in _entity.items(): + solver.add_entity(value) +# format of program +def p_program(p): + '''program : program statement ''' + p[1] += [p[2]] + p[0] = p[1] + +def p_program_single(p): + '''program : statement ''' + p[0] = [ p[1] ] + + +# Format of all BASIC statements. + +def p_statement_entity_def(p): + '''statement : entity_def ''' + p[0] = p[1] + +def p_statement_entity_initialize(p): + ''' statement : entity_initialize_wrap ''' + p[0] = p[1] + +def p_statement_entity_assignment(p): + ''' statement : entity_action ''' + p[0] = p[1] + +def p_statement_query(p): + ''' statement : query_wrap ''' + p[0] = p[1] + + +################################################################################ +############################ HELPERS ##################################### +################################################################################ + +def p_empty(p): + 'empty :' + pass + + +################################################################################ +############################ ENTITY DEF ##################################### +################################################################################ +# entity coin[H,T](H::head;T::tail) +# entity coin[H=0.5,T=0.5](H::head;T::tail) +# +def p_entity_def(p): + ''' entity_def : ENTITY IDEN ed_feature ''' + feature = p[3]['feature'] + default = [] + for key, value in feature.items(): + default.append(value) + + p[0] = {'entity': p[2], 'feature' : p[3]['feature'],'p_default': default } + if float(p[3]['sum']) > 1.005: # sum of prob <1 + print("WARNING: Sum of probability is greater than one! ", p.lineno(3)) + if float(p[3]['sum']) < 0.995: # sum of prob <=1 + print("WARNING: Sum of probability is less than one! ", p.lineno(3)) + if p[2] in _entity: + print("This entity is already defined, this will be rejected") + else: + solver.add_entity(p[0]) + _entity[p[2]] = p[0] + + +# ############ -------------------------------------------------------------- +# +# def p_ed_params(p): +# ''' ed_params : LEFTSQRBRACKET alias_list RIGHTSQRBRACKET ''' +# p[0] = p[2] +# +# def p_alias_list(p): +# ''' alias_list : alias_list COMMA ALIAS ASSIGNMENT FLOAT +# | alias_list COMMA ALIAS +# ''' +# size = len(p) +# if size == 6: +# ne = { p[3]:p[5] } +# p[0] = { **p[1], **ne } +# elif size == 4: +# ne = { p[3]: 0.0 } +# p[0] = { **p[1], **ne } +# +# +# def p_alias_list_single(p): +# ''' alias_list : ALIAS ASSIGNMENT FLOAT +# | ALIAS +# ''' +# if len(p) == 4: +# p[0] = { p[1] : p[3]} +# elif len(p) == 2: +# p[0] = { p[1] : 0.0 } +# +# ############ --------------------------------------------------------------- + +def p_ed_feature(p): #(iden @ number ; iden @ number) + ''' ed_feature : LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET''' + p[0] = p[2] + +def p_ed_feature_inner(p): #iden @ number ; iden @ number + ''' ed_feature_inner : entity_prop_prob ''' + p[0] = p[1] + +def p_entity_prop_prob(p): #NUMBER :: iden @ number;NUMBER :: iden @ number + ''' entity_prop_prob : entity_prop_prob SEMICOLON entity_prop_prob_atom ''' + p[1]['feature'].update(p[3]['feature']) + p[1]['sum'] = float(p[1]['sum']) + float(p[3]['sum']) + p[0] = p[1] + +def p_entity_prop_prob_single(p): #NUMBER :: iden @ number + ''' entity_prop_prob : entity_prop_prob_atom ''' + p[0] = p[1] + +def p_entity_prop_prob_atom(p): #NUMBER :: iden @ number + ''' entity_prop_prob_atom : IDEN + | NUMBER + ''' + p[0] = { 'feature' : odict([(p[1],0)]) , 'sum' : 0 } + +def p_entity_prop_prob_atom_n(p): # NUMBER :: iden @ number + ''' entity_prop_prob_atom : NUMBER DOUBLECOLON IDEN + | NUMBER DOUBLECOLON NUMBER + ''' + p[0] = { 'feature' : odict([(p[3],p[1])]), 'sum' : p[1] } + +def p_entity_prop_prob_atom_f(p): # float :: iden @ number + ''' entity_prop_prob_atom : FLOAT DOUBLECOLON IDEN + | FLOAT DOUBLECOLON NUMBER + ''' + p[0] = { 'feature' : odict([(p[3],p[1])]), 'sum' : p[1] } + + +################################################################################ +############################ ENTITY Initialize ############################## +################################################################################ +def p_entity_initialize_wrap(p): #ALIAS =IDEN (float, float ,float |iden){number} + ''' entity_initialize_wrap : ALIAS ASSIGNMENT entity_initialize ''' + alias = {'id': p[1], 'type' : 'entity_instance', 'instance': p[3]} + global _alias + if p[1] in _alias: + print("Alias already exist", p.lineno(1)) + else: + solver.add_entity_instance(p[3]) + _alias[p[1]] = alias + +def p_entity_initialize(p): # IDEN (float, float ,float |iden){number} + ''' entity_initialize : IDEN ei_params ei_number ''' + if p[1] in _entity: + entity = _entity[p[1]] + e_p_length = len(entity['p_default']) + if p[2]['flag'] == 'empty': + e_param = entity['p_default'] + elif len(p[2]['params'])== e_p_length: + e_param = p[2]['params'] + else: + print("Pass all the required parameters") + + p[0] = {'entity': p[1], 'label': p[2]['flag'], 'params': e_param , 'count' : p[3] } + + else: + print(_entity) + print("entity not defined") + +def p_ei_params(p): #(float, float ,float |iden) + ''' ei_params : LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET ''' + p[0] = {'flag' : p[3], 'params': p[2]} + +def p_ei_params_empty(p): + ''' ei_params : empty ''' + p[0] = {'flag':'empty', 'params' : [] } + +def p_float_list(p): # float, float ,float + ''' float_list : float_list COMMA FLOAT + | float_list COMMA NUMBER + ''' + p[1] += [p[3]] + p[0] = p[1] + +def p_float_list_single(p): #float @ number + ''' float_list : FLOAT + | NUMBER + ''' + p[0] = [ p[1] ] + +def p_ei_flag(p): # |iden + ''' ei_flag_option : BAR IDEN + | empty + ''' + if len(p) == 3: + p[0] = p[2] + else: + p[0] = "f" + +def p_ei_number(p): #{number} + ''' ei_number : LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE ''' + p[0] = p[2] + +################################################################################ +############################ ENTITY Action ############################## +################################################################################ +def p_entity_action(p): + ''' entity_action : ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + ''' + if p[1] in _alias: + print("Alias already exist", p.lineno(1)) + else: + if p[3] in _alias and _alias[p[3]]['type'] == 'entity_instance': + entity_instance = _alias[p[3]]['instance'] + + entity_action = {'action_alias' : p[1], 'entity_instance': entity_instance } + action_return = solver.add_entity_action(entity_action) + + _alias[p[1]] = { 'id':p[1],'type':'entity_action','return' : action_return, + 'length' : entity_instance['count'],'instance': entity_instance} + else: + print("wrong alias",p.lineno(3)) + + +def p_entity_action_e(p): # ALIAS = IDEN (float, float ,float |iden){number}.ROLL{NUMBER} + ''' entity_action : ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET ''' + if p[1] in _alias: + print("Alias already exist", p.lineno(1)) + else: + entity_instance = p[3] + solver.add_entity_instance(p[3]) + + entity_action = {'action_alias' : p[1], 'entity_instance': entity_instance } + action_return = solver.add_entity_action(entity_action) + + _alias[p[1]] = { 'id':p[1],'type':'entity_action','return' : action_return, + 'length' : entity_instance['count'],'instance': entity_instance} + +def p_option_number(p): + ''' option_number : NUMBER ''' + p[0] = p[1] + +def p_option_number_wo(p): #default 1 + ''' option_number : empty ''' + p[0] = 1 + + +################################################################################ +############################ Probability QUERY ########################### +################################################################################ + + +def p_query_wrap(p): #QUERY () + ''' query_wrap : QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET ''' + solver.add_query(p[3]) + + + #in_order(p[3]) + p[0] = p[3] + +################################################################################ + +def p_q_expr(p): + ''' q_expr : q_term_list OR q_term ''' + root = QNode("or","or") + for e_ch in p[1]: + root.add_child(e_ch) + root.add_child(p[3]) + p[0] = root + +def p_q_expr_s(p): + ''' q_expr : q_term ''' + p[0] = p[1] + +def p_q_term(p): + ''' q_term : q_factor_list AND q_factor ''' + root = QNode("and","and") + for e_ch in p[1]: + root.add_child(e_ch) + root.add_child(p[3]) + p[0] = root + +def p_q_term_s(p): + ''' q_term : q_factor ''' + p[0] = p[1] + +def p_q_term_list(p): + ''' q_term_list : q_term_list OR q_term ''' + p[0] = p[1] + [p[3]] + +def p_q_term_list_s(p): + ''' q_term_list : q_term ''' + + p[0] = [p[1]] + +def p_q_factor_a(p): + ''' q_factor : q_atom ''' + p[0] = p[1] + +def p_q_factor_n(p): + ''' q_factor : NOT q_factor ''' + root = QNode("not","not") + root.add_child(p[2]) + p[0] = root + +def p_q_factor_e(p): + ''' q_factor : LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET ''' + p[0] = p[2] + +def p_q_factor_list(p): + ''' q_factor_list : q_factor_list AND q_factor ''' + p[0] = p[1] + [p[3]] + +def p_q_factor_list_s(p): + ''' q_factor_list : q_factor ''' + p[0] = [p[1]] + + +def p_q_atom(p): + ''' q_atom : q_equal_atom_3 + | q_equal_atom_2 + | q_sum_atom + | me_atom + ''' + p[0] = QNode("q_atom", p[1]) + +################################ Keep adding new atom here #################### + + +def p_q_equal_atom3(p): #equal (3,X,s) + ''' q_equal_atom_3 : q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + | q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + ''' + + query_atom = {'construct' : p[1],'params_count' : 3 ,'number':p[3] , 'equal' : p[7], + 'alias_list' : p[5]['alias_list'], + 'list' : p[5]['list'] , + 'list_len' : p[5]['list_len'] + } + p[0] = {'type': 'nl', 'body' :query_atom} + +def p_q_sum(p): # sum(X,3) + ''' q_sum_atom : q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + + ''' + + query_atom = {'construct' : p[1],'params_count' : 2 ,'number':1 , 'equal' : p[5], + 'alias_list' : p[3]['alias_list'], + 'list' : p[3]['list'] , + 'list_len' : p[3]['list_len'] + } + p[0] = {'type': 'nl', 'body' :query_atom} + +def p_q_alias_sum_concat_wrap(p):#ALIAS[0,3]| + ''' + q_alias_sum_concat_wrap : LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET + | q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap + | q_alias_sum_concat_wrap_atom + + ''' + size = len(p) + if size == 4: + l = p[3]['list'] + ' + ' + p[1]['list'] + a_list = p[3]['alias_list'] + [p[1]['name']] + a_len = p[3]['list_len'] + p[1]['len'] + p[0] = {'list': l , 'alias_list' : a_list, 'list_len': a_len } + if size == 6: + l = p[2]['list'] + ' + ' + p[4]['list'] + a_list = p[4]['alias_list'] + [p[2]['name']] + a_len = p[4]['list_len'] + p[2]['len'] + p[0] = {'list': l , 'alias_list' : a_list, 'list_len': a_len } + + + + elif size == 2: + p[0] = {'list': p[1]['list'], 'alias_list' : [p[1]['name']], 'list_len' : p[1]['len'] } + + +def p_q_alias_sum_concat_wrap_atom(p): #ALIAS[0,3]| + ''' + q_alias_sum_concat_wrap_atom : ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + | ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET + ''' + alias = _alias[p[1]] + a_name = str(p[1]) + if len(p) == 5: + res = '' + a_len = alias['length'] + for i in range(int(p[3]), int(p[3])+1 ): + res = res + a_name + str(i) + '+ ' + if len(p) == 7: + res = '' + a_len = int(p[5]) - int(p[3]) + 1 + for i in range(int(p[3]), int(p[5])+1): + res = res + a_name + str(i) + '+ ' + res = res.strip('+ ') + p[0] = {'list' : res, 'name' : a_name, 'len' : a_len } + +def p_q_equal_atom2(p): + ''' q_equal_atom_2 : q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET + | q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET + ''' + query_atom = {'construct' : p[1],'params_count' : 2 ,'number': 0 , 'equal' : p[5], + 'alias_list' : p[3]['alias_list'], + 'list' : p[3]['list'] , + 'list_len' : p[3]['list_len'] + } + p[0] = {'type': 'nl', 'body' :query_atom} + +def p_q_sum_atom(p): + ''' q_sum : SUM + | SUMATLEAST + | SUMATMOST + ''' + p[0] = p[1] + +def p_query_iden_3(p): + ''' q_iden_3 : EQUALATMOST + | EQUALATLEAST + | EQUALFEW ''' + p[0] = p[1] + +def p_query_iden_2(p): + ''' q_iden_2 : EQUALALL + | EQUALANY ''' + p[0] = p[1] + + +def p_q_alias_concat_wrap(p): + ''' q_alias_concat_wrap : alias_slice + | LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET + ''' + size = len(p) + if size == 4: + p[0] = p[2] + elif size == 2: + p[0] = {'list': p[1]['list'], 'alias_list' : [p[1]['name']], 'list_len' : p[1]['len'] } + + +def p_q_alias_concat(p): + ''' q_alias_concat : q_alias_concat BAR alias_slice + | alias_slice + ''' + size = len(p) + if size == 4: + l = p[1]['list'] + ' , ' + p[3]['list'] + a_list = p[1]['alias_list'] + [p[3]['name']] + a_len = p[1]['list_len'] + p[3]['len'] + p[0] = {'list': l , 'alias_list' : a_list, 'list_len': a_len } + + elif size == 2: + p[0] = {'list': p[1]['list'], 'alias_list' : [p[1]['name']], 'list_len' : p[1]['len'] } + + +def p_alias_slice(p): + ''' alias_slice : ALIAS + | ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET''' + alias = _alias[p[1]] + a_name = str(p[1]) + if len(p) == 2: + res = '' + a_len = alias['length'] + for i in range(1, a_len+1 ): + res = res + a_name + str(i) + ', ' + if len(p) == 7: + res = '' + a_len = int(p[5]) - int(p[3]) + 1 + for i in range(p[3], p[5] ): + res = res + a_name + str(i) + ', ' + + res = res.strip(', ') + p[0] = {'list' : res, 'name' : a_name, 'len' : a_len } + +############################### ME :- constructer :- me_atom ################ +def p_me_atom(p): + ''' me_atom : a_expression_atom ''' + res = {'type' : 'me', 'body': p[1]} + p[0] = res + +############################### ME :- a_expression_atom ######################## +def p_a_expr_atom_e(p): + ''' a_expression_atom : a_expression EQUAL a_expression ''' + p[0] = p[1] + ' =:= ' + p[3] + +def p_a_expr_atom_ne(p): + ''' a_expression_atom : a_expression NOTEQUAL a_expression ''' + p[0] = p[1] + ' =\= ' + p[3] + +def p_a_expr_atom_ge(p): + ''' a_expression_atom : a_expression GREATEREQUAL a_expression ''' + p[0] = p[1] + ' >= ' + p[3] + +def p_a_expr_atom_g(p): + ''' a_expression_atom : a_expression GREATER a_expression ''' + p[0] = p[1] + ' > ' + p[3] +def p_a_expr_atom_le(p): + ''' a_expression_atom : a_expression LESSEQUAL a_expression ''' + p[0] = p[1] + ' =< ' + p[3] + +def p_a_expr_atom_l(p): + ''' a_expression_atom : a_expression LESS a_expression ''' + p[0] = p[1] + ' < ' + p[3] + +def p_a_expression_plus(p): + 'a_expression : a_expression PLUS a_term' + p[0] = str(p[1]) + ' + ' + str(p[3]) + +def p_a_expression_minus(p): + 'a_expression : a_expression MINUS a_term' + p[0] = str(p[1]) + ' - ' + str(p[3]) + +def p_a_expression_term(p): + 'a_expression : a_term' + p[0] = str(p[1]) + +def p_term_times(p): + 'a_term : a_term TIMES a_factor' + p[0] = str(p[1]) + ' * ' + str(p[3]) + +def p_term_div(p): + 'a_term : a_term DIVIDE a_factor' + p[0] = str(p[1]) + ' / ' + str(p[3]) + +def p_term_factor(p): + 'a_term : a_factor' + p[0] = p[1] + +def p_factor_num(p): + ''' a_factor : NUMBER + | ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET + ''' + if len(p) == 2: + p[0] = str(p[1]) + if len(p) == 5: + p[0] = str(p[1]) + str(p[3]) + +def p_factor_expr(p): + 'a_factor : LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET' + p[0] = '( ' + str(p[2]) + ' )' + + +############################### ME END ######################################## + + +def p_error(p): + print("Syntax error in input!", p) + + + +# Catastrophic erro-r handler + +probQparser = yacc.yacc() + + +def parse(data, debug=0): + probQparser.error = 0 + p = probQparser.parse(data, debug=debug) + if probQparser.error: + return None + return p diff --git a/probQparser/parsetab.py b/probQparser/parsetab.py index 1ae09b4..a0dc08e 100644 --- a/probQparser/parsetab.py +++ b/probQparser/parsetab.py @@ -1,108 +1,118 @@ - -# parsetab.py -# This file is automatically generated. Do not edit. -_tabversion = '3.5' - -_lr_method = 'LALR' - -_lr_signature = '34E70C4E90C6B1A97FC2FA873DF1F241' - -_lr_action_items = {'EQUALALL':([13,40,41,54,64,],[20,20,20,20,20,]),'TIMES':([21,29,38,88,91,96,97,103,123,],[-76,65,-77,65,65,-74,-75,-79,-78,]),'LEFTCURLYBRACE':([14,44,45,127,],[-7,76,-22,-21,]),'RIGHTSMALLBRACKET':([21,24,25,26,29,34,35,36,37,38,39,48,49,50,51,53,70,71,72,73,74,75,84,86,88,89,90,91,92,93,94,95,96,97,103,104,106,108,110,111,112,113,114,115,116,118,123,124,125,126,129,130,131,132,135,136,143,144,146,147,149,150,],[-76,-47,-41,-48,-73,-38,-64,-36,-46,-77,69,-13,-12,-14,81,-10,-42,103,104,-26,-25,-7,-35,-70,-71,-66,-68,-72,-67,-65,-69,-37,-74,-75,-79,-43,-28,127,-7,-7,-15,-16,-17,-18,-11,103,-78,-27,-24,-23,139,-32,-33,140,143,144,-52,-51,149,150,-50,-49,]),'IDEN':([6,10,18,80,82,83,105,120,141,],[12,14,48,112,114,48,124,136,147,]),'AND':([21,24,25,26,28,29,34,35,37,38,70,86,88,89,90,91,92,93,94,95,96,97,103,104,123,143,144,149,150,],[-76,-47,-41,-48,64,-73,-45,-64,-46,-77,-42,-70,-71,-66,-68,-72,-67,-65,-69,-44,-74,-75,-79,-43,-78,-52,-51,-50,-49,]),'GREATEREQUAL':([21,23,29,38,71,88,91,96,97,103,123,],[-76,61,-73,-77,61,-71,-72,-74,-75,-79,-78,]),'RIGHTCURLYBRACE':([109,],[128,]),'ALIAS':([0,2,3,4,5,7,8,10,11,13,16,17,40,41,54,56,57,58,59,60,61,62,63,64,65,66,67,69,77,81,87,101,117,128,137,139,140,],[1,-5,1,-6,-4,-2,-3,15,-1,33,-19,-8,33,33,33,33,33,33,33,33,33,33,33,33,33,33,98,-34,-20,-9,33,98,98,-29,98,-30,-31,]),'PLUS':([21,23,29,38,71,86,88,89,90,91,92,93,94,96,97,103,118,123,],[-76,57,-73,-77,57,57,-71,57,57,-72,57,57,57,-74,-75,-79,57,-78,]),'NOTEQUAL':([21,23,29,38,71,88,91,96,97,103,123,],[-76,58,-73,-77,58,-71,-72,-74,-75,-79,-78,]),'DIVIDE':([21,29,38,88,91,96,97,103,123,],[-76,66,-77,66,66,-74,-75,-79,-78,]),'FLOAT':([18,43,83,107,],[52,74,52,126,]),'DOT':([15,16,77,128,],[46,47,-20,-29,]),'ROLL':([46,47,],[78,79,]),'EQUALFEW':([13,40,41,54,64,],[27,27,27,27,27,]),'SEMICOLON':([48,49,50,53,112,113,114,115,116,],[-13,-12,-14,83,-15,-16,-17,-18,-11,]),'EQUALATLEAST':([13,40,41,54,64,],[31,31,31,31,31,]),'EQUALANY':([13,40,41,54,64,],[32,32,32,32,32,]),'GREATER':([21,23,29,38,71,88,91,96,97,103,123,],[-76,59,-73,-77,59,-71,-72,-74,-75,-79,-78,]),'MINUS':([21,23,29,38,71,86,88,89,90,91,92,93,94,96,97,103,118,123,],[-76,60,-73,-77,60,60,-71,60,60,-72,60,60,60,-74,-75,-79,60,-78,]),'ASSIGNMENT':([1,],[10,]),'$end':([2,3,4,5,7,8,11,16,17,69,77,81,128,139,140,],[-5,0,-6,-4,-2,-3,-1,-19,-8,-34,-20,-9,-29,-30,-31,]),'RIGHTSQRBRACKET':([98,102,121,122,145,148,151,],[-62,123,138,-61,-60,151,-63,]),'NUMBER':([13,18,40,41,43,54,55,56,57,58,59,60,61,62,63,64,65,66,68,76,80,82,83,87,107,110,111,119,120,141,142,],[38,50,38,38,73,38,85,38,38,38,38,38,38,38,38,38,38,38,102,109,113,115,50,38,125,130,130,134,135,146,148,]),'DOUBLECOLON':([50,52,],[80,82,]),'LESS':([21,23,29,38,71,88,91,96,97,103,123,],[-76,56,-73,-77,56,-71,-72,-74,-75,-79,-78,]),'COLON':([134,],[142,]),'BAR':([73,74,75,98,121,122,125,126,145,151,],[-26,-25,105,-62,137,-61,-24,-23,-60,-63,]),'NOT':([13,40,41,54,64,],[40,40,40,40,40,]),'QUERY':([0,2,3,4,5,7,8,11,16,17,69,77,81,128,139,140,],[9,-5,9,-6,-4,-2,-3,-1,-19,-8,-34,-20,-9,-29,-30,-31,]),'LEFTSQRBRACKET':([33,67,98,117,],[68,101,119,101,]),'ENTITY':([0,2,3,4,5,7,8,11,16,17,69,77,81,128,139,140,],[6,-5,6,-6,-4,-2,-3,-1,-19,-8,-34,-20,-9,-29,-30,-31,]),'OR':([19,21,24,25,26,29,34,35,36,37,38,70,84,86,88,89,90,91,92,93,94,95,96,97,103,104,123,143,144,149,150,],[54,-76,-47,-41,-48,-73,-38,-64,-40,-46,-77,-42,-39,-70,-71,-66,-68,-72,-67,-65,-69,-37,-74,-75,-79,-43,-78,-52,-51,-50,-49,]),'COMMA':([73,74,75,85,98,99,100,125,126,133,138,151,],[-26,-25,107,117,-62,-58,120,-24,-23,141,-59,-63,]),'LEFTSMALLBRACKET':([9,12,13,14,20,22,27,30,31,32,40,41,42,54,56,57,58,59,60,61,62,63,64,65,66,78,79,87,],[13,18,41,43,-56,55,-55,67,-54,-57,41,41,-53,41,87,87,87,87,87,87,87,87,41,87,87,110,111,87,]),'LESSEQUAL':([21,23,29,38,71,88,91,96,97,103,123,],[-76,63,-73,-77,63,-71,-72,-74,-75,-79,-78,]),'EQUAL':([21,23,29,38,71,88,91,96,97,103,123,],[-76,62,-73,-77,62,-71,-72,-74,-75,-79,-78,]),'EQUALATMOST':([13,40,41,54,64,],[42,42,42,42,42,]),} - -_lr_action = {} -for _k, _v in _lr_action_items.items(): - for _x,_y in zip(_v[0],_v[1]): - if not _x in _lr_action: _lr_action[_x] = {} - _lr_action[_x][_k] = _y -del _lr_action_items - -_lr_goto_items = {'ed_feature':([12,],[17,]),'q_term_list':([13,41,],[19,19,]),'ed_feature_inner':([18,],[51,]),'q_iden_3':([13,40,41,54,64,],[22,22,22,22,22,]),'a_expression':([13,40,41,54,56,58,59,61,62,63,64,87,],[23,23,71,23,86,89,90,92,93,94,23,118,]),'entity_prop_prob':([18,],[53,]),'ei_flag_option':([75,],[108,]),'alias_slice':([67,101,117,137,],[99,122,99,145,]),'a_factor':([13,40,41,54,56,57,58,59,60,61,62,63,64,65,66,87,],[21,21,21,21,21,21,21,21,21,21,21,21,21,96,97,21,]),'q_equal_atom_2':([13,40,41,54,64,],[24,24,24,24,24,]),'entity_initialize_wrap':([0,3,],[5,5,]),'entity_prop_prob_atom':([18,83,],[49,116,]),'q_atom':([13,40,41,54,64,],[25,25,25,25,25,]),'me_atom':([13,40,41,54,64,],[26,26,26,26,26,]),'a_expression_atom':([13,40,41,54,64,],[35,35,35,35,35,]),'empty':([14,75,110,111,],[45,106,131,131,]),'q_term':([13,41,54,],[36,36,84,]),'q_iden_2':([13,40,41,54,64,],[30,30,30,30,30,]),'ei_params':([14,],[44,]),'entity_action':([0,3,],[2,2,]),'query_wrap':([0,3,],[4,4,]),'program':([0,],[3,]),'option_number':([110,111,],[129,132,]),'ei_number':([44,],[77,]),'entity_initialize':([10,],[16,]),'q_factor_list':([13,41,54,],[28,28,28,]),'q_factor':([13,40,41,54,64,],[34,70,34,34,95,]),'q_alias_concat_wrap':([67,117,],[100,133,]),'q_alias_concat':([101,],[121,]),'a_term':([13,40,41,54,56,57,58,59,60,61,62,63,64,87,],[29,29,29,29,29,88,29,29,91,29,29,29,29,29,]),'q_expr':([13,41,],[39,72,]),'q_equal_atom_3':([13,40,41,54,64,],[37,37,37,37,37,]),'statement':([0,3,],[7,11,]),'entity_def':([0,3,],[8,8,]),'float_list':([43,],[75,]),} - -_lr_goto = {} -for _k, _v in _lr_goto_items.items(): - for _x, _y in zip(_v[0], _v[1]): - if not _x in _lr_goto: _lr_goto[_x] = {} - _lr_goto[_x][_k] = _y -del _lr_goto_items -_lr_productions = [ - ("S' -> program","S'",1,None,None,None), - ('program -> program statement','program',2,'p_program','parser.py',32), - ('program -> statement','program',1,'p_program_single','parser.py',37), - ('statement -> entity_def','statement',1,'p_statement_entity_def','parser.py',44), - ('statement -> entity_initialize_wrap','statement',1,'p_statement_entity_initialize','parser.py',48), - ('statement -> entity_action','statement',1,'p_statement_entity_assignment','parser.py',52), - ('statement -> query_wrap','statement',1,'p_statement_query','parser.py',56), - ('empty -> ','empty',0,'p_empty','parser.py',65), - ('entity_def -> ENTITY IDEN ed_feature','entity_def',3,'p_entity_def','parser.py',76), - ('ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET','ed_feature',3,'p_ed_feature','parser.py',123), - ('ed_feature_inner -> entity_prop_prob','ed_feature_inner',1,'p_ed_feature_inner','parser.py',127), - ('entity_prop_prob -> entity_prop_prob SEMICOLON entity_prop_prob_atom','entity_prop_prob',3,'p_entity_prop_prob','parser.py',131), - ('entity_prop_prob -> entity_prop_prob_atom','entity_prop_prob',1,'p_entity_prop_prob_single','parser.py',137), - ('entity_prop_prob_atom -> IDEN','entity_prop_prob_atom',1,'p_entity_prop_prob_atom','parser.py',141), - ('entity_prop_prob_atom -> NUMBER','entity_prop_prob_atom',1,'p_entity_prop_prob_atom','parser.py',142), - ('entity_prop_prob_atom -> NUMBER DOUBLECOLON IDEN','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_n','parser.py',147), - ('entity_prop_prob_atom -> NUMBER DOUBLECOLON NUMBER','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_n','parser.py',148), - ('entity_prop_prob_atom -> FLOAT DOUBLECOLON IDEN','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_f','parser.py',153), - ('entity_prop_prob_atom -> FLOAT DOUBLECOLON NUMBER','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_f','parser.py',154), - ('entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize','entity_initialize_wrap',3,'p_entity_initialize_wrap','parser.py',163), - ('entity_initialize -> IDEN ei_params ei_number','entity_initialize',3,'p_entity_initialize','parser.py',172), - ('ei_params -> LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET','ei_params',4,'p_ei_params','parser.py',190), - ('ei_params -> empty','ei_params',1,'p_ei_params_empty','parser.py',194), - ('float_list -> float_list COMMA FLOAT','float_list',3,'p_float_list','parser.py',198), - ('float_list -> float_list COMMA NUMBER','float_list',3,'p_float_list','parser.py',199), - ('float_list -> FLOAT','float_list',1,'p_float_list_single','parser.py',205), - ('float_list -> NUMBER','float_list',1,'p_float_list_single','parser.py',206), - ('ei_flag_option -> BAR IDEN','ei_flag_option',2,'p_ei_flag','parser.py',211), - ('ei_flag_option -> empty','ei_flag_option',1,'p_ei_flag','parser.py',212), - ('ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE','ei_number',3,'p_ei_number','parser.py',220), - ('entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET','entity_action',8,'p_entity_action','parser.py',227), - ('entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET','entity_action',8,'p_entity_action_e','parser.py',245), - ('option_number -> NUMBER','option_number',1,'p_option_number','parser.py',259), - ('option_number -> empty','option_number',1,'p_option_number_wo','parser.py',263), - ('query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET','query_wrap',4,'p_query_wrap','parser.py',273), - ('q_expr -> q_term_list OR q_term','q_expr',3,'p_q_expr','parser.py',283), - ('q_expr -> q_term','q_expr',1,'p_q_expr_s','parser.py',291), - ('q_term -> q_factor_list AND q_factor','q_term',3,'p_q_term','parser.py',295), - ('q_term -> q_factor','q_term',1,'p_q_term_s','parser.py',303), - ('q_term_list -> q_term_list OR q_term','q_term_list',3,'p_q_term_list','parser.py',307), - ('q_term_list -> q_term','q_term_list',1,'p_q_term_list_s','parser.py',311), - ('q_factor -> q_atom','q_factor',1,'p_q_factor_a','parser.py',316), - ('q_factor -> NOT q_factor','q_factor',2,'p_q_factor_n','parser.py',320), - ('q_factor -> LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET','q_factor',3,'p_q_factor_e','parser.py',326), - ('q_factor_list -> q_factor_list AND q_factor','q_factor_list',3,'p_q_factor_list','parser.py',330), - ('q_factor_list -> q_factor','q_factor_list',1,'p_q_factor_list_s','parser.py',334), - ('q_atom -> q_equal_atom_3','q_atom',1,'p_q_atom','parser.py',339), - ('q_atom -> q_equal_atom_2','q_atom',1,'p_q_atom','parser.py',340), - ('q_atom -> me_atom','q_atom',1,'p_q_atom','parser.py',341), - ('q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET','q_equal_atom_3',8,'p_q_equal_atom3','parser.py',349), - ('q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET','q_equal_atom_3',8,'p_q_equal_atom3','parser.py',350), - ('q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET','q_equal_atom_2',6,'p_q_equal_atom2','parser.py',361), - ('q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET','q_equal_atom_2',6,'p_q_equal_atom2','parser.py',362), - ('q_iden_3 -> EQUALATMOST','q_iden_3',1,'p_query_iden_3','parser.py',373), - ('q_iden_3 -> EQUALATLEAST','q_iden_3',1,'p_query_iden_3','parser.py',374), - ('q_iden_3 -> EQUALFEW','q_iden_3',1,'p_query_iden_3','parser.py',375), - ('q_iden_2 -> EQUALALL','q_iden_2',1,'p_query_iden_2','parser.py',379), - ('q_iden_2 -> EQUALANY','q_iden_2',1,'p_query_iden_2','parser.py',380), - ('q_alias_concat_wrap -> alias_slice','q_alias_concat_wrap',1,'p_q_alias_concat_wrap','parser.py',385), - ('q_alias_concat_wrap -> LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET','q_alias_concat_wrap',3,'p_q_alias_concat_wrap','parser.py',386), - ('q_alias_concat -> q_alias_concat BAR alias_slice','q_alias_concat',3,'p_q_alias_concat','parser.py',396), - ('q_alias_concat -> alias_slice','q_alias_concat',1,'p_q_alias_concat','parser.py',397), - ('alias_slice -> ALIAS','alias_slice',1,'p_alias_slice','parser.py',411), - ('alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET','alias_slice',6,'p_alias_slice','parser.py',412), - ('me_atom -> a_expression_atom','me_atom',1,'p_me_atom','parser.py',431), - ('a_expression_atom -> a_expression EQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_e','parser.py',437), - ('a_expression_atom -> a_expression NOTEQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_ne','parser.py',441), - ('a_expression_atom -> a_expression GREATEREQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_ge','parser.py',445), - ('a_expression_atom -> a_expression GREATER a_expression','a_expression_atom',3,'p_a_expr_atom_g','parser.py',449), - ('a_expression_atom -> a_expression LESSEQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_le','parser.py',452), - ('a_expression_atom -> a_expression LESS a_expression','a_expression_atom',3,'p_a_expr_atom_l','parser.py',456), - ('a_expression -> a_expression PLUS a_term','a_expression',3,'p_a_expression_plus','parser.py',460), - ('a_expression -> a_expression MINUS a_term','a_expression',3,'p_a_expression_minus','parser.py',464), - ('a_expression -> a_term','a_expression',1,'p_a_expression_term','parser.py',468), - ('a_term -> a_term TIMES a_factor','a_term',3,'p_term_times','parser.py',472), - ('a_term -> a_term DIVIDE a_factor','a_term',3,'p_term_div','parser.py',476), - ('a_term -> a_factor','a_term',1,'p_term_factor','parser.py',480), - ('a_factor -> NUMBER','a_factor',1,'p_factor_num','parser.py',484), - ('a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET','a_factor',4,'p_factor_num','parser.py',485), - ('a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET','a_factor',3,'p_factor_expr','parser.py',493), -] + +# parsetab.py +# This file is automatically generated. Do not edit. +_tabversion = '3.10' + +_lr_method = 'LALR' + +_lr_signature = 'leftPLUSMINUSleftNOTANDORIDEN ALIAS E_ACTION B_ACTION COMMENT ASSIGNMENT COMMA DOT SEMICOLON COLON BAR DOUBLECOLON LEFTSQRBRACKET RIGHTSQRBRACKET LEFTSMALLBRACKET RIGHTSMALLBRACKET LEFTCURLYBRACE RIGHTCURLYBRACE NUMBER EQUAL NOTEQUAL GREATEREQUAL GREATER LESSEQUAL LESS SUM SUMATMOST SUMATLEAST FRACTION FLOAT PLUS MINUS TIMES DIVIDE BUCKET ENTITY ROLL FLAG ACTION PICK QUERY EVIDENCE EQUAL EQUALATMOST EQUALATLEAST EQUALFEW EQUALALL EQUALANY SUM SUMATMOST SUMATLEAST AND OR NOT ODD EVENprogram : program statement program : statement statement : entity_def statement : entity_initialize_wrap statement : entity_action statement : query_wrap empty : entity_def : ENTITY IDEN ed_feature ed_feature : LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET ed_feature_inner : entity_prop_prob entity_prop_prob : entity_prop_prob SEMICOLON entity_prop_prob_atom entity_prop_prob : entity_prop_prob_atom entity_prop_prob_atom : IDEN\n | NUMBER\n entity_prop_prob_atom : NUMBER DOUBLECOLON IDEN \n | NUMBER DOUBLECOLON NUMBER\n entity_prop_prob_atom : FLOAT DOUBLECOLON IDEN\n | FLOAT DOUBLECOLON NUMBER\n entity_initialize_wrap : ALIAS ASSIGNMENT entity_initialize entity_initialize : IDEN ei_params ei_number ei_params : LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET ei_params : empty float_list : float_list COMMA FLOAT\n | float_list COMMA NUMBER\n float_list : FLOAT\n | NUMBER\n ei_flag_option : BAR IDEN\n | empty\n ei_number : LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE entity_action : ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET\n entity_action : ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET option_number : NUMBER option_number : empty query_wrap : QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET q_expr : q_term_list OR q_term q_expr : q_term q_term : q_factor_list AND q_factor q_term : q_factor q_term_list : q_term_list OR q_term q_term_list : q_term q_factor : q_atom q_factor : NOT q_factor q_factor : LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET q_factor_list : q_factor_list AND q_factor q_factor_list : q_factor q_atom : q_equal_atom_3\n | q_equal_atom_2\n | q_sum_atom\n | me_atom\n q_equal_atom_3 : q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET\n | q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET\n q_sum_atom : q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET\n \n \n q_alias_sum_concat_wrap : LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET\n | q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap\n | q_alias_sum_concat_wrap_atom\n\n \n q_alias_sum_concat_wrap_atom : ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET\n | ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET\n q_equal_atom_2 : q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET\n | q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET\n q_sum : SUM \n | SUMATLEAST\n | SUMATMOST\n q_iden_3 : EQUALATMOST\n | EQUALATLEAST\n | EQUALFEW q_iden_2 : EQUALALL\n | EQUALANY q_alias_concat_wrap : alias_slice\n | LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET\n q_alias_concat : q_alias_concat BAR alias_slice\n | alias_slice\n alias_slice : ALIAS\n | ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET me_atom : a_expression_atom a_expression_atom : a_expression EQUAL a_expression a_expression_atom : a_expression NOTEQUAL a_expression a_expression_atom : a_expression GREATEREQUAL a_expression a_expression_atom : a_expression GREATER a_expression a_expression_atom : a_expression LESSEQUAL a_expression a_expression_atom : a_expression LESS a_expression a_expression : a_expression PLUS a_terma_expression : a_expression MINUS a_terma_expression : a_terma_term : a_term TIMES a_factora_term : a_term DIVIDE a_factora_term : a_factor a_factor : NUMBER\n | ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET\n a_factor : LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET' + +_lr_action_items = {'ENTITY':([0,1,2,3,4,5,6,10,14,17,61,79,85,142,157,158,],[7,7,-2,-3,-4,-5,-6,-1,-8,-19,-34,-9,-20,-29,-30,-31,]),'ALIAS':([0,1,2,3,4,5,6,10,12,13,14,17,19,26,61,62,63,66,67,68,69,70,71,72,73,74,75,76,77,79,85,97,99,104,127,134,142,151,153,157,158,],[8,8,-2,-3,-4,-5,-6,-1,16,47,-8,-19,47,47,-34,47,47,98,102,47,47,47,47,47,47,47,47,47,47,-9,-20,98,102,47,98,102,-29,98,102,-30,-31,]),'QUERY':([0,1,2,3,4,5,6,10,14,17,61,79,85,142,157,158,],[9,9,-2,-3,-4,-5,-6,-1,-8,-19,-34,-9,-20,-29,-30,-31,]),'$end':([1,2,3,4,5,6,10,14,17,61,79,85,142,157,158,],[0,-2,-3,-4,-5,-6,-1,-8,-19,-34,-9,-20,-29,-30,-31,]),'IDEN':([7,12,15,80,81,82,125,128,159,],[11,18,51,51,117,118,146,148,169,]),'ASSIGNMENT':([8,],[12,]),'LEFTSMALLBRACKET':([9,11,13,18,19,26,31,33,34,36,37,38,39,40,41,42,43,62,63,67,68,69,70,71,72,73,74,75,76,77,83,84,104,134,153,],[13,15,19,57,19,19,65,66,67,-63,-64,-65,-66,-67,-60,-61,-62,19,19,99,104,104,104,104,104,104,104,104,104,104,120,121,104,99,99,]),'NOT':([13,19,26,62,63,],[26,26,26,26,26,]),'EQUALATMOST':([13,19,26,62,63,],[36,36,36,36,36,]),'EQUALATLEAST':([13,19,26,62,63,],[37,37,37,37,37,]),'EQUALFEW':([13,19,26,62,63,],[38,38,38,38,38,]),'EQUALALL':([13,19,26,62,63,],[39,39,39,39,39,]),'EQUALANY':([13,19,26,62,63,],[40,40,40,40,40,]),'SUM':([13,19,26,62,63,],[41,41,41,41,41,]),'SUMATLEAST':([13,19,26,62,63,],[42,42,42,42,42,]),'SUMATMOST':([13,19,26,62,63,],[43,43,43,43,43,]),'NUMBER':([13,15,19,26,57,62,63,65,68,69,70,71,72,73,74,75,76,77,78,80,81,82,86,104,120,121,124,128,131,133,135,159,163,167,],[32,52,32,32,89,32,32,94,32,32,32,32,32,32,32,32,32,32,114,52,116,119,122,32,139,139,145,149,152,154,156,168,170,172,]),'FLOAT':([15,57,80,124,],[53,88,53,144,]),'DOT':([16,17,85,142,],[54,55,-20,-29,]),'LEFTCURLYBRACE':([18,56,58,143,],[-7,86,-22,-21,]),'RIGHTSMALLBRACKET':([20,22,24,25,27,28,29,30,32,35,45,46,48,49,50,51,52,59,60,64,87,88,89,90,91,92,93,101,103,105,106,107,108,109,110,111,112,113,115,116,117,118,119,120,121,123,126,136,137,138,139,140,141,144,145,146,148,149,154,155,160,161,164,165,166,168,169,171,173,174,176,],[61,-36,-38,-41,-46,-47,-48,-49,-87,-74,-83,-86,79,-10,-12,-13,-14,90,91,-42,-7,-25,-26,-43,-89,-35,-37,-55,-75,-76,-77,-78,-79,-80,-81,-82,-84,-85,-11,-16,-15,-17,-18,-7,-7,143,-28,91,-88,157,-32,-33,158,-23,-24,-27,160,161,165,-54,-58,-59,171,-52,-56,173,174,-53,-51,-50,-57,]),'OR':([21,22,24,25,27,28,29,30,32,35,45,46,64,90,91,92,93,103,105,106,107,108,109,110,111,112,113,137,160,161,165,173,174,],[62,-40,-38,-41,-46,-47,-48,-49,-87,-74,-83,-86,-42,-43,-89,-39,-37,-75,-76,-77,-78,-79,-80,-81,-82,-84,-85,-88,-58,-59,-52,-51,-50,]),'AND':([23,24,25,27,28,29,30,32,35,45,46,64,90,91,93,103,105,106,107,108,109,110,111,112,113,137,160,161,165,173,174,],[63,-45,-41,-46,-47,-48,-49,-87,-74,-83,-86,-42,-43,-89,-44,-75,-76,-77,-78,-79,-80,-81,-82,-84,-85,-88,-58,-59,-52,-51,-50,]),'TIMES':([32,45,46,91,110,111,112,113,137,],[-87,76,-86,-89,76,76,-84,-85,-88,]),'DIVIDE':([32,45,46,91,110,111,112,113,137,],[-87,77,-86,-89,77,77,-84,-85,-88,]),'EQUAL':([32,44,45,46,60,91,110,111,112,113,137,],[-87,68,-83,-86,68,-89,-81,-82,-84,-85,-88,]),'NOTEQUAL':([32,44,45,46,60,91,110,111,112,113,137,],[-87,69,-83,-86,69,-89,-81,-82,-84,-85,-88,]),'GREATEREQUAL':([32,44,45,46,60,91,110,111,112,113,137,],[-87,70,-83,-86,70,-89,-81,-82,-84,-85,-88,]),'GREATER':([32,44,45,46,60,91,110,111,112,113,137,],[-87,71,-83,-86,71,-89,-81,-82,-84,-85,-88,]),'LESSEQUAL':([32,44,45,46,60,91,110,111,112,113,137,],[-87,72,-83,-86,72,-89,-81,-82,-84,-85,-88,]),'LESS':([32,44,45,46,60,91,110,111,112,113,137,],[-87,73,-83,-86,73,-89,-81,-82,-84,-85,-88,]),'PLUS':([32,44,45,46,60,91,103,105,106,107,108,109,110,111,112,113,136,137,],[-87,74,-83,-86,74,-89,74,74,74,74,74,74,-81,-82,-84,-85,74,-88,]),'MINUS':([32,44,45,46,60,91,103,105,106,107,108,109,110,111,112,113,136,137,],[-87,75,-83,-86,75,-89,75,75,75,75,75,75,-81,-82,-84,-85,75,-88,]),'LEFTSQRBRACKET':([47,66,98,102,127,],[78,97,131,135,97,]),'SEMICOLON':([49,50,51,52,115,116,117,118,119,],[80,-12,-13,-14,-11,-16,-15,-17,-18,]),'DOUBLECOLON':([52,53,],[81,82,]),'ROLL':([54,55,],[83,84,]),'COMMA':([87,88,89,94,95,96,98,100,101,144,145,147,150,155,166,171,175,176,],[124,-25,-26,127,128,-68,-72,133,-55,-23,-24,159,-69,-54,-56,-53,-73,-57,]),'BAR':([87,88,89,98,101,129,130,132,144,145,162,166,175,176,],[125,-25,-26,-72,134,151,-71,153,-23,-24,-70,-56,-73,-57,]),'RIGHTSQRBRACKET':([98,114,129,130,156,162,170,172,175,],[-72,137,150,-71,166,-70,175,176,-73,]),'RIGHTCURLYBRACE':([122,],[142,]),'COLON':([152,156,],[163,167,]),} + +_lr_action = {} +for _k, _v in _lr_action_items.items(): + for _x,_y in zip(_v[0],_v[1]): + if not _x in _lr_action: _lr_action[_x] = {} + _lr_action[_x][_k] = _y +del _lr_action_items + +_lr_goto_items = {'program':([0,],[1,]),'statement':([0,1,],[2,10,]),'entity_def':([0,1,],[3,3,]),'entity_initialize_wrap':([0,1,],[4,4,]),'entity_action':([0,1,],[5,5,]),'query_wrap':([0,1,],[6,6,]),'ed_feature':([11,],[14,]),'entity_initialize':([12,],[17,]),'q_expr':([13,19,],[20,59,]),'q_term_list':([13,19,],[21,21,]),'q_term':([13,19,62,],[22,22,92,]),'q_factor_list':([13,19,62,],[23,23,23,]),'q_factor':([13,19,26,62,63,],[24,24,64,24,93,]),'q_atom':([13,19,26,62,63,],[25,25,25,25,25,]),'q_equal_atom_3':([13,19,26,62,63,],[27,27,27,27,27,]),'q_equal_atom_2':([13,19,26,62,63,],[28,28,28,28,28,]),'q_sum_atom':([13,19,26,62,63,],[29,29,29,29,29,]),'me_atom':([13,19,26,62,63,],[30,30,30,30,30,]),'q_iden_3':([13,19,26,62,63,],[31,31,31,31,31,]),'q_iden_2':([13,19,26,62,63,],[33,33,33,33,33,]),'q_sum':([13,19,26,62,63,],[34,34,34,34,34,]),'a_expression_atom':([13,19,26,62,63,],[35,35,35,35,35,]),'a_expression':([13,19,26,62,63,68,69,70,71,72,73,104,],[44,60,44,44,44,103,105,106,107,108,109,136,]),'a_term':([13,19,26,62,63,68,69,70,71,72,73,74,75,104,],[45,45,45,45,45,45,45,45,45,45,45,110,111,45,]),'a_factor':([13,19,26,62,63,68,69,70,71,72,73,74,75,76,77,104,],[46,46,46,46,46,46,46,46,46,46,46,46,46,112,113,46,]),'ed_feature_inner':([15,],[48,]),'entity_prop_prob':([15,],[49,]),'entity_prop_prob_atom':([15,80,],[50,115,]),'ei_params':([18,],[56,]),'empty':([18,87,120,121,],[58,126,140,140,]),'ei_number':([56,],[85,]),'float_list':([57,],[87,]),'q_alias_concat_wrap':([66,127,],[95,147,]),'alias_slice':([66,97,127,151,],[96,130,96,162,]),'q_alias_sum_concat_wrap':([67,134,153,],[100,155,164,]),'q_alias_sum_concat_wrap_atom':([67,99,134,153,],[101,132,101,101,]),'ei_flag_option':([87,],[123,]),'q_alias_concat':([97,],[129,]),'option_number':([120,121,],[138,141,]),} + +_lr_goto = {} +for _k, _v in _lr_goto_items.items(): + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_goto: _lr_goto[_x] = {} + _lr_goto[_x][_k] = _y +del _lr_goto_items +_lr_productions = [ + ("S' -> program","S'",1,None,None,None), + ('program -> program statement','program',2,'p_program','parser.py',36), + ('program -> statement','program',1,'p_program_single','parser.py',41), + ('statement -> entity_def','statement',1,'p_statement_entity_def','parser.py',48), + ('statement -> entity_initialize_wrap','statement',1,'p_statement_entity_initialize','parser.py',52), + ('statement -> entity_action','statement',1,'p_statement_entity_assignment','parser.py',56), + ('statement -> query_wrap','statement',1,'p_statement_query','parser.py',60), + ('empty -> ','empty',0,'p_empty','parser.py',69), + ('entity_def -> ENTITY IDEN ed_feature','entity_def',3,'p_entity_def','parser.py',80), + ('ed_feature -> LEFTSMALLBRACKET ed_feature_inner RIGHTSMALLBRACKET','ed_feature',3,'p_ed_feature','parser.py',129), + ('ed_feature_inner -> entity_prop_prob','ed_feature_inner',1,'p_ed_feature_inner','parser.py',133), + ('entity_prop_prob -> entity_prop_prob SEMICOLON entity_prop_prob_atom','entity_prop_prob',3,'p_entity_prop_prob','parser.py',137), + ('entity_prop_prob -> entity_prop_prob_atom','entity_prop_prob',1,'p_entity_prop_prob_single','parser.py',143), + ('entity_prop_prob_atom -> IDEN','entity_prop_prob_atom',1,'p_entity_prop_prob_atom','parser.py',147), + ('entity_prop_prob_atom -> NUMBER','entity_prop_prob_atom',1,'p_entity_prop_prob_atom','parser.py',148), + ('entity_prop_prob_atom -> NUMBER DOUBLECOLON IDEN','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_n','parser.py',153), + ('entity_prop_prob_atom -> NUMBER DOUBLECOLON NUMBER','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_n','parser.py',154), + ('entity_prop_prob_atom -> FLOAT DOUBLECOLON IDEN','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_f','parser.py',159), + ('entity_prop_prob_atom -> FLOAT DOUBLECOLON NUMBER','entity_prop_prob_atom',3,'p_entity_prop_prob_atom_f','parser.py',160), + ('entity_initialize_wrap -> ALIAS ASSIGNMENT entity_initialize','entity_initialize_wrap',3,'p_entity_initialize_wrap','parser.py',169), + ('entity_initialize -> IDEN ei_params ei_number','entity_initialize',3,'p_entity_initialize','parser.py',179), + ('ei_params -> LEFTSMALLBRACKET float_list ei_flag_option RIGHTSMALLBRACKET','ei_params',4,'p_ei_params','parser.py',197), + ('ei_params -> empty','ei_params',1,'p_ei_params_empty','parser.py',201), + ('float_list -> float_list COMMA FLOAT','float_list',3,'p_float_list','parser.py',205), + ('float_list -> float_list COMMA NUMBER','float_list',3,'p_float_list','parser.py',206), + ('float_list -> FLOAT','float_list',1,'p_float_list_single','parser.py',212), + ('float_list -> NUMBER','float_list',1,'p_float_list_single','parser.py',213), + ('ei_flag_option -> BAR IDEN','ei_flag_option',2,'p_ei_flag','parser.py',218), + ('ei_flag_option -> empty','ei_flag_option',1,'p_ei_flag','parser.py',219), + ('ei_number -> LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE','ei_number',3,'p_ei_number','parser.py',227), + ('entity_action -> ALIAS ASSIGNMENT ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET','entity_action',8,'p_entity_action','parser.py',234), + ('entity_action -> ALIAS ASSIGNMENT entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET','entity_action',8,'p_entity_action_e','parser.py',252), + ('option_number -> NUMBER','option_number',1,'p_option_number','parser.py',266), + ('option_number -> empty','option_number',1,'p_option_number_wo','parser.py',270), + ('query_wrap -> QUERY LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET','query_wrap',4,'p_query_wrap','parser.py',280), + ('q_expr -> q_term_list OR q_term','q_expr',3,'p_q_expr','parser.py',290), + ('q_expr -> q_term','q_expr',1,'p_q_expr_s','parser.py',298), + ('q_term -> q_factor_list AND q_factor','q_term',3,'p_q_term','parser.py',302), + ('q_term -> q_factor','q_term',1,'p_q_term_s','parser.py',310), + ('q_term_list -> q_term_list OR q_term','q_term_list',3,'p_q_term_list','parser.py',314), + ('q_term_list -> q_term','q_term_list',1,'p_q_term_list_s','parser.py',318), + ('q_factor -> q_atom','q_factor',1,'p_q_factor_a','parser.py',323), + ('q_factor -> NOT q_factor','q_factor',2,'p_q_factor_n','parser.py',327), + ('q_factor -> LEFTSMALLBRACKET q_expr RIGHTSMALLBRACKET','q_factor',3,'p_q_factor_e','parser.py',333), + ('q_factor_list -> q_factor_list AND q_factor','q_factor_list',3,'p_q_factor_list','parser.py',337), + ('q_factor_list -> q_factor','q_factor_list',1,'p_q_factor_list_s','parser.py',341), + ('q_atom -> q_equal_atom_3','q_atom',1,'p_q_atom','parser.py',346), + ('q_atom -> q_equal_atom_2','q_atom',1,'p_q_atom','parser.py',347), + ('q_atom -> q_sum_atom','q_atom',1,'p_q_atom','parser.py',348), + ('q_atom -> me_atom','q_atom',1,'p_q_atom','parser.py',349), + ('q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET','q_equal_atom_3',8,'p_q_equal_atom3','parser.py',357), + ('q_equal_atom_3 -> q_iden_3 LEFTSMALLBRACKET NUMBER COMMA q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET','q_equal_atom_3',8,'p_q_equal_atom3','parser.py',358), + ('q_sum_atom -> q_sum LEFTSMALLBRACKET q_alias_sum_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET','q_sum_atom',6,'p_q_sum','parser.py',369), + ('q_alias_sum_concat_wrap -> LEFTSMALLBRACKET q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap RIGHTSMALLBRACKET','q_alias_sum_concat_wrap',5,'p_q_alias_sum_concat_wrap','parser.py',382), + ('q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom BAR q_alias_sum_concat_wrap','q_alias_sum_concat_wrap',3,'p_q_alias_sum_concat_wrap','parser.py',383), + ('q_alias_sum_concat_wrap -> q_alias_sum_concat_wrap_atom','q_alias_sum_concat_wrap',1,'p_q_alias_sum_concat_wrap','parser.py',384), + ('q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET','q_alias_sum_concat_wrap_atom',4,'p_q_alias_sum_concat_wrap_atom','parser.py',407), + ('q_alias_sum_concat_wrap_atom -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET','q_alias_sum_concat_wrap_atom',6,'p_q_alias_sum_concat_wrap_atom','parser.py',408), + ('q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA IDEN RIGHTSMALLBRACKET','q_equal_atom_2',6,'p_q_equal_atom2','parser.py',426), + ('q_equal_atom_2 -> q_iden_2 LEFTSMALLBRACKET q_alias_concat_wrap COMMA NUMBER RIGHTSMALLBRACKET','q_equal_atom_2',6,'p_q_equal_atom2','parser.py',427), + ('q_sum -> SUM','q_sum',1,'p_q_sum_atom','parser.py',437), + ('q_sum -> SUMATLEAST','q_sum',1,'p_q_sum_atom','parser.py',438), + ('q_sum -> SUMATMOST','q_sum',1,'p_q_sum_atom','parser.py',439), + ('q_iden_3 -> EQUALATMOST','q_iden_3',1,'p_query_iden_3','parser.py',444), + ('q_iden_3 -> EQUALATLEAST','q_iden_3',1,'p_query_iden_3','parser.py',445), + ('q_iden_3 -> EQUALFEW','q_iden_3',1,'p_query_iden_3','parser.py',446), + ('q_iden_2 -> EQUALALL','q_iden_2',1,'p_query_iden_2','parser.py',450), + ('q_iden_2 -> EQUALANY','q_iden_2',1,'p_query_iden_2','parser.py',451), + ('q_alias_concat_wrap -> alias_slice','q_alias_concat_wrap',1,'p_q_alias_concat_wrap','parser.py',456), + ('q_alias_concat_wrap -> LEFTSQRBRACKET q_alias_concat RIGHTSQRBRACKET','q_alias_concat_wrap',3,'p_q_alias_concat_wrap','parser.py',457), + ('q_alias_concat -> q_alias_concat BAR alias_slice','q_alias_concat',3,'p_q_alias_concat','parser.py',467), + ('q_alias_concat -> alias_slice','q_alias_concat',1,'p_q_alias_concat','parser.py',468), + ('alias_slice -> ALIAS','alias_slice',1,'p_alias_slice','parser.py',482), + ('alias_slice -> ALIAS LEFTSQRBRACKET NUMBER COLON NUMBER RIGHTSQRBRACKET','alias_slice',6,'p_alias_slice','parser.py',483), + ('me_atom -> a_expression_atom','me_atom',1,'p_me_atom','parser.py',502), + ('a_expression_atom -> a_expression EQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_e','parser.py',508), + ('a_expression_atom -> a_expression NOTEQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_ne','parser.py',512), + ('a_expression_atom -> a_expression GREATEREQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_ge','parser.py',516), + ('a_expression_atom -> a_expression GREATER a_expression','a_expression_atom',3,'p_a_expr_atom_g','parser.py',520), + ('a_expression_atom -> a_expression LESSEQUAL a_expression','a_expression_atom',3,'p_a_expr_atom_le','parser.py',523), + ('a_expression_atom -> a_expression LESS a_expression','a_expression_atom',3,'p_a_expr_atom_l','parser.py',527), + ('a_expression -> a_expression PLUS a_term','a_expression',3,'p_a_expression_plus','parser.py',531), + ('a_expression -> a_expression MINUS a_term','a_expression',3,'p_a_expression_minus','parser.py',535), + ('a_expression -> a_term','a_expression',1,'p_a_expression_term','parser.py',539), + ('a_term -> a_term TIMES a_factor','a_term',3,'p_term_times','parser.py',543), + ('a_term -> a_term DIVIDE a_factor','a_term',3,'p_term_div','parser.py',547), + ('a_term -> a_factor','a_term',1,'p_term_factor','parser.py',551), + ('a_factor -> NUMBER','a_factor',1,'p_factor_num','parser.py',555), + ('a_factor -> ALIAS LEFTSQRBRACKET NUMBER RIGHTSQRBRACKET','a_factor',4,'p_factor_num','parser.py',556), + ('a_factor -> LEFTSMALLBRACKET a_expression RIGHTSMALLBRACKET','a_factor',3,'p_factor_expr','parser.py',564), +] diff --git a/probQsolver/__pycache__/solver.cpython-36.pyc b/probQsolver/__pycache__/solver.cpython-36.pyc new file mode 100644 index 0000000..b3bb585 Binary files /dev/null and b/probQsolver/__pycache__/solver.cpython-36.pyc differ diff --git a/probQsolver/solver.py b/probQsolver/solver.py index 22ab66e..a2b33dd 100644 --- a/probQsolver/solver.py +++ b/probQsolver/solver.py @@ -1,221 +1,241 @@ -import sys -import os -from random import randint - -class QNode(object): - def __init__(self,q_type, q_atom): - self.q_type = q_type # [and, or, not q_atom] - self.q_atom = q_atom - self.children = [] - - def add_child(self, obj): - self.children.append(obj) - - def __str__(self): - return 'TYPE:{}, CH:{}'.format(self.q_type, self.children) - - -def get_entity_layout(entity): - problog_string = '' - e_action_layout_atom = entity['entity'] + '_roll(L' - e_iden_layout = entity['entity'] + '(L' - name = entity['entity'] - for key, value in entity['feature'].items(): - new_p = 'P_' + str(name).strip().capitalize() + '_' + str(key) - e_action_layout_atom = e_action_layout_atom + ', ' + new_p - e_iden_layout = e_iden_layout + ', ' + new_p - - e_action_layout_atom = e_action_layout_atom + ', D' - e_iden_layout = e_iden_layout + ', D)' - entity_layout = '' - - for key, value in entity['feature'].items(): - p = 'P_' + str(name).strip().capitalize() + '_' + str(key) - n = str(key).strip() - entity_layout = entity_layout + p + ' :: ' + e_action_layout_atom + ', ' + n + '); ' - - entity_layout = entity_layout.strip('; ') + ' :- ' + e_iden_layout + '.' - - return entity_layout - -def get_entity_instance(instance): - e_instance_layout = instance['entity'] + '(' + instance['label'] + ', ' - for p in instance['params']: - e_instance_layout = e_instance_layout + str(p) + ', ' - - e_instance_layout = e_instance_layout + 'D ) :- between(1, ' + str(instance['count']) + ', D).' - - return e_instance_layout - -def get_entity_action(action): - alias = action['action_alias'] - ei = action['entity_instance'] - action_name = 'alias_' + alias.strip() - count = int(ei['count']) - - action_layout = action_name + '(' - for i in range(count): - action_layout = action_layout + alias + str(i+1) +', ' - - action_term = action_layout.strip(', ') + ')' - - action_layout = action_layout.strip(', ') + ') :- ' - - - flag = ei['label'] - params = ei['params'] - action_atom = ei['entity'] + '_roll(' + flag + ', ' - - for p in params: - action_atom = action_atom + str(p) + ', ' - - for i in range(count): - action_layout = action_layout + action_atom + str(i+1) + ', ' + alias + str(i+1) + ' ), ' - - action_layout = action_layout.strip(', ') + ' .' - - return [action_term , action_layout] - - -def get_alias_term_list(alias,start,end): - l = '' - for i in range(int(start),int(end)+1): - l = l + alias + str(i) +', ' - l = l.strip(', ') - return l - -def get_action_terms_and_list(aliases): - q_list = '' - q_actions = '' - for al in aliases: - q_list = q_list + get_alias_term_list(al['name'],1, al['length']) + ' ,' - q_actions = q_actions + al['return'] + ' ,' - q_list = q_list.strip(', ') - q_actions = q_actions.strip(', ') - return q_actions + ', L = [{}]'.format(q_list) - - -def q_tree_inorder(q_tree,q_alias): - ''' - returns a core query string to be added in query - ''' - if(q_tree.q_type == "q_atom"): - q_atom_str = q_add_atom(q_tree.q_atom,q_alias) - return q_atom_str - - query_str = '' - for child in q_tree.children: - q_atom_str = q_tree_inorder(child, q_alias) - if(q_tree.q_type == "and"): - query_str = query_str + q_atom_str + ' , ' - elif(q_tree.q_type == "or"): - query_str = query_str + q_atom_str + ' ; ' - elif(q_tree.q_type == "not"): - query_str = ' \+ ' + query_str + q_atom_str - else: - return("# SOMTHING BROKE") - - query_str = query_str.strip(',; ') - query_str = '( ' + query_str + ' )' - return query_str - - -def q_add_atom(q_atom,q_alias): - q_type = q_atom['type'] - body = q_atom['body'] - - if q_type == 'me': - query = '( ' + body + ' )' - # to do parse body to get alias list - return query - elif q_type == 'nl': - construct = body['construct'] - params_count = body['params_count'] - - num = body['number'] - equal = body['equal'] - - iden = str(randint(1000,9999)) - query = '( count([{}],{}, C{})'.format(body['list'],equal,iden) - if construct == 'equalAtmost': - query = query + ' , C{} =< {} )'.format(iden, num) - if construct == 'equalAtleast': - query = query + ' , C{} >= {} )'.format(iden,num) - if construct == 'equalFew': - query = query + ' , C{} = {} )'.format(iden,num) - if construct == 'equalAll': - query = query + ' , C{} = {} )'.format(iden,body['list_len']) - if construct == 'equalAny': - query = query + ' , C{} >= 1 )'.format(iden) - - alias_list = body['alias_list'] - q_alias += alias_list - - return query - - - - -class blackbox: - def __init__(self): - self.entities = {} - self.buckets = {} - self.alias = {} - self.entity_instances = [] - self.action ={} - self.query = {} - self.action_def = {} - - def add_enitity(self,entity): - entity_layout = get_entity_layout(entity) - self.entities[entity['entity']] = entity_layout - - def add_entity_instance(self,instance): - instance_layout = get_entity_instance(instance) - self.entity_instances.append(instance_layout) - - def add_entity_action(self,action): - action_layout = get_entity_action(action) - self.action[action['action_alias']] = action_layout[1] - self.action_def[action['action_alias']] = action_layout[0] - return action_layout[0] - - def add_query(self, query_tree): - q_alias = [] - query_core = q_tree_inorder(query_tree,q_alias) - q_alias_unique = list(set(q_alias)) - query_alias_def = '' - for al in q_alias_unique: - query_alias_def += self.action_def[str(al)] + ', ' - - query_name = str(randint(1000,9999)) - query_str = 'q({}) :- {} {} . '.format(query_name,query_alias_def,query_core) - self.query[query_name] = query_str - return - - def get_code(self): - code = '' - for key, value in self.entities.items(): - code = code + str(value) + '\n' - code = code + '\n' - for value in self.entity_instances: - code = code + str(value) + '\n' - code = code + '\n' - for key, value in self.action.items(): - code = code + str(value) + '\n' - code = code + '\n' - for key, value in self.query.items(): - code = code + str(value) + '\n' - code = code + '\n' - - count = ''' - -:- use_module(library(lists)). -count([],X,0). -count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. -count([X1|T],X,Z):- X1\=X,count(T,X,Z). - -''' - - code = code + count + 'query(q(_)).' - return code +import sys +import os +from random import randint + +class QNode(object): + def __init__(self,q_type, q_atom): + self.q_type = q_type # [and, or, not q_atom] + self.q_atom = q_atom + self.children = [] + + def add_child(self, obj): + self.children.append(obj) + + def __str__(self): + return 'TYPE:{}, CH:{}'.format(self.q_type, self.children) + +###################define entities####################### + +def get_entity_layout(entity): + problog_string = '' #initialising problog code + e_action_layout_atom = entity['entity'] + '_roll(L' + e_iden_layout = entity['entity'] + '(L' + name = entity['entity'] + for key, value in entity['feature'].items(): + new_p = 'P_' + str(name).strip().capitalize() + '_' + str(key) + e_action_layout_atom = e_action_layout_atom + ', ' + new_p + e_iden_layout = e_iden_layout + ', ' + new_p + + + e_action_layout_atom = e_action_layout_atom + ', D' + e_iden_layout = e_iden_layout + ', D)' + entity_layout = '' + + for key, value in entity['feature'].items(): + p = 'P_' + str(name).strip().capitalize() + '_' + str(key) + n = str(key).strip() + entity_layout = entity_layout + p + ' :: ' + e_action_layout_atom + ', ' + n + '); ' + + entity_layout = entity_layout.strip('; ') + ' :- ' + e_iden_layout + '.' + + return entity_layout + + +###################define instance####################### + +def get_entity_instance(instance): + e_instance_layout = instance['entity'] + '(' + instance['label'] + ', ' + for p in instance['params']: + e_instance_layout = e_instance_layout + str(p) + ', ' + + e_instance_layout = e_instance_layout + 'D ) :- between(1, ' + str(instance['count']) + ', D).' + + return e_instance_layout +###################define alias####################### +def get_entity_action(action): + alias = action['action_alias'] + ei = action['entity_instance'] + action_name = 'alias_' + alias.strip() + count = int(ei['count']) + + action_layout = action_name + '(' + for i in range(count): + action_layout = action_layout + alias + str(i+1) +', ' + + action_term = action_layout.strip(', ') + ')' + + action_layout = action_layout.strip(', ') + ') :- ' + + + flag = ei['label'] + params = ei['params'] + action_atom = ei['entity'] + '_roll(' + flag + ', ' + + for p in params: + action_atom = action_atom + str(p) + ', ' + + for i in range(count): + action_layout = action_layout + action_atom + str(i+1) + ', ' + alias + str(i+1) + ' ), ' + + action_layout = action_layout.strip(', ') + ' .' + + return [action_term , action_layout] + + +def get_alias_term_list(alias,start,end): + l = '' + for i in range(int(start),int(end)+1): + l = l + alias + str(i) +', ' + l = l.strip(', ') + return l + +def get_action_terms_and_list(aliases): + q_list = '' + q_actions = '' + for al in aliases: + q_list = q_list + get_alias_term_list(al['name'],1, al['length']) + ' ,' + q_actions = q_actions + al['return'] + ' ,' + q_list = q_list.strip(', ') + q_actions = q_actions.strip(', ') + return q_actions + ', L = [{}]'.format(q_list) + +#####################query######################### +def q_tree_inorder(q_tree,q_alias): + ''' + returns a core query string to be added in query + ''' + if(q_tree.q_type == "q_atom"): + q_atom_str = q_add_atom(q_tree.q_atom,q_alias) + return q_atom_str +#####################formin query string##################### + query_str = '' + for child in q_tree.children: + q_atom_str = q_tree_inorder(child, q_alias) + if(q_tree.q_type == "and"): + query_str = query_str + q_atom_str + ' , ' + elif(q_tree.q_type == "or"): + query_str = query_str + q_atom_str + ' ; ' + elif(q_tree.q_type == "not"): + query_str = ' \+ ' + query_str + q_atom_str + else: + return("# SOMTHING BROKE") + + query_str = query_str.strip(',; ') + query_str = '( ' + query_str + ' )' + return query_str + + +def q_add_atom(q_atom,q_alias): + q_type = q_atom['type'] + body = q_atom['body'] + + if q_type == 'me': + query = '( ' + body + ' )' + #print(body) + # to do parse body to get alias list + return query + elif q_type == 'nl': + construct = body['construct'] + params_count = body['params_count'] + + num = body['number'] + equal = body['equal'] + + iden = str(randint(1000,9999)) + query = '' + + if construct == 'equalAtmost': + query = '( count([{}],{}, C{})'.format(body['list'],equal,iden) + query = query + ' , C{} =< {} )'.format(iden, num) + if construct == 'sum' : + + query = query + ' ( {} =:= {} )'.format(body['list'],equal) + if construct == 'sumAtmost' : + + query = query + ' ,( {} >= {} )'.format(body['list'],equal) + if construct == 'sumAtleast' : + + query = query + ' , ({} <= {} )'.format(body['list'],equal) + if construct == 'equalAtleast': + query = '( count([{}],{}, C{})'.format(body['list'],equal,iden) + query = query + ' , C{} >= {} )'.format(iden,num) + if construct == 'equalFew': + query = '( count([{}],{}, C{})'.format(body['list'],equal,iden) + query = query + ' , C{} = {} )'.format(iden,num) + if construct == 'equalAll': + query = '( count([{}],{}, C{})'.format(body['list'],equal,iden) + query = query + ' , C{} = {} )'.format(iden,body['list_len']) + if construct == 'equalAny': + query = '( count([{}],{}, C{})'.format(body['list'],equal,iden) + query = query + ' , C{} >= 1 )'.format(iden) + + alias_list = body['alias_list'] + q_alias += alias_list + return query + + + +#############################CODE GENERATOR################################# +class blackbox: + def __init__(self): + self.entities = {} + self.buckets = {} + self.alias = {} + self.entity_instances = [] + self.action ={} + self.query = {} + self.action_def = {} +#####################adding entity layout############################### + def add_entity(self,entity): + entity_layout = get_entity_layout(entity) + self.entities[entity['entity']] = entity_layout + + def add_entity_instance(self,instance): + instance_layout = get_entity_instance(instance) + self.entity_instances.append(instance_layout) + + def add_entity_action(self,action): + action_layout = get_entity_action(action) + self.action[action['action_alias']] = action_layout[1] + self.action_def[action['action_alias']] = action_layout[0] + return action_layout[0] + + def add_query(self, query_tree): + q_alias = [] + query_core = q_tree_inorder(query_tree,q_alias) + q_alias_unique = list(set(q_alias)) + query_alias_def = '' + for al in q_alias_unique: + query_alias_def += self.action_def[str(al)] + ', ' + + query_name = str(randint(1000,9999)) + query_str = 'q({}) :- {} {} . '.format(query_name,query_alias_def,query_core) + self.query[query_name] = query_str + return +####################PRINT CODE########################## + def get_code(self): + code = '' + for key, value in self.entities.items(): + code = code + str(value) + '\n' + code = code + '\n' + for value in self.entity_instances: + code = code + str(value) + '\n' + code = code + '\n' + for key, value in self.action.items(): + code = code + str(value) + '\n' + code = code + '\n' + for key, value in self.query.items(): + code = code + str(value) + '\n' + code = code + '\n' + + count = ''' + +:- use_module(library(lists)). +count([],X,0). +count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. +count([X1|T],X,Z):- X1\=X,count(T,X,Z). + +''' + + code = code + count + 'query(q(_)).' + return code \ No newline at end of file diff --git a/probq.py b/probq.py index 259802e..246785d 100644 --- a/probq.py +++ b/probq.py @@ -1,43 +1,50 @@ -from probQparser.parser import getSolver -import time -import sys -import os - -print('----------------------------------------------------------------------------------') -print('------------------------------ WELCOME TO ProbQ-----------------------------------') -print('----------------------------------------------------------------------------------') - -start_time = time.time() -script_dir = os.path.dirname(__file__) -input_file = str(sys.argv[1]) -if input_file.split('.')[1] != 'pq': - print('>>>>>>>>>> wrong file. Please Give a pq file \n') - exit() -print('>>>>>>>>>> reading source file ' , input_file, '\n') - -with open(os.path.join(script_dir, input_file), 'r') as f: - source = f.read() -if source == '': - print('>>>>>>>>>> specified file is empty \n') - -# get the solver from probQparser -print(">>>>>>>>>> compiling the source ",'\n') -solver = getSolver(source,0) -code = solver.get_code() -# print('\n',code,'\n') - -output_file = input_file.split('.')[0] + '.pl' -print('\n>>>>>>>>>> writing output file ' , output_file, '\n') - -with open(output_file, 'w') as problog_file: - problog_file.write(code) - -elapsed_time = time.time() - start_time -print(">>>>>>>>>> Time taken to compile: ", str(elapsed_time), '\n') -print(">>>>>>>>>> Running generated problog code ",'\n') - -start_time = time.time() -os.system("problog " + str(output_file)) -elapsed_time = time.time() - start_time - -print("\n>>>>>>>>>> Total time taken : ", str(elapsed_time), '\n') +from probQparser.parser import * +import time +import sys +import os + +print('----------------------------------------------------------------------------------') +print('------------------------------- WELCOME TO ProbQ-----------------------------------') +print('----------------------------------------------------------------------------------') + +start_time = time.time() +script_dir = os.path.dirname(__file__) +print(script_dir) +input_file = str(sys.argv[1]) +if input_file.split('.')[1] != 'pq': + print('wrong file. Please Give a pq file') + exit() +print('>>>>>>>>>> reading source file ' , input_file) +with open(os.path.join(script_dir, input_file), 'r') as f: + source = f.read() +if source == '': + print('EMPTY FILE') +print('----------------------------------------------------------------------------------') +#print(source) +parse(source,0) #call parser +print('----------------------------------------------------------------------------------') +print('------------------------------- PROBLOG CODE--------------------------------------') +print('----------------------------------------------------------------------------------') +code = solver.get_code() #call solver +#print(code) #print ProbLogCode + +output_file = input_file.split('.')[0] + '.pl' +print('\n>>>>>>>>>> writing output file ' , output_file) +with open(output_file, 'w') as problog_file: + problog_file.write(code) + +elapsed_time = time.time() - start_time +print(">>>>>>>>>> Time taken to compile: ", str(elapsed_time)) +print('----------------------------------------------------------------------------------') +print('-------------------------------RUNNING PROBLOG CODE--------------------------------') +print('----------------------------------------------------------------------------------\n \n') +start_time = time.time() +print('----------------------------------------------------------------------------------') +print('--------------------------------------ANSWER--------------------------------------') +print('----------------------------------------------------------------------------------\n') +os.system("problog " + str(output_file)) +elapsed_time = time.time() - start_time #time taken +print('\n----------------------------------------------------------------------------------') +print('--------------------------------------ANSWER--------------------------------------') +print('----------------------------------------------------------------------------------\n \n') +print("\nTotal time elapsed : ", str(elapsed_time)) diff --git a/temp/old_parser.py b/temp/old_parser.py index 323d18d..d0cc315 100644 --- a/temp/old_parser.py +++ b/temp/old_parser.py @@ -1,287 +1,287 @@ -from ply import yacc -import probQlexer as lexer - -tokens = lexer.tokens -precedence = ( - ('left', 'PLUS', 'MINUS'), - -) - -# A BASIC program is a series of statements. We represent the program as a -# dictionary of tuples indexed by line number. - -coin_entity = { 'entity': 'coin', - 'flags': {'flag': 'fair', 'action': 'flip'}, - 'params': {'H': 0.5}, - 'props': [{'head': {'prob': 0.5}, 'tail': {'prob': 13}}] - } -dice_entity = { 'entity': 'dice', - 'flags': {'flag': 'fair', 'action': 'roll'}, - 'params': {'O' : 1/6,'T': 1/6,'Th' : 1/6 , 'F': 1/6, 'Fv' : 1/6, 'S': 1/6}, - 'props': [{'1': {'prob': 1/6 }, '2': {'prob': 1/6},'3': {'prob': 1/6 }, '4': {'prob': 1/6},'5': {'prob': 1/6 }, '6': {'prob': 1/6}}] - } - - -_entities = {'coin' : coin_entity , 'dice' : dice_entity } -_alias_list = {} - -def p_program(p): - '''program : program statement ''' - p[1] += [p[2]] + ["@@@@@@@@@@@@@@@@@@@@@2"] - p[0] = p[1] - -def p_program_single(p): - '''program : statement ''' - p[0] = [ p[1] ] - - - - -# Format of all BASIC statements. - -def p_statement_entity_def(p): - '''statement : entity ''' - p[0] = p[1] - -def p_statement_entity_assignment(p): - ''' statement : entity_assignment ''' - p[0] = p[1] - -################################################################################ -############################ ENTITY DEF ##################################### -################################################################################ -def p_entity_def(p): - ''' entity : ENTITY IDEN flag_action params entity_props ''' - p[0] = {'entity': p[2], 'flags': p[3] , 'params': p[4] , 'props' : p[5] } - global _entities - _entities = { **_entities, **{ (str(p[2]) + str(p[3]['flag'])) : p[0]} } - - -def p_entity_def_wo_flag_action(p): - ''' entity : ENTITY IDEN params entity_props ''' - p[0] = {'entity': p[2], 'flags':{'flag':'def','action':'roll'}, 'params': p[3] , 'props' : p[4] } - -def p_entity_def_wo_params(p): - ''' entity : ENTITY IDEN flag_action entity_props ''' - p[0] = {'entity': p[2], 'flags': p[3], 'params': {} , 'props' : p[4] } - - - ############ --------------------------------------------------------------- - -def p_flag_action(p): - ''' flag_action : LEFTSQRBRACKET FLAG ASSIGNMENT IDEN COMMA ACTION ASSIGNMENT IDEN RIGHTSQRBRACKET ''' - p[0] = {'flag' : p[4], 'action' : p[8]} - -def p_flag_action_without_identifier(p): - ''' flag_action : LEFTSQRBRACKET IDEN COMMA IDEN RIGHTSQRBRACKET ''' - p[0] = {'flag' : p[2], 'action' : p[4]} - -def p_flag_action_with_flag(p): - ''' flag_action : LEFTSQRBRACKET IDEN RIGHTSQRBRACKET ''' - p[0] = {'flag' : p[2], 'action' : 'roll'} - - ############ -------------------------------------------------------------- - -def p_params(p): - ''' params : LEFTSMALLBRACKET alias_list RIGHTSMALLBRACKET ''' - p[0] = p[2] - -def p_alias_list(p): - ''' alias_list : alias_list COMMA ALIAS ASSIGNMENT FLOAT - | alias_list COMMA ALIAS - ''' - size = len(p) - if size == 6: - ne = { p[3]:p[5] } - p[0] = { **p[1], **ne } - elif size == 4: - ne = { p[3]: 0.0 } - p[0] = { **p[1], **ne } - - -def p_alias_list_single(p): - ''' alias_list : ALIAS ASSIGNMENT FLOAT - | ALIAS - ''' - if len(p) == 4: - p[0] = { p[1] : p[3]} - elif len(p) == 2: - p[0] = { p[1] : 0.0 } - - ############ --------------------------------------------------------------- - -def p_entity_props(p): - ''' entity_props : LEFTCURLYBRACE entity_props_inner RIGHTCURLYBRACE''' - p[0] = p[2] - -def p_entity_prop_inner(p): - ''' entity_props_inner : entity_props_inner COMMA entity_prop - | entity_prop - ''' - if len(p) == 3: - p[1] += [p[2]] - p[0] = p[1] - - elif len(p) == 2: - p[0] = [p[1]] - - -def p_entity_prop(p): - ''' entity_prop : entity_prop_prob - | entity_prop_num - ''' - p[0] = p[1] - -def p_entity_prop_num(p): - ''' entity_prop_num : entity_prop_num SEMICOLON entity_prop_num_atom ''' - p[0] = { **p[1], **p[3]} - -def p_entity_prop_num_single(p): - ''' entity_prop_num : entity_prop_num_atom ''' - p[0] = p[1] - -def p_entity_prop_num_atom(p): - ''' entity_prop_num_atom : NUMBER COLON IDEN - | FLOAT COLON IDEN - | NUMBER COLON NUMBER - | FLOAT COLON NUMBER - - ''' - p[0] = {p[3] : {'num' : p[1]} } - -def p_entity_prop_prob(p): - ''' entity_prop_prob : entity_prop_prob SEMICOLON entity_prop_prob_atom ''' - p[0] = { **p[1], **p[3]} - -def p_entity_prop_prob_single(p): - ''' entity_prop_prob : entity_prop_prob_atom ''' - p[0] = p[1] - -def p_entity_prop_prob_atom(p): - ''' entity_prop_prob_atom : NUMBER DOUBLECOLON IDEN - | FLOAT DOUBLECOLON IDEN - | NUMBER DOUBLECOLON NUMBER - | FLOAT DOUBLECOLON NUMBER - ''' - p[0] = {p[3] : {'prob' : p[1]}} - - - # to do add simple expr for prob. - ############ --------------------------------------------------------------- - -################################################################################ -############################ ENTITY Initialize ############################## -################################################################################ -def p_entity_initialize(p): - ''' entity_initialize : entity_name ei_flag ei_params ei_number ''' - p[0] = {'entity': p[1], 'flags': p[2], 'info': p[3] , 'num' : p[4] } - -def p_entity_name(p): - ''' entity_name : IDEN ''' - p[0] = p[1] - -def p_empty(p): - 'empty :' - pass - -######################-----------------------------------###################### -def p_ei_flag(p): - ''' ei_flag : LEFTSQRBRACKET IDEN RIGHTSQRBRACKET ''' - p[0] = p[2] - -def p_ei_flag_empty(p): - ''' ei_flag : empty ''' - p[0] = 'default' - -######################-----------------------------------###################### - -def p_ei_params(p): - ''' ei_params : LEFTSMALLBRACKET float_list RIGHTSMALLBRACKET - | LEFTSMALLBRACKET entity_prop RIGHTSMALLBRACKET - ''' - p[0] = p[2] -def p_ei_params_empty(p): - ''' ei_params : empty ''' - p[0] = 'empty' - -def p_float_list(p): - ''' float_list : float_list COMMA FLOAT - | float_list COMMA NUMBER - ''' - p[1] += [p[3]] - p[0] = p[1] - -def p_float_list_single(p): - ''' float_list : FLOAT - | NUMBER - ''' - p[0] = [ p[1] ] - -def p_ei_number(p): - ''' ei_number : LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE ''' - p[0] = p[2] - -################################################################################ -############################ ENTITY Action ############################## -################################################################################ -def p_entity_action(p): - ''' entity_action : ALIAS DOT IDEN LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET - | ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET - ''' - p[0] = {'entity' : p[1], 'action' : p[3], 'num' : p[5]} - -def p_entity_action_e(p): - ''' entity_action : entity_initialize DOT IDEN LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET - | entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET - - ''' - p[0] = {'entity' : p[1], 'action' : p[3], 'num' : p[5]} - -def p_option_number(p): - ''' option_number : NUMBER ''' - p[0] = p[1] - -def p_option_number_wo(p): - ''' option_number : empty ''' - p[0] = 1 - - -################################################################################ -############################ ENTITY Assignment ########################## -################################################################################ - -def p_entity_assignment(p): - ''' entity_assignment : ALIAS ASSIGNMENT entity_initialize - | ALIAS ASSIGNMENT entity_action - ''' - global _alias_list - _alias_list[p[1]] = p[3] - p[0] = {p[1] : p[3] } - -# Catastrophic error handler - -probQparser = yacc.yacc() - - -def parse(data, debug=0): - probQparser.error = 0 - p = probQparser.parse(data, debug=debug) - if probQparser.error: - return None - return p - -source = ''' -entity dice[flag=fair, action=rollu](H,T){ - H ::1; 0.16::2; 0.16::3; 0.16::4; 0.16::5; 0.16::6 -} -X = dice[fair]{5} -Y = X.roll(5) -X = dice[fair]{5} -Y = X.roll(5) -''' -print(parse(source,1)) - - -# import pprint -# pp = pprint.PrettyPrinter(indent=4) -# pp.pprint(_entities) +from ply import yacc +import probQlexer as lexer + +tokens = lexer.tokens +precedence = ( + ('left', 'PLUS', 'MINUS'), + +) + +# A BASIC program is a series of statements. We represent the program as a +# dictionary of tuples indexed by line number. + +coin_entity = { 'entity': 'coin', + 'flags': {'flag': 'fair', 'action': 'flip'}, + 'params': {'H': 0.5}, + 'props': [{'head': {'prob': 0.5}, 'tail': {'prob': 13}}] + } +dice_entity = { 'entity': 'dice', + 'flags': {'flag': 'fair', 'action': 'roll'}, + 'params': {'O' : 1/6,'T': 1/6,'Th' : 1/6 , 'F': 1/6, 'Fv' : 1/6, 'S': 1/6}, + 'props': [{'1': {'prob': 1/6 }, '2': {'prob': 1/6},'3': {'prob': 1/6 }, '4': {'prob': 1/6},'5': {'prob': 1/6 }, '6': {'prob': 1/6}}] + } + + +_entities = {'coin' : coin_entity , 'dice' : dice_entity } +_alias_list = {} + +def p_program(p): + '''program : program statement ''' + p[1] += [p[2]] + ["@@@@@@@@@@@@@@@@@@@@@2"] + p[0] = p[1] + +def p_program_single(p): + '''program : statement ''' + p[0] = [ p[1] ] + + + + +# Format of all BASIC statements. + +def p_statement_entity_def(p): + '''statement : entity ''' + p[0] = p[1] + +def p_statement_entity_assignment(p): + ''' statement : entity_assignment ''' + p[0] = p[1] + +################################################################################ +############################ ENTITY DEF ##################################### +################################################################################ +def p_entity_def(p): + ''' entity : ENTITY IDEN flag_action params entity_props ''' + p[0] = {'entity': p[2], 'flags': p[3] , 'params': p[4] , 'props' : p[5] } + global _entities + _entities = { **_entities, **{ (str(p[2]) + str(p[3]['flag'])) : p[0]} } + + +def p_entity_def_wo_flag_action(p): + ''' entity : ENTITY IDEN params entity_props ''' + p[0] = {'entity': p[2], 'flags':{'flag':'def','action':'roll'}, 'params': p[3] , 'props' : p[4] } + +def p_entity_def_wo_params(p): + ''' entity : ENTITY IDEN flag_action entity_props ''' + p[0] = {'entity': p[2], 'flags': p[3], 'params': {} , 'props' : p[4] } + + + ############ --------------------------------------------------------------- + +def p_flag_action(p): + ''' flag_action : LEFTSQRBRACKET FLAG ASSIGNMENT IDEN COMMA ACTION ASSIGNMENT IDEN RIGHTSQRBRACKET ''' + p[0] = {'flag' : p[4], 'action' : p[8]} + +def p_flag_action_without_identifier(p): + ''' flag_action : LEFTSQRBRACKET IDEN COMMA IDEN RIGHTSQRBRACKET ''' + p[0] = {'flag' : p[2], 'action' : p[4]} + +def p_flag_action_with_flag(p): + ''' flag_action : LEFTSQRBRACKET IDEN RIGHTSQRBRACKET ''' + p[0] = {'flag' : p[2], 'action' : 'roll'} + + ############ -------------------------------------------------------------- + +def p_params(p): + ''' params : LEFTSMALLBRACKET alias_list RIGHTSMALLBRACKET ''' + p[0] = p[2] + +def p_alias_list(p): + ''' alias_list : alias_list COMMA ALIAS ASSIGNMENT FLOAT + | alias_list COMMA ALIAS + ''' + size = len(p) + if size == 6: + ne = { p[3]:p[5] } + p[0] = { **p[1], **ne } + elif size == 4: + ne = { p[3]: 0.0 } + p[0] = { **p[1], **ne } + + +def p_alias_list_single(p): + ''' alias_list : ALIAS ASSIGNMENT FLOAT + | ALIAS + ''' + if len(p) == 4: + p[0] = { p[1] : p[3]} + elif len(p) == 2: + p[0] = { p[1] : 0.0 } + + ############ --------------------------------------------------------------- + +def p_entity_props(p): + ''' entity_props : LEFTCURLYBRACE entity_props_inner RIGHTCURLYBRACE''' + p[0] = p[2] + +def p_entity_prop_inner(p): + ''' entity_props_inner : entity_props_inner COMMA entity_prop + | entity_prop + ''' + if len(p) == 3: + p[1] += [p[2]] + p[0] = p[1] + + elif len(p) == 2: + p[0] = [p[1]] + + +def p_entity_prop(p): + ''' entity_prop : entity_prop_prob + | entity_prop_num + ''' + p[0] = p[1] + +def p_entity_prop_num(p): + ''' entity_prop_num : entity_prop_num SEMICOLON entity_prop_num_atom ''' + p[0] = { **p[1], **p[3]} + +def p_entity_prop_num_single(p): + ''' entity_prop_num : entity_prop_num_atom ''' + p[0] = p[1] + +def p_entity_prop_num_atom(p): + ''' entity_prop_num_atom : NUMBER COLON IDEN + | FLOAT COLON IDEN + | NUMBER COLON NUMBER + | FLOAT COLON NUMBER + + ''' + p[0] = {p[3] : {'num' : p[1]} } + +def p_entity_prop_prob(p): + ''' entity_prop_prob : entity_prop_prob SEMICOLON entity_prop_prob_atom ''' + p[0] = { **p[1], **p[3]} + +def p_entity_prop_prob_single(p): + ''' entity_prop_prob : entity_prop_prob_atom ''' + p[0] = p[1] + +def p_entity_prop_prob_atom(p): + ''' entity_prop_prob_atom : NUMBER DOUBLECOLON IDEN + | FLOAT DOUBLECOLON IDEN + | NUMBER DOUBLECOLON NUMBER + | FLOAT DOUBLECOLON NUMBER + ''' + p[0] = {p[3] : {'prob' : p[1]}} + + + # to do add simple expr for prob. + ############ --------------------------------------------------------------- + +################################################################################ +############################ ENTITY Initialize ############################## +################################################################################ +def p_entity_initialize(p): + ''' entity_initialize : entity_name ei_flag ei_params ei_number ''' + p[0] = {'entity': p[1], 'flags': p[2], 'info': p[3] , 'num' : p[4] } + +def p_entity_name(p): + ''' entity_name : IDEN ''' + p[0] = p[1] + +def p_empty(p): + 'empty :' + pass + +######################-----------------------------------###################### +def p_ei_flag(p): + ''' ei_flag : LEFTSQRBRACKET IDEN RIGHTSQRBRACKET ''' + p[0] = p[2] + +def p_ei_flag_empty(p): + ''' ei_flag : empty ''' + p[0] = 'default' + +######################-----------------------------------###################### + +def p_ei_params(p): + ''' ei_params : LEFTSMALLBRACKET float_list RIGHTSMALLBRACKET + | LEFTSMALLBRACKET entity_prop RIGHTSMALLBRACKET + ''' + p[0] = p[2] +def p_ei_params_empty(p): + ''' ei_params : empty ''' + p[0] = 'empty' + +def p_float_list(p): + ''' float_list : float_list COMMA FLOAT + | float_list COMMA NUMBER + ''' + p[1] += [p[3]] + p[0] = p[1] + +def p_float_list_single(p): + ''' float_list : FLOAT + | NUMBER + ''' + p[0] = [ p[1] ] + +def p_ei_number(p): + ''' ei_number : LEFTCURLYBRACE NUMBER RIGHTCURLYBRACE ''' + p[0] = p[2] + +################################################################################ +############################ ENTITY Action ############################## +################################################################################ +def p_entity_action(p): + ''' entity_action : ALIAS DOT IDEN LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + | ALIAS DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + ''' + p[0] = {'entity' : p[1], 'action' : p[3], 'num' : p[5]} + +def p_entity_action_e(p): + ''' entity_action : entity_initialize DOT IDEN LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + | entity_initialize DOT ROLL LEFTSMALLBRACKET option_number RIGHTSMALLBRACKET + + ''' + p[0] = {'entity' : p[1], 'action' : p[3], 'num' : p[5]} + +def p_option_number(p): + ''' option_number : NUMBER ''' + p[0] = p[1] + +def p_option_number_wo(p): + ''' option_number : empty ''' + p[0] = 1 + + +################################################################################ +############################ ENTITY Assignment ########################## +################################################################################ + +def p_entity_assignment(p): + ''' entity_assignment : ALIAS ASSIGNMENT entity_initialize + | ALIAS ASSIGNMENT entity_action + ''' + global _alias_list + _alias_list[p[1]] = p[3] + p[0] = {p[1] : p[3] } + +# Catastrophic error handler + +probQparser = yacc.yacc() + + +def parse(data, debug=0): + probQparser.error = 0 + p = probQparser.parse(data, debug=debug) + if probQparser.error: + return None + return p + +source = ''' +entity dice[flag=fair, action=rollu](H,T){ + H ::1; 0.16::2; 0.16::3; 0.16::4; 0.16::5; 0.16::6 +} +X = dice[fair]{5} +Y = X.roll(5) +X = dice[fair]{5} +Y = X.roll(5) +''' +print(parse(source,1)) + + +# import pprint +# pp = pprint.PrettyPrinter(indent=4) +# pp.pprint(_entities)