Changeset e7de6cc for src/dgp/grammar.hh
- Timestamp:
- 02/21/12 20:02:51 (13 years ago)
- Branches:
- master
- Children:
- b242df2
- Parents:
- 354ba3d
- git-author:
- Tomasz Obrebski <to@…> (02/21/12 20:02:51)
- git-committer:
- Tomasz Obrebski <to@…> (02/21/12 20:02:51)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/dgp/grammar.hh
r5f4d9c3 re7de6cc 10 10 #include "thesymbols.hh" 11 11 #include "sgraph.hh" 12 13 14 class Link 15 { 12 #include "boubble.hh" 13 14 using namespace std; 15 16 //enum PROP { INIT=0, FIN=1 }; 17 //typedef bitset<16> PropSet; 18 19 const PropSet EmptyPropSet = PropSet(); 20 21 const FlagSet EmptyFlagSet = FlagSet(); 22 23 //==================================================================================================== 24 // class Link 25 //==================================================================================================== 26 27 struct Link 28 { 29 Link(Role r, Flag dfplus="NULL", Flag dfminus="NULL") : role(r), dflagplus(dfplus), dflagminus(dfminus) { } 30 Link(Role r, PropSet ps=EmptyPropSet, Flag hfp="NULL", Flag hfm="NULL", Flag dfp="NULL", Flag dfm="NULL") 31 : role(r), props(ps), hflagplus(hfp), hflagminus(hfm), dflagplus(dfp), dflagminus(dfm) { } 32 //Link(Role r) : role(r), dflagplus("NULL") { } 33 16 34 Role role; 17 FlagSet hflags; 18 FlagSet dflags; 35 Flag hflagplus; 36 Flag hflagminus; 37 Flag dflagplus; 38 Flag dflagminus; 39 PropSet props; 40 41 bool operator<(const Link& l) const 42 { 43 if(role < l.role) return true; 44 if(hflagplus < l.hflagplus) return true; 45 if(hflagminus < l.hflagminus) return true; 46 if(dflagplus < l.dflagplus) return true; 47 if(dflagminus < l.dflagminus) return true; 48 if(props.to_ulong() < l.props.to_ulong()) return true; 49 return false; 50 } 51 19 52 }; 20 53 54 typedef set<Link> Links; 55 56 //==================================================================================================== 57 // class Grammar 58 //==================================================================================================== 21 59 22 60 class Grammar … … 25 63 public: 26 64 27 // enum CONSTR { SGL, OBL, LEFT, RIGHT, INIT, NONINIT, FIN, NONFIN }; 28 29 Grammar() : types_sz(0), cats_sz(0), flags_sz(0) {} ; 65 static const int RESIZE_DELTA=16; 66 67 Grammar() {} ; 68 69 Roles& connectable(Cat h, Cat d); 70 Roles connectable(Cat h, Cat d, FlagSet f, FlagSet df); 71 72 list<const Link*> connectable2(Cat h, Cat d, FlagSet hfs, FlagSet dfs); 73 74 bool check_constr(NodeProp& hprop, NodeProp& dprop, int dir, Role role); 75 bool check_constr2(NodeProp& hprop, NodeProp& dprop, int dir, const Link& link); 76 77 bool check_longrel(Cat hcat, Cat dcat, LongRel rel); 78 bool is_sgl(Role r); 79 RoleSet is_obl(Cat c); 80 81 RoleSet& constr_include(Role r) { return include[r]; }; 82 RoleSet& constr_exclude(Role r) { return exclude[r]; }; 30 83 31 int types_sz; 32 int cats_sz; 33 int flags_sz; 34 35 vector< vector< Roles > > connect; 84 FlagSet initial_flags(Cat c) { return set[c]; } 85 FlagSet pass_flags(Role r) { return pass[r]; } 86 87 list<Boubble*> trigger_boubbles(Cat c, Role r, Dir d); 88 89 bool read(FILE* f); 90 void write(ostream& os); 91 void write(FILE* f); 92 93 private: 94 36 95 RoleSet sgl; 37 vector< RoleSet > obl; 96 vector< RoleSet > obl; //[Cat] 38 97 RoleSet left; 39 98 RoleSet right; 40 vector< RoleSet > lt; 41 vector< RoleSet > gt; 42 43 44 // vector< vector< vector< 45 vector< FlagSet > set; 46 vector< FlagSet > pass; 47 48 bool read(FILE* f); 49 void write(FILE* f); 99 RoleSet init; 100 RoleSet fin; 101 FlagSet initf; 102 FlagSet finf; 103 104 vector< RoleSet > lt; //[Role] 105 vector< RoleSet > gt; //[Role] 106 107 vector< FlagSet > set; //[Cat] 108 // vector< FlagSet > rset; //[Role] 109 vector< FlagSet > pass; //[Role] 110 111 vector< vector< Roles > > connect; //[Cat][Cat] 112 113 vector< vector< Links > > connect1; //[Cat][Cat] 114 115 vector< RoleSet > include; //[Role] 116 vector< RoleSet > exclude; //[Role] 117 118 vector< vector< LongRels > > longrel; //[Cat][Cat] 119 120 list< Boubble* > boubbles; 121 122 vector< vector< list<Boubble*> > > uptrigger;//[Cat][Role] 123 vector< vector< list<Boubble*> > > dntrigger;//[Cat][Role] 50 124 51 125 void add_category(const char* s); 52 126 void add_type(const char* s); 53 void add_flag(const char* s); 54 55 void set_sgl(Role r) { sgl.set(r); } 56 void set_obl(Cat c, Role r) { obl[c].set(r); } 57 void set_left(Role r) { left.set(r); } 58 void set_right(Role r) { right.set(r); } 59 void set_order(Role r, Role s) { lt[s].set(r); } 60 void set_connect(Cat c, Cat d, Role r) { connect[c][d].insert(r); } 127 void add_flag(const char* s) { Flag::add(s); } 128 void add_long(const char* l, const char* p) { LongRel::add(l); boubbles.push_back( new Boubble(p,l) ); } 129 void add_triggers(Cat h, Cat d, LongRel l); 130 131 void set_sgl(Role r) { sgl.set(r); } 132 void set_obl(Cat c, Role r) { obl[c].set(r); } 133 void set_left(Role r) { left.set(r); } 134 void set_right(Role r) { right.set(r); } 135 void set_init(Role r) { init.set(r); } 136 void set_fin(Role r) { fin.set(r); } 137 void set_initf(Flag f) { initf.set(f); } 138 void set_finf(Flag f) { finf.set(f); } 139 void set_order(Role r, Role s) { lt[s].set(r); } 140 141 // void set_connect(Cat c, Cat d, Role r) { connect[c][d].insert(r); } 142 // void set_connect(Cat c, Cat d, Flag f, Role r) { connect1[c][d].insert(Link(r,f)); } 143 144 void set_connect(Cat h, Flag hfp, Flag hfm, Cat d, Flag dfp, Flag dfm, Role r, PropSet ps ) { connect1[h][d].insert(Link(r,ps,hfp,hfm,dfp,dfm)); } 145 146 void set_include(Role r, Role s) { include[r].set(s); } 147 void set_exclude(Role r, Role s) { exclude[r].set(s); } 148 void set_longrel(Cat c, Cat d, LongRel l){ longrel[c][d].insert(l); } 149 void set_set(Cat c, Flag f) { set[c].set(f); } 150 void set_pass(Role r, Flag f) { pass[r].set(f); } 61 151 void set_lt(Role r, Role s); 62 152 void compute_gt(); 63 64 65 bool check_constr(NodeProp& hprop, NodeProp& dprop, int dir, Role role); 153 void compute_triggers(); 154 bool contains_boubble(const list<Boubble*> boubble_list, Boubble* bp) const; 66 155 67 156 }; 68 157 69 inline bool Grammar::check_constr(NodeProp& hprop, NodeProp& dprop, int dir, Role role) 158 //---------------------------------------------------------------------------------------------------- 159 160 inline 161 Roles& Grammar::connectable(Cat h, Cat d) 162 { 163 return connect[h][d]; 164 } 165 166 //---------------------------------------------------------------------------------------------------- 167 168 inline 169 Roles Grammar::connectable(Cat h, Cat d, FlagSet hfs, FlagSet dfs) // ZBYT WOLNE!!!!!!!!!!!!!!!!!!!!!!!!!! (-> Roles&) 170 { 171 Roles ret; 172 for(Links::const_iterator l = connect1[h][d].begin(); l != connect1[h][d].end(); l++) 173 if( (l->hflagplus==0 || hfs[l->hflagplus]) && (l->hflagminus==0 || !hfs[l->hflagminus]) ) 174 if( (l->dflagplus==0 || dfs[l->dflagplus]) && (l->dflagminus==0 || !dfs[l->dflagminus]) ) 175 ret.insert(l->role); 176 return ret; 177 } 178 179 //---------------------------------------------------------------------------------------------------- 180 181 inline 182 list<const Link*> Grammar::connectable2(Cat h, Cat d, FlagSet hfs, FlagSet dfs) // ZBYT WOLNE!!!!!!!!!!!!!!!!!!!!!!!!!! (-> Roles&) 183 { 184 list<const Link*> ret; 185 for(Links::const_iterator l = connect1[h][d].begin(); l != connect1[h][d].end(); l++) 186 if( (l->hflagplus==0 || hfs[l->hflagplus]) && (l->hflagminus==0 || !hfs[l->hflagminus]) ) 187 if( (l->dflagplus==0 || dfs[l->dflagplus]) && (l->dflagminus==0 || !dfs[l->dflagminus]) ) 188 ret.push_back(&(*l)); 189 return ret; 190 } 191 192 //---------------------------------------------------------------------------------------------------- 193 194 inline 195 bool Grammar::check_constr(NodeProp& hprop, NodeProp& dprop, int dir, Role role) // dir: 0-left 1-right 70 196 { 71 197 return 72 198 !hprop.forbidden[role] && 73 ( !right[role] || dir==1 ) && 74 ( !left[role] || dir==0 ) 199 ( dir==1 || !right[role] ) && 200 ( dir==0 || !left[role] ) && 201 ( dir==1 || (hprop.attached&init).none() ) && 202 ( dir==0 || (hprop.attached&fin).none() ) 75 203 ; 76 204 } 77 205 206 //---------------------------------------------------------------------------------------------------- 207 208 inline 209 bool Grammar::check_constr2(NodeProp& hprop, NodeProp& dprop, int dir, const Link& link) // dir: 0-left 1-right 210 { 211 return 212 !hprop.forbidden[link.role] && 213 ( dir==1 || !right[link.role] ) && 214 ( dir==0 || !left[link.role] ) && 215 ( dir!=0 || !hprop.init_attached ) && 216 ( dir!=1 || !hprop.fin_attached ) 217 ; 218 } 219 220 //---------------------------------------------------------------------------------------------------- 221 222 inline 223 bool Grammar::check_longrel(Cat hcat, Cat dcat, LongRel rel) 224 { 225 return longrel[hcat][dcat].find(rel) != longrel[hcat][dcat].end(); 226 } 227 228 //---------------------------------------------------------------------------------------------------- 229 230 inline bool Grammar::is_sgl(Role r) 231 { 232 return sgl[r]; 233 } 234 235 //---------------------------------------------------------------------------------------------------- 236 237 inline RoleSet Grammar::is_obl(Cat c) 238 { 239 return obl[c]; 240 } 241 242 //==================================================================================================== 78 243 79 244 #endif
Note: See TracChangeset
for help on using the changeset viewer.