Arbitrary trimming with HFST

From Apertium
Jump to navigation Jump to search

fran@ipek:/tmp$ cat foo.lexc 
Multichar_Symbols

%<n%> %<px3sp%> %<loc%> %<subst%>

LEXICON Root

ev%<n%>%<px3sp%>%<loc%>%<subst%>%<px3sp%>%<loc%>%<subst%>%<px3sp%>:evindekinindekini # ;
ev%<n%>%<px3sp%>%<loc%>%<subst%>%<px3sp%>:evindekini # ;
ev%<n%>%<px3sp%>%<loc%>:evinde # ;

fran@ipek:/tmp$ hfst-lexc foo.lexc -o foo.hfst
hfst-lexc: warning: Defaulting to OpenFst tropical type
Root...

fran@ipek:/tmp$ hfst-fst2strings foo.hfst 
ev<n><px3sp><loc>:evinde
ev<n><px3sp><loc><subst><px3sp>:evindekini
ev<n><px3sp><loc><subst><px3sp><loc><subst><px3sp>:evindekinindekini

fran@ipek:/tmp$ echo "~[?* %<subst%> ?* %<subst%> ?*];" | hfst-regexp2fst -o trim.hfst

fran@ipek:/tmp$ hfst-invert foo.hfst | hfst-compose -1 - -2 trim.hfst | hfst-fst2strings 
evinde:ev<n><px3sp><loc>
evindekini:ev<n><px3sp><loc><subst><px3sp>