-
Notifications
You must be signed in to change notification settings - Fork 39
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
Make rules more inspectable #5
Comments
Hi, thanks for the feature request! Returning JSON doesn't make sense to me - I assume you mean returning a list of suggestions with start, end, replacements and message? This is already implemented to some degree (copied from the Readme) in v0.1.9: suggestions = rules.suggest_sentence("She was not been here since Monday.")
for s in suggestions:
print(s.start, s.end, s.text)
# prints:
# 4 16 ['was not', 'has not been'] On suggestions = rules.suggest_sentence("She was not been here since Monday.")
for s in suggestions:
print(s.start, s.end, s.text, s.source, s.message)
# prints:
# 4 16 ['was not', 'has not been'] WAS_BEEN.1 Did you mean was not or has not been? This will be part of v0.2.0 which I'll release soon. Let me know if that's what you meant. |
Release 0.2.0 is now out so the code in the sample above works now. |
Great, thanks! |
Hi, I looked into setting Is there any reason something like this doesn't work for you: import json
# ...
suggestions = rules.suggest_sentence("She was not been here since Monday.")
for s in suggestions:
print(
json.dumps(
{
"start": s.start,
"end": s.end,
"text": s.text,
"source": s.source,
"message": s.message,
}
)
) I believe that's good enough, unless you really care about never repeating yourself. |
but that wouldn't give me:
I know nothing about rust, other than it's a cool name, but if it's OOP, then I would expect an object with all properties of a rule, and if that exists, then it would be rather easy to convert the rule to json and return that with the word, something like ruleO.serialize() ? Anyway, it was just a suggestion if you don't see the point, maybe someone else can contribute a pull request. Thanks. |
Hi, sorry, I was thrown of a bit by the "JSON" then. Edit: Actually these things make more sense as attributes on a rule (as you suggested) so:
|
Cool, thank you, I'll be looking forward to that. |
Let's keep this issue open to remind me and thanks for bringing it up :) |
I ran into this problem a while back, if you feel comfortable enabling slots, this could work (slots provide a speed and memory boost, but you can't assign attributes to instances unless the underlying class has that attribute in slots): def __iter__(self):
for attr in itertools.chain.from_iterable(getattr(cls, '__slots__', []) for cls in self.__class__.__mro__):
yield attr, getattr(self, attr) It might work for |
Thanks! That looks interesting. The thing is that I always have to look at that in the context of PyO3 as the Python bindings are written in Rust as well so how to set I'd definitely like |
Just finished implementing this. This is the API: suggestion = rules.suggest_sentence("She was not been here since Monday.")[0]
# .rule(..) finds a rule by id
rule = rules.rule(suggestion.source)
print(rule.url, rule.short, rule.name, rule.category_id, rule.category_name, rule.category_type)
for example in rule.examples:
print(example.text, example.suggestion) A more detailed example is in the unit tests: nlprule/bindings/python/test.py Lines 54 to 89 in a9b7f40
This will be part of release v0.3.0 which I'll release in a couple of days. NLPRule will also be roughly x4 faster for English and x2.5 faster for German with that Release :) |
Thanks! The speed boosts and additional functionality look super fun :) |
I just released v0.3.0 so the code above works now. I'll close this issue for now, let me know if I forgot anything in the API. |
It would be nice to return JSON (like LT HTTP server). It's frequent to not want a specific correction, some are even just suggestions.
The text was updated successfully, but these errors were encountered: