Skip to content

PmatchContainer

eaxelson edited this page Feb 8, 2018 · 17 revisions

class PmatchContainer

A class for performing pattern matching.

Probably the easiest way to perform pattern matching is with functions hfst.compile_pmatch_expression and hfst.compile_pmatch_file


__init__ (self)

Initialize a PmatchContainer. Is this needed?


__init__ (self, defs)

Create a PmatchContainer based on definitions defs.

  • defs: A tuple of transducers in HFST_OLW_TYPE defining how pmatch is done.

An example:

If we have a file named streets.txt that contains:

define CapWord UppercaseAlpha Alpha* ;
define StreetWordFr [{avenue} | {boulevard} | {rue}] ;
define DeFr [ [{de} | {du} | {des} | {de la}] Whitespace ] | [{d'} | {l'}] ;
define StreetFr StreetWordFr (Whitespace DeFr) CapWord+ ;
regex StreetFr EndTag(FrenchStreetName) ;

and which has been earlier compiled and stored in file streets.pmatch.hfst.ol:

defs = hfst.compile_pmatch_file('streets.txt')
ostr = hfst.HfstOutputStream(filename='streets.pmatch.hfst.ol', type=hfst.ImplementationType.HFST_OLW_TYPE)
for tr in defs:
    ostr.write(tr)
ostr.close()

we can read the pmatch definitions from file and perform string matching with:

istr = hfst.HfstInputStream('streets.pmatch.hfst.ol')
defs = []
while(not istr.is_eof()):
    defs.append(istr.read())
istr.close()
cont = hfst.PmatchContainer(defs)
assert cont.match("Je marche seul dans l'avenue des Ternes.") == "Je marche seul dans l'<FrenchStreetName>avenue des Ternes</FrenchStreetName>."

See also: hfst.compile_pmatch_file, hfst.compile_pmatch_expression


match (self, input, time_cutoff = 0)

Match input input.


get_profiling_info (self)

todo


set_verbose (self, b)

todo


set_extract_tags_mode (self, b)

todo


set_profile (self, b)