{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# FstStr\n\nFstStr is a small library providing a string-oriented Python interface to\nOpenFST. It is build on the `pywrapfst` library that is distributed with\nOpenFST.\n\n## Usage\n\nFstStr includes several types of functions that make working with strings in\nOpenFST more comfortable. These include defining SymbolTables, applying FSTs to\nstrings, and several component steps.\n\n### Working with symbols and SymbolTables\n\nSymbolTables define a mapping between integer indices and the input/output\nalphabet of an FST. An example alphabet for English (`EN_SYMB`) is included in fststr.\n\n```python\n>>> from fststr import fststr\n>>> fststr.EN_SYMB\n['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-', \"'\", \"'\", '+Known', '+Guess', '', '', '']\n```\n\nTo convert this alphabet to a symbol table, use `symbol_table_from_alphabet`:\n\n```python\n>>> st = fststr.symbols_table_from_alphabet(fststr.EN_SYMB)\n```\n\nThis symbol table can then be passed to an FST compiler as the input/output\nsymbols tables for an FST.\n\n### Compiling and manipulating FSTs\n\nFstStr currently provides no abstraction over the process of defining and\ncompiling FSTs, but does provide some functions for maniuplating FSTs once they\nare compiled. To compile an FST, instantiate a compiler (using the symbol table\n`st` for both input and output):\n\n```python\n>>> import pywrapfst as fst\n>>> compiler = fst.Compiler(isymbols=st, osymbols=st, keep_isymbols=True, keep_osymbols=True)\n```\n\nThe resulting object, `compiler` is a file-like object. You pass a transition\ntable to `compiler` by writing to it and compile the FST corresponding to the\ntransition table by calling the `compile` method:\n\n```python\n>>> print('0 1 a b\\n1 2 b c\\n2 3 c d\\n3', file=compiler)\n>>> abc2bcd = compiler.compile()\n```\n\nSome shortcuts are often taken when defining FSTs. One is to use \u201cother\u201d as a\nlabel on arcs, meaning that there is a transition with the label *x*:*x* for\nevery *x* not in the set of outgoing arcs from that state. This relieves the\nauthor of the FST from the tedious and error-prone process of defining these\narcs manually. OpenFST does not support this notation directly, but `fststr`\nprovides a function that will take an FST including the symbol `` and\nmutate it so that the arcs with `` are paralleled by the implied arc.\nConsider the following example:\n\n```python\n>>> st = fststr.symbols_table_from_alphabet(alphabet)\n>>> alphabet = ['A', 'a', 'b', 'c', '']\n>>> st = fststr.symbols_table_from_alphabet(alphabet)\n>>> compiler = fst.Compiler(isymbols=st, osymbols=st, keep_isymbols=True, keep_osymbols=True)\n>>> compiler.write('0 1 a A\\n0 1 \\n1\\n')\n>>> other = compiler.compile()\n>>> print(other.__str__().decode('utf-8'))\n0 1 a A\n0 1 \n1\n>>> fststr.expand_other_symbols(other)\n>>> print(other.__str__().decode('utf-8'))\n0 1 a A\n0 1 \n0 1 A A\n0 1 b b\n0 1 c c\n1\n```\n\nNote that the arc labeled `` will not be deleted, but this does not\nmatter as long as the input string does not contain the sequence \"\".\n\nOther, similar wildcard symbols can be defined and used following the example of\n``.\n\n### Application\n\nOnce you have an FST, you can apply it to a string. In reality, this is a four-step process:\n\n1. Convert a string to a list of symbols and the list of symbols to a linear-chain automaton\n2. Compose the FST from 2 with this automaton\n3. Extract the unique paths through the resulting lattice\n4. Convert these to strings\n\nFstStr provides functions for doing each of these things and also provides a\nsingle convenience function, `apply` that does all of them. This allows the\nprogrammer to simply take a string, apply and FST to it, and get back the\nresulting strings.\n\n```python\n>>> st = fststr.symbols_table_from_alphabet(['a', 'b', 'c', 'd', ''])\n>>> compiler = fst.Compiler(isymbols=st, osymbols=st, keep_isymbols=True, keep_osymbols=True)\n>>> compiler.write('0 1 a \\n0 1 \\n1\\n')\n>>> del_a = compiler.compile()\n>>> fststr.expand_other_symbols(del_a)\n>>> fststr.apply('a', del_a)\n['']\n>>> fststr.apply('b', del_a)\n['b']\n>>> fststr.apply('c', del_a)\n['c']\n>>> fststr.apply('d', del_a)\n['d']\n```\n\n### Example\nExamples are in `examples/FSTs`. We will examine `e-insertion.txt. \nThe FST takes in morphologically separated inputs like `fox<^>s<#>` and outputs \n`foxes<#>`.\n\nEach line of the file represents information about the FST.\n\nThe first line `0` represents that q0 is a final state\n\nThe second line `0 0 ` represents an arc from q0 to q0 with the value ` : `\n\nThe fifth line `0 1 z z` represents an arc from q0 to q1 with the value `z : z`\n\nSee e-insertion.py for an example of how to run the FST.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "MIT license", "maintainer": "", "maintainer_email": "", "name": "fststr", "package_url": "https://pypi.org/project/fststr/", "platform": "", "project_url": "https://pypi.org/project/fststr/", "project_urls": null, "release_url": "https://pypi.org/project/fststr/0.2/", "requires_dist": null, "requires_python": "", "summary": "", "version": "0.2" }, "last_serial": 5784379, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "62555a7658a3a329a3c7087a1df35a31", "sha256": "ae52090b7a0b754aef86ad704e30fc18e8ad6a5b5b81e784654202f126a0df99" }, "downloads": -1, "filename": "fststr-0.1.tar.gz", "has_sig": false, "md5_digest": "62555a7658a3a329a3c7087a1df35a31", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6214, "upload_time": "2019-08-31T19:30:15", "url": "https://files.pythonhosted.org/packages/25/82/58f8f3cf1c7186d2e3316bf1184919884c292593de5b084ea5b664863b47/fststr-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "dfbe403f2585486b2520ea071308e1fd", "sha256": "53a5fde4653e753db186b96d5e6af0a1e6b88faa98661e5c67c2143fa9a59266" }, "downloads": -1, "filename": "fststr-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "dfbe403f2585486b2520ea071308e1fd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7322, "upload_time": "2019-09-05T03:08:12", "url": "https://files.pythonhosted.org/packages/54/b0/33740ef55832b98a936773d0d11b08fe68ce7f5caf1974e354cdcc5b2be5/fststr-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e811f8c8f2bcbc69c00e5486ee3df85b", "sha256": "e5f86aef6c3fdc03db799bc4b6d86e870a09cd5912d6b340cac434be09b4f700" }, "downloads": -1, "filename": "fststr-0.2.tar.gz", "has_sig": false, "md5_digest": "e811f8c8f2bcbc69c00e5486ee3df85b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6117, "upload_time": "2019-09-05T03:08:14", "url": "https://files.pythonhosted.org/packages/57/1c/fdae5b071c1cbfe3cf8ce87b51ec0ddc59bae11f3f3d8e6b7a244de64282/fststr-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dfbe403f2585486b2520ea071308e1fd", "sha256": "53a5fde4653e753db186b96d5e6af0a1e6b88faa98661e5c67c2143fa9a59266" }, "downloads": -1, "filename": "fststr-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "dfbe403f2585486b2520ea071308e1fd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7322, "upload_time": "2019-09-05T03:08:12", "url": "https://files.pythonhosted.org/packages/54/b0/33740ef55832b98a936773d0d11b08fe68ce7f5caf1974e354cdcc5b2be5/fststr-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e811f8c8f2bcbc69c00e5486ee3df85b", "sha256": "e5f86aef6c3fdc03db799bc4b6d86e870a09cd5912d6b340cac434be09b4f700" }, "downloads": -1, "filename": "fststr-0.2.tar.gz", "has_sig": false, "md5_digest": "e811f8c8f2bcbc69c00e5486ee3df85b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6117, "upload_time": "2019-09-05T03:08:14", "url": "https://files.pythonhosted.org/packages/57/1c/fdae5b071c1cbfe3cf8ce87b51ec0ddc59bae11f3f3d8e6b7a244de64282/fststr-0.2.tar.gz" } ] }