9 using TSeq = std::vector<BindingTree*>;
10 using TtoT = std::function<BindingTree*(BindingTree*)>;
11 using TtoTSeq = std::function<TSeq(BindingTree*)>;
12 using TtoBool = std::function<bool(BindingTree*)>;
13 using TxTtoBool = std::function<bool(BindingTree*,BindingTree*)>;
21 if(x ==
nullptr)
return nullptr;
26 if(x ==
nullptr)
return {};
29 for(
size_t i=0;i<x->nchildren();i++) {
30 out.push_back(&x->child(i));
37 if(x ==
nullptr)
return {};
40 while(x->parent !=
nullptr) {
41 out.push_back(x->parent);
49 return (x !=
nullptr) and (x->pos==
POS::NPS);
53 return (x !=
nullptr) and (x->referent != -1);
63 return (x !=
nullptr) and (y !=
nullptr) and (x->
referent == y->referent);
67 return (x !=
nullptr) and (y !=
nullptr) and (x->
linear_order > y->linear_order);
72 class MyGrammar :
public Grammar<BindingTree*,bool, S,POS,int,bool,BindingTree*,TSeq,TtoT,TtoTSeq,TtoBool,TxTtoBool>,
75 using Super =
Grammar<BindingTree*,bool, S,POS,int,bool,BindingTree*,TSeq,TtoT,TtoTSeq,TtoBool,TxTtoBool>;
93 add(
"true", +[]() ->
bool {
return true; }, 0.1);
94 add(
"false", +[]() ->
bool {
return false; }, 0.1);
95 add(
"and(%s,%s)", Builtins::And<MyGrammar>, 1./4.);
96 add(
"or(%s,%s)", Builtins::Or<MyGrammar>, 1./4.);
97 add(
"iff(%s,%s)", Builtins::Iff<MyGrammar>, 1./4.);
98 add(
"not(%s)", Builtins::Not<MyGrammar>, 1./4.);
100 add(
"if(%s,%s,%s)", Builtins::If<MyGrammar,S>, 1./3.);
101 add(
"if(%s,%s,%s)", Builtins::If<MyGrammar,POS>, 1./3.);
102 add(
"if(%s,%s,%s)", Builtins::If<MyGrammar,BindingTree*>, 1./3.);
106 for(
auto& w :
words) {
110 for(
auto [l,p] :
posmap) {
111 add_terminal<POS>(
Q(l), p,
TERMINAL_P/posmap.size());
155 return (t !=
nullptr) and (t->pos == a);
171 return (t !=
nullptr) and (a !=
nullptr) and (t->pos == a->
pos);
177 add(
"empty(%s)", +[](
TSeq s) ->
bool {
178 return s.size() == 0;
214 for(
auto& y : f(x)) {
224 if(f(x)) out.push_back(x);
POS
Definition: BindingTree.h:14
Definition: Singleton.h:6
std::function ancestors
Definition: MyGrammar.h:36
std::function gt_linear
Definition: MyGrammar.h:66
std::function has_index
Definition: MyGrammar.h:52
std::function children
Definition: MyGrammar.h:25
std::function< BindingTree *(BindingTree *)> TtoT
Definition: MyGrammar.h:10
Definition: BindingTree.h:46
std::string reverse(std::string x)
Definition: Strings.h:185
std::function null
Definition: MyGrammar.h:56
int referent
Definition: BindingTree.h:48
std::function eq_tree
Definition: MyGrammar.h:60
std::function< bool(BindingTree *, BindingTree *)> TxTtoBool
Definition: MyGrammar.h:13
std::vector< BindingTree * > TSeq
Definition: MyGrammar.h:9
std::string Q(const std::string &x)
Definition: Strings.h:199
std::function< TSeq(BindingTree *)> TtoTSeq
Definition: MyGrammar.h:11
const double TERMINAL_P
Definition: Main.cpp:24
int linear_order
Definition: BindingTree.h:50
this_t * parent
Definition: BaseNode.h:26
std::function< bool(BindingTree *)> TtoBool
Definition: MyGrammar.h:12
Definition: MyGrammar.h:72
MyGrammar()
Definition: MyGrammar.h:79
std::function corefers
Definition: MyGrammar.h:62
std::function is_subject
Definition: MyGrammar.h:48
POS pos
Definition: BindingTree.h:51
Grammar< BindingTree *, bool, S, POS, int, bool, BindingTree *, TSeq, TtoT, TtoTSeq, TtoBool, TxTtoBool >::add void add(std::string fmt, Primitive< T, args... > &b, double p=1.0, int a=0)
Definition: Grammar.h:312
std::function parent
Definition: MyGrammar.h:20
std::map< std::string, POS > posmap
Definition: BindingTree.h:16
const std::vector< std::string > words
Definition: Main.cpp:15
A grammar stores all of the rules associated with any kind of nonterminal and permits us to sample as...