Last active
October 11, 2015 09:07
-
-
Save vchahun/3835477 to your computer and use it in GitHub Desktop.
pyfst demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "pyfst" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import fst" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"t = fst.Transducer()\n", | |
"\n", | |
"t.add_arc(0, 1, 'a', 'A', 0.5)\n", | |
"t.add_arc(0, 1, 'b', 'B', 1.5)\n", | |
"t.add_arc(1, 2, 'c', 'C', 2.5)\n", | |
"\n", | |
"t[2].final = 3.5" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"t" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 3, | |
"svg": [ | |
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", | |
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", | |
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", | |
"<!-- Generated by graphviz version 2.28.0 (20111028.1807)\n", | |
" -->\n", | |
"<!-- Title: FST Pages: 1 -->\n", | |
"<svg width=\"294pt\" height=\"76pt\"\n", | |
" viewBox=\"0.00 0.00 294.00 76.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", | |
"<g id=\"graph1\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 72)\">\n", | |
"<title>FST</title>\n", | |
"<polygon fill=\"white\" stroke=\"white\" points=\"-4,5 -4,-72 291,-72 291,5 -4,5\"/>\n", | |
"<!-- 0 -->\n", | |
"<g id=\"node1\" class=\"node\"><title>0</title>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" stroke-width=\"2\" cx=\"18\" cy=\"-34\" rx=\"18\" ry=\"18\"/>\n", | |
"<text text-anchor=\"middle\" x=\"18\" y=\"-28.4\" font-family=\"Times,serif\" font-size=\"14.00\">0</text>\n", | |
"</g>\n", | |
"<!-- 1 -->\n", | |
"<g id=\"node3\" class=\"node\"><title>1</title>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" cx=\"126\" cy=\"-34\" rx=\"18\" ry=\"18\"/>\n", | |
"<text text-anchor=\"middle\" x=\"126\" y=\"-28.4\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n", | |
"</g>\n", | |
"<!-- 0->1 -->\n", | |
"<g id=\"edge2\" class=\"edge\"><title>0->1</title>\n", | |
"<path fill=\"none\" stroke=\"black\" d=\"M36.0307,-34C52.622,-34 78.1173,-34 97.5694,-34\"/>\n", | |
"<polygon fill=\"black\" stroke=\"black\" points=\"97.6594,-37.5001 107.659,-34 97.6594,-30.5001 97.6594,-37.5001\"/>\n", | |
"<text text-anchor=\"middle\" x=\"72\" y=\"-36.8\" font-family=\"Times,serif\" font-size=\"14.00\">a:A/0.5</text>\n", | |
"</g>\n", | |
"<!-- 0->1 -->\n", | |
"<g id=\"edge4\" class=\"edge\"><title>0->1</title>\n", | |
"<path fill=\"none\" stroke=\"black\" d=\"M32.4597,-22.7807C37.8731,-18.9586 44.3931,-15.1585 51,-13.2 68.8969,-7.89465 75.1031,-7.89465 93,-13.2 96.4067,-14.2099 99.7903,-15.7093 103.011,-17.449\"/>\n", | |
"<polygon fill=\"black\" stroke=\"black\" points=\"101.205,-20.4479 111.54,-22.7807 104.916,-14.5122 101.205,-20.4479\"/>\n", | |
"<text text-anchor=\"middle\" x=\"72\" y=\"-15.8\" font-family=\"Times,serif\" font-size=\"14.00\">b:B/1.5</text>\n", | |
"</g>\n", | |
"<!-- 2 -->\n", | |
"<g id=\"node6\" class=\"node\"><title>2</title>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" cx=\"251\" cy=\"-34\" rx=\"30.7249\" ry=\"30.7249\"/>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" cx=\"251\" cy=\"-34\" rx=\"34.7388\" ry=\"34.7388\"/>\n", | |
"<text text-anchor=\"middle\" x=\"251\" y=\"-28.4\" font-family=\"Times,serif\" font-size=\"14.00\">2/3.5</text>\n", | |
"</g>\n", | |
"<!-- 1->2 -->\n", | |
"<g id=\"edge6\" class=\"edge\"><title>1->2</title>\n", | |
"<path fill=\"none\" stroke=\"black\" d=\"M144.103,-34C160.1,-34 184.678,-34 206.131,-34\"/>\n", | |
"<polygon fill=\"black\" stroke=\"black\" points=\"206.359,-37.5001 216.359,-34 206.359,-30.5001 206.359,-37.5001\"/>\n", | |
"<text text-anchor=\"middle\" x=\"180\" y=\"-36.8\" font-family=\"Times,serif\" font-size=\"14.00\">c:C/2.5</text>\n", | |
"</g>\n", | |
"</g>\n", | |
"</svg>\n" | |
], | |
"text": [ | |
"<StdVectorFst with 3 states>" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"t.shortest_path()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "pyout", | |
"prompt_number": 4, | |
"svg": [ | |
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", | |
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", | |
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", | |
"<!-- Generated by graphviz version 2.28.0 (20111028.1807)\n", | |
" -->\n", | |
"<!-- Title: FST Pages: 1 -->\n", | |
"<svg width=\"294pt\" height=\"76pt\"\n", | |
" viewBox=\"0.00 0.00 294.00 76.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", | |
"<g id=\"graph1\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 72)\">\n", | |
"<title>FST</title>\n", | |
"<polygon fill=\"white\" stroke=\"white\" points=\"-4,5 -4,-72 291,-72 291,5 -4,5\"/>\n", | |
"<!-- 2 -->\n", | |
"<g id=\"node1\" class=\"node\"><title>2</title>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" stroke-width=\"2\" cx=\"18\" cy=\"-34\" rx=\"18\" ry=\"18\"/>\n", | |
"<text text-anchor=\"middle\" x=\"18\" y=\"-28.4\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n", | |
"</g>\n", | |
"<!-- 1 -->\n", | |
"<g id=\"node3\" class=\"node\"><title>1</title>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" cx=\"126\" cy=\"-34\" rx=\"18\" ry=\"18\"/>\n", | |
"<text text-anchor=\"middle\" x=\"126\" y=\"-28.4\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n", | |
"</g>\n", | |
"<!-- 2->1 -->\n", | |
"<g id=\"edge2\" class=\"edge\"><title>2->1</title>\n", | |
"<path fill=\"none\" stroke=\"black\" d=\"M36.0307,-34C52.622,-34 78.1173,-34 97.5694,-34\"/>\n", | |
"<polygon fill=\"black\" stroke=\"black\" points=\"97.6594,-37.5001 107.659,-34 97.6594,-30.5001 97.6594,-37.5001\"/>\n", | |
"<text text-anchor=\"middle\" x=\"72\" y=\"-36.8\" font-family=\"Times,serif\" font-size=\"14.00\">a:A/0.5</text>\n", | |
"</g>\n", | |
"<!-- 0 -->\n", | |
"<g id=\"node4\" class=\"node\"><title>0</title>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" cx=\"251\" cy=\"-34\" rx=\"30.7249\" ry=\"30.7249\"/>\n", | |
"<ellipse fill=\"none\" stroke=\"black\" cx=\"251\" cy=\"-34\" rx=\"34.7388\" ry=\"34.7388\"/>\n", | |
"<text text-anchor=\"middle\" x=\"251\" y=\"-28.4\" font-family=\"Times,serif\" font-size=\"14.00\">0/3.5</text>\n", | |
"</g>\n", | |
"<!-- 1->0 -->\n", | |
"<g id=\"edge4\" class=\"edge\"><title>1->0</title>\n", | |
"<path fill=\"none\" stroke=\"black\" d=\"M144.103,-34C160.1,-34 184.678,-34 206.131,-34\"/>\n", | |
"<polygon fill=\"black\" stroke=\"black\" points=\"206.359,-37.5001 216.359,-34 206.359,-30.5001 206.359,-37.5001\"/>\n", | |
"<text text-anchor=\"middle\" x=\"180\" y=\"-36.8\" font-family=\"Times,serif\" font-size=\"14.00\">c:C/2.5</text>\n", | |
"</g>\n", | |
"</g>\n", | |
"</svg>\n" | |
], | |
"text": [ | |
"<StdVectorFst with 3 states>" | |
] | |
} | |
], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment