Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

HfstOutputStream

eaxelson edited this pageFeb 8, 2018 ·13 revisions

class HfstOutputStream

A stream for writing binary transducers.

An example:

res = ['foo:bar','0','0 - 0','"?":?','a* b+']ostr = hfst.HfstOutputStream(filename='testfile1.hfst')for re in res:    ostr.write(hfst.regex(re))    ostr.flush()ostr.close()

For more information on HFST transducer structure, seehere.


__init__ (self, **kwargs)

Open a stream for writing binary transducers.

  • kwargs Arguments recognized are filename, hfst_format, type.
  • filename The name of the file where transducers are written. If the file exists, it is overwritten. Iffilename is not given, transducers are written to standard output.
  • hfst_format Whether transducers are written in hfst format (default is True) or as such in their backend format.
  • type The type of the transducers that will be written to the stream. Default ishfst.get_default_fst_type().
ostr = hfst.HfstOutputStream()  # a stream for writing default type transducers in hfst format to standard outputtransducer = hfst.regex('foo:bar::0.5')ostr.write(transducer)ostr.flush()
ostr = hfst.HfstOutputStream(filename='transducer.sfst', hfst_format=False, type=hfst.ImplementationType.SFST_TYPE)  # a stream for writing SFST_TYPE transducers in their back-end format to a filetransducer1 = hfst.regex('foo:bar')transducer1.convert(hfst.ImplementationType.SFST_TYPE)  # if not set as the default typetransducer2 = hfst.regex('bar:baz')transducer2.convert(hfst.ImplementationType.SFST_TYPE)  # if not set as the default typeostr.write(transducer1)ostr.write(transducer2)ostr.flush()ostr.close()

flush (self)

Flush the stream.


write (self, transducers)

Write one or moretransducers in binary format to the stream.

  • transducers: An HfstTransducer or an iterable object of several HfstTransducers.

All transducers that are written to the stream must have the same type as the stream, else a TransducerTypeMismatchException is thrown.

Throws:


close (self)

Close the stream.If the stream points to standard output, nothing is done.

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp