Changeset e7de6cc for src


Ignore:
Timestamp:
02/21/12 20:02:51 (12 years ago)
Author:
Tomasz Obrebski <to@…>
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)
Message:

new version of dgp
added dgc, tre and compdic components
compiledic renamed to compdic_utf8
./configure updated

Location:
src
Files:
33 added
13 edited
11 moved

Legend:

Unmodified
Added
Removed
  • src/compdic_utf8/Makefile

    r5f4d9c3 re7de6cc  
    11include ../../config.mak 
    22 
    3 all: compiledic 
     3all: compdic 
    44 
    5 .PHONY: compiledic 
     5.PHONY: compdic 
    66compiledic: 
    77 
     
    99install: 
    1010ifdef BIN_DIR 
    11         install -m 0755 compiledic $(BIN_DIR) 
     11        install -m 0755 compdic $(BIN_DIR) 
    1212        install -m 0755 text2fst.py $(BIN_DIR) 
    1313        install -m 0755 symbols.py $(BIN_DIR) 
     
    1717uninstall: 
    1818ifdef BIN_DIR 
    19         rm $(BIN_DIR)/compiledic 
     19        rm $(BIN_DIR)/compdic 
    2020        rm $(BIN_DIR)/text2fst.py 
    2121        rm $(BIN_DIR)/symbols.py 
  • src/dgp/Makefile

    r5f4d9c3 re7de6cc  
     1 
    12include ../../config.mak 
     3 
    24 
    35SHELL = /bin/sh 
     
    68CMDLINE_FILE='"../dgp/cmdline.h"' 
    79 
     10 
    811#vpath %.o  . 
    912 
    10 ifeq ($(BUILD_STATIC), yes) 
    11         LDFLAGS += -static 
    12 endif 
     13CXXFLAGS = -g -static 
    1314 
    14 CXXFLAGS += -O2 
    15  
    16 sources = main.cc grammar.cc symbol.cc mgraph.cc sgraph.cc dgp0.cc cmdline.cc \ 
     15sources = main.cc grammar.cc symbol.cc mgraph.cc sgraph.cc dgp1.cc cmdline.cc \ 
    1716          $(COMMON_PATH)/common.cc global.cc 
    1817 
     
    2322 
    2423${bin}: ${objs} 
    25         $(CXX) $(CXXFLAGS) -D _CMDLINE_FILE=$(CMDLINE_FILE) -o $@ ${objs} $(LDFLAGS) 
     24        ${CXX} ${CXXFLAGS} -D _CMDLINE_FILE=$(CMDLINE_FILE) -o $@ ${objs} 
    2625 
    2726include $(sources:.cc=.d) 
    2827 
    2928%.o: %.cc 
    30         $(CXX) -D _CMDLINE_FILE=$(CMDLINE_FILE) -c ${CXXFLAGS} -o $@ $< 
     29        ${CXX} -D _CMDLINE_FILE=$(CMDLINE_FILE) -c ${CXXFLAGS} -o $@ $< 
    3130 
    3231%.d: %.cc 
     
    3534        rm -f $@.$$$$ 
    3635 
    37 # stare: 
    38 # cmdline.cc cmdline.h : cmdline.ggo 
    39 #       gengetopt --c-extension=cc -i cmdline.ggo 
    40 # nowe 
     36 
    4137cmdline.cc cmdline.h: cmdline.ggo 
    42         $(GENGETOPT) -i cmdline.ggo  --c-extension=cc --conf-parser 
     38        gengetopt -i cmdline.ggo  --c-extension=cc --conf-parser 
    4339 
    4440cmdline.ggo: cmdline_dgp.ggo ../common/cmdline_common.ggo 
    4541        cat cmdline_dgp.ggo ../common/cmdline_common.ggo > cmdline.ggo 
    46 # endnowe 
    4742 
    4843 
     44 
     45.PHONY: clean 
    4946clean: 
    50         rm ${bin} ${objs} cmdline.cc cmdline.h 
    51         rm -rf *.d 
     47        rm -f ${bin} ${objs} cmdline.* 
     48        rm -f *.d 
    5249 
     50.PHONY: prof 
    5351prof: dgp 
    5452        gprof dgp ~/tmp/dgp-pl/gmon.out > dgp.prof 
     53 
    5554 
    5655.PHONY: install 
     
    5857ifdef BIN_DIR 
    5958        install -m 0755 dgp $(BIN_DIR) 
    60         install -m 0755 dgc $(BIN_DIR) 
    61         install -m 0755 canonize $(BIN_DIR) 
    62         install -m 0755 tre $(BIN_DIR) 
    6359endif 
    6460 
     
    6763ifdef BIN_DIR 
    6864        rm $(BIN_DIR)/dgp 
    69         rm $(BIN_DIR)/dgc 
    70         rm $(BIN_DIR)/canonize 
    71         rm $(BIN_DIR)/tre 
    7265endif 
  • src/dgp/const.hh

    r5f4d9c3 re7de6cc  
    33 
    44#define MAXTYPES 32 
     5#define MAXCATS 4096 
    56#define MAXFLAGS 64 
    6 #define MAXNODES 1024 
     7#define MAXPROPS 16 
     8#define MAXNODES 2048 
    79#define MAXCONSTRS 32 
    8 #define MAXLINE 256 
     10#define MAXLINE 512 
    911#define MAXFORMLEN 64 
    1012#define MAXDESCRLEN 80 
  • src/dgp/dgp0.cc

    r5f4d9c3 re7de6cc  
    66extern SGraph sgraph; 
    77 
    8 SNode* snodes; 
    9  
    108extern bool debug; 
    119 
     
    1614void set_initial_constraints(int node) 
    1715{ 
    18   snodes[node].prop.forbidden.reset(); 
    19   snodes[node].prop.required=grammar.obl[snodes[node].mnode->cat]; 
     16  sgraph[node].prop.forbidden.reset(); 
     17  sgraph[node].prop.required=grammar.is_obl(mgraph[sgraph[node].mnode].cat); 
    2018} 
    2119 
     
    2321bool changing_constraints(int head, Role role) 
    2422{ 
    25   return grammar.sgl[role] || snodes[head].prop.required[role]; 
     23  return grammar.is_sgl(role) || sgraph[head].prop.required[role]; 
    2624} 
    2725 
    2826void apply_constraints(int head, Role role) 
    2927{ 
    30   if(grammar.sgl[role]) snodes[head].prop.forbidden.set(role); 
    31   snodes[head].prop.required.reset(role); 
     28  if(grammar.is_sgl(role)) sgraph[head].prop.forbidden.set(role); 
     29  sgraph[head].prop.required.reset(role); 
    3230} 
    3331 
     
    3533{ 
    3634  NodeProp ret=headprop; 
    37   if(grammar.sgl[role]) ret.forbidden.set(role); 
     35  if(grammar.is_sgl(role)) ret.forbidden.set(role); 
    3836  ret.required.reset(role); 
    3937  return ret; 
     
    4442  NodeProp ret=headprop; 
    4543 
    46   if(grammar.sgl[role]) ret.forbidden.set(role); 
     44  if(grammar.is_sgl(role)) ret.forbidden.set(role); 
    4745  ret.required.reset(role); 
    4846  return ret; 
     
    5250{ 
    5351  for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps) 
    54     if(snodes[*ps].prop==p && snodes[*ps].LH==newheadLH && snodes[*ps].LV==newheadLV) 
     52    if(sgraph[*ps].prop==p && sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) 
    5553      return *ps; 
    5654  return -1; 
     
    5957void connect_left(list<int>::iterator h, list<int>::iterator d, Role r) 
    6058{ 
    61   NodeProp &oldheadprop = snodes[*h].prop; 
    62   NodeProp newheadprop; 
    63   bitset<MAXNODES> newheadLV; 
    64   bitset<MAXNODES> newheadLH; 
    65   bitset<MAXNODES> newheadLD; 
    66    
    67   newheadprop=compute_prop_left(oldheadprop,r); 
     59  NodeProp &oldheadprop = sgraph[*h].prop; 
     60  NodeProp newheadprop  = compute_prop_left(oldheadprop,r); 
    6861   
    6962  int newheadind; 
     
    7265  else 
    7366  { 
    74     newheadLH = snodes[*h].LH; 
    75     newheadLV = snodes[*d].LV; 
    76     newheadLD = snodes[*h].LD; 
    77  
    78     newheadind = get_node(*(snodes[*h].mnode), newheadprop, newheadLH, newheadLV); 
     67    bitset<MAXNODES> newheadLH = sgraph[*h].LH; 
     68    bitset<MAXNODES> newheadLV = sgraph[*d].LV; 
     69    bitset<MAXNODES> newheadLD = sgraph[*h].LD; 
     70 
     71    newheadind = get_node(mgraph[sgraph[*h].mnode], newheadprop, newheadLH, newheadLV); 
    7972    if( newheadind < 0 ) 
    8073    { 
     
    8275      list<int>::iterator nextit=h; ++nextit; 
    8376      nodelist.insert(nextit,newheadind); 
    84       snodes[newheadind].LH=newheadLH; 
    85       snodes[newheadind].in_LH=true; 
    86       snodes[newheadind].LV.reset(); 
    87       snodes[newheadind].LD = newheadLD; 
     77      sgraph[newheadind].LH=newheadLH; 
     78      sgraph[newheadind].LD = newheadLD; 
     79      sgraph[newheadind].in_LH=true; 
     80      sgraph[newheadind].LV.reset(); 
    8881       
    8982      if(debug) sgraph.print_node_debug(stderr," C ",newheadind); 
    9083    } 
    9184    else 
    92       snodes[newheadind].LD |= newheadLD; // TYLKO DLA LD 
     85      sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 
    9386  } 
    9487 
    95   snodes[newheadind].deps.push_back(Arc(*d,r,*h)); 
    96    
    97   if(snodes[*d].saturated()) snodes[newheadind].LV |= snodes[*d].LV; 
    98   snodes[newheadind].LD.set(*d); 
    99   if(snodes[*d].saturated()) snodes[newheadind].LD |= snodes[*d].LD; 
    100    
    101   if(debug) 
    102     sgraph.print_arc(stderr,*d,newheadind,r,0), sgraph.print_node_debug(stderr," U ",newheadind); 
    103 } 
    104  
     88  sgraph[newheadind].deps.push_back(Arc(*d,r,*h)); 
     89   
     90  if(sgraph[*d].saturated()) sgraph[newheadind].LV |= sgraph[*d].LV; 
     91 
     92  sgraph[newheadind].LD.set(*d); 
     93  if(sgraph[*d].saturated()) sgraph[newheadind].LD |= sgraph[*d].LD; 
     94   
     95  if(debug) sgraph.print_arc(stderr,*d,newheadind,r,0), sgraph.print_node_debug(stderr," U ",newheadind); 
     96} 
    10597 
    10698void connect_right(list<int>::iterator h, list<int>::iterator d, Role r) 
    10799{ 
    108   NodeProp &oldheadprop = snodes[*h].prop; 
    109   NodeProp newheadprop; 
    110   bitset<MAXNODES> newheadLV; 
    111   bitset<MAXNODES> newheadLH; 
    112   bitset<MAXNODES> newheadLD; 
     100  NodeProp &oldheadprop = sgraph[*h].prop; 
     101  NodeProp newheadprop = compute_prop_right(oldheadprop,r); 
    113102  int newheadind; 
    114103   
    115   newheadprop = compute_prop_right(oldheadprop,r); 
    116104  if(oldheadprop==newheadprop) 
    117105    newheadind = *h; 
    118106  else 
    119107  { 
    120     newheadLH = snodes[*h].LH; 
    121     newheadLV = snodes[*h].LV; 
    122     newheadLD = snodes[*h].LD; 
    123  
    124     newheadind = get_node(*(snodes[*h].mnode), newheadprop, newheadLH, newheadLV); 
     108    bitset<MAXNODES> newheadLH = sgraph[*h].LH; 
     109    bitset<MAXNODES> newheadLV = sgraph[*h].LV; 
     110    bitset<MAXNODES> newheadLD = sgraph[*h].LD; 
     111 
     112    newheadind = get_node(mgraph[sgraph[*h].mnode], newheadprop, newheadLH, newheadLV); 
    125113    if( newheadind < 0 ) 
    126114    { 
    127115      newheadind = sgraph.clone(*h,newheadprop); 
    128       snodes[newheadind].LH=newheadLH; 
    129       snodes[newheadind].in_LH=false; 
    130       snodes[newheadind].LV=newheadLV; 
    131       snodes[newheadind].LD=newheadLD; 
    132116      list<int>::iterator nextit=h; ++nextit; 
    133117      nodelist.insert(nextit,newheadind); 
     118      sgraph[newheadind].LH=newheadLH; 
     119      sgraph[newheadind].LD=newheadLD; 
     120      sgraph[newheadind].in_LH=false; 
     121      sgraph[newheadind].LV=newheadLV; 
    134122       
    135123      if(debug) sgraph.print_node_debug(stderr," C ",newheadind); 
    136124    } 
    137125    else 
    138       snodes[newheadind].LD |= newheadLD; // TYLKO DLA LD 
     126      sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 
    139127  } 
    140128   
    141   snodes[*d].heads.push_back(Arc(newheadind,r,*h)); 
    142  
    143   snodes[*d].LH.set(newheadind); 
    144  
    145   if(snodes[newheadind].saturated()) snodes[*d].LH |= snodes[newheadind].LH; 
    146  
    147   if(debug) 
    148     sgraph.print_arc(stderr,newheadind,*d,r,1), sgraph.print_node_debug(stderr," U ",*d); 
     129  sgraph[*d].heads.push_back(Arc(newheadind,r,*h)); 
     130 
     131  sgraph[*d].LH.set(newheadind); 
     132 
     133  if(sgraph[newheadind].saturated()) sgraph[*d].LH |= sgraph[newheadind].LH; 
     134 
     135  if(debug) sgraph.print_arc(stderr,newheadind,*d,r,1), sgraph.print_node_debug(stderr," U ",*d); 
    149136   
    150137} 
     
    156143    if(sgraph.visible(*i,*j) && sgraph.saturated(*i)) 
    157144    { 
    158       Roles& ji_roles = grammar.connect[snodes[*j].mnode->cat][snodes[*i].mnode->cat]; 
     145      Roles& ji_roles = grammar.connectable( mgraph[sgraph[*j].mnode].cat, mgraph[sgraph[*i].mnode].cat ); 
    159146      for(RolesIter r=ji_roles.begin(); r!=ji_roles.end();++r) 
    160         if(grammar.check_constr(snodes[*j].prop,snodes[*i].prop,0,*r)) 
     147        if(grammar.check_constr(sgraph[*j].prop,sgraph[*i].prop,0,*r)) 
    161148          connect_left(j,i,*r); 
    162149    } 
     
    169156    if(sgraph.visible(*i,*j)) 
    170157    { 
    171       Roles& ij_roles = grammar.connect[snodes[*i].mnode->cat][snodes[*j].mnode->cat]; 
     158      Roles& ij_roles = grammar.connectable( mgraph[sgraph[*i].mnode].cat, mgraph[sgraph[*j].mnode].cat ); 
    172159      for(RolesIter r=ij_roles.begin(); r!=ij_roles.end();++r) 
    173         if(grammar.check_constr(snodes[*i].prop,snodes[*j].prop,1,*r)) 
     160        if(grammar.check_constr(sgraph[*i].prop,sgraph[*j].prop,1,*r)) 
    174161          connect_right(i,j,*r); 
    175162    } 
     
    182169  for(++i; i!=nodelist.end(); ++i) 
    183170    { 
    184       for(vector<Arc>::iterator da=sgraph.nodes[*i].deps.begin()--; da!=sgraph.nodes[*i].deps.end(); ++da) 
    185         sgraph.nodes[da->dst].heads.push_back(Arc(*i,da->role,da->anc)); 
    186       for(vector<Arc>::iterator ha=sgraph.nodes[*i].heads.begin(); ha!=sgraph.nodes[*i].heads.end(); ++ha) 
    187         sgraph.nodes[ha->dst].deps.push_back(Arc(*i,ha->role,ha->anc)); 
     171      for(vector<Arc>::iterator da=sgraph[*i].deps.begin()--; da!=sgraph[*i].deps.end(); ++da) 
     172        sgraph[da->dst].heads.push_back(Arc(*i,da->role,da->anc)); 
     173      for(vector<Arc>::iterator ha=sgraph[*i].heads.begin(); ha!=sgraph[*i].heads.end(); ++ha) 
     174        sgraph[ha->dst].deps.push_back(Arc(*i,ha->role,ha->anc)); 
    188175    } 
    189176} 
     
    192179void dgp0() 
    193180{ 
    194   snodes=sgraph.nodes; 
    195181 
    196182  nodelist.clear(); 
     
    198184  processed=nodelist.begin(); 
    199185 
    200   for(int m=0; m<mgraph.n ; ++m) 
     186  for(int m=0; m<mgraph.size() ; ++m) 
    201187  { 
    202     int basenode = sgraph.add_base_snode(mgraph.nodes+m); // ma zwracaæ SNode* 
     188    int basenode = sgraph.add_base_snode(m); // ma zwracaæ SNode* 
     189 
    203190    set_initial_constraints(basenode); 
    204191    nodelist.push_back(basenode); 
     
    213200      processed=cursor; 
    214201    } 
     202 
    215203  } 
    216204  reverse_links(); 
  • src/dgp/grammar.cc

    r5f4d9c3 re7de6cc  
    11 
    2 #include <stdio.h> 
     2#include <cstdio> 
    33 
    44#include "grammar.hh" 
    55 
    6 bool (*constraint[MAXCONSTRS])(int head, int dep); 
    7  
    8  
    9 int chk_type(const char* s, int lineno) // SIDE EFECTS! 
    10 { 
    11   if(Role::index(s)>0) return 1; 
    12  
    13   fprintf(stderr,"%8d: Invalid type '%s'. Line ignored.\n",lineno,s); 
    14   return 0; 
    15 } 
    16  
    17 int chk_cat(const char* s, int lineno) 
    18 { 
    19   if(Cat::index(s)>0) return 1; 
    20  
    21   fprintf(stderr,"%8d: Invalid category '%s'. Line ignored.\n",lineno,s); 
    22   return 0; 
    23 } 
     6//bool (*constraint[MAXCONSTRS])(int head, int dep); 
     7 
     8//==================================================================================================== 
     9//inline !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
     10bool chk_type(const char* s) { return Role::index(s)>0; } // PRZENIEŠÆ DO Role 
     11//---------------------------------------------------------------------------------------------------- 
     12//inline !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
     13bool chk_long(const char* s) { return LongRel::index(s)>0; } // jw 
     14//---------------------------------------------------------------------------------------------------- 
     15//inline !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
     16bool chk_cat(const char* s) { return Cat::index(s)>0; } //jw 
     17//---------------------------------------------------------------------------------------------------- 
     18//inline !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
     19bool chk_flag(const char* s) { return Flag::index(s)>0; } //jw 
     20//==================================================================================================== 
     21 
     22void grammar_error(int lineno, string s="Grammar error.") 
     23{ 
     24  fprintf(stderr,"%8d: %s Line ignored.\n",lineno,s.c_str()); 
     25} 
     26 
     27//==================================================================================================== 
    2428 
    2529void Grammar::add_category(const char* s) 
    2630{ 
    2731  Cat::add(s); 
    28   if(Cat::count()>cats_sz) 
     32 
     33  if(connect.size() <= Cat::count()) 
    2934  { 
    30     cats_sz += 16; 
    31     connect.resize(cats_sz); 
    32     for(int i=0; i<cats_sz; ++i) 
    33       connect[i].resize(cats_sz); 
    34     obl.resize(cats_sz); 
     35    connect.resize(Cat::count()+RESIZE_DELTA); 
     36    for(int i=0; i<connect.size(); ++i) 
     37      if(connect[i].size() <= Cat::count()) connect[i].resize(Cat::count()+RESIZE_DELTA); 
    3538  } 
     39  if(connect1.size() <= Cat::count()) 
     40  { 
     41    connect1.resize(Cat::count()+RESIZE_DELTA); 
     42    for(int i=0; i<=connect1.size(); ++i) 
     43      if(connect1[i].size() <= Cat::count()) connect1[i].resize(Cat::count()+RESIZE_DELTA); 
     44  } 
     45 
     46  if(longrel.size() <= Cat::count()) 
     47  { 
     48    longrel.resize(Cat::count()+RESIZE_DELTA); 
     49    for(int i=0; i<longrel.size(); ++i) 
     50      if(longrel[i].size() <= Cat::count()) longrel[i].resize(Cat::count()+RESIZE_DELTA); 
     51  } 
     52 
     53  if(uptrigger.size() <= Cat::count()) 
     54    uptrigger.resize(Cat::count()+RESIZE_DELTA); 
     55  if(dntrigger.size() <= Cat::count()) 
     56    dntrigger.resize(Cat::count()+RESIZE_DELTA); 
     57   
     58  if(obl.size() <= Cat::count()) obl.resize(Cat::count()+RESIZE_DELTA); 
     59  if(set.size() <= Cat::count()) set.resize(Cat::count()+RESIZE_DELTA); 
    3660} 
    3761 
     
    3963 
    4064  Role::add(s); 
    41   if(Role::count()>types_sz) 
    42   { 
    43     types_sz += 16; 
    44     lt.resize(types_sz); 
    45     gt.resize(types_sz); 
    46   } 
    47 } 
    48  
    49 void Grammar::add_flag(const char* s) 
    50  
    51   Flag::add(s); 
    52   if(Flag::count()>flags_sz) 
    53   { 
    54     flags_sz += 16; 
    55     pass.resize(flags_sz); 
    56   } 
    57 } 
    58  
     65 
     66  if(lt.size() <= Role::count()) lt.resize(Role::count()+RESIZE_DELTA); 
     67  if(gt.size() <= Role::count()) gt.resize(Role::count()+RESIZE_DELTA); 
     68  if(pass.size() <= Role::count()) pass.resize(Role::count()+RESIZE_DELTA); 
     69  if(include.size() <= Role::count()) include.resize(Role::count()+RESIZE_DELTA); 
     70  if(exclude.size() <= Role::count()) exclude.resize(Role::count()+RESIZE_DELTA); 
     71  for(int i=0; i<uptrigger.size(); i++) 
     72    if(uptrigger[i].size() <= Role::count()) uptrigger[i].resize(Role::count()+RESIZE_DELTA); 
     73  for(int i=0; i<dntrigger.size(); i++) 
     74    if(dntrigger[i].size() <= Role::count()) dntrigger[i].resize(Role::count()+RESIZE_DELTA); 
     75} 
     76 
     77//==================================================================================================== 
     78 
     79bool Grammar::contains_boubble(const list<Boubble*> boubble_list, Boubble* bp) const 
     80{ 
     81  for(list<Boubble*>::const_iterator bi = boubble_list.begin(); bi != boubble_list.end(); bi++ ) 
     82    if(**bi == *bp) return true; 
     83  return false; 
     84} 
     85 
     86//---------------------------------------------------------------------------------------------------- 
     87 
     88void Grammar::add_triggers(Cat src, Cat dest, LongRel l) 
     89{ 
     90  for(list<Boubble*>::const_iterator b=boubbles.begin(); b!=boubbles.end(); b++) 
     91    if((*b)->rel() == l) 
     92      { 
     93        list<Boubble*>& boubble_list = ((*b)->dir()==UP) ? uptrigger[src][(*b)->next()] : dntrigger[src][(*b)->next()] ; 
     94        if(!contains_boubble(boubble_list,*b)) 
     95          boubble_list.push_back(*b); 
     96      } 
     97} 
     98 
     99//==================================================================================================== 
    59100 
    60101void Grammar::set_lt(Role s, Role t) 
     
    85126 
    86127 
     128void Grammar::compute_triggers() 
     129{ 
     130  //init uptrigger array 
     131  uptrigger.resize(Cat::count()); 
     132  for(int i=0; i<uptrigger.size(); i++) 
     133    uptrigger[i].resize(Role::count()); 
     134  //init dntrigger array 
     135  dntrigger.resize(Cat::count()); 
     136  for(int i=0; i<dntrigger.size(); i++) 
     137    dntrigger[i].resize(Role::count()); 
     138 
     139  // for(int c=0; c<Cat::count(); c++) 
     140  //   for(int r=0; r<Role::count(); r++) 
     141  //     for(list<Boubble>::const_iterator b=boubbles.begin(); b!=boubbles.end; b++) 
     142  //    if(b->dir()==UP && ) 
     143} 
     144 
     145//==================================================================================================== 
     146 
     147list<Boubble*> Grammar::trigger_boubbles(Cat c, Role r, Dir d) 
     148{ 
     149  list<Boubble*> boubble_list = (d == UP) ? uptrigger[c][r] : dntrigger[c][r]; 
     150  list<Boubble*> ret; 
     151  for(list<Boubble*>::iterator b = boubble_list.begin(); b != boubble_list.end(); ++b) 
     152    ret.push_back((*b)->step(r,d)); 
     153  return ret;   
     154} 
     155 
     156//==================================================================================================== 
     157 
     158Flag parse_flags(const char* s, const char* v) 
     159{ 
     160  char buf[16][17]; 
     161  int n=sscanf(s,"%[A-Z]%[+-]%[A-Z]%[+-]%[A-Z]%[+-]%[A-Z]%[+-]%[A-Z]%[+-]%[A-Z]%[+-]%[A-Z]%[+-]%[A-Z]%[+-]", 
     162               buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],buf[8],buf[9],buf[10],buf[11],buf[12],buf[13],buf[14],buf[15],buf[16]); 
     163  for(int i=2; i<=n; i+=2) 
     164    if(strcmp(buf[i-1],v)==0) 
     165      return Flag(buf[i-2]); 
     166  return Flag("NULL"); 
     167} 
     168 
     169 
     170PropSet parse_props(const char* s) 
     171{ 
     172  PropSet ret; 
     173  char buf[8][17]; 
     174  int n=sscanf(s,"&%[A-Z]&%[A-Z]&%[A-Z]&%[A-Z]&%[A-Z]&%[A-Z]&%[A-Z]&%[A-Z]",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]); 
     175  for(int i=1; i<=n; i++) 
     176    ret.set(Prop(buf[i-1])); 
     177  return ret;  
     178   
     179} 
     180 
     181 
    87182bool Grammar::read(FILE* f) 
    88183{ 
     184 
     185  //>>> TU? 
     186 
     187  Prop::add("INIT"); 
     188  Prop::add("FIN"); 
     189 
     190  //<<< TU? 
     191 
     192 
    89193  int lineno=0; 
    90194  char line[MAXLINE]; // line has the structure: key [arg1 [arg2 [arg3]]] 
     
    93197  char arg2[MAXLINE]; 
    94198  char arg3[MAXLINE]; 
     199  char arg4[MAXLINE]; 
    95200 
    96201  while(fgets(line,MAXLINE,f)) 
    97   { 
    98     lineno++; 
    99     int fields=sscanf(line,"%s %s %s %s",key,arg1,arg2,arg3); 
    100  
    101     if(fields<1 || key[0]=='#') continue; // skip empty lines and comments 
    102  
    103     if     (strcmp(key,"CAT")==0 && fields>=2) 
    104202    { 
    105       add_category(arg1); 
     203      lineno++; 
     204      int fields=sscanf(line,"%s %s %s %s %s",key,arg1,arg2,arg3,arg4); 
     205       
     206       if(fields<1 || key[0]=='#') continue; // skip empty lines and comments 
     207 
     208      if(fields>1 && arg1[0] == '#') fields=1; 
     209      if(fields>2 && arg2[0] == '#') fields=2; 
     210      if(fields>3 && arg3[0] == '#') fields=3; 
     211      if(fields>4 && arg4[0] == '#') fields=4; 
     212       
     213      if     (strcmp(key,"CAT")==0 && fields==2) 
     214        { 
     215          add_category(arg1); 
     216        } 
     217      else if(strcmp(key,"ROLE")==0 && fields==2) 
     218        { 
     219          add_type(arg1); 
     220        } 
     221      else if(strcmp(key,"SGL")==0 && fields==2) 
     222        {   
     223          if(chk_type(arg1)) 
     224            set_sgl(arg1); 
     225          else 
     226            grammar_error(lineno); 
     227        } 
     228      else if(strcmp(key,"LEFT")==0 && fields==2) 
     229        {  
     230          if(chk_type(arg1)) 
     231            set_left(arg1); 
     232          else 
     233            grammar_error(lineno); 
     234        } 
     235      else if(strcmp(key,"RIGHT")==0 && fields==2) 
     236        { 
     237          if(chk_type(arg1)) 
     238            set_right(arg1); 
     239          else 
     240            grammar_error(lineno); 
     241        } 
     242      else if(strcmp(key,"INITR")==0 && fields==2) 
     243        { 
     244          if(chk_type(arg1)) 
     245            set_init(arg1); 
     246          else 
     247            grammar_error(lineno); 
     248        } 
     249      else if(strcmp(key,"FINR")==0 && fields==2) 
     250        { 
     251          if(chk_type(arg1)) 
     252            set_fin(arg1); 
     253          else 
     254            grammar_error(lineno); 
     255        } 
     256      else if(strcmp(key,"INITF")==0 && fields==2) 
     257        { 
     258          if(chk_flag(arg1)) 
     259            set_initf(arg1); 
     260          else 
     261            grammar_error(lineno); 
     262        } 
     263      else if(strcmp(key,"FINF")==0 && fields==2) 
     264        { 
     265          if(chk_flag(arg1)) 
     266            set_finf(arg1); 
     267          else 
     268            grammar_error(lineno); 
     269        } 
     270      else if(strcmp(key,"REQ")==0 && fields==3) 
     271        { 
     272          if( chk_cat(arg1) && chk_type(arg2) ) 
     273            set_obl(arg1,arg2); 
     274          else 
     275            grammar_error(lineno); 
     276        } 
     277      else if(strcmp(key,"CONSTRE")==0 && fields==3) 
     278        { 
     279          if( chk_type(arg1) && chk_type(arg2) ) 
     280            set_exclude(arg1,arg2); 
     281          else 
     282            grammar_error(lineno); 
     283        } 
     284      else if(strcmp(key,"CONSTRI")==0 && fields==3) 
     285        { 
     286          if( chk_type(arg1) && chk_type(arg2) ) 
     287            set_include(arg1,arg2); 
     288          else 
     289            grammar_error(lineno); 
     290        } 
     291      else if(strcmp(key,"LONG")==0 &&  fields ==3) 
     292        { 
     293            add_long(arg1,arg2); 
     294        } 
     295      else if(strcmp(key,"LINK")==0 && fields==4) 
     296        {  
     297          char cat1[MAXLINE],flags1[MAXLINE],cat2[MAXLINE],flags2[MAXLINE],type[MAXLINE],props[MAXLINE]; 
     298 
     299          if(sscanf(arg1,"%[^;];%s",cat1,flags1)==1) *flags1='\0';  
     300          if(sscanf(arg2,"%[^;];%s",cat2,flags2)==1) *flags2='\0';  
     301          if(sscanf(arg3,"%[^&]%s",type,props)==1) *props='\0'; 
     302           
     303          //      printf("line=%s\n\tcat1=%s flags1=%s cat2=%s flags2=%s type=%s props=%s\n",line,cat1,flags1,cat2,flags2,type,props); 
     304 
     305          if( chk_cat(cat1) && chk_cat(cat2) && chk_type(type) ) 
     306            set_connect(cat1,parse_flags(flags1,"+"),parse_flags(flags1,"-"),cat2,parse_flags(flags2,"+"),parse_flags(flags2,"-"),type,parse_props(props)); 
     307          else if( chk_cat(cat1) && chk_cat(cat2) && chk_long(type) ) 
     308            { 
     309              set_longrel(cat1,cat2,type); 
     310              add_triggers(cat1,cat2,type); 
     311            } 
     312          else 
     313              grammar_error(lineno); 
     314        } 
     315      // else if(strcmp(key,"LINK")==0 && fields==5) 
     316      //        {  
     317      //          if( chk_cat(arg1) && chk_cat(arg2) && chk_type(arg4) ) 
     318      //            set_connect(arg1,arg2,arg3,arg4); 
     319      //          else 
     320      //              grammar_error(lineno); 
     321      //        } 
     322      // FLAG DECLARATION 
     323      else if(strcmp(key,"FLAG")==0 && fields==2) 
     324        {  
     325          add_flag(arg1); 
     326        } 
     327      else if(strcmp(key,"SET")==0 && fields==3) 
     328        { 
     329          if( chk_cat(arg1) && chk_flag(arg2) ) 
     330            set_set(arg1,arg2); 
     331          else 
     332            grammar_error(lineno); 
     333        } 
     334      else if(strcmp(key,"PASS")==0 && fields==3) 
     335        { 
     336          if( chk_type(arg1) && chk_flag(arg2) ) 
     337            set_pass(arg1,arg2); 
     338          else 
     339            grammar_error(lineno); 
     340        } 
     341       
     342      else fprintf(stderr,"Statement not recognized in line %d. Ignored.\n", lineno); 
    106343    } 
    107     else if(strcmp(key,"ROLE")==0 && fields>=2) 
    108     { 
    109       add_type(arg1); 
    110     } 
    111     else if(strcmp(key,"SGL")==0 && fields>=2) 
    112     {   
    113       if(chk_type(arg1,lineno)) 
    114         set_sgl(arg1); 
    115     } 
    116     else if(strcmp(key,"LEFT")==0 && fields>=2) 
    117     {  
    118       if(chk_type(arg1,lineno)) 
    119         set_left(arg1); 
    120     } 
    121     else if(strcmp(key,"RIGHT")==0 && fields>=2) 
    122     { 
    123       if(chk_type(arg1,lineno)) 
    124         set_right(arg1); 
    125     } 
    126     else if(strcmp(key,"REQ")==0 && fields>=3) 
    127     { 
    128       if(chk_cat(arg1,lineno) + chk_type(arg2,lineno) == 2) 
    129         set_obl(arg1,arg2); 
    130     } 
    131     else if(strcmp(key,"LINK")==0 && fields>=4) 
    132     {  
    133       if(chk_cat(arg1,lineno) + chk_cat(arg2,lineno) + chk_type(arg3,lineno) == 3)     
    134         set_connect(arg1,arg2,arg3); 
    135     } 
    136     // FLAG DECLARATION 
    137     else if(strcmp(key,"FLAG")==0 && fields>=2) 
    138     {  
    139       add_flag(arg1); 
    140     } 
    141  
    142     else fprintf(stderr,"Invalid line %d. Ignored.\n", lineno); 
    143   } 
    144  
    145 //   compute_gt(); 
    146  
     344   
     345  //   compute_gt(); 
     346   
    147347  return true; 
    148348   
    149349} 
     350 
     351 
     352void Grammar::write(ostream& os) 
     353{ 
     354  for(Cat i=1; i<Cat::count(); ++i) 
     355    os << "CAT\t" << i.str() << endl; 
     356 
     357  for(Role i=1; i<Role::count(); ++i) 
     358    os << "ROLE\t" << i.str() << endl; 
     359 
     360  for(Role i=1; i<Role::count(); ++i) 
     361    if(sgl.test(i)) 
     362      os << "SGL\t" << i.str() << endl; 
     363   
     364  for(Role i=1; i<Role::count(); ++i) 
     365    if(left.test(i)) 
     366      os << "LEFT\t" << i.str() << endl; 
     367 
     368  for(Role i=1; i<Role::count(); ++i) 
     369    if(right.test(i)) 
     370      os << "RIGHT\t" << i.str() << endl; 
     371 
     372  for(Cat c=1; c<Cat::count(); ++c) 
     373    for(Role r=1; r<Role::count(); ++r) 
     374      if(obl[c].test(r)) 
     375        os << "REQ\t" << c.str() << "\t" << r.str() << endl; 
     376   
     377  for(Cat c=1; c<Cat::count(); ++c) 
     378    for(Cat d=1; d<Cat::count(); ++d) 
     379      for(Links::const_iterator l = connect1[c][d].begin(); l != connect1[c][d].end(); l++) 
     380        { 
     381          os << "LINK\t" << c.str(); 
     382          if(l->hflagplus||l->hflagminus) 
     383            { 
     384              os << ";"; 
     385              if(l->hflagplus) os << (l->hflagplus).str() << "+"; 
     386              if(l->hflagminus) os << (l->hflagminus).str() << "-";  
     387            } 
     388          os << "\t" << d.str(); 
     389          if(l->dflagplus||l->dflagminus) 
     390            { 
     391              os << ";"; 
     392              if(l->dflagplus) os << (l->dflagplus).str() << "+"; 
     393              if(l->dflagminus) os << (l->dflagminus).str() << "-";  
     394            } 
     395          os << "\t" << (l->role).str(); 
     396          for(Prop p=0; p<Prop::count(); ++p) 
     397            if(l->props[p]) 
     398              os << "&" << p.str(); 
     399          os << endl; 
     400        } 
     401 
     402  for(LongRel i=1; i<LongRel::count(); ++i) 
     403    os << "LONG\t" << i.str() << endl; 
     404 
     405  for(list<Boubble*>::const_iterator b = boubbles.begin(); b != boubbles.end(); b++) 
     406    os << "BOUBBLE\t" << **b << endl; 
     407 
     408  for(Cat c=1; c<Cat::count(); ++c) 
     409    for(Cat d=1; d<Cat::count(); ++d) 
     410      for(LongRel l=1; l<LongRel::count(); ++l) 
     411        if(longrel[c][d].count(l)) 
     412          os << "LLINK\t" << c.str() << "\t" << d.str() << "\t" << l.str() << endl; 
     413 
     414  for(Cat c=1; c<Cat::count(); ++c) 
     415    for(Flag f=1; f<Flag::count(); ++f) 
     416      if(set[c].test(f)) 
     417        os << "SET\t" << c.str() << "\t" << f.str() << endl; 
     418 
     419  for(Role r=1; r<Role::count(); ++r) 
     420    for(Flag f=1; f<Flag::count(); ++f) 
     421      if(pass[r].test(f)) 
     422        os << "PASS\t" << r.str() << "\t" << f.str() << endl; 
     423   
     424  for(Role r=1; r<Role::count(); ++r) 
     425    for(Role t=1; t<Role::count(); ++t) 
     426      if(include[r].test(t)) 
     427        os << "CONSTRI\t" << r.str() << "\t" << t.str() << endl; 
     428   
     429  for(Role r=1; r<Role::count(); ++r) 
     430    for(Role t=1; t<Role::count(); ++t) 
     431      if(exclude[r].test(t)) 
     432        os << "CONSTRE\t" << r.str() << "\t" << t.str() << endl; 
     433   
     434  for(Cat c=1; c<Cat::count(); ++c) 
     435    for(Role r=1; r<Role::count(); ++r) 
     436      for(list<Boubble*>::const_iterator b=uptrigger[c][r].begin(); b!=uptrigger[c][r].end(); b++) 
     437        os << "TRIGGER-UP\t" << c.str() << "\t" << r.str() << "\t" << (*b)->rel().str() << endl; 
     438 
     439  for(Cat c=1; c<Cat::count(); ++c) 
     440    for(Role r=1; r<Role::count(); ++r) 
     441      for(list<Boubble*>::const_iterator b=dntrigger[c][r].begin(); b!=dntrigger[c][r].end(); b++) 
     442        os << "TRIGGER-DN\t" << c.str() << "\t" << r.str() << "\t" << (*b)->rel().str() << endl; 
     443 
     444  for(Flag i=1; i<Flag::count(); ++i) 
     445    os << "FLAG\t" << i.str() << endl; 
     446} 
     447 
     448 
     449 
     450 
     451 
     452 
     453 
     454 
     455 
     456//================================= OLD 
    150457 
    151458void Grammar::write(FILE* f) 
     
    155462 
    156463  for(Role i=1; i<Role::count(); ++i) 
    157     fprintf(f,"ROLE\t%s\n",i.str()); 
     464    fprintf(f,"ROLE\t%s (%d)(%d)\n",i.str(),Role::index(i.str()),chk_type(i.str())); 
    158465 
    159466  for(Role i=1; i<Role::count(); ++i) 
     
    176483          fprintf(f,"LINK\t%s\t%s\t%s\n",c.str(),d.str(),t.str()); 
    177484 
     485  for(LongRel i=1; i<LongRel::count(); ++i) 
     486    fprintf(f,"LONG\t%s\n",i.str()); 
     487 
     488  for(Cat c=1; c<Cat::count(); ++c) 
     489    for(Cat d=1; d<Cat::count(); ++d) 
     490      for(LongRel l=1; l<LongRel::count(); ++l) 
     491        if(longrel[c][d].count(l)) 
     492          fprintf(f,"LLINK\t%s\t%s\t%s\n",c.str(),d.str(),l.str()); 
     493 
     494  for(Cat c=1; c<Cat::count(); ++c) 
     495    for(Role r=1; r<Role::count(); ++r) 
     496      for(list<Boubble*>::const_iterator b=uptrigger[c][r].begin(); b!=uptrigger[c][r].end(); b++) 
     497        fprintf(f,"#TRIGGER\t%s\t%s\t%s\n",c.str(),r.str(),(*b)->rel().str()); 
     498 
     499  for(Cat c=1; c<Cat::count(); ++c) 
     500    for(Role r=1; r<Role::count(); ++r) 
     501      for(list<Boubble*>::const_iterator b=dntrigger[c][r].begin(); b!=dntrigger[c][r].end(); b++) 
     502        fprintf(f,"#TRIGGER\t%s\t%s\t%s\n",c.str(),r.str(),(*b)->rel().str()); 
     503 
    178504  for(Flag i=1; i<Flag::count(); ++i) 
    179505    fprintf(f,"FLAG\t%s\n",i.str()); 
    180506} 
    181  
  • src/dgp/grammar.hh

    r5f4d9c3 re7de6cc  
    1010#include "thesymbols.hh" 
    1111#include "sgraph.hh" 
    12  
    13  
    14 class Link 
    15 { 
     12#include "boubble.hh" 
     13 
     14using namespace std; 
     15 
     16//enum PROP { INIT=0, FIN=1 }; 
     17//typedef bitset<16> PropSet; 
     18 
     19const PropSet EmptyPropSet = PropSet(); 
     20 
     21const FlagSet EmptyFlagSet = FlagSet(); 
     22 
     23//==================================================================================================== 
     24// class Link 
     25//==================================================================================================== 
     26 
     27struct 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 
    1634  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 
    1952}; 
    2053 
     54typedef set<Link> Links; 
     55 
     56//==================================================================================================== 
     57// class Grammar 
     58//==================================================================================================== 
    2159 
    2260class Grammar 
     
    2563 public: 
    2664 
    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]; }; 
    3083   
    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 
     93private: 
     94 
    3695  RoleSet                      sgl; 
    37   vector< RoleSet >            obl; 
     96  vector< RoleSet >            obl;      //[Cat] 
    3897  RoleSet                      left; 
    3998  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] 
    50124 
    51125  void add_category(const char* s); 
    52126  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); } 
    61151  void set_lt(Role r, Role s); 
    62152  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; 
    66155 
    67156}; 
    68157 
    69 inline bool Grammar::check_constr(NodeProp& hprop, NodeProp& dprop, int dir, Role role) 
     158//---------------------------------------------------------------------------------------------------- 
     159 
     160inline 
     161Roles&  Grammar::connectable(Cat h, Cat d) 
     162{ 
     163  return connect[h][d]; 
     164} 
     165 
     166//---------------------------------------------------------------------------------------------------- 
     167 
     168inline 
     169Roles 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 
     181inline 
     182list<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 
     194inline 
     195bool Grammar::check_constr(NodeProp& hprop, NodeProp& dprop, int dir, Role role)    // dir: 0-left 1-right 
    70196{ 
    71197  return  
    72198    !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() ) 
    75203    ; 
    76204} 
    77205 
     206//---------------------------------------------------------------------------------------------------- 
     207 
     208inline 
     209bool 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 
     222inline 
     223bool 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 
     230inline bool Grammar::is_sgl(Role r) 
     231{ 
     232  return sgl[r]; 
     233} 
     234 
     235//---------------------------------------------------------------------------------------------------- 
     236 
     237inline RoleSet Grammar::is_obl(Cat c) 
     238{ 
     239  return obl[c]; 
     240} 
     241 
     242//==================================================================================================== 
    78243 
    79244#endif 
  • src/dgp/main.cc

    r5f4d9c3 re7de6cc  
    1111#include "sgraph.hh" 
    1212#include "grammar.hh" 
    13 #include "dgp0.hh" 
     13#include "dgp1.hh" 
    1414#include "../common/common.h" 
    1515#include "cmdline.h" 
     
    2525Grammar grammar; 
    2626MGraph mgraph; 
    27 SGraph sgraph; 
     27SGraph sgraph(mgraph); 
    2828 
    2929FILE* grammarf; 
     
    6565  fclose(grammarf); 
    6666 
     67 
     68 
     69  // grammar.write(cout); 
     70  // exit(0); 
     71 
     72 
     73 
    6774  mgraph.clear(); 
    6875  sgraph.clear(); 
     
    8390    if(strcmp(segtype,"EOS")==0) 
    8491    { 
    85       dgp0(); // parametry!!! MGraph, SGraph, Grammar 
     92      dgp1(); // parametry!!! MGraph, SGraph, Grammar 
    8693      output(); 
    8794       
     
    105112    if(seg_mnode[si]>=0) 
    106113    { 
    107       MNode& m=mgraph.nodes[seg_mnode[si]]; 
     114      MNode& m=mgraph[seg_mnode[si]]; 
    108115      for(vector<int>::iterator s=m.snodes.begin(); s!=m.snodes.end(); ++s) 
    109116      { 
  • src/dgp/mgraph.cc

    r5f4d9c3 re7de6cc  
    44#include "const.hh" 
    55 
    6 #include <stdio.h> 
     6#include <cstdio> 
    77 
    88int MGraph::add_node(char* seg) 
    99{ 
    10   nodes[n].clear(); 
     10  MNode newnode; 
     11  newnode.clear(); 
    1112   
    12   char field1[80], field3[80], descr[256], gph[256]; 
     13  char field1[80], field3[80], field4[256], descr[256], gph[256]; 
    1314  char* cat; 
    1415   
    1516  getfield(seg,"1",field1); 
    16   nodes[n].pos=atoi(field1); 
     17  newnode.pos=atoi(field1); 
    1718 
    1819  getfield(seg,"3",field3); 
     20 
     21  getfield(seg,"4",field4); 
     22  strcpy(newnode.form,field4); 
     23 
    1924  if(!getfield(seg,"lem",descr)) strcpy(descr,"?,?"); 
    2025 
     
    2328  if(*cat) ++cat; 
    2429   
    25 //  Cat::add(cat); 
    2630  if(Cat::index(cat)>0) 
    27     nodes[n].cat=cat; 
     31    newnode.cat=cat; 
    2832  else 
    29     nodes[n].cat="NULL"; 
     33    newnode.cat="NULL"; 
    3034   
    31   nodes[n].pred.clear(); 
     35  newnode.pred.clear(); 
    3236   
    3337  char* tok; 
     
    4145 
    4246  char* ids=strtok(gph,":"); 
    43   if(n!=atoi(ids)){fprintf(stderr,"Invalid node id in line ?. Program aborted.\n"); exit(1); } 
     47  if(size() != atoi(ids)) {fprintf(stderr,"Invalid node id in line ?. Program aborted.\n"); exit(1); } 
    4448   
    4549  char *preds; 
     
    4751  { 
    4852    previd=atoi(preds); 
    49     nodes[n].pred.push_back(&nodes[previd]); 
     53    newnode.pred.push_back(previd); 
    5054  } 
    5155 
    52   return n++; 
     56  nodes.push_back(newnode); 
     57  return nodes.size()-1; 
    5358} 
    5459 
  • src/dgp/mgraph.hh

    r5f4d9c3 re7de6cc  
    88#include "../common/common.h" 
    99 
     10 
     11using namespace std; 
     12 
    1013class MNode 
    1114{ 
    1215public: 
    1316 
    14   char           type[MAXFORMLEN]; 
     17  int            pos; 
     18  char           form[256]; 
    1519  Cat            cat; 
    16   int            pos; 
    17   vector<MNode*> pred; 
     20  vector<int>    pred; 
    1821  vector<int>    snodes; 
    1922 
    2023  void           clear() { snodes.clear(); }; 
    2124}; 
    22  
     25  
    2326class MGraph 
    2427{ 
    25  public: 
     28public: 
    2629 
    27   MNode nodes[MAXNODES]; 
    28   int   n; 
     30  void clear() { nodes.clear(); } 
     31  int size() { return nodes.size(); } 
     32  int add_node(char* seg); 
     33  MNode& operator[](int i) { return nodes[i]; } 
    2934 
    30   void clear() { n=0; }; 
    31   int add_node(char* seg); 
     35private: 
     36 
     37  vector<MNode> nodes; 
     38 
    3239}; 
    3340 
  • src/dgp/sgraph.cc

    r5f4d9c3 re7de6cc  
    11#include "global.hh" 
    22#include "sgraph.hh" 
    3 #include "mgraph.hh" 
    43#include "grammar.hh" 
    54#include "const.hh" 
    6 #include <stdio.h> 
     5#include <cstdio> 
     6#include <sstream> 
    77 
     8extern MGraph mgraph; 
    89 
    9 int SGraph::add_base_snode(MNode* mn) 
     10//==================================================================================================== 
     11 
     12int SGraph::add_base_snode(int mnodeind) 
    1013{ 
    11   int nodeind=n; 
    12   SNode &node=nodes[n]; 
     14  SNode& newnode =  makenewnode();  
    1315 
    14   node.clear(); 
     16  newnode.mnode=mnodeind; 
    1517 
    16   node.mnode=mn; 
    17  
    18   for(vector<MNode*>::iterator pm=node.mnode->pred.begin(); pm!=node.mnode->pred.end(); ++pm) 
    19     for(vector<int>::iterator ps=(*pm)->snodes.begin(); ps!=(*pm)->snodes.end(); ++ps) 
     18  for(vector<int>::iterator pm=mgraph[newnode.mnode].pred.begin(); pm!=mgraph[newnode.mnode].pred.end(); ++pm) 
     19    for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) 
    2020      if(nodes[*ps].in_LH) 
    2121      { 
    22         node.LV.set(*ps); 
    23         if(nodes[*ps].saturated()) node.LV |= nodes[*ps].LH; 
     22        newnode.LV.set(*ps); 
     23        if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH; 
    2424      } 
    2525 
    26   mn->snodes.push_back(nodeind); 
    27   ++n; 
     26  mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 
    2827 
    29   node.in_LH=true; 
     28  newnode.in_LH=true; 
    3029 
    31   return nodeind; 
     30  return lastnodeind(); 
    3231} 
    3332 
     33//==================================================================================================== 
    3434 
    3535void SGraph::update_left(int headind, int depind) 
     
    3737  SNode &head=nodes[headind], &dep=nodes[depind]; 
    3838 
    39   if(dep.saturated()) head.LV |= dep.LV, head.LD |= dep.LD; 
     39  if(dep.saturated())  head.LV |= dep.LV, head.LD |= dep.LD; 
    4040} 
    4141 
     
    4646 
    4747  dep.LH.set(headind); 
    48   if(head.saturated()) 
    49     dep.LH |= head.LH; 
    50 } 
     48  if(head.saturated())  dep.LH |= head.LH; 
     49}  
    5150 
     51//==================================================================================================== 
    5252 
    5353int SGraph::clone(int ancind, NodeProp newprop) 
    5454{ 
    55   int newind = n++; 
    56   SNode &newnode=nodes[newind]; 
     55  SNode &newnode=makenewnode(); 
    5756  SNode &ancnode = nodes[ancind]; 
    5857 
    59   newnode.clear(); 
     58 
     59 
    6060  newnode.prop=newprop; 
    6161  newnode.mnode=ancnode.mnode; 
    62   newnode.mnode->snodes.push_back(newind); 
    63   return newind; 
     62  mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 
     63 
     64  return lastnodeind(); 
    6465} 
    6566 
    66  
    67 //------------------------------------------------------------------------- 
    68 //------------------------------------------------------------------------- 
    69  
     67//==================================================================================================== 
    7068 
    7169int SGraph::print_node(FILE* f, int n, unsigned int info) 
    7270{ 
    73   char buf[1000]; 
    74   sprint_node(buf,n,info); 
     71  char buf[50000]; 
     72  sprint_node(buf,n,-1,info); 
    7573  fputs(buf,f); 
    7674} 
    7775 
    78 int SGraph::sprint_node(char* buf, int nodeind, unsigned int info) 
     76//---------------------------------------------------------------------------------------------------- 
     77 
     78int SGraph::print_node_debug(FILE* f, const char* pref, int n, int anc) 
     79{ 
     80  char buf[50000]; 
     81  sprint_node_debug(buf,pref,n,anc); 
     82  fputs(buf,f); 
     83} 
     84 
     85//---------------------------------------------------------------------------------------------------- 
     86 
     87void SGraph::print_arc(FILE* f, int head, int dep, Role role, int dir) // 0 - left, 1 - right 
     88{ 
     89  if(dir==0) 
     90    fprintf(f,"#A  %s:%d <-- %d\n", role.str(), dep, head); 
     91  else 
     92    fprintf(f,"#A  %s:%d --> %d\n", role.str(), head, dep); 
     93} 
     94 
     95//==================================================================================================== 
     96 
     97int SGraph::sprint_node(char* buf, int nodeind, int anc, unsigned int info) 
    7998{ 
    8099  char* buf0=buf; 
    81   char descr[256]; 
    82   char nodeinfo[16]; 
    83100 
    84101  SNode &node=nodes[nodeind]; 
    85102 
    86103  buf+=sprintf(buf," dgp:%d",nodeind); 
     104  if(anc>=0) buf+=sprintf(buf,"(%d)",anc); 
    87105  buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u"); 
    88106 
     107  if (info&HEADS || info&DEPS) 
     108    buf+=sprintf(buf,";"); 
     109 
    89110  bool cont=false; 
     111 
    90112  if (info&HEADS) 
    91   { 
    92     buf+=sprintf(buf,";"); 
    93113    for(vector<Arc>::iterator h=node.heads.begin(); h!=node.heads.end(); ++h) 
    94114    { 
    95115      if(cont) buf+=sprintf(buf,","); else cont=true; 
    96       buf+=sprintf(buf,"++%s-%d/%d",h->role.str(),h->dst,h->anc); 
     116      buf+=sprintf(buf,"++%s-%d(%d~%d)",h->role.str(),h->dst,h->headanc,h->depanc); 
    97117    } 
    98   } 
    99    
     118 
    100119  if (info&DEPS) 
    101   { 
    102     buf+=sprintf(buf,";"); 
    103120    for(vector<Arc>::iterator d=node.deps.begin(); d!=node.deps.end(); ++d) 
    104121    { 
    105122      //      if(! nodes[d->dst].saturated()) continue; // NIE DRUKUJ NIENASYCONYCH PODRZEDNIKOW 
    106123      if(cont) buf+=sprintf(buf,","); else cont=true; 
    107       buf+=sprintf(buf,"--%s-%d/%d",d->role.str(),d->dst,d->anc); 
     124      buf+=sprintf(buf,"--%s-%d(%d~%d)",d->role.str(),d->dst,d->headanc,d->depanc); 
    108125    } 
    109   } 
    110126   
    111127  if (info&SETS) 
     
    113129    int ord=0; 
    114130    buf+=sprintf(buf,";{"); 
    115     for(vector<MNode*>::iterator pm=node.mnode->pred.begin(); pm!=node.mnode->pred.end(); ++pm) 
    116       for(vector<int>::iterator ps=(*pm)->snodes.begin(); ps!=(*pm)->snodes.end(); ++ps) 
     131    for(vector<int>::iterator pm=mgraph[node.mnode].pred.begin(); pm!=mgraph[node.mnode].pred.end(); ++pm) 
     132      for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) 
    117133        buf+=sprintf(buf, ord++ ? ",%d" : "%d", *ps); 
    118134    buf+=sprintf(buf,"};{"); 
    119     ord=0;for(int j=0; j<=n; ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 
     135    ord=0;for(int j=0; j<size(); ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 
    120136    buf+=sprintf(buf,"};{"); 
    121     ord=0;for(int j=0; j<=n; ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 
     137    ord=0;for(int j=0; j<size(); ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 
    122138    buf+=sprintf(buf,"};{"); 
    123     ord=0;for(int j=0; j<=n; ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 
     139    ord=0;for(int j=0; j<size(); ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 
    124140    buf+=sprintf(buf,"}"); 
    125141  } 
     
    133149    for(Role i=1; i<=Role::count(); ++i) 
    134150      if(node.prop.required[i]) buf+=sprintf(buf,"%s&%s",(cont++)?",":"",i.str()); 
     151    for(Role i=1; i<=Role::count(); ++i) 
     152      if(node.prop.attached[i]) buf+=sprintf(buf,"%s+%s",(cont++)?",":"",i.str()); 
     153    for(Flag i=1; i<=Flag::count(); ++i) 
     154      if(node.prop.flags [i]) buf+=sprintf(buf,"%s<%s>",(cont++)?",":"",i.str()); 
     155    if(node.prop.init_attached) 
     156      buf+=sprintf(buf,"<init>"); 
     157    if(node.prop.fin_attached) 
     158      buf+=sprintf(buf,"<fin>"); 
     159 
     160    stringstream oss; 
     161    for(list<Boubble*>::iterator b = node.prop.boubbles.begin(); b != node.prop.boubbles.end(); b++) 
     162      oss << (cont++ ? "," : "") << **b; 
     163    buf+=sprintf(buf,oss.str().c_str()); 
    135164  } 
    136165   
     
    141170 
    142171 
    143 int SGraph::sprint_node_debug(char* buf, const char* pref, int n) 
     172int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc) 
    144173{ 
    145174  char *buf0 = buf; 
    146175  buf+=sprintf(buf,"#%s",pref); 
    147   buf+=sprint_node(buf,n,HEADS|DEPS|SETS|CONSTRAINTS); 
     176 
     177  buf+=sprintf(buf,"%-16s",form(n)); 
     178 
     179  buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS); 
    148180  buf+=sprintf(buf,"\n"); 
    149181  return buf-buf0; 
    150182} 
    151183 
    152 int SGraph::print_node_debug(FILE* f, const char* pref, int n) 
    153 { 
    154   char buf[1000]; 
    155   sprint_node_debug(buf,pref,n); 
    156   fputs(buf,f); 
    157 } 
    158  
    159 void SGraph::print_arc(FILE* f, int left, int right, Role role, int dir) // 0 - left, 1 - right 
    160 { 
    161   fprintf(f,"#   %s:%s.%02d %s %s.%02d\n", 
    162           role.str(),nodes[left].mnode->type,left, 
    163           dir ? "-->" : "<--", 
    164           nodes[right].mnode->type,right); 
    165 } 
  • src/dgp/sgraph.hh

    r5f4d9c3 re7de6cc  
    99 
    1010#include "const.hh" 
     11#include "mgraph.hh" 
    1112#include "thesymbols.hh" 
    12  
    13  
    14 class MNode; 
    15  
    16  
     13#include "boubble.hh" 
     14 
     15 
     16using namespace std; 
     17 
     18//==================================================================================================== 
     19// CLASS Arc 
     20//==================================================================================================== 
    1721struct Arc 
    1822{ 
    1923  int dst; 
    2024  Role role; 
    21   int anc; 
     25  int headanc; 
     26  int depanc; 
    2227  
    23   Arc(int d, Role r, int a) : dst(d), role(r), anc(a) {}; 
    24  }; 
    25  
     28  Arc(int d, Role r, int ha, int da) : dst(d), role(r), headanc(ha), depanc(da) {}; 
     29}; 
     30 
     31//==================================================================================================== 
     32// CLASS NodeProp 
     33//==================================================================================================== 
    2634 
    2735struct NodeProp 
    2836{ 
    29   bitset<MAXTYPES> required; 
    30   bitset<MAXTYPES> forbidden; 
    31  
    32   bool operator==(const NodeProp& p) 
    33   { return required==p.required && forbidden==p.forbidden; } 
    34  
    35   void clear() 
    36   { required.reset(), forbidden.reset(); } 
    37  
    38 }; 
    39  
     37  NodeProp(); 
     38  NodeProp(const NodeProp& p); 
     39  ~NodeProp(); 
     40 
     41  bool operator==(const NodeProp& p); 
     42  NodeProp& operator=(const NodeProp& p); 
     43 
     44  void clear_boubbles(); 
     45  void merge_boubbles(list<Boubble*> new_boubbles); 
     46 
     47  void copy(const NodeProp& p); 
     48  void clear(); 
     49 
     50  RoleSet required; 
     51  RoleSet forbidden; 
     52  RoleSet attached; 
     53 
     54  bool init_attached; 
     55  bool fin_attached; 
     56   
     57  FlagSet flags; 
     58 
     59  list<Boubble*>   boubbles; 
     60}; 
     61 
     62//---------------------------------------------------------------------------------------------------- 
     63 
     64inline 
     65bool NodeProp::operator==(const NodeProp& p) 
     66{ 
     67  if(required != p.required) return false; 
     68  if(forbidden != p.forbidden) return false; 
     69  if(attached != p.attached) return false; 
     70  if(flags != p.flags) return false; 
     71  if(init_attached != p.init_attached) return false; 
     72  if(fin_attached != p.fin_attached) return false; 
     73   
     74  list<Boubble*>::const_iterator b1 = p.boubbles.begin(); 
     75  for(list<Boubble*>::const_iterator b = boubbles.begin(); b != boubbles.end(); b++) 
     76    { 
     77      if(b1 == p.boubbles.end()) 
     78        return false; 
     79      if(!(**b == **b1)) 
     80        return false; 
     81    } 
     82  if(b1 != p.boubbles.end()) 
     83    return false; 
     84   
     85  return true; 
     86} 
     87 
     88//---------------------------------------------------------------------------------------------------- 
     89 
     90inline 
     91void NodeProp::clear_boubbles() 
     92{ 
     93  for(list<Boubble*>::iterator b = boubbles.begin(); b!=boubbles.end(); b++) 
     94    delete *b; 
     95  boubbles.clear(); 
     96} 
     97 
     98//---------------------------------------------------------------------------------------------------- 
     99 
     100inline 
     101void NodeProp::merge_boubbles(list<Boubble*> new_boubbles) 
     102{ 
     103  boubbles.merge(new_boubbles); 
     104} 
     105 
     106//---------------------------------------------------------------------------------------------------- 
     107 
     108inline 
     109void NodeProp::copy(const NodeProp& p) 
     110{ 
     111  required=p.required; 
     112  forbidden=p.forbidden; 
     113  attached=p.attached; 
     114  flags=p.flags; 
     115  init_attached=p.init_attached; 
     116  fin_attached=p.fin_attached; 
     117  for(list<Boubble*>::const_iterator b = p.boubbles.begin(); b!=p.boubbles.end(); b++) 
     118    boubbles.push_back(new Boubble(**b)); 
     119} 
     120 
     121//---------------------------------------------------------------------------------------------------- 
     122 
     123inline 
     124NodeProp::~NodeProp() 
     125{ 
     126  clear_boubbles(); 
     127} 
     128//---------------------------------------------------------------------------------------------------- 
     129 
     130inline 
     131NodeProp::NodeProp() 
     132{ 
     133  clear(); 
     134} 
     135 
     136//---------------------------------------------------------------------------------------------------- 
     137 
     138inline 
     139NodeProp::NodeProp(const NodeProp& p) 
     140{ 
     141  copy(p); 
     142} 
     143 
     144//---------------------------------------------------------------------------------------------------- 
     145 
     146inline 
     147NodeProp& NodeProp::operator=(const NodeProp& p) 
     148{ 
     149  clear(); 
     150  copy(p); 
     151  return *this; 
     152} 
     153 
     154//---------------------------------------------------------------------------------------------------- 
     155 
     156inline 
     157void NodeProp::clear() 
     158{ 
     159  required.reset(); 
     160  forbidden.reset(); 
     161  attached.reset(); 
     162  init_attached=false; 
     163  fin_attached=false; 
     164  clear_boubbles(); 
     165} 
     166 
     167//==================================================================================================== 
     168// CLASS SNode 
     169//==================================================================================================== 
    40170 
    41171struct SNode 
    42172{ 
    43173   
    44   MNode* mnode; 
     174  int mnode; 
    45175 
    46176  NodeProp prop; 
     
    54184  vector<Arc> deps; 
    55185 
    56   void clear()      { prop.clear(), LV.reset(), LD.reset(), LH.reset(), heads.clear(), deps.clear(); } 
    57   bool saturated()  { return prop.required.none(); } 
    58 }; 
    59  
    60  
     186  void clear(); 
     187  bool saturated(); 
     188}; 
     189 
     190//---------------------------------------------------------------------------------------------------- 
     191inline 
     192void SNode::clear() 
     193{ prop.clear(), LV.reset(), LD.reset(), LH.reset(), heads.clear(), deps.clear(); } 
     194//---------------------------------------------------------------------------------------------------- 
     195inline 
     196bool SNode::saturated() 
     197{ return prop.required.none(); } 
     198 
     199//==================================================================================================== 
     200// SGraph CLASS 
     201//==================================================================================================== 
    61202 
    62203class SGraph 
     
    64205public: 
    65206 
    66   SNode nodes[MAXNODES]; 
    67   int n; // number of nodes 
    68  
    69   enum Output { HEADS=1, DEPS=2, SETS=4, CONSTRAINTS=8 }; 
    70  
    71   SGraph() : n(0) {} 
    72  
    73   void clear() { n=0; } 
    74   
    75   int add_base_snode(MNode* mn); 
    76   int clone(int ancind, NodeProp newprop); 
     207  enum Output { HEADS=1, DEPS=2, SETS=4, CONSTRAINTS=8, BOUBBLES=16 }; 
     208 
     209  SGraph(MGraph& mg) : mgraph(mg)               { clear(); } 
     210 
     211  SNode& operator[](const int i)                { return nodes[i]; } 
     212 
     213  void clear()                                  { nodes.clear(); } 
     214  int  add_base_snode(int mnodeind); 
     215  int  clone(int ancind, NodeProp newprop); 
    77216  void update_left(int headind, int depind); 
    78217  void update_right(int headind, int depind); 
    79  
    80218  bool visible(int left, int right); 
    81219  bool saturated(int node); 
    82220 
    83   //-------------------------------------------------------------------- 
    84  
    85   void read(FILE* f); 
    86   void write(FILE* f, list<int> nodelist, unsigned int info); 
    87  
    88   int sprint_node(char* buf, int n, unsigned int info); 
     221  Cat  cat(int i) const { return mgraph[nodes[i].mnode].cat; }     
     222  char* form(int i) const { return mgraph[nodes[i].mnode].form; } 
     223 
    89224  int print_node(FILE* f, int n, unsigned int info); 
    90   int sprint_node_debug(char* buf, const char* pref, int n); 
    91   int print_node_debug(FILE* f, const char* pref, int n); 
     225  int print_node_debug(FILE* f, const char* pref, int n, int anc); 
    92226 
    93227  void print_arc(FILE* f, int left, int right, Role role, int dir); // 0 - left, 1 - right 
    94228 
    95 }; 
    96  
     229  //private: 
     230 
     231  int size()              {return nodes.size(); } 
     232 
     233private: 
     234 
     235  MGraph& mgraph; 
     236   
     237  vector<SNode> nodes; 
     238 
     239  int lastnodeind()       { return nodes.size()-1; } 
     240  SNode& makenewnode()    { nodes.push_back(SNode()); nodes.back().clear(); return nodes.back(); } 
     241 
     242  int sprint_node(char* buf, int n, int anc, unsigned int info); 
     243  int sprint_node_debug(char* buf, const char* pref, int n, int anc); 
     244}; 
     245 
     246//---------------------------------------------------------------------------------------------------- 
    97247 
    98248inline bool SGraph::visible(int left, int right) 
     
    101251} 
    102252 
     253//---------------------------------------------------------------------------------------------------- 
     254 
    103255inline bool SGraph::saturated(int node) 
    104256{ 
     
    106258} 
    107259 
     260//---------------------------------------------------------------------------------------------------- 
     261 
    108262#endif 
  • src/dgp/symbol.hh

    r5f4d9c3 re7de6cc  
    33 
    44#include <ext/hash_map> 
    5 //#include <ext/hash_fun.h> 
    65#include <string> 
    7 #include <string.h> 
     6#include <cstring> 
    87#include <fstream> 
    98#include <vector> 
     
    5857/// Symbol class template.  
    5958/** The template argument determines the symbol space. 
    60     Each space is created with symbol "NULL" with indexed 0 already in. 
     59    Each space is created with symbol "NULL" with index 0 already in. 
    6160*/ 
    6261 
     
    104103 
    105104  Symbol(const char * s) : val(defs[s]) {}; 
    106    
     105 
     106  Symbol(string s) : val(defs[(char*)s]) {}; 
     107 
     108 
     109  bool empty() const { return val==0; } 
     110 
    107111  /// Symbol to char* conversion. If symbol is invalid, NULL is returned. 
    108112  const char* str() const { return (val>=0 && val<count())?defs[val]:NULL; }; 
     
    113117      s=0; while(++s) ... 
    114118   */ 
     119 
    115120  (operator int)() const { return val; }; 
    116121 
  • src/dgp/thesymbols.hh

    r5f4d9c3 re7de6cc  
    99#include <bitset> 
    1010 
    11 typedef Symbol<1> Cat; 
     11using namespace std; 
    1212 
    13 typedef Symbol<2> Role; 
    14 typedef list<Role> RoleList; 
    15 typedef list<Role>::iterator RoleListIter; 
    16 typedef bitset<MAXTYPES> RoleSet; 
    17 typedef set<Role> Roles; 
    18 typedef Roles::iterator RolesIter; 
     13typedef Symbol<1>              Cat; 
     14typedef bitset<MAXCATS>        CatSet; 
    1915 
    20 typedef Symbol<3> Constr; 
    21 typedef list<Constr> ConstrList; 
     16typedef Symbol<2>              Role; 
     17typedef list<Role>             RoleList; 
     18typedef list<Role>::iterator   RoleListIter; 
     19typedef bitset<MAXTYPES>       RoleSet; 
     20typedef set<Role>              Roles; 
     21typedef Roles::iterator        RolesIter; 
     22 
     23typedef Symbol<3>              Constr; 
     24typedef list<Constr>           ConstrList; 
    2225typedef list<Constr>::iterator ConstrListIter; 
    2326 
    24 typedef Symbol<4> Rel; 
     27typedef Symbol<4>              LongRel; 
     28typedef set<LongRel>           LongRels; 
    2529 
    26 typedef Symbol<5> Flag; 
    27 typedef bitset<MAXFLAGS> FlagSet; 
     30typedef Symbol<5>              Flag; 
     31typedef bitset<MAXFLAGS>       FlagSet; 
     32 
     33typedef Symbol<6>              Prop; 
     34typedef bitset<MAXPROPS>       PropSet; 
    2835 
    2936#endif 
  • src/gph/gph

    r5f4d9c3 re7de6cc  
    1414 
    1515 
    16 my $systemconfigfile='/usr/local/etc/utt/gph.conf'; 
     16my $systemconfigfile='/etc/utt/gph.conf'; 
    1717my $userconfigfile=home()."/.utt/gph.conf"; 
    1818 
Note: See TracChangeset for help on using the changeset viewer.