diff --git a/configure b/configure index 9945b6d..1ebe147 100755 --- a/configure +++ b/configure @@ -8,7 +8,7 @@ CUR_DIR=$(pwd) SRC_DIR="${CUR_DIR}/src" # list of components to compile -CMPLIST="compdic cor dgc dgp fla gph grp gue kon kor kot lem mar rm12 rs12 sen sen-nl ser tags tok.c tok.l tok.pl tre unfla" +CMPLIST="compdic cor dgc dgp fla gph grp gue kon kor kot lem mar rat rm12 rs12 sen sen-nl ser tags tok.c tok.l tok.pl tre unfla" COMP= diff --git a/doc/utt.texinfo b/doc/utt.texinfo index 73376e0..5878a19 100644 --- a/doc/utt.texinfo +++ b/doc/utt.texinfo @@ -29,7 +29,7 @@ Documentation License,,GNU Free Documentation License. @titlepage @title UAM Text Tools 0.90 - User Manual -@subtitle edition 0.01, @today +@subtitle edition 0.01, @today{} @subtitle status: prescript @author by Justyna Walkowska, Tomasz ObrÄ™bski and MichaÅ‚ Stolarski @page diff --git a/share/Makefile b/share/Makefile index 595db31..0a3c840 100644 --- a/share/Makefile +++ b/share/Makefile @@ -4,7 +4,7 @@ include ../config.mak TARGETS = gram.dgp .PHONY: all -all: $(TARGETS) +all: # ------------------------------------------------------------------ # main section @@ -15,7 +15,7 @@ gram.dgp: gram.dgc .PHONY: install -install: install-grammar install-dictionaries +install: .PHONY: install-grammar install-grammar: diff --git a/share/gram.dgc b/share/gram.dgc index c4866c0..e3b7b57 100644 --- a/share/gram.dgc +++ b/share/gram.dgc @@ -1,362 +1,223 @@ -# TODO! - - -#==================================================================================================== -#==================================================================================================== -# FLAGI -#==================================================================================================== -#==================================================================================================== - +#==================================================================================================== FLAGI FLAG RQ FLAG NEG FLAG init - -#==================================================================================================== -#==================================================================================================== -# KLASY DYSTRYBUCYJNE BIERNE -#==================================================================================================== -#==================================================================================================== - +#==================================================================================================== KLASY DYSTRYBUCYJNE BIERNE class $V- = V|VM|AUX|BYC class $N- = N|NV|NPRO|NUMCRD class $ADJ- = ADJ|ADJPRP|ADJPAP|ADJPP|ADJPRO -class $ADV- = ADV|ADVPRP|ADVANP - -#==================================================================================================== -#==================================================================================================== -# KLASY DYSTRYBUCYJNE CZYNNE -#==================================================================================================== -#==================================================================================================== - +class $ADV- = ADV|ADVPRP|ADVANP|ADVPRO|P +#==================================================================================================== KLASY DYSTRYBUCYJNE CZYNNE class $V+ = V|ADVPRP|ADVANP|ADJPRP|ADJPAP|NV +class $FIN+ = (V|BYC)/Vp|V/Vi - -#################################################################################################### -# NEG -#################################################################################################### - +#==================================================================================================== NEGACJA +#==================================================================================================== neg ROLE neg SGL neg LEFT neg - LINK V|VM|AUX|BYC|ADJPRP|ADJPAP|ADJPP NEG neg +#==================================================================================================== PYTANIE CZY +#==================================================================================================== czy +ROLE czy +SGL czy +RIGHT czy +LINK CZY $FIN+/Mdc|V/Vb czy -#################################################################################################### -# subj -#################################################################################################### - +#==================================================================================================== PODMIOT +#==================================================================================================== subj ROLE subj SGL subj AGR subj N AGR subj G GOV subj */Cn +LINK (V/Kn|BYC|ZOSTAC)/VpP3 (N|NUMCRD) subj +LINK (V/Kn|BYC|ZOSTAC)/VpP12 NPRO//RQ- subj +LINK (V/Kn|BYC|ZOSTAC)/VpP3 NPRO//RQ- subj +LINK (V/Kn|BYC|ZOSTAC)/VpP3 NPRO//RQ+ subj&INIT -LINK (V/Kn|BYC)/VpP3 (N|NUMCRD) subj -LINK (V/Kn|BYC)/VpP12 NPRO//RQ- subj -LINK (V/Kn|BYC)/VpP3 NPRO//RQ- subj -LINK (V/Kn|BYC)/VpP3 NPRO//RQ+ subj&INIT - - - -#==================================================================================================== -# cmpl_g -#==================================================================================================== - -ROLE cmpl_g -SGL cmpl_g -GOV cmpl_g */Cg - -LINK $V+ $N-//RQ- cmpl_g -LINK $V+ $N-//RQ+ cmpl_g&INIT - -#==================================================================================================== -# cmpl_a -#==================================================================================================== - -ROLE cmpl_a -SGL cmpl_a -GOV cmpl_a */Ca - -LINK $V+ $N-//RQ-NEG- cmpl_a -LINK $V+ $N-//RQ+NEG- cmpl_a&INIT - -#==================================================================================================== -# cmpl_d -#==================================================================================================== - -ROLE cmpl_d -SGL cmpl_d -GOV cmpl_d */Cd - -LINK $V+ $N-//RQ- cmpl_d - -#==================================================================================================== -# cmpl_i -#==================================================================================================== - -ROLE cmpl_i -SGL cmpl_i -GOV cmpl_i */Ci - -LINK $V+ $N-//RQ- cmpl_i - -#==================================================================================================== -# cmpl_ze -#==================================================================================================== - -ROLE cmpl_ze -SGL cmpl_ze - -LINK $V+ CONJ/Si cmpl_ze&FIN - -#==================================================================================================== -# cmpl_inf -#==================================================================================================== - -ROLE cmpl_inf -SGL cmpl_inf - -LINK $V+ V/Vb cmpl_inf - -#==================================================================================================== -# cmpl_s -#==================================================================================================== - -ROLE cmpl_s -SGL cmpl_s - -LINK $V+ V/Vp//RQ+ cmpl_s - -#==================================================================================================== -#==================================================================================================== -# aux -#==================================================================================================== -#==================================================================================================== - -ROLE aux -SGL aux -AGR aux N -AGR aux G - -LINK BYC/VpMdTf (V/VpP3|V/Vb)/Ai aux #czas przyszly analityczny -LINK BYC/VpMc V/VpP3 aux #czas zaprzesz³y -LINK BYC (ADJPAP|ADJ)/Cn aux #BYC jako lacznik w (jest bialy, jest zaszlachtowany) -LINK BYC N/Ci aux #BYC jako lacznik w (jest pilotem) - - -#==================================================================================================== -# MOD -#==================================================================================================== - +#==================================================================================================== DOPE£NIENIA +#==================================================================================================== gen +#ROLE gen +#SGL gen +#GOV gen */Cg +#LINK $V+ $N-//RQ- gen +#LINK $V+ $N-//RQ+ gen&INIT +#==================================================================================================== obj +ROLE obj +SGL obj +LINK $V+//NEG- $N-/Ca//RQ- obj +LINK $V+//NEG+ $N-/Cg//RQ- obj +LINK $V+//NEG- $N-/Ca//RQ+ obj&LEFT&INIT +LINK $V+//NEG+ $N-/Cg//RQ+ obj&LEFT&INIT +#==================================================================================================== dat +ROLE dat +SGL dat +GOV dat */Cd +LINK $V+ $N-//RQ- dat +#==================================================================================================== instr +ROLE instr +SGL instr +GOV instr */Ci +LINK $V+ $N-//RQ- instr +#==================================================================================================== ze +ROLE ze +SGL ze +LINK $V+ CONJ/Si ze&FIN +#==================================================================================================== inf +ROLE inf +SGL inf +LINK $V+ V/Vb inf +#==================================================================================================== int +ROLE int +SGL int +LINK $V+ V/Vp//RQ+ int +#==================================================================================================== CZASY +#==================================================================================================== fut +ROLE pred +SGL pred +AGR pred N +AGR pred G +ROLE fut +SGL fut +LINK BYC/VpMdTf (V/VpP3|V/Vb)/Ai fut #czas przyszly analityczny +#==================================================================================================== pass +ROLE pass +SGL pass +LINK BYC/Vpb ADJPAP/Cn pass #strona bierna +LINK ZOSTAC/Vpb ADJPAP/ApCn pass #strona bierna +#==================================================================================================== past +ROLE past +SGL past +LINK BYC/VpMc V/VpP3 past #czas zaprzesz³y +#==================================================================================================== cop +ROLE qpred +#ONE qpred +AGR qpred N +ROLE pred qpred +AGR pred G +ROLE fut pred +ROLE pass pred +ROLE past pred +ROLE pred +SGL pred +AGR pred N +AGR pred G +LINK BYC ADJ/Cn pred #BYC jako lacznik w (jest bialy, jest zaszlachtowany) +LINK BYC N/Ci pred #BYC jako lacznik w (jest pilotem) +#==================================================================================================== mod ROLE mod AGR mod N AGR mod C AGR mod G - -LINK V|VM|AUX|BYC $ADV- mod -LINK V|VM|AUX|BYC ADVPRO/Zqr mod&LEFT&INIT # kiedy u¶nie -LINK N|NV $ADJ- mod -LINK N|NV ADJPRO/Zqr mod&LEFT&INIT -LINK N|NV P mod -LINK N|NV P/Zqr mod&LEFT&INIT - - -#==================================================================================================== -# PREP -#==================================================================================================== - -ROLE prep - -LINK V P prep -LINK N P//RQ- prep - -#==================================================================================================== -# PCMPL -#==================================================================================================== - +LINK V|VM|AUX|BYC $ADV-//RQ- mod +LINK V|VM|AUX|BYC $ADV-//RQ+ mod&LEFT&INIT # kiedy u¶nie +LINK N|NV $ADJ-//RQ- mod +LINK N|NV $ADJ-//RQ+ mod&LEFT&INIT +#==================================================================================================== pp +ROLE pp +#LINK V P prep +LINK N|NV P//RQ- pp +LINK N|NV P//RQ+ pp&LEFT&INIT +#==================================================================================================== pcmpl ROLE pcmpl RIGHT pcmpl SGL pcmpl AGR pcmpl C - LINK P $N- pcmpl - REQ P pcmpl - -#==================================================================================================== -# conj -#==================================================================================================== - +#==================================================================================================== conj ROLE conj RIGHT conj - -LINK $V+ CONJ/Sc conj&FIN +LINK $V+ CONJ/Sc conj&FIN LINK $N- CONJ/Sc conj LINK $ADJ- CONJ/Sc conj LINK $ADV- CONJ/Sc conj - -#==================================================================================================== -# conj1 -#==================================================================================================== - +#==================================================================================================== conj1 ROLE conj1 SGL conj1 LEFT conj1 -LINK N CONJ/S1 conj1 - -#==================================================================================================== -# conj2 -#==================================================================================================== - +LINK N CONJ/S1 conj1 +#==================================================================================================== conj2 ROLE conj2 SGL conj2 RIGHT conj2 -LINK N CONJ/S2 conj2 - -#==================================================================================================== -# ccmpl -#==================================================================================================== - +LINK N CONJ/S2 conj2 +#==================================================================================================== ¿e +ROLE ze +SGL ze +LINK $V+ CONJ/S<¿e> ze +#==================================================================================================== ccmpl ROLE ccmpl SGL ccmpl RIGHT ccmpl - -LINK CONJ/JcSci2 V/Vf ccmpl +LINK CONJ/JcSci2 V/Vpi ccmpl LINK CONJ/JpSci2 ($N-|$V+|$ADJ-|$ADV-) ccmpl - REQ CONJ/Sci2 ccmpl - -#==================================================================================================== -# poss -#==================================================================================================== - +#==================================================================================================== poss ROLE poss SGL poss GOV poss */Cg - LINK N $N- ~ NPRO poss LINK N NPRO/Zqr poss&LEFT&INIT - -#==================================================================================================== -# numa -#==================================================================================================== - +#==================================================================================================== numa ROLE num_a SGL num_a AGR num_a C AGR num_a G GOV num_a */Ns - LINK NUMCRD/Sa N|NV num_a - -#==================================================================================================== -# num -#==================================================================================================== - +#==================================================================================================== num ROLE num SGL num - LINK NUMCRD N|NV num - -#==================================================================================================== -# restr -#==================================================================================================== - +#==================================================================================================== restr ROLE restr SGL restr - LINK ADJ ADV restr - -#==================================================================================================== -# quant -#==================================================================================================== - +#==================================================================================================== quant ROLE quant SGL quant AGR quant N AGR quant C AGR quant G LEFT quant - LINK N ADJPRO/Zg quant - -#==================================================================================================== -# part -#==================================================================================================== - +#==================================================================================================== part ROLE part - LINK $V+ PART part - -#==================================================================================================== -# part -#==================================================================================================== - -ROLE czy - -LINK $V+ CZY czy - -#==================================================================================================== -# subj_copred -#==================================================================================================== - +#==================================================================================================== subj_copred ROLE subj_copred SGL subj_copred - -#==================================================================================================== -# cmpl_g_copred -#==================================================================================================== - -ROLE cmpl_g_copred -SGL cmpl_g_copred - -#==================================================================================================== -# cmpl_a_copred -#==================================================================================================== - -ROLE cmpl_a_copred -SGL cmpl_a_copred - -#==================================================================================================== -# CMPL_D_COPRED -#==================================================================================================== - +#==================================================================================================== gen_copred +ROLE gen_copred +SGL gen_copred +#==================================================================================================== acc_copred +ROLE acc_copred +SGL acc_copred +#==================================================================================================== cmpl_d_copred ROLE cmpl_d_copred SGL cmpl_d_copred - -#==================================================================================================== -# CMPL_I_COPRED -#==================================================================================================== - +#==================================================================================================== cmpl_i_copred ROLE cmpl_i_copred SGL cmpl_i_copred - - -#==================================================================================================== -# REL -#==================================================================================================== - +#==================================================================================================== rel ROLE rel RIGHT rel SGL rel FIN rel +LINK N V/Vpi//RQ+ rel&FIN -LINK N V/Vp//RQ+ rel&FIN -#==================================================================================================== #==================================================================================================== # CONSTR #==================================================================================================== -#==================================================================================================== - -CONSTRE cmpl_g cmpl_a -CONSTRE cmpl_a cmpl_g - +#CONSTRE gen acc +#CONSTRE acc gen CONSTRI conj1 conj2 CONSTRI conj2 conj1 - #CONSTR cmpl_g ~cmpl_a #CONSTR cmpl_a ~cmpl_g #CONSTR cmpl_inf ~cmpl_g ~cmpl_d ~cmpl_a ~cmpl_p ~cmpl_ez ~cmpl_s @@ -366,79 +227,47 @@ CONSTRI conj2 conj1 #CONSTR cmpl_i_copred => cmpl_i #CONSTR cmpl_d_copred => cmpl_d - - -#==================================================================================================== -#==================================================================================================== # LONG -#==================================================================================================== -#==================================================================================================== - -#==================================================================================================== -# ncoord -#==================================================================================================== - +#==================================================================================================== ncoord LONG ncoord ^conj,ccmpl LONG ncoord ^conj2,ccmpl - AGR ncoord C AGR ncoord N - LINK N N ncoord - -#==================================================================================================== -# vcoord -#==================================================================================================== - +#==================================================================================================== vcoord LONG vcoord ^conj,ccmpl - AGR vcoord P AGR vcoord N AGR vcoord A AGR vcoord G - LINK V V vcoord - -#==================================================================================================== -# adjcoord -#==================================================================================================== - +#==================================================================================================== adjcoord LONG adjcoord ^conj,ccmpl - AGR adjcoord C AGR adjcoord N AGR adjcoord G - LINK ADJ ADJ ncoord - -#==================================================================================================== -# advcoord -#==================================================================================================== - +#==================================================================================================== advcoord LONG advcoord ^conj,ccmpl - AGR ncoord C AGR ncoord N - LINK ADV ADV ncoord - - -#==================================================================================================== -# relagr -#==================================================================================================== - +#==================================================================================================== predagr +LONG predagr subj^pred +AGR predagr N +AGR predagr G +LINK N * predagr +#==================================================================================================== relagr LONG relagr subj,rel^ -LONG relagr poss,cmpl_a,rel^ -LONG relagr cmpl_a,rel^ -LONG relagr cmpl_g,rel^ -LONG relagr pcmpl,rel^ - +LONG relagr poss,acc,rel^ +LONG relagr obj,rel^ +LONG relagr dat,rel^ +LONG relagr instr,rel^ +LONG relagr pcmpl,mod,rel^ AGR relagr N AGR relagr G - LINK NPRO/Zqr N relagr - #==================================================================================================== #==================================================================================================== # FLAG @@ -452,17 +281,17 @@ LINK NPRO/Zqr N relagr SET NPRO/Zrq RQ SET ADJPRO/Zrq RQ SET ADVPRO/Zqr RQ -SET NEG NEG - +SET CZY RQ PASS subj RQ -PASS cmpl_g RQ -PASS cmpl_d RQ -PASS cmpl_a RQ -PASS cmpl_i RQ +PASS dat RQ +PASS obj RQ +PASS instr RQ PASS mod RQ PASS pcmpl RQ -PASS prep RQ +PASS pp RQ PASS poss RQ + +SET NEG NEG PASS neg NEG diff --git a/src/compdic/compdic b/src/compdic/compdic index 7f590ba..27f7b17 100755 --- a/src/compdic/compdic +++ b/src/compdic/compdic @@ -140,6 +140,8 @@ _ 85 * 93 + 94 Ö 95 +< 96 +> 97 EOF diff --git a/src/compdic/compdic-dic-to-fst b/src/compdic/compdic-dic-to-fst index bf7dac1..4308c47 100755 --- a/src/compdic/compdic-dic-to-fst +++ b/src/compdic/compdic-dic-to-fst @@ -145,6 +145,8 @@ _ 85 * 93 + 94 Ö 95 +< 96 +> 97 EOF diff --git a/src/compdic/compdic-fst-to-bin b/src/compdic/compdic-fst-to-bin index 7a146f0..445cae4 100755 --- a/src/compdic/compdic-fst-to-bin +++ b/src/compdic/compdic-fst-to-bin @@ -111,6 +111,8 @@ _ 85 * 93 + 94 Ö 95 +< 96 +> 97 EOF cat $1 | fstrmepsilon | fstdeterminize | fstminimize | fstprint --acceptor --isymbols=$alphabet | fsm2aut | aut2fsa > $2 diff --git a/src/dgc/dgc b/src/dgc/dgc index 49b3242..2b2b57e 100755 --- a/src/dgc/dgc +++ b/src/dgc/dgc @@ -102,23 +102,24 @@ our $statementgrammar = q( statement : statement1 ";" { $item[1] } -statement1: /cat/i acat { ['cat', { cat=>$item{acat}, catexp=>attr::parse($item{acat}) }, $item{acat}] } - | /flag/i flag { ['flag', { flag=>$item{flag} }, $item{flag}] } - | /role/i role { ['role', { role=>$item{role} }, $item{role}] } - | /left/i role { ['left', { role=>$item{role} }, 0] } - | /right/i role { ['right', { role=>$item{role} }, 0] } - | /sgl/i role { ['sgl', { role=>$item{role} }, 0] } - | /req/i xcat role { ['req', { cats=>$item{xcat}, role=>$item{role} }, 0] } - | /agr/i role attr { ['agr', { role=>$item{role}, attr=>$item{attr} }, $item{role}] } - | /gov/i role xcat { ['gov', { role=>$item{role}, cats=>$item{xcat} }, $item{role}] } - | /init/i flagconstr { ['initf', { flag=>$item{flagconstr} }, 0] } - | /fin/i flagconstr { ['finf', { flag=>$item{flagconstr} }, 0] } - | /init/i role { ['initr', { role=>$item{role} }, 0] } - | /fin/i role { ['finr', { role=>$item{role} }, 0] } - | /set/i xcat flag { ['set', { cats=>$item{xcat}, flag=>$item{flag} }, 0] } - | /pass/i role flag { ['pass', { role=>$item{role}, flag=>$item{flag} }, 0] } - | /constre/i role role { ['constre', { role1=>$item[2], role2=>$item[3] }, 0] } - | /constri/i role role { ['constri', { role1=>$item[2], role2=>$item[3] }, 0] } +statement1: /cat/i acat { ['cat', { cat=>$item{acat}, catexp=>attr::parse($item{acat}) }, $item{acat}] } + | /flag/i flag { ['flag', { flag=>$item{flag} }, $item{flag}] } + | /role/i role role { ['role', { role=>$item[2], super=>$item[3] }, $item{role}] } + | /role/i role { ['role', { role=>$item{role} }, $item{role}] } + | /left/i role { ['left', { role=>$item{role} }, 0] } + | /right/i role { ['right', { role=>$item{role} }, 0] } + | /sgl/i role { ['sgl', { role=>$item{role} }, 0] } + | /req/i xcat role { ['req', { cats=>$item{xcat}, role=>$item{role} }, 0] } + | /agr/i role attr { ['agr', { role=>$item{role}, attr=>$item{attr} }, $item{role}] } + | /gov/i role xcat { ['gov', { role=>$item{role}, cats=>$item{xcat} }, $item{role}] } + | /init/i flagconstr { ['initf', { flag=>$item{flagconstr} }, 0] } + | /fin/i flagconstr { ['finf', { flag=>$item{flagconstr} }, 0] } + | /init/i role { ['initr', { role=>$item{role} }, 0] } + | /fin/i role { ['finr', { role=>$item{role} }, 0] } + | /set/i xcat flag { ['set', { cats=>$item{xcat}, flag=>$item{flag} }, 0] } + | /pass/i role flag { ['pass', { role=>$item{role}, flag=>$item{flag} }, 0] } + | /constre/i role role { ['constre', { role1=>$item[2], role2=>$item[3] }, 0] } + | /constri/i role role { ['constri', { role1=>$item[2], role2=>$item[3] }, 0] } | /link/i xcat optflags(?) xcat optflags(?) role prop(s?) { ['link', { hcats=>$item[2], hflagconstr=>$item[3], @@ -126,7 +127,7 @@ statement1: /cat/i acat { ['cat', { cat=>$item{acat}, catex role=>$item[6], props=>$item[7] }, 0] } | /long/i role role(s? /,/) '^' role(s? /,/) - { ['long', { rel=>$item[2], up=>$item[3], down=>$item[5] }, 0] } + { ['long', { rel=>$item[2], up=>$item[3], down=>$item[5] }, $item[2]] } | /class/i classname '=' xcat { ['class', { name=>$item{classname}, cats=>$item{xcat} }, $item{classname}] } @@ -142,11 +143,11 @@ flag: /\w+/ optflags: "//" flagconstr { $item[2] } -flagconstr: /\w+[+-]/ +flagconstr: /(\w+[+-])+/ prop: '&' /\w+/ { $item[2] } -classname: /\$\w+[+-]/ +classname: /\$\w+[+-]?/ classexpr : classexpr1 '|' classexpr { main::union($item[1],$item[3]) } | classexpr1 '~' classexpr { main::intersection( $item[1], main::complement($item[3]) ) } @@ -213,7 +214,6 @@ while() # print "#input line $inputlineno\n"; # print Dumper($result); - if($result) { register($_, @{$result}) } else { print STDERR "ERROR at line $inputlineno\n" } } @@ -225,22 +225,24 @@ my $outline = 0; # print Dumper($idx{gov}->{subj}); +# print Dumper(%idx); +#role closure +for my $x (@{$in{role}}) +{ + print Dumper($x),"\n"; +} -for my $x (@{$in{cat}}) { print_outin("CAT $x->{cat}", $x); } - -for my $x (@{$in{flag}}) { print_outin("FLAG $x->{flag}", $x); } - -for my $x (@{$in{role}}) { print_outin("ROLE $x->{role}", $x); } - -for my $x (@{$in{long}}) { print_outin("LONG $x->{rel} " . join(",",@{$x->{up}}) . "^" . join(",",@{$x->{down}}), $x) } - -for my $x (@{$in{left}}) { print_outin("LEFT $x->{role}", $x) if chk_role($x->{role}, $x) } - -for my $x (@{$in{right}}) { print_outin("RIGHT $x->{role}", $x) if chk_role($x->{role}, $x) } - -for my $x (@{$in{sgl}}) { print_outin("SGL $x->{role}", $x) if chk_role($x->{role}, $x) } +exit; +for my $x (@{$in{cat}}) { print_outin("CAT $x->{cat}", $x); } +for my $x (@{$in{flag}}) { print_outin("FLAG $x->{flag}", $x); } +for my $x (@{$in{role}}) { print_outin("ROLE $x->{role}", $x); } +for my $x (@{$in{derivedrole}}) { print_outin("ROLE $x->{role}", $x); } +for my $x (@{$in{long}}) { print_outin("LONG $x->{rel} " . join(",",@{$x->{up}}) . "^" . join(",",@{$x->{down}}), $x) } +for my $x (@{$in{left}}) { print_outin("LEFT $x->{role}", $x) if chk_role($x->{role}, $x) } +for my $x (@{$in{right}}) { print_outin("RIGHT $x->{role}", $x) if chk_role($x->{role}, $x) } +for my $x (@{$in{sgl}}) { print_outin("SGL $x->{role}", $x) if chk_role($x->{role}, $x) } for my $x (@{$in{req}}) { if( chk_role($x->{role}, $x) ) @@ -251,15 +253,10 @@ for my $x (@{$in{req}}) } } } - -for my $x (@{$in{initr}}) { print_outin("INITR $x->{role}", $x) if chk_role($x->{role}, $x) } - -for my $x (@{$in{finr}}) { print_outin("FINR $x->{role}", $x) if chk_role($x->{role}, $x) } - -for my $x (@{$in{initf}}) { print_outin("INITF $x->{flag}", $x) } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA - -for my $x (@{$in{finf}}) { print_outin("FINF $x->{flag}", $x); } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA - +for my $x (@{$in{initr}}) { print_outin("INITR $x->{role}", $x) if chk_role($x->{role}, $x) } +for my $x (@{$in{finr}}) { print_outin("FINR $x->{role}", $x) if chk_role($x->{role}, $x) } +for my $x (@{$in{initf}}) { print_outin("INITF $x->{flag}", $x) } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA +for my $x (@{$in{finf}}) { print_outin("FINF $x->{flag}", $x); } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA for my $x (@{$in{set}}) { for my $atomcat (map{$_->{cat}} @{$x->{cats}}) @@ -267,15 +264,13 @@ for my $x (@{$in{set}}) print_outin("SET $atomcat $x->{flag}", $x); } } - -for my $x (@{$in{pass}}) { print_outin("PASS $x->{role} $x->{flag}", $x); } - -for my $x (@{$in{constre}}) { print_outin("CONSTRE $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } - -for my $x (@{$in{constri}}) { print_outin("CONSTRI $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } - +for my $x (@{$in{pass}}) { print_outin("PASS $x->{role} $x->{flag}", $x); } +for my $x (@{$in{constre}}) { print_outin("CONSTRE $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } +for my $x (@{$in{constri}}) { print_outin("CONSTRI $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } for my $x (@{$in{link}}) { + next unless chk_role($x->{role},$x); + my @agrs = @{ $idx{agr}->{$x->{role} } or [] }; my @govs = @{ $idx{gov}->{$x->{role} } or [] }; @@ -303,7 +298,7 @@ for my $x (@{$in{link}}) sub chk_role { ($role, $statement_details) = @_; - if($idx{role}{$role}) { 1; } else { print_error("undefined role", $statement_details); 0; } + if($idx{role}{$role} || $idx{long}{$role}) { 1; } else { print_error("undefined role", $statement_details); 0; } } sub print_outin diff --git a/src/dgp/cmdline.cc b/src/dgp/cmdline.cc new file mode 100644 index 0000000..af61620 --- /dev/null +++ b/src/dgp/cmdline.cc @@ -0,0 +1,1556 @@ +/* + File autogenerated by gengetopt version 2.22.6 + generated with the following command: + gengetopt -i cmdline.ggo --c-extension=cc --conf-parser + + The developers of gengetopt consider the fixed text that goes in all + gengetopt output files to be in the public domain: + we make no copyright claims on it. +*/ + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifndef FIX_UNUSED +#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ +#endif + +#include + +#include "cmdline.h" + +const char *gengetopt_args_info_purpose = ""; + +const char *gengetopt_args_info_usage = "Usage: dgp [OPTIONS]..."; + +const char *gengetopt_args_info_versiontext = ""; + +const char *gengetopt_args_info_description = ""; + +const char *gengetopt_args_info_full_help[] = { + " -h, --help Print help and exit", + " --full-help Print help, including hidden options, and exit", + " -V, --version Print version and exit", + " -g, --grammar=filename Grammar file", + " -l, --long Long output (default=off)", + " -d, --debug Debug mode. (default=off)", + " --time Print parse time. (default=off)", + " --info=STRING Print info. \n h - heads d - dependents\n s - sets\n c - constraints n - node/arc counts\n (default=`h')", + " -f, --input=STRING Input file", + " -o, --output=STRING Output file", + " --only-fail Print only segments the program failed to process\n (default=off)", + " --no-fail Print only segments the program processed\n (default=off)", + " -c, --copy Copy succesfully processed segments to output\n (default=off)", + " -p, --process=STRING Process segments of this type only", + " -s, --select=STRING Select only segments containing this field", + " -S, --ignore=STRING Select only segments, which doesn't contain this\n field", + " -O, --output-field=STRING Output field name (default: program name)", + " -I, --input-field=STRING Input field name (default: the FORM field)", + " -i, --interactive Toggle interactive mode (default=off)", + " --config=FILENAME Configuration file", + " -1, --one-field Print all alternative results in one field\n (creates compact ambiguous annotation)\n (default=off)", + " --one-line Print annotation alternatives as additional fields\n in the same segment (default=off)", + " --language=STRING Language.", + 0 +}; + +static void +init_help_array(void) +{ + gengetopt_args_info_help[0] = gengetopt_args_info_full_help[0]; + gengetopt_args_info_help[1] = gengetopt_args_info_full_help[1]; + gengetopt_args_info_help[2] = gengetopt_args_info_full_help[2]; + gengetopt_args_info_help[3] = gengetopt_args_info_full_help[3]; + gengetopt_args_info_help[4] = gengetopt_args_info_full_help[4]; + gengetopt_args_info_help[5] = gengetopt_args_info_full_help[5]; + gengetopt_args_info_help[6] = gengetopt_args_info_full_help[6]; + gengetopt_args_info_help[7] = gengetopt_args_info_full_help[7]; + gengetopt_args_info_help[8] = gengetopt_args_info_full_help[8]; + gengetopt_args_info_help[9] = gengetopt_args_info_full_help[9]; + gengetopt_args_info_help[10] = gengetopt_args_info_full_help[12]; + gengetopt_args_info_help[11] = gengetopt_args_info_full_help[13]; + gengetopt_args_info_help[12] = gengetopt_args_info_full_help[14]; + gengetopt_args_info_help[13] = gengetopt_args_info_full_help[15]; + gengetopt_args_info_help[14] = gengetopt_args_info_full_help[16]; + gengetopt_args_info_help[15] = gengetopt_args_info_full_help[17]; + gengetopt_args_info_help[16] = gengetopt_args_info_full_help[18]; + gengetopt_args_info_help[17] = gengetopt_args_info_full_help[19]; + gengetopt_args_info_help[18] = gengetopt_args_info_full_help[20]; + gengetopt_args_info_help[19] = gengetopt_args_info_full_help[21]; + gengetopt_args_info_help[20] = gengetopt_args_info_full_help[22]; + gengetopt_args_info_help[21] = 0; + +} + +const char *gengetopt_args_info_help[22]; + +typedef enum {ARG_NO + , ARG_FLAG + , ARG_STRING +} cmdline_parser_arg_type; + +static +void clear_given (struct gengetopt_args_info *args_info); +static +void clear_args (struct gengetopt_args_info *args_info); + +static int +cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error); + +static int +cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); +struct line_list +{ + char * string_arg; + struct line_list * next; +}; + +static struct line_list *cmd_line_list = 0; +static struct line_list *cmd_line_list_tmp = 0; + +static void +free_cmd_list(void) +{ + /* free the list of a previous call */ + if (cmd_line_list) + { + while (cmd_line_list) { + cmd_line_list_tmp = cmd_line_list; + cmd_line_list = cmd_line_list->next; + free (cmd_line_list_tmp->string_arg); + free (cmd_line_list_tmp); + } + } +} + + +static char * +gengetopt_strdup (const char *s); + +static +void clear_given (struct gengetopt_args_info *args_info) +{ + args_info->help_given = 0 ; + args_info->full_help_given = 0 ; + args_info->version_given = 0 ; + args_info->grammar_given = 0 ; + args_info->long_given = 0 ; + args_info->debug_given = 0 ; + args_info->time_given = 0 ; + args_info->info_given = 0 ; + args_info->input_given = 0 ; + args_info->output_given = 0 ; + args_info->only_fail_given = 0 ; + args_info->no_fail_given = 0 ; + args_info->copy_given = 0 ; + args_info->process_given = 0 ; + args_info->select_given = 0 ; + args_info->ignore_given = 0 ; + args_info->output_field_given = 0 ; + args_info->input_field_given = 0 ; + args_info->interactive_given = 0 ; + args_info->config_given = 0 ; + args_info->one_field_given = 0 ; + args_info->one_line_given = 0 ; + args_info->language_given = 0 ; +} + +static +void clear_args (struct gengetopt_args_info *args_info) +{ + FIX_UNUSED (args_info); + args_info->grammar_arg = NULL; + args_info->grammar_orig = NULL; + args_info->long_flag = 0; + args_info->debug_flag = 0; + args_info->time_flag = 0; + args_info->info_arg = gengetopt_strdup ("h"); + args_info->info_orig = NULL; + args_info->input_arg = NULL; + args_info->input_orig = NULL; + args_info->output_arg = NULL; + args_info->output_orig = NULL; + args_info->only_fail_flag = 0; + args_info->no_fail_flag = 0; + args_info->copy_flag = 0; + args_info->process_arg = NULL; + args_info->process_orig = NULL; + args_info->select_arg = NULL; + args_info->select_orig = NULL; + args_info->ignore_arg = NULL; + args_info->ignore_orig = NULL; + args_info->output_field_arg = NULL; + args_info->output_field_orig = NULL; + args_info->input_field_arg = NULL; + args_info->input_field_orig = NULL; + args_info->interactive_flag = 0; + args_info->config_arg = NULL; + args_info->config_orig = NULL; + args_info->one_field_flag = 0; + args_info->one_line_flag = 0; + args_info->language_arg = NULL; + args_info->language_orig = NULL; + +} + +static +void init_args_info(struct gengetopt_args_info *args_info) +{ + + init_help_array(); + args_info->help_help = gengetopt_args_info_full_help[0] ; + args_info->full_help_help = gengetopt_args_info_full_help[1] ; + args_info->version_help = gengetopt_args_info_full_help[2] ; + args_info->grammar_help = gengetopt_args_info_full_help[3] ; + args_info->long_help = gengetopt_args_info_full_help[4] ; + args_info->debug_help = gengetopt_args_info_full_help[5] ; + args_info->time_help = gengetopt_args_info_full_help[6] ; + args_info->info_help = gengetopt_args_info_full_help[7] ; + args_info->input_help = gengetopt_args_info_full_help[8] ; + args_info->output_help = gengetopt_args_info_full_help[9] ; + args_info->only_fail_help = gengetopt_args_info_full_help[10] ; + args_info->no_fail_help = gengetopt_args_info_full_help[11] ; + args_info->copy_help = gengetopt_args_info_full_help[12] ; + args_info->process_help = gengetopt_args_info_full_help[13] ; + args_info->process_min = 0; + args_info->process_max = 0; + args_info->select_help = gengetopt_args_info_full_help[14] ; + args_info->select_min = 0; + args_info->select_max = 0; + args_info->ignore_help = gengetopt_args_info_full_help[15] ; + args_info->ignore_min = 0; + args_info->ignore_max = 0; + args_info->output_field_help = gengetopt_args_info_full_help[16] ; + args_info->input_field_help = gengetopt_args_info_full_help[17] ; + args_info->input_field_min = 0; + args_info->input_field_max = 0; + args_info->interactive_help = gengetopt_args_info_full_help[18] ; + args_info->config_help = gengetopt_args_info_full_help[19] ; + args_info->one_field_help = gengetopt_args_info_full_help[20] ; + args_info->one_line_help = gengetopt_args_info_full_help[21] ; + args_info->language_help = gengetopt_args_info_full_help[22] ; + +} + +void +cmdline_parser_print_version (void) +{ + printf ("%s %s\n", + (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), + CMDLINE_PARSER_VERSION); + + if (strlen(gengetopt_args_info_versiontext) > 0) + printf("\n%s\n", gengetopt_args_info_versiontext); +} + +static void print_help_common(void) { + cmdline_parser_print_version (); + + if (strlen(gengetopt_args_info_purpose) > 0) + printf("\n%s\n", gengetopt_args_info_purpose); + + if (strlen(gengetopt_args_info_usage) > 0) + printf("\n%s\n", gengetopt_args_info_usage); + + printf("\n"); + + if (strlen(gengetopt_args_info_description) > 0) + printf("%s\n\n", gengetopt_args_info_description); +} + +void +cmdline_parser_print_help (void) +{ + int i = 0; + print_help_common(); + while (gengetopt_args_info_help[i]) + printf("%s\n", gengetopt_args_info_help[i++]); +} + +void +cmdline_parser_print_full_help (void) +{ + int i = 0; + print_help_common(); + while (gengetopt_args_info_full_help[i]) + printf("%s\n", gengetopt_args_info_full_help[i++]); +} + +void +cmdline_parser_init (struct gengetopt_args_info *args_info) +{ + clear_given (args_info); + clear_args (args_info); + init_args_info (args_info); +} + +void +cmdline_parser_params_init(struct cmdline_parser_params *params) +{ + if (params) + { + params->override = 0; + params->initialize = 1; + params->check_required = 1; + params->check_ambiguity = 0; + params->print_errors = 1; + } +} + +struct cmdline_parser_params * +cmdline_parser_params_create(void) +{ + struct cmdline_parser_params *params = + (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); + cmdline_parser_params_init(params); + return params; +} + +static void +free_string_field (char **s) +{ + if (*s) + { + free (*s); + *s = 0; + } +} + +/** @brief generic value variable */ +union generic_value { + char *string_arg; + const char *default_string_arg; +}; + +/** @brief holds temporary values for multiple options */ +struct generic_list +{ + union generic_value arg; + char *orig; + struct generic_list *next; +}; + +/** + * @brief add a node at the head of the list + */ +static void add_node(struct generic_list **list) { + struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); + new_node->next = *list; + *list = new_node; + new_node->arg.string_arg = 0; + new_node->orig = 0; +} + + +static void +free_multiple_string_field(unsigned int len, char ***arg, char ***orig) +{ + unsigned int i; + if (*arg) { + for (i = 0; i < len; ++i) + { + free_string_field(&((*arg)[i])); + free_string_field(&((*orig)[i])); + } + free_string_field(&((*arg)[0])); /* free default string */ + + free (*arg); + *arg = 0; + free (*orig); + *orig = 0; + } +} + +static void +cmdline_parser_release (struct gengetopt_args_info *args_info) +{ + + free_string_field (&(args_info->grammar_arg)); + free_string_field (&(args_info->grammar_orig)); + free_string_field (&(args_info->info_arg)); + free_string_field (&(args_info->info_orig)); + free_string_field (&(args_info->input_arg)); + free_string_field (&(args_info->input_orig)); + free_string_field (&(args_info->output_arg)); + free_string_field (&(args_info->output_orig)); + free_multiple_string_field (args_info->process_given, &(args_info->process_arg), &(args_info->process_orig)); + free_multiple_string_field (args_info->select_given, &(args_info->select_arg), &(args_info->select_orig)); + free_multiple_string_field (args_info->ignore_given, &(args_info->ignore_arg), &(args_info->ignore_orig)); + free_string_field (&(args_info->output_field_arg)); + free_string_field (&(args_info->output_field_orig)); + free_multiple_string_field (args_info->input_field_given, &(args_info->input_field_arg), &(args_info->input_field_orig)); + free_string_field (&(args_info->config_arg)); + free_string_field (&(args_info->config_orig)); + free_string_field (&(args_info->language_arg)); + free_string_field (&(args_info->language_orig)); + + + + clear_given (args_info); +} + + +static void +write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) +{ + FIX_UNUSED (values); + if (arg) { + fprintf(outfile, "%s=\"%s\"\n", opt, arg); + } else { + fprintf(outfile, "%s\n", opt); + } +} + +static void +write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) +{ + int i; + + for (i = 0; i < len; ++i) + write_into_file(outfile, opt, (arg ? arg[i] : 0), values); +} + +int +cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) +{ + int i = 0; + + if (!outfile) + { + fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); + return EXIT_FAILURE; + } + + if (args_info->help_given) + write_into_file(outfile, "help", 0, 0 ); + if (args_info->full_help_given) + write_into_file(outfile, "full-help", 0, 0 ); + if (args_info->version_given) + write_into_file(outfile, "version", 0, 0 ); + if (args_info->grammar_given) + write_into_file(outfile, "grammar", args_info->grammar_orig, 0); + if (args_info->long_given) + write_into_file(outfile, "long", 0, 0 ); + if (args_info->debug_given) + write_into_file(outfile, "debug", 0, 0 ); + if (args_info->time_given) + write_into_file(outfile, "time", 0, 0 ); + if (args_info->info_given) + write_into_file(outfile, "info", args_info->info_orig, 0); + if (args_info->input_given) + write_into_file(outfile, "input", args_info->input_orig, 0); + if (args_info->output_given) + write_into_file(outfile, "output", args_info->output_orig, 0); + if (args_info->only_fail_given) + write_into_file(outfile, "only-fail", 0, 0 ); + if (args_info->no_fail_given) + write_into_file(outfile, "no-fail", 0, 0 ); + if (args_info->copy_given) + write_into_file(outfile, "copy", 0, 0 ); + write_multiple_into_file(outfile, args_info->process_given, "process", args_info->process_orig, 0); + write_multiple_into_file(outfile, args_info->select_given, "select", args_info->select_orig, 0); + write_multiple_into_file(outfile, args_info->ignore_given, "ignore", args_info->ignore_orig, 0); + if (args_info->output_field_given) + write_into_file(outfile, "output-field", args_info->output_field_orig, 0); + write_multiple_into_file(outfile, args_info->input_field_given, "input-field", args_info->input_field_orig, 0); + if (args_info->interactive_given) + write_into_file(outfile, "interactive", 0, 0 ); + if (args_info->config_given) + write_into_file(outfile, "config", args_info->config_orig, 0); + if (args_info->one_field_given) + write_into_file(outfile, "one-field", 0, 0 ); + if (args_info->one_line_given) + write_into_file(outfile, "one-line", 0, 0 ); + if (args_info->language_given) + write_into_file(outfile, "language", args_info->language_orig, 0); + + + i = EXIT_SUCCESS; + return i; +} + +int +cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) +{ + FILE *outfile; + int i = 0; + + outfile = fopen(filename, "w"); + + if (!outfile) + { + fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); + return EXIT_FAILURE; + } + + i = cmdline_parser_dump(outfile, args_info); + fclose (outfile); + + return i; +} + +void +cmdline_parser_free (struct gengetopt_args_info *args_info) +{ + cmdline_parser_release (args_info); +} + +/** @brief replacement of strdup, which is not standard */ +char * +gengetopt_strdup (const char *s) +{ + char *result = 0; + if (!s) + return result; + + result = (char*)malloc(strlen(s) + 1); + if (result == (char*)0) + return (char*)0; + strcpy(result, s); + return result; +} + +static char * +get_multiple_arg_token(const char *arg) +{ + const char *tok; + char *ret; + size_t len, num_of_escape, i, j; + + if (!arg) + return 0; + + tok = strchr (arg, ','); + num_of_escape = 0; + + /* make sure it is not escaped */ + while (tok) + { + if (*(tok-1) == '\\') + { + /* find the next one */ + tok = strchr (tok+1, ','); + ++num_of_escape; + } + else + break; + } + + if (tok) + len = (size_t)(tok - arg + 1); + else + len = strlen (arg) + 1; + + len -= num_of_escape; + + ret = (char *) malloc (len); + + i = 0; + j = 0; + while (arg[i] && (j < len-1)) + { + if (arg[i] == '\\' && + arg[ i + 1 ] && + arg[ i + 1 ] == ',') + ++i; + + ret[j++] = arg[i++]; + } + + ret[len-1] = '\0'; + + return ret; +} + +static const char * +get_multiple_arg_token_next(const char *arg) +{ + const char *tok; + + if (!arg) + return 0; + + tok = strchr (arg, ','); + + /* make sure it is not escaped */ + while (tok) + { + if (*(tok-1) == '\\') + { + /* find the next one */ + tok = strchr (tok+1, ','); + } + else + break; + } + + if (! tok || strlen(tok) == 1) + return 0; + + return tok+1; +} + +static int +check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc); + +int +check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc) +{ + int error_occurred = 0; + + if (option_given && (min > 0 || max > 0)) + { + if (min > 0 && max > 0) + { + if (min == max) + { + /* specific occurrences */ + if (option_given != (unsigned int) min) + { + fprintf (stderr, "%s: %s option occurrences must be %d\n", + prog_name, option_desc, min); + error_occurred = 1; + } + } + else if (option_given < (unsigned int) min + || option_given > (unsigned int) max) + { + /* range occurrences */ + fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", + prog_name, option_desc, min, max); + error_occurred = 1; + } + } + else if (min > 0) + { + /* at least check */ + if (option_given < min) + { + fprintf (stderr, "%s: %s option occurrences must be at least %d\n", + prog_name, option_desc, min); + error_occurred = 1; + } + } + else if (max > 0) + { + /* at most check */ + if (option_given > max) + { + fprintf (stderr, "%s: %s option occurrences must be at most %d\n", + prog_name, option_desc, max); + error_occurred = 1; + } + } + } + + return error_occurred; +} +int +cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) +{ + return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); +} + +int +cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params) +{ + int result; + result = cmdline_parser_internal (argc, argv, args_info, params, 0); + + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) +{ + int result; + struct cmdline_parser_params params; + + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); + + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) +{ + int result = EXIT_SUCCESS; + + if (cmdline_parser_required2(args_info, prog_name, 0) > 0) + result = EXIT_FAILURE; + + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) +{ + int error_occurred = 0; + FIX_UNUSED (additional_error); + + /* checks for required options */ + if (check_multiple_option_occurrences(prog_name, args_info->process_given, args_info->process_min, args_info->process_max, "'--process' ('-p')")) + error_occurred = 1; + + if (check_multiple_option_occurrences(prog_name, args_info->select_given, args_info->select_min, args_info->select_max, "'--select' ('-s')")) + error_occurred = 1; + + if (check_multiple_option_occurrences(prog_name, args_info->ignore_given, args_info->ignore_min, args_info->ignore_max, "'--ignore' ('-S')")) + error_occurred = 1; + + if (check_multiple_option_occurrences(prog_name, args_info->input_field_given, args_info->input_field_min, args_info->input_field_max, "'--input-field' ('-I')")) + error_occurred = 1; + + + /* checks for dependences among options */ + + return error_occurred; +} + + +static char *package_name = 0; + +/** + * @brief updates an option + * @param field the generic pointer to the field to update + * @param orig_field the pointer to the orig field + * @param field_given the pointer to the number of occurrence of this option + * @param prev_given the pointer to the number of occurrence already seen + * @param value the argument for this option (if null no arg was specified) + * @param possible_values the possible values for this option (if specified) + * @param default_value the default value (in case the option only accepts fixed values) + * @param arg_type the type of this option + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity + * @param override @see cmdline_parser_params.override + * @param no_free whether to free a possible previous value + * @param multiple_option whether this is a multiple option + * @param long_opt the corresponding long option + * @param short_opt the corresponding short option (or '-' if none) + * @param additional_error possible further error specification + */ +static +int update_arg(void *field, char **orig_field, + unsigned int *field_given, unsigned int *prev_given, + char *value, const char *possible_values[], + const char *default_value, + cmdline_parser_arg_type arg_type, + int check_ambiguity, int override, + int no_free, int multiple_option, + const char *long_opt, char short_opt, + const char *additional_error) +{ + char *stop_char = 0; + const char *val = value; + int found; + char **string_field; + FIX_UNUSED (field); + + stop_char = 0; + found = 0; + + if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) + { + if (short_opt != '-') + fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", + package_name, long_opt, short_opt, + (additional_error ? additional_error : "")); + else + fprintf (stderr, "%s: `--%s' option given more than once%s\n", + package_name, long_opt, + (additional_error ? additional_error : "")); + return 1; /* failure */ + } + + FIX_UNUSED (default_value); + + if (field_given && *field_given && ! override) + return 0; + if (prev_given) + (*prev_given)++; + if (field_given) + (*field_given)++; + if (possible_values) + val = possible_values[found]; + + switch(arg_type) { + case ARG_FLAG: + *((int *)field) = !*((int *)field); + break; + case ARG_STRING: + if (val) { + string_field = (char **)field; + if (!no_free && *string_field) + free (*string_field); /* free previous string */ + *string_field = gengetopt_strdup (val); + } + break; + default: + break; + }; + + + /* store the original value */ + switch(arg_type) { + case ARG_NO: + case ARG_FLAG: + break; + default: + if (value && orig_field) { + if (no_free) { + *orig_field = value; + } else { + if (*orig_field) + free (*orig_field); /* free previous string */ + *orig_field = gengetopt_strdup (value); + } + } + }; + + return 0; /* OK */ +} + +/** + * @brief store information about a multiple option in a temporary list + * @param list where to (temporarily) store multiple options + */ +static +int update_multiple_arg_temp(struct generic_list **list, + unsigned int *prev_given, const char *val, + const char *possible_values[], const char *default_value, + cmdline_parser_arg_type arg_type, + const char *long_opt, char short_opt, + const char *additional_error) +{ + /* store single arguments */ + char *multi_token; + const char *multi_next; + + if (arg_type == ARG_NO) { + (*prev_given)++; + return 0; /* OK */ + } + + multi_token = get_multiple_arg_token(val); + multi_next = get_multiple_arg_token_next (val); + + while (1) + { + add_node (list); + if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, + prev_given, multi_token, possible_values, default_value, + arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { + if (multi_token) free(multi_token); + return 1; /* failure */ + } + + if (multi_next) + { + multi_token = get_multiple_arg_token(multi_next); + multi_next = get_multiple_arg_token_next (multi_next); + } + else + break; + } + + return 0; /* OK */ +} + +/** + * @brief free the passed list (including possible string argument) + */ +static +void free_list(struct generic_list *list, short string_arg) +{ + if (list) { + struct generic_list *tmp; + while (list) + { + tmp = list; + if (string_arg && list->arg.string_arg) + free (list->arg.string_arg); + if (list->orig) + free (list->orig); + list = list->next; + free (tmp); + } + } +} + +/** + * @brief updates a multiple option starting from the passed list + */ +static +void update_multiple_arg(void *field, char ***orig_field, + unsigned int field_given, unsigned int prev_given, union generic_value *default_value, + cmdline_parser_arg_type arg_type, + struct generic_list *list) +{ + int i; + struct generic_list *tmp; + + if (prev_given && list) { + *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); + + switch(arg_type) { + case ARG_STRING: + *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; + default: + break; + }; + + for (i = (prev_given - 1); i >= 0; --i) + { + tmp = list; + + switch(arg_type) { + case ARG_STRING: + (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; + default: + break; + } + (*orig_field) [i + field_given] = list->orig; + list = list->next; + free (tmp); + } + } else { /* set the default value */ + if (default_value && ! field_given) { + switch(arg_type) { + case ARG_STRING: + if (! *((char ***)field)) { + *((char ***)field) = (char **)malloc (sizeof (char *)); + (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); + } + break; + default: break; + } + if (!(*orig_field)) { + *orig_field = (char **) malloc (sizeof (char *)); + (*orig_field)[0] = 0; + } + } + } +} + +int +cmdline_parser_internal ( + int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error) +{ + int c; /* Character of the parsed option. */ + + struct generic_list * process_list = NULL; + struct generic_list * select_list = NULL; + struct generic_list * ignore_list = NULL; + struct generic_list * input_field_list = NULL; + int error_occurred = 0; + struct gengetopt_args_info local_args_info; + + int override; + int initialize; + int check_required; + int check_ambiguity; + + package_name = argv[0]; + + override = params->override; + initialize = params->initialize; + check_required = params->check_required; + check_ambiguity = params->check_ambiguity; + + if (initialize) + cmdline_parser_init (args_info); + + cmdline_parser_init (&local_args_info); + + optarg = 0; + optind = 0; + opterr = params->print_errors; + optopt = '?'; + + while (1) + { + int option_index = 0; + + static struct option long_options[] = { + { "help", 0, NULL, 'h' }, + { "full-help", 0, NULL, 0 }, + { "version", 0, NULL, 'V' }, + { "grammar", 1, NULL, 'g' }, + { "long", 0, NULL, 'l' }, + { "debug", 0, NULL, 'd' }, + { "time", 0, NULL, 0 }, + { "info", 1, NULL, 0 }, + { "input", 1, NULL, 'f' }, + { "output", 1, NULL, 'o' }, + { "only-fail", 0, NULL, 0 }, + { "no-fail", 0, NULL, 0 }, + { "copy", 0, NULL, 'c' }, + { "process", 1, NULL, 'p' }, + { "select", 1, NULL, 's' }, + { "ignore", 1, NULL, 'S' }, + { "output-field", 1, NULL, 'O' }, + { "input-field", 1, NULL, 'I' }, + { "interactive", 0, NULL, 'i' }, + { "config", 1, NULL, 0 }, + { "one-field", 0, NULL, '1' }, + { "one-line", 0, NULL, 0 }, + { "language", 1, NULL, 0 }, + { 0, 0, 0, 0 } + }; + + c = getopt_long (argc, argv, "hVg:ldf:o:cp:s:S:O:I:i1", long_options, &option_index); + + if (c == -1) break; /* Exit from `while (1)' loop. */ + + switch (c) + { + case 'h': /* Print help and exit. */ + cmdline_parser_print_help (); + cmdline_parser_free (&local_args_info); + exit (EXIT_SUCCESS); + + case 'V': /* Print version and exit. */ + cmdline_parser_print_version (); + cmdline_parser_free (&local_args_info); + exit (EXIT_SUCCESS); + + case 'g': /* Grammar file. */ + + + if (update_arg( (void *)&(args_info->grammar_arg), + &(args_info->grammar_orig), &(args_info->grammar_given), + &(local_args_info.grammar_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "grammar", 'g', + additional_error)) + goto failure; + + break; + case 'l': /* Long output. */ + + + if (update_arg((void *)&(args_info->long_flag), 0, &(args_info->long_given), + &(local_args_info.long_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "long", 'l', + additional_error)) + goto failure; + + break; + case 'd': /* Debug mode.. */ + + + if (update_arg((void *)&(args_info->debug_flag), 0, &(args_info->debug_given), + &(local_args_info.debug_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "debug", 'd', + additional_error)) + goto failure; + + break; + case 'f': /* Input file. */ + + + if (update_arg( (void *)&(args_info->input_arg), + &(args_info->input_orig), &(args_info->input_given), + &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "input", 'f', + additional_error)) + goto failure; + + break; + case 'o': /* Output file. */ + + + if (update_arg( (void *)&(args_info->output_arg), + &(args_info->output_orig), &(args_info->output_given), + &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "output", 'o', + additional_error)) + goto failure; + + break; + case 'c': /* Copy succesfully processed segments to output. */ + + + if (update_arg((void *)&(args_info->copy_flag), 0, &(args_info->copy_given), + &(local_args_info.copy_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "copy", 'c', + additional_error)) + goto failure; + + break; + case 'p': /* Process segments of this type only. */ + + if (update_multiple_arg_temp(&process_list, + &(local_args_info.process_given), optarg, 0, 0, ARG_STRING, + "process", 'p', + additional_error)) + goto failure; + + break; + case 's': /* Select only segments containing this field. */ + + if (update_multiple_arg_temp(&select_list, + &(local_args_info.select_given), optarg, 0, 0, ARG_STRING, + "select", 's', + additional_error)) + goto failure; + + break; + case 'S': /* Select only segments, which doesn't contain this field. */ + + if (update_multiple_arg_temp(&ignore_list, + &(local_args_info.ignore_given), optarg, 0, 0, ARG_STRING, + "ignore", 'S', + additional_error)) + goto failure; + + break; + case 'O': /* Output field name (default: program name). */ + + + if (update_arg( (void *)&(args_info->output_field_arg), + &(args_info->output_field_orig), &(args_info->output_field_given), + &(local_args_info.output_field_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "output-field", 'O', + additional_error)) + goto failure; + + break; + case 'I': /* Input field name (default: the FORM field). */ + + if (update_multiple_arg_temp(&input_field_list, + &(local_args_info.input_field_given), optarg, 0, 0, ARG_STRING, + "input-field", 'I', + additional_error)) + goto failure; + + break; + case 'i': /* Toggle interactive mode. */ + + + if (update_arg((void *)&(args_info->interactive_flag), 0, &(args_info->interactive_given), + &(local_args_info.interactive_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "interactive", 'i', + additional_error)) + goto failure; + + break; + case '1': /* Print all alternative results in one field (creates compact ambiguous annotation). */ + + + if (update_arg((void *)&(args_info->one_field_flag), 0, &(args_info->one_field_given), + &(local_args_info.one_field_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "one-field", '1', + additional_error)) + goto failure; + + break; + + case 0: /* Long option with no short option */ + if (strcmp (long_options[option_index].name, "full-help") == 0) { + cmdline_parser_print_full_help (); + cmdline_parser_free (&local_args_info); + exit (EXIT_SUCCESS); + } + + /* Print parse time.. */ + if (strcmp (long_options[option_index].name, "time") == 0) + { + + + if (update_arg((void *)&(args_info->time_flag), 0, &(args_info->time_given), + &(local_args_info.time_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "time", '-', + additional_error)) + goto failure; + + } + /* Print info. + h - heads d - dependents + s - sets + c - constraints n - node/arc counts. */ + else if (strcmp (long_options[option_index].name, "info") == 0) + { + + + if (update_arg( (void *)&(args_info->info_arg), + &(args_info->info_orig), &(args_info->info_given), + &(local_args_info.info_given), optarg, 0, "h", ARG_STRING, + check_ambiguity, override, 0, 0, + "info", '-', + additional_error)) + goto failure; + + } + /* Print only segments the program failed to process. */ + else if (strcmp (long_options[option_index].name, "only-fail") == 0) + { + + + if (update_arg((void *)&(args_info->only_fail_flag), 0, &(args_info->only_fail_given), + &(local_args_info.only_fail_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "only-fail", '-', + additional_error)) + goto failure; + + } + /* Print only segments the program processed. */ + else if (strcmp (long_options[option_index].name, "no-fail") == 0) + { + + + if (update_arg((void *)&(args_info->no_fail_flag), 0, &(args_info->no_fail_given), + &(local_args_info.no_fail_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "no-fail", '-', + additional_error)) + goto failure; + + } + /* Configuration file. */ + else if (strcmp (long_options[option_index].name, "config") == 0) + { + + + if (update_arg( (void *)&(args_info->config_arg), + &(args_info->config_orig), &(args_info->config_given), + &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "config", '-', + additional_error)) + goto failure; + + } + /* Print annotation alternatives as additional fields in the same segment. */ + else if (strcmp (long_options[option_index].name, "one-line") == 0) + { + + + if (update_arg((void *)&(args_info->one_line_flag), 0, &(args_info->one_line_given), + &(local_args_info.one_line_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "one-line", '-', + additional_error)) + goto failure; + + } + /* Language.. */ + else if (strcmp (long_options[option_index].name, "language") == 0) + { + + + if (update_arg( (void *)&(args_info->language_arg), + &(args_info->language_orig), &(args_info->language_given), + &(local_args_info.language_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "language", '-', + additional_error)) + goto failure; + + } + + break; + case '?': /* Invalid option. */ + /* `getopt_long' already printed an error message. */ + goto failure; + + default: /* bug: option not considered. */ + fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); + abort (); + } /* switch */ + } /* while */ + + + update_multiple_arg((void *)&(args_info->process_arg), + &(args_info->process_orig), args_info->process_given, + local_args_info.process_given, 0, + ARG_STRING, process_list); + update_multiple_arg((void *)&(args_info->select_arg), + &(args_info->select_orig), args_info->select_given, + local_args_info.select_given, 0, + ARG_STRING, select_list); + update_multiple_arg((void *)&(args_info->ignore_arg), + &(args_info->ignore_orig), args_info->ignore_given, + local_args_info.ignore_given, 0, + ARG_STRING, ignore_list); + update_multiple_arg((void *)&(args_info->input_field_arg), + &(args_info->input_field_orig), args_info->input_field_given, + local_args_info.input_field_given, 0, + ARG_STRING, input_field_list); + + args_info->process_given += local_args_info.process_given; + local_args_info.process_given = 0; + args_info->select_given += local_args_info.select_given; + local_args_info.select_given = 0; + args_info->ignore_given += local_args_info.ignore_given; + local_args_info.ignore_given = 0; + args_info->input_field_given += local_args_info.input_field_given; + local_args_info.input_field_given = 0; + + if (check_required) + { + error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error); + } + + cmdline_parser_release (&local_args_info); + + if ( error_occurred ) + return (EXIT_FAILURE); + + return 0; + +failure: + free_list (process_list, 1 ); + free_list (select_list, 1 ); + free_list (ignore_list, 1 ); + free_list (input_field_list, 1 ); + + cmdline_parser_release (&local_args_info); + return (EXIT_FAILURE); +} + +#ifndef CONFIG_FILE_LINE_SIZE +#define CONFIG_FILE_LINE_SIZE 2048 +#endif +#define ADDITIONAL_ERROR " in configuration file " + +#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) +/* 3 is for "--" and "=" */ + +static int +_cmdline_parser_configfile (const char *filename, int *my_argc) +{ + FILE* file; + char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; + char linebuf[CONFIG_FILE_LINE_SIZE]; + int line_num = 0; + int result = 0, equal; + char *fopt, *farg; + char *str_index; + size_t len, next_token; + char delimiter; + + if ((file = fopen(filename, "r")) == 0) + { + fprintf (stderr, "%s: Error opening configuration file '%s'\n", + CMDLINE_PARSER_PACKAGE, filename); + return EXIT_FAILURE; + } + + while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0) + { + ++line_num; + my_argv[0] = '\0'; + len = strlen(linebuf); + if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) + { + fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", + CMDLINE_PARSER_PACKAGE, filename, line_num); + result = EXIT_FAILURE; + break; + } + + /* find first non-whitespace character in the line */ + next_token = strspn (linebuf, " \t\r\n"); + str_index = linebuf + next_token; + + if ( str_index[0] == '\0' || str_index[0] == '#') + continue; /* empty line or comment line is skipped */ + + fopt = str_index; + + /* truncate fopt at the end of the first non-valid character */ + next_token = strcspn (fopt, " \t\r\n="); + + if (fopt[next_token] == '\0') /* the line is over */ + { + farg = 0; + equal = 0; + goto noarg; + } + + /* remember if equal sign is present */ + equal = (fopt[next_token] == '='); + fopt[next_token++] = '\0'; + + /* advance pointers to the next token after the end of fopt */ + next_token += strspn (fopt + next_token, " \t\r\n"); + + /* check for the presence of equal sign, and if so, skip it */ + if ( !equal ) + if ((equal = (fopt[next_token] == '='))) + { + next_token++; + next_token += strspn (fopt + next_token, " \t\r\n"); + } + str_index += next_token; + + /* find argument */ + farg = str_index; + if ( farg[0] == '\"' || farg[0] == '\'' ) + { /* quoted argument */ + str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ + if (! str_index) + { + fprintf + (stderr, + "%s:%s:%d: unterminated string in configuration file\n", + CMDLINE_PARSER_PACKAGE, filename, line_num); + result = EXIT_FAILURE; + break; + } + } + else + { /* read up the remaining part up to a delimiter */ + next_token = strcspn (farg, " \t\r\n#\'\""); + str_index += next_token; + } + + /* truncate farg at the delimiter and store it for further check */ + delimiter = *str_index, *str_index++ = '\0'; + + /* everything but comment is illegal at the end of line */ + if (delimiter != '\0' && delimiter != '#') + { + str_index += strspn(str_index, " \t\r\n"); + if (*str_index != '\0' && *str_index != '#') + { + fprintf + (stderr, + "%s:%s:%d: malformed string in configuration file\n", + CMDLINE_PARSER_PACKAGE, filename, line_num); + result = EXIT_FAILURE; + break; + } + } + + noarg: + if (!strcmp(fopt,"include")) { + if (farg && *farg) { + result = _cmdline_parser_configfile(farg, my_argc); + } else { + fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", + CMDLINE_PARSER_PACKAGE, filename, line_num); + } + continue; + } + len = strlen(fopt); + strcat (my_argv, len > 1 ? "--" : "-"); + strcat (my_argv, fopt); + if (len > 1 && ((farg && *farg) || equal)) + strcat (my_argv, "="); + if (farg && *farg) + strcat (my_argv, farg); + ++(*my_argc); + + cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup(my_argv); + } /* while */ + + if (file) + fclose(file); + return result; +} + +int +cmdline_parser_configfile ( + const char *filename, + struct gengetopt_args_info *args_info, + int override, int initialize, int check_required) +{ + struct cmdline_parser_params params; + + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + return cmdline_parser_config_file (filename, args_info, ¶ms); +} + +int +cmdline_parser_config_file (const char *filename, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params) +{ + int i, result; + int my_argc = 1; + char **my_argv_arg; + char *additional_error; + + /* store the program name */ + cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_PACKAGE); + + result = _cmdline_parser_configfile(filename, &my_argc); + + if (result != EXIT_FAILURE) { + my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); + cmd_line_list_tmp = cmd_line_list; + + for (i = my_argc - 1; i >= 0; --i) { + my_argv_arg[i] = cmd_line_list_tmp->string_arg; + cmd_line_list_tmp = cmd_line_list_tmp->next; + } + + my_argv_arg[my_argc] = 0; + + additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); + strcpy (additional_error, ADDITIONAL_ERROR); + strcat (additional_error, filename); + result = + cmdline_parser_internal (my_argc, my_argv_arg, args_info, + params, + additional_error); + + free (additional_error); + free (my_argv_arg); + } + + free_cmd_list(); + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} diff --git a/src/dgp/cmdline.d b/src/dgp/cmdline.d new file mode 100644 index 0000000..620fb6c --- /dev/null +++ b/src/dgp/cmdline.d @@ -0,0 +1 @@ +cmdline.o cmdline.d : cmdline.cc cmdline.h diff --git a/src/dgp/cmdline.ggo b/src/dgp/cmdline.ggo new file mode 100644 index 0000000..9caa35c --- /dev/null +++ b/src/dgp/cmdline.ggo @@ -0,0 +1,52 @@ +package "dgp" +version "0.1" + +option "grammar" g "Grammar file" + string no typestr="filename" + +option "long" l "Long output" + flag off + +option "debug" d "Debug mode." + flag off + +option "time" - "Print parse time." + flag off + +option "info" - "Print info. + h - heads d - dependents + s - sets + c - constraints n - node/arc counts" +string no default="h" +#section "Common UTT options" + + +option "input" f "Input file" string no + +option "output" o "Output file" string no + +option "only-fail" - "Print only segments the program failed to process" flag off hidden + +option "no-fail" - "Print only segments the program processed" flag off hidden + +option "copy" c "Copy succesfully processed segments to output" flag off + +option "process" p "Process segments of this type only" string no multiple + +option "select" s "Select only segments containing this field" string no multiple + +option "ignore" S "Select only segments, which doesn't contain this field" string no multiple + +option "output-field" O "Output field name (default: program name)" string no + +option "input-field" I "Input field name (default: the FORM field)" string no multiple + +option "interactive" i "Toggle interactive mode" flag off + +option "config" - "Configuration file" string typestr="FILENAME" no + +option "one-field" 1 "Print all alternative results in one field (creates compact ambiguous annotation)" flag off + +option "one-line" - "Print annotation alternatives as additional fields in the same segment" flag off + +option "language" - "Language." string no diff --git a/src/dgp/cmdline.h b/src/dgp/cmdline.h new file mode 100644 index 0000000..2f505cc --- /dev/null +++ b/src/dgp/cmdline.h @@ -0,0 +1,294 @@ +/** @file cmdline.h + * @brief The header file for the command line option parser + * generated by GNU Gengetopt version 2.22.6 + * http://www.gnu.org/software/gengetopt. + * DO NOT modify this file, since it can be overwritten + * @author GNU Gengetopt by Lorenzo Bettini */ + +#ifndef CMDLINE_H +#define CMDLINE_H + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include /* for FILE */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef CMDLINE_PARSER_PACKAGE +/** @brief the program name (used for printing errors) */ +#define CMDLINE_PARSER_PACKAGE "dgp" +#endif + +#ifndef CMDLINE_PARSER_PACKAGE_NAME +/** @brief the complete program name (used for help and version) */ +#define CMDLINE_PARSER_PACKAGE_NAME "dgp" +#endif + +#ifndef CMDLINE_PARSER_VERSION +/** @brief the program version */ +#define CMDLINE_PARSER_VERSION "0.1" +#endif + +/** @brief Where the command line options are stored */ +struct gengetopt_args_info +{ + const char *help_help; /**< @brief Print help and exit help description. */ + const char *full_help_help; /**< @brief Print help, including hidden options, and exit help description. */ + const char *version_help; /**< @brief Print version and exit help description. */ + char * grammar_arg; /**< @brief Grammar file. */ + char * grammar_orig; /**< @brief Grammar file original value given at command line. */ + const char *grammar_help; /**< @brief Grammar file help description. */ + int long_flag; /**< @brief Long output (default=off). */ + const char *long_help; /**< @brief Long output help description. */ + int debug_flag; /**< @brief Debug mode. (default=off). */ + const char *debug_help; /**< @brief Debug mode. help description. */ + int time_flag; /**< @brief Print parse time. (default=off). */ + const char *time_help; /**< @brief Print parse time. help description. */ + char * info_arg; /**< @brief Print info. + h - heads d - dependents + s - sets + c - constraints n - node/arc counts (default='h'). */ + char * info_orig; /**< @brief Print info. + h - heads d - dependents + s - sets + c - constraints n - node/arc counts original value given at command line. */ + const char *info_help; /**< @brief Print info. + h - heads d - dependents + s - sets + c - constraints n - node/arc counts help description. */ + char * input_arg; /**< @brief Input file. */ + char * input_orig; /**< @brief Input file original value given at command line. */ + const char *input_help; /**< @brief Input file help description. */ + char * output_arg; /**< @brief Output file. */ + char * output_orig; /**< @brief Output file original value given at command line. */ + const char *output_help; /**< @brief Output file help description. */ + int only_fail_flag; /**< @brief Print only segments the program failed to process (default=off). */ + const char *only_fail_help; /**< @brief Print only segments the program failed to process help description. */ + int no_fail_flag; /**< @brief Print only segments the program processed (default=off). */ + const char *no_fail_help; /**< @brief Print only segments the program processed help description. */ + int copy_flag; /**< @brief Copy succesfully processed segments to output (default=off). */ + const char *copy_help; /**< @brief Copy succesfully processed segments to output help description. */ + char ** process_arg; /**< @brief Process segments of this type only. */ + char ** process_orig; /**< @brief Process segments of this type only original value given at command line. */ + unsigned int process_min; /**< @brief Process segments of this type only's minimum occurreces */ + unsigned int process_max; /**< @brief Process segments of this type only's maximum occurreces */ + const char *process_help; /**< @brief Process segments of this type only help description. */ + char ** select_arg; /**< @brief Select only segments containing this field. */ + char ** select_orig; /**< @brief Select only segments containing this field original value given at command line. */ + unsigned int select_min; /**< @brief Select only segments containing this field's minimum occurreces */ + unsigned int select_max; /**< @brief Select only segments containing this field's maximum occurreces */ + const char *select_help; /**< @brief Select only segments containing this field help description. */ + char ** ignore_arg; /**< @brief Select only segments, which doesn't contain this field. */ + char ** ignore_orig; /**< @brief Select only segments, which doesn't contain this field original value given at command line. */ + unsigned int ignore_min; /**< @brief Select only segments, which doesn't contain this field's minimum occurreces */ + unsigned int ignore_max; /**< @brief Select only segments, which doesn't contain this field's maximum occurreces */ + const char *ignore_help; /**< @brief Select only segments, which doesn't contain this field help description. */ + char * output_field_arg; /**< @brief Output field name (default: program name). */ + char * output_field_orig; /**< @brief Output field name (default: program name) original value given at command line. */ + const char *output_field_help; /**< @brief Output field name (default: program name) help description. */ + char ** input_field_arg; /**< @brief Input field name (default: the FORM field). */ + char ** input_field_orig; /**< @brief Input field name (default: the FORM field) original value given at command line. */ + unsigned int input_field_min; /**< @brief Input field name (default: the FORM field)'s minimum occurreces */ + unsigned int input_field_max; /**< @brief Input field name (default: the FORM field)'s maximum occurreces */ + const char *input_field_help; /**< @brief Input field name (default: the FORM field) help description. */ + int interactive_flag; /**< @brief Toggle interactive mode (default=off). */ + const char *interactive_help; /**< @brief Toggle interactive mode help description. */ + char * config_arg; /**< @brief Configuration file. */ + char * config_orig; /**< @brief Configuration file original value given at command line. */ + const char *config_help; /**< @brief Configuration file help description. */ + int one_field_flag; /**< @brief Print all alternative results in one field (creates compact ambiguous annotation) (default=off). */ + const char *one_field_help; /**< @brief Print all alternative results in one field (creates compact ambiguous annotation) help description. */ + int one_line_flag; /**< @brief Print annotation alternatives as additional fields in the same segment (default=off). */ + const char *one_line_help; /**< @brief Print annotation alternatives as additional fields in the same segment help description. */ + char * language_arg; /**< @brief Language.. */ + char * language_orig; /**< @brief Language. original value given at command line. */ + const char *language_help; /**< @brief Language. help description. */ + + unsigned int help_given ; /**< @brief Whether help was given. */ + unsigned int full_help_given ; /**< @brief Whether full-help was given. */ + unsigned int version_given ; /**< @brief Whether version was given. */ + unsigned int grammar_given ; /**< @brief Whether grammar was given. */ + unsigned int long_given ; /**< @brief Whether long was given. */ + unsigned int debug_given ; /**< @brief Whether debug was given. */ + unsigned int time_given ; /**< @brief Whether time was given. */ + unsigned int info_given ; /**< @brief Whether info was given. */ + unsigned int input_given ; /**< @brief Whether input was given. */ + unsigned int output_given ; /**< @brief Whether output was given. */ + unsigned int only_fail_given ; /**< @brief Whether only-fail was given. */ + unsigned int no_fail_given ; /**< @brief Whether no-fail was given. */ + unsigned int copy_given ; /**< @brief Whether copy was given. */ + unsigned int process_given ; /**< @brief Whether process was given. */ + unsigned int select_given ; /**< @brief Whether select was given. */ + unsigned int ignore_given ; /**< @brief Whether ignore was given. */ + unsigned int output_field_given ; /**< @brief Whether output-field was given. */ + unsigned int input_field_given ; /**< @brief Whether input-field was given. */ + unsigned int interactive_given ; /**< @brief Whether interactive was given. */ + unsigned int config_given ; /**< @brief Whether config was given. */ + unsigned int one_field_given ; /**< @brief Whether one-field was given. */ + unsigned int one_line_given ; /**< @brief Whether one-line was given. */ + unsigned int language_given ; /**< @brief Whether language was given. */ + +} ; + +/** @brief The additional parameters to pass to parser functions */ +struct cmdline_parser_params +{ + int override; /**< @brief whether to override possibly already present options (default 0) */ + int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ + int check_required; /**< @brief whether to check that all required options were provided (default 1) */ + int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ + int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ +} ; + +/** @brief the purpose string of the program */ +extern const char *gengetopt_args_info_purpose; +/** @brief the usage string of the program */ +extern const char *gengetopt_args_info_usage; +/** @brief the description string of the program */ +extern const char *gengetopt_args_info_description; +/** @brief all the lines making the help output */ +extern const char *gengetopt_args_info_help[]; +/** @brief all the lines making the full help output (including hidden options) */ +extern const char *gengetopt_args_info_full_help[]; + +/** + * The command line parser + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser (int argc, char **argv, + struct gengetopt_args_info *args_info); + +/** + * The command line parser (version with additional parameters - deprecated) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use cmdline_parser_ext() instead + */ +int cmdline_parser2 (int argc, char **argv, + struct gengetopt_args_info *args_info, + int override, int initialize, int check_required); + +/** + * The command line parser (version with additional parameters) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_ext (int argc, char **argv, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params); + +/** + * Save the contents of the option struct into an already open FILE stream. + * @param outfile the stream where to dump options + * @param args_info the option struct to dump + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_dump(FILE *outfile, + struct gengetopt_args_info *args_info); + +/** + * Save the contents of the option struct into a (text) file. + * This file can be read by the config file parser (if generated by gengetopt) + * @param filename the file where to save + * @param args_info the option struct to save + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_file_save(const char *filename, + struct gengetopt_args_info *args_info); + +/** + * Print the help + */ +void cmdline_parser_print_help(void); +/** + * Print the full help (including hidden options) + */ +void cmdline_parser_print_full_help(void); +/** + * Print the version + */ +void cmdline_parser_print_version(void); + +/** + * Initializes all the fields a cmdline_parser_params structure + * to their default values + * @param params the structure to initialize + */ +void cmdline_parser_params_init(struct cmdline_parser_params *params); + +/** + * Allocates dynamically a cmdline_parser_params structure and initializes + * all its fields to their default values + * @return the created and initialized cmdline_parser_params structure + */ +struct cmdline_parser_params *cmdline_parser_params_create(void); + +/** + * Initializes the passed gengetopt_args_info structure's fields + * (also set default values for options that have a default) + * @param args_info the structure to initialize + */ +void cmdline_parser_init (struct gengetopt_args_info *args_info); +/** + * Deallocates the string fields of the gengetopt_args_info structure + * (but does not deallocate the structure itself) + * @param args_info the structure to deallocate + */ +void cmdline_parser_free (struct gengetopt_args_info *args_info); + +/** + * The config file parser (deprecated version) + * @param filename the name of the config file + * @param args_info the structure where option information will be stored + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use cmdline_parser_config_file() instead + */ +int cmdline_parser_configfile (const char *filename, + struct gengetopt_args_info *args_info, + int override, int initialize, int check_required); + +/** + * The config file parser + * @param filename the name of the config file + * @param args_info the structure where option information will be stored + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_config_file (const char *filename, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params); + +/** + * Checks that all the required options were specified + * @param args_info the structure to check + * @param prog_name the name of the program that will be used to print + * possible errors + * @return + */ +int cmdline_parser_required (struct gengetopt_args_info *args_info, + const char *prog_name); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* CMDLINE_H */ diff --git a/src/dgp/cmdline.o b/src/dgp/cmdline.o new file mode 100644 index 0000000..d495a14 Binary files /dev/null and b/src/dgp/cmdline.o differ diff --git a/src/dgp/const.hh b/src/dgp/const.hh index bab8833..f20329c 100644 --- a/src/dgp/const.hh +++ b/src/dgp/const.hh @@ -1,7 +1,7 @@ #ifndef CONST_HH #define CONST_HH -#define MAXTYPES 32 +#define MAXTYPES 64 #define MAXCATS 4096 #define MAXFLAGS 64 #define MAXPROPS 16 diff --git a/src/dgp/dgp b/src/dgp/dgp new file mode 100755 index 0000000..6df0a54 Binary files /dev/null and b/src/dgp/dgp differ diff --git a/src/dgp/dgp1.cc b/src/dgp/dgp1.cc index d4068b1..0be7469 100644 --- a/src/dgp/dgp1.cc +++ b/src/dgp/dgp1.cc @@ -43,8 +43,8 @@ NodeProp compute_head_prop(NodeProp headprop, const Link& link, list b if(grammar.is_sgl(link.role)) { ret.forbidden.set(link.role); - ret.attached.set(link.role); } + ret.attached.set(link.role); ret.required.reset(link.role); ret.required |= (grammar.constr_include(link.role) & ~ret.attached); @@ -154,7 +154,7 @@ int create_new_node(int anc, NodeProp& prop, Edge edge) nodelist.push_back(newheadind); copy_links(anc,newheadind); create_reverse_links(newheadind); - if(debug) sgraph.print_node_debug(stderr,"clone",newheadind,anc); + if(debug) sgraph.print_node_debug(stderr,"clone",newheadind); // if(debug) print_sets(newheadind); return newheadind; } @@ -174,13 +174,17 @@ void connect_left(int h, int d, const Link& l, list& new_head_boubbles if( newd < 0 ) { newd = create_new_node(d,new_dep_prop,new_dep_edge); + sgraph[newd].set_skip_conditional(sgraph[d]); sgraph[newd].prop.has_head = true; } Edge new_head_edge(sgraph[newd].edge,newd); int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); if( newh < 0 ) - newh = create_new_node(h,new_head_prop,new_head_edge); + { + newh = create_new_node(h,new_head_prop,new_head_edge); + sgraph[newh].set_skip_false(); + } sgraph[newh].deps.push_back(Arc(newd,l.role,h,d)); sgraph[newd].heads.push_back(Arc(newh,l.role,h,d)); @@ -188,8 +192,8 @@ void connect_left(int h, int d, const Link& l, list& new_head_boubbles if(debug) { sgraph.print_arc(stderr,"link",newh,d,l.role,0); - sgraph.print_node_debug(stderr,"",newh,h); - sgraph.print_node_debug(stderr,"",newd,d); + sgraph.print_node_debug(stderr,"",newh); + sgraph.print_node_debug(stderr,"",newd); } } @@ -204,18 +208,22 @@ void connect_right(int h, int d, const Link& l, list& new_head_boubble Edge new_head_edge(sgraph[h].edge); int newh = -1; - if(!new_head_prop.forbidden[l.role]) newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); + // if(!new_head_prop.forbidden[l.role]) + newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); if( newh < 0 ) { newh = create_new_node(h,new_head_prop,new_head_edge); + sgraph[newh].set_skip_conditional(sgraph[h]); sgraph[newh].prop.visible_as_neighbour = false; } Edge new_dep_edge; int newd = d; - if( ! (new_dep_edge == sgraph[d].edge) || ! (old_dep_prop == new_dep_prop) ) + // if( ! (new_dep_edge == sgraph[d].edge) || ! (old_dep_prop == new_dep_prop) ) + if( ! (old_dep_prop == new_dep_prop) ) { newd = create_new_node(d,new_dep_prop,new_dep_edge); + sgraph[newd].set_skip_conditional(sgraph[d]); sgraph[newd].prop.has_head = true; } @@ -226,8 +234,8 @@ void connect_right(int h, int d, const Link& l, list& new_head_boubble if(debug) { sgraph.print_arc(stderr,"link",newh,newd,l.role,1); - sgraph.print_node_debug(stderr,"",newh,h); - sgraph.print_node_debug(stderr,"",newd,d); + sgraph.print_node_debug(stderr,"",newh); + sgraph.print_node_debug(stderr,"",newd); } } @@ -470,18 +478,24 @@ void dgp1() set_initial_constraints(basenode); nodelist.push_back(basenode); - if(debug) sgraph.print_node_debug(stderr,"node",basenode,-1); // STDOUT!!! + if(debug) sgraph.print_node_debug(stderr,"node",basenode); // STDOUT!!! // if(debug) print_sets(basenode); list::iterator cursor=processed; while(++cursor != nodelist.end()) { - if(debug) sgraph.print_node_debug(stderr,"CUR>",*cursor,-1); - try_connect_dependents(*cursor); - try_connect_heads(*cursor); + if(sgraph[*cursor].skip()) + { + if(debug) sgraph.print_node_debug(stderr,"SKIP>",*cursor); + } + else + { + if(debug) sgraph.print_node_debug(stderr,"CUR>",*cursor); + try_connect_dependents(*cursor); + try_connect_heads(*cursor); + } processed=cursor; } - } // reverse_links(); update_sets(); diff --git a/src/dgp/dgp1.d b/src/dgp/dgp1.d new file mode 100644 index 0000000..20dac4f --- /dev/null +++ b/src/dgp/dgp1.d @@ -0,0 +1,3 @@ +dgp1.o dgp1.d : dgp1.cc dgp1.hh grammar.hh const.hh thesymbols.hh symbol.hh \ + sgraph.hh mgraph.hh ../common/common.h ../common/../lib/const.h \ + ../common/../dgp/cmdline.h boubble.hh global.hh diff --git a/src/dgp/dgp1.o b/src/dgp/dgp1.o new file mode 100644 index 0000000..996c956 Binary files /dev/null and b/src/dgp/dgp1.o differ diff --git a/src/dgp/global.d b/src/dgp/global.d new file mode 100644 index 0000000..a6cb932 --- /dev/null +++ b/src/dgp/global.d @@ -0,0 +1 @@ +global.o global.d : global.cc global.hh diff --git a/src/dgp/global.o b/src/dgp/global.o new file mode 100644 index 0000000..f2adbce Binary files /dev/null and b/src/dgp/global.o differ diff --git a/src/dgp/grammar.cc b/src/dgp/grammar.cc index 15ce814..5348047 100644 --- a/src/dgp/grammar.cc +++ b/src/dgp/grammar.cc @@ -62,7 +62,7 @@ void Grammar::add_category(const char* s) void Grammar::add_type(const char* s) { Role::add(s); - + if(Role::count() > MAXTYPES) { fprintf(stderr,"ERROR: too many types. Aborting.\n"); exit(1); } if(lt.size() <= Role::count()) lt.resize(Role::count()+RESIZE_DELTA); if(gt.size() <= Role::count()) gt.resize(Role::count()+RESIZE_DELTA); if(pass.size() <= Role::count()) pass.resize(Role::count()+RESIZE_DELTA); @@ -155,15 +155,16 @@ list Grammar::trigger_boubbles(Cat c, Role r, Dir d) //==================================================================================================== -Flag parse_flags(const char* s, const char* v) +FlagSet parse_flags(const char* s, const char* v) { + FlagSet ret; char buf[16][17]; 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],buf[8],buf[9],buf[10],buf[11],buf[12],buf[13],buf[14],buf[15],buf[16]); for(int i=2; i<=n; i+=2) if(strcmp(buf[i-1],v)==0) - return Flag(buf[i-2]); - return Flag("NULL"); + ret.set(Flag(buf[i-2])); + return ret; } @@ -406,18 +407,18 @@ void Grammar::write(ostream& os) for(Links::const_iterator l = connect1[c][d].begin(); l != connect1[c][d].end(); l++) { os << "LINK\t" << c.str(); - if(l->hflagplus||l->hflagminus) + if(l->hflagplus.any()||l->hflagminus.any()) { os << ";"; - if(l->hflagplus) os << (l->hflagplus).str() << "+"; - if(l->hflagminus) os << (l->hflagminus).str() << "-"; + for(Flag f=1; fhflagplus.test(f)) os << "f" << f.str() << "+"; + for(Flag f=1; fhflagminus.test(f)) os << "f" << f.str() << "-"; } os << "\t" << d.str(); - if(l->dflagplus||l->dflagminus) + if(l->dflagplus.any()||l->dflagminus.any()) { os << ";"; - if(l->dflagplus) os << (l->dflagplus).str() << "+"; - if(l->dflagminus) os << (l->dflagminus).str() << "-"; + for(Flag f=1; fdflagplus.test(f)) os << "f" << f.str() << "+"; + for(Flag f=1; fdflagminus.test(f)) os << "f" << f.str() << "-"; } os << "\t" << (l->role).str(); for(Prop p=0; p Grammar::connectable2(Cat h, Cat d, FlagSet hfs, FlagSet dfs) { list ret; for(Links::const_iterator l = connect1[h][d].begin(); l != connect1[h][d].end(); l++) - if( (l->hflagplus==0 || hfs[l->hflagplus]) && (l->hflagminus==0 || !hfs[l->hflagminus]) ) - if( (l->dflagplus==0 || dfs[l->dflagplus]) && (l->dflagminus==0 || !dfs[l->dflagminus]) ) - ret.push_back(&(*l)); + { + // cout << l->hflagplus.count() << " " << l->hflagminus.count() << " " << hfs.count() << endl; + // cout << l->dflagplus.count() << " " << l->dflagminus.count() << " " << dfs.count() << endl; + if( ((l->hflagplus & hfs) == l->hflagplus) && (l->hflagminus & hfs).none() ) + if( ((l->dflagplus & dfs) == l->dflagplus) && (l->dflagminus & dfs).none() ) + ret.push_back(&(*l)); + } return ret; } diff --git a/src/dgp/grammar.o b/src/dgp/grammar.o new file mode 100644 index 0000000..7542e5d Binary files /dev/null and b/src/dgp/grammar.o differ diff --git a/src/dgp/main.cc b/src/dgp/main.cc index c768bf6..0280ebc 100644 --- a/src/dgp/main.cc +++ b/src/dgp/main.cc @@ -38,7 +38,7 @@ unsigned int info=0U; bool printtimeinfo=false; -void output(); +void output(unsigned int); main(int argc, char* argv[]) { @@ -70,6 +70,11 @@ main(int argc, char* argv[]) case 'd': info|=SGraph::DEPS; break; case 's': info|=SGraph::SETS; break; case 'c': info|=SGraph::CONSTRAINTS; break; + case 'a': info|=SGraph::ANCESTOR; break; + case 'v': info|=SGraph::VIS_AS_NEIGH; break; + case 'e': info|=SGraph::EDGE; break; + case 'k': info|=SGraph::SKIP; break; + case '*': info|=0b1111111111111111U; break; } gettimeofday(&readgrammar_starttime,NULL); @@ -114,7 +119,7 @@ main(int argc, char* argv[]) dgp1(); // parametry!!! MGraph, SGraph, Grammar gettimeofday(&afterparse,NULL); - output(); + output(info); gettimeofday(&endtime,NULL); if(printtimeinfo) @@ -138,7 +143,7 @@ main(int argc, char* argv[]) exit(0); } -void output() +void output(unsigned int info) { for(int si=0; si=0) buf+=sprintf(buf,"(%d)",anc); + if(node.anc>=0 && info&ANCESTOR) buf+=sprintf(buf,"(%d)",node.anc); buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u"); if (info&HEADS || info&DEPS) @@ -162,13 +162,30 @@ int SGraph::sprint_node(char* buf, int nodeind, int anc, unsigned int info) buf+=sprintf(buf,oss.str().c_str()); } + if(info&VIS_AS_NEIGH) + buf += sprintf(buf,nodes[nodeind].prop.visible_as_neighbour ? "(van=1)" : "(van=0)"); + + if(info&EDGE) + { + buf += sprintf(buf,"(edge="); + for(list::iterator e = nodes[nodeind].edge.others().begin(); e != nodes[nodeind].edge.others().end(); e++ ) + buf += sprintf(buf,"%d ", *e); + if(nodes[nodeind].edge.self()) + buf += sprintf(buf,"* "); + buf += sprintf(buf,")"); + } + + if(info&SKIP) + if(nodes[nodeind].skip()) buf += sprintf(buf,"(skip)"); + + // buf+=sprintf(buf,"\n"); return buf-buf0; } -int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc) +int SGraph::sprint_node_debug(char* buf, const char* pref, int n) { char *buf0 = buf; buf+=sprintf(buf,"%-8s",pref); @@ -176,14 +193,8 @@ int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc) buf+=sprintf(buf,";"); buf+=sprintf(buf,"%s ",cat(n).str()); while(buf-buf0<40) buf+=sprintf(buf," "); - buf+=sprint_node(buf,n,anc,HEADS|DEPS|CONSTRAINTS); - - buf+=sprintf(buf,"/"); - buf+=sprintf(buf,nodes[n].prop.visible_as_neighbour ? "o" : "x"); - if(nodes[n].edge.self()) - buf += sprintf(buf,"* "); - for(list::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ ) - buf += sprintf(buf,"%d ", *e); + + buf+=sprint_node(buf,n,HEADS|DEPS|CONSTRAINTS|ANCESTOR|VIS_AS_NEIGH|EDGE|SKIP); buf+=sprintf(buf,"\n"); return buf-buf0; diff --git a/src/dgp/sgraph.d b/src/dgp/sgraph.d new file mode 100644 index 0000000..a1f23b3 --- /dev/null +++ b/src/dgp/sgraph.d @@ -0,0 +1,3 @@ +sgraph.o sgraph.d : sgraph.cc sgraph.hh const.hh mgraph.hh thesymbols.hh symbol.hh \ + ../common/common.h ../common/../lib/const.h ../common/../dgp/cmdline.h \ + boubble.hh global.hh grammar.hh diff --git a/src/dgp/sgraph.hh b/src/dgp/sgraph.hh index 58cdf64..c171fc8 100644 --- a/src/dgp/sgraph.hh +++ b/src/dgp/sgraph.hh @@ -168,9 +168,10 @@ private: struct SNode { - SNode() { prop.clear(); } + SNode() : _skip(false), anc(-1) { prop.clear(); } int mnode; + int anc; NodeProp prop; Edge edge; @@ -184,8 +185,21 @@ struct SNode vector deps; void clear() { prop.clear(), LV.reset(), LD.reset(), LH.reset(), heads.clear(), deps.clear(); } - bool saturated() { return prop.required.none(); } - + bool saturated() const { return prop.required.none(); } + + void skip(bool b) { _skip=b; } + bool skip() { return _skip; } + void set_skip_false() { skip(false); } + void set_skip_conditional(const SNode& ancnode) + { + if(saturated() && !ancnode.saturated()) skip(false); + else if((prop.flags & ancnode.prop.flags) != ancnode.prop.flags) skip(false); + else skip(true); + } + + +private: + bool _skip; // void edge_clear() { edge.clear(); edge_contains_self=false;} // void edge_set(int i) { edge.clear(); edge_contains_self=false; edge.push_back(i); } @@ -204,7 +218,7 @@ class SGraph { public: - enum Output { HEADS=1, DEPS=2, SETS=4, CONSTRAINTS=8, BOUBBLES=16 }; + enum Output { HEADS=1, DEPS=2, SETS=4, CONSTRAINTS=8, BOUBBLES=16, ANCESTOR=32, VIS_AS_NEIGH=64, EDGE=128, SKIP=256 }; SGraph(MGraph& mg) : mgraph(mg) { clear(); } @@ -223,7 +237,7 @@ public: char* form(int i) const { return mgraph[nodes[i].mnode].form; } int print_node(FILE* f, int n, unsigned int info); - int print_node_debug(FILE* f, const char* pref, int n, int anc); + int print_node_debug(FILE* f, const char* pref, int n); void print_arc(FILE* f, const char* msg, int left, int right, Role role, int dir); // 0 - left, 1 - right @@ -245,8 +259,8 @@ private: int lastnodeind() { return nodes.size()-1; } SNode& makenewnode() { nodes.push_back(SNode()); nodes.back().clear(); return nodes.back(); } - int sprint_node(char* buf, int n, int anc, unsigned int info); - int sprint_node_debug(char* buf, const char* pref, int n, int anc); + int sprint_node(char* buf, int n, unsigned int info); + int sprint_node_debug(char* buf, const char* pref, int n); }; //---------------------------------------------------------------------------------------------------- @@ -332,7 +346,7 @@ inline int LViterator::next() { if(waydown.empty()) { - if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); + //if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); return -1; // } else @@ -343,7 +357,7 @@ inline int LViterator::next() push_ln(k); if(wayup.empty()) { - if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); + //if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); return -1; // k NIE MA POPRZEDNIKÓW, NIE MO¯E TE¯ ZATEM MIEÆ LEWOSTRONNYCH PODRZÊDNIKÓW } else @@ -351,7 +365,7 @@ inline int LViterator::next() int i = wayup.top(); wayup.pop(); push_lh(i); - if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); + //if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); return i; } } @@ -362,7 +376,7 @@ inline int LViterator::next() int i = wayup.top(); wayup.pop(); push_lh(i); - if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); + //if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); return i; }; } @@ -374,7 +388,7 @@ inline void LViterator::push_ld(int i) if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) { push(waydown,a->dst); - if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LD waydown %d\n",snode,a->dst); + //if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LD waydown %d\n",snode,a->dst); } } @@ -385,7 +399,7 @@ inline void LViterator::push_lh(int i) if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) { push(wayup,a->dst); - if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LH wayup %d\n",snode,a->dst); + //if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LH wayup %d\n",snode,a->dst); } } @@ -399,7 +413,7 @@ inline void LViterator::push_ln(int i) if(sgraph[*sp].prop.visible_as_neighbour || !strict) { push(wayup,*sp); - if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LN wayup %d\n",snode, *sp); + //if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LN wayup %d\n",snode, *sp); } } } @@ -433,14 +447,14 @@ inline int LNiterator::next() { if(wayup.empty()) { - if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,-1); + //if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,-1); return -1; } else { int i = wayup.top(); wayup.pop(); - if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,i); + //if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,i); return i; }; } @@ -454,7 +468,7 @@ inline void LNiterator::push_ln(int i) for(vector::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) { wayup.push(*sp); - if(debug) fprintf(stderr,"\t\tLNiterator(%d)\tPUSH %d\n",snode,-1); + //if(debug) fprintf(stderr,"\t\tLNiterator(%d)\tPUSH %d\n",snode,-1); } } } @@ -504,7 +518,7 @@ inline void LHiterator::push_lh(int i) if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) { wayup.push(a->dst); - if(debug) fprintf(stderr,"\t\tLHiterator(%d)\tPUSH %d\n",snode,-1); + //if(debug) fprintf(stderr,"\t\tLHiterator(%d)\tPUSH %d\n",snode,-1); } } @@ -552,7 +566,7 @@ inline void LDiterator::push_ld(int i) if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[snode].mnode].pos) { waydown.push(a->dst); - if(debug) fprintf(stderr,"\t\tLDiterator(%d)\tPUSH %d\n",snode,-1); + //if(debug) fprintf(stderr,"\t\tLDiterator(%d)\tPUSH %d\n",snode,-1); } } diff --git a/src/dgp/sgraph.o b/src/dgp/sgraph.o new file mode 100644 index 0000000..59c70fa Binary files /dev/null and b/src/dgp/sgraph.o differ diff --git a/src/dgp/symbol.d b/src/dgp/symbol.d new file mode 100644 index 0000000..9ecd7ff --- /dev/null +++ b/src/dgp/symbol.d @@ -0,0 +1 @@ +symbol.o symbol.d : symbol.cc symbol.hh diff --git a/src/dgp/symbol.o b/src/dgp/symbol.o new file mode 100644 index 0000000..16b51d7 Binary files /dev/null and b/src/dgp/symbol.o differ diff --git a/src/rat/Makefile b/src/rat/Makefile new file mode 100644 index 0000000..c87db34 --- /dev/null +++ b/src/rat/Makefile @@ -0,0 +1,16 @@ +include ../../config.mak +rat: + +.PHONY: install +install: +ifdef BIN_DIR + install -m 0755 rat $(BIN_DIR) +endif + +.PHONY: uninstall +uninstall: +ifdef BIN_DIR + rm $(BIN_DIR)/rat +endif + +clean: diff --git a/src/rat/rat b/src/rat/rat new file mode 100755 index 0000000..8f649d9 --- /dev/null +++ b/src/rat/rat @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby +# encoding: UTF-8 + +require 'attr' +require 'getoptlong' + +Help = < ") + " }" + (0...(words.length)).each{|i| puts "w#{i} [label=\"#{words[i]}\"]"} + dgprange.each{|i| puts "#{i} [label=< #{i}.#{nodeinfo(i)} >]"} + $arcs.each{|a| puts "#{a[0]} -> #{a[1]} [label=\"#{a[2]}\"]" } + for wi in (0...(words.length)) + puts "{ rank=same; w#{wi}; " + dgprange.select{|i| $ord[i]==wi}.map{|x| " #{x};"}.join + " }" + end + puts "}" +end + def printconll for i in 1...($form.length-1) id = $ord1[i]