New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NFA.to_regex() not implemented #55
Comments
@abhinavsinha-adrino Oh, shoot. How soon can you submit me a PR with the code for |
@caleb531 GNFA is derived from NFA, I'm not sure if I can import GNFA into NFA class. Without GNFA, we can't convert it to regex. |
@abhinavsinha-adrino I see. Well, we already have I will work on this now, and push out a supplemental release. |
@caleb531 Yeah, that will be great; we are using GNFA class primarily for NFA & DFA to regex conversion. Adding a direct function will cause circular imports; maybe there is a workaround in these cases, but I'm not aware of it. Maybe in the release notes or README, we can mention how one should convert NFA/DFA to regex using this package, it's not very trivial. Again very sorry for this mistake. |
@caleb531 instead of removing Are you working on this part, or should I do it? Its just one/two line change. |
@abhinavsinha-adrino No worries! It was my executive decision to subclass And thanks for the heads up re: the documentation—I will take care of updating the README accordingly. I had actually just removed it in 9453d1f but as you said, I will resurrect it and correct to But the GNFA.from_nfa(my_nfa).to_regex() |
@caleb531 Thanks a lot! |
@abhinavsinha-adrino Understood. Could you please take a look at my https://github.com/caleb531/automata/compare/develop I have included documentation on converting NFA to a regular expression, as well as some other corrections. |
@caleb531 It looks great and will avoid any more confusion. Thanks again for cleaning up my mistakes. |
@abhinavsinha-adrino Hey, I decided to try one last thing. It looks like circular imports can work if we implement them correctly. Per https://stackoverflow.com/a/22210807/560642, if we import the entire module (rather than a diff --git a/automata/fa/nfa.py b/automata/fa/nfa.py
index 133289d..1d64fdd 100644
--- a/automata/fa/nfa.py
+++ b/automata/fa/nfa.py
@@ -9,6 +9,7 @@
import automata.base.exceptions as exceptions
import automata.fa.fa as fa
+import automata.fa.gnfa as gnfa
from automata.fa.dfa import DFA
class NFA(fa.FA):
@@ -710,3 +711,6 @@ def _add_new_state(state_set, start=0):
state_set.add(new_state)
return new_state
+
+ def to_regex(self):
+ return gnfa.GNFA.from_nfa(self).to_regex() With that, can you please submit me a PR with this |
@caleb531 Oh, then I will update soon. |
@abhinavsinha-adrino Just merged your PR into my |
@abhinavsinha-adrino Alright, just released v6.0.1 with the restored |
@abhinavsinha-adrino Reopening this issue, because we have a MAJOR problem. If I try to
It turns out that per our circular changes, importing Apparently, the tests didn't catch this because GNFA must somehow be imported before NFA by the test runner. Ugghh lol. |
@abhinavsinha-adrino Okay, just pushed v6.0.2 that effectively reverts your PR and instead points to the simple workaround for direct NFA->regex conversions. |
@caleb531 I think by mistake I wrote
NFA.to_regex()
but this function is not there, insteadNFA.from_regex(regex)
is there. For converting NFA to regex, one has to convert NFA to GNFA and then GNFA to regex.Very sorry for this.
The text was updated successfully, but these errors were encountered: