mhulden / pyfoma Goto Github PK
View Code? Open in Web Editor NEWPython Finite-State Toolkit
License: Apache License 2.0
Python Finite-State Toolkit
License: Apache License 2.0
That is, the equivalents to Foma’s _isambiguous
, _ambpart
, and _unambpart
.
This would be useful for testing that a given transducer is unambiguous as a sanity check.
I have been trying to escape '.' to match a string with an actual period instead of using it as a wild card character, but all escaping methods don't work. I've tried all the following:
x = FST.re("A'.'")
x = FST.re("A\.")
x = FST.re("A\\.")
x = FST.re("A\\\.")
x = FST.re(r"A\.")
x = FST.re(r"A.")
None of them does what I want them to do. Interestingly, escaping two periods is possible using single quotations but not one. So this code works to match two periods followed by an 'A' x = FST.re("A'..'")
We should raise an error when the Graphviz executible is not installed, telling the user to do so.
pyfoma uses some shortcuts when outputting AT&T format which are not really part of the AT&T format, might not be accepted by OpenFST, and definitely aren't accepted by foma, namely:
fstcompile --acceptor
won't work)Since there isn't any universal standard for what to call epsilon (OpenFST just uses index 0 in the symbol table, whatever it happens to correspond to, while foma seems to use @0@
) probably there should be an actual method for outputting AT&T format along with symbol tables.
This is a somewhat marginal problem which can pop up when composing (somewhat artificial) FSTs:
f1 = FST.re("(foo):(bar)")
print(list(f1.apply("foo")))
# prints ["bar"]
f2 = FST.re("'':'foo' b a r:z")
print(list(f1.compose(f2).apply("foo")))
# prints [] ... you might expect it to print "foobaz"?
I'm not sure this is a serious problem as I'm having a hard time coming up with a less contrived example. Feel free to close this if you can't think of one either :)
The following is linked from the README but does not actually exist:
https://github.com/mhulden/pyfoma/blob/main/docs/Algorithms.ipynb
Because pyfoma's regex language, unlike foma/xfst, separates characters by default, what might appear to be single input symbols in a regex frequently are not. This is quite obviously true in the case where your data is in NFKD / NFD form, but much more perniciously so in NFKC / NFC, where, for instance, č is a single character, and so is ḥ, but x̌ is not.
This means that rewrite rules in particular may not do what you (or someone reading your code) might expect at first glance.
The defensive linguist will resort to putting single quotes around everything, which is probably a good idea, but this leads to rules that are, well, kind of ugly. Also there are lots of situations where something is fairly obviously not a single character but it would be nice to treat it as one.
This could for instance be an extra argument to FST.regex
and FST.rlg
, e.g.:
MULTICHARS = "kʷ kʷ̓ x̌".split()
rule = FST.re(some_regex, multichar_tokens=MULTICHARS)
I might make a PR to see if this is easily doable...
In the released version of pyfoma, one creates a flag-eliminated fst with:
from pyfoma.eliminate_flags import eliminate_flags
efst = eliminate_flags(some_other_fst)
This has been changed to something more logical:
from pyfoma.algorithms import eliminate_flags
efst = eliminate_flags(some_other_fst)
Unfortunately, the old function has also changed its name, so the original code will break. If there is no urgent reason to change pyfoma.eliminate_flags.eliminate_flags
to pyfoma.eliminate_flags.eliminate_fst_flags
then I suggest changing it back so older code will still work.
Implement convenience pickle
methods to save and load FSTs
In foma/xfst, you can use multi-character symbols in "character classes" and then take the complement of these classes, for example:
def U [ u | uː ];
def Unround kw -> k || \U _ .#.;
There doesn't seem to be any way to do this in pyfoma without some kind of workaround, transforming uː
into a single character, for example - I had thought I could use the complement operator ~
but it doesn't appear to be implemented yet.
It's not really clear to me how this works in foma since the resulting FSTs have magical @
symbols in them when you look at them with graphviz or export them as AT&T format, but it does seem to work :)
The readme.md
file contains a link at the bottom to algorithms overview but the Algorithms.ipynb
file is missing from the docs
folder.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.