Skip to content
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

Show ReplacementRule while using replace() in ManyToOneReplacer #10

Open
arihantparsoya opened this issue Jul 10, 2017 · 5 comments
Open
Assignees

Comments

@arihantparsoya
Copy link

Is it possible to know/display the ReplacementRule if the replace() is able apply the rule?

@arihantparsoya arihantparsoya changed the title ReplacementRule while using replace() in ManyToOneReplacer Show ReplacementRule while using replace() in ManyToOneReplacer Jul 10, 2017
@wheerd
Copy link
Collaborator

wheerd commented Jul 10, 2017

You can use the underlying matcher to find out which rules match: replacer.matcher.match(subject). If you want to see the replacement steps that are taken, there is currently no function for that. A "debug" function sounds like a good idea though.

@arihantparsoya
Copy link
Author

I have used the following code:

    matches = rubi.matcher.match(expr)
    for matched_pattern, substitution in sorted(map(lambda m: (str(m[0]), str(m[1])), matches)):
        print('{} matched with {}'.format(matched_pattern, substitution))

which returns:

<function rubi_object.<locals>.<lambda> at 0x10bf93d08> matched with {xx}

What do I need to do in order to print the ReplacementRule?

@wheerd
Copy link
Collaborator

wheerd commented Jul 11, 2017

Sorry, I didn't realize that the labels used by the ManyToOneReplacer are the replacement lambda functions and do not contain the patterns. Here is a workaround you can try until I can provide debugging functionality:

matches = rubi.matcher.match(expr)
for _ in matches._match(rubi.matcher.root):
    for pattern_index in matches.patterns:
        renaming = rubi.matcher.pattern_vars[pattern_index]
        substitution = matches.substitution.rename({renamed: original for original, renamed in renaming.items()})
        pattern = rubi.matcher.patterns[pattern_index][0]
        print('{} matched with {}'.format(pattern , substitution))

I will try to add some debugging functionality to the ManyToOneReplacer as soon as possible.

@arihantparsoya
Copy link
Author

Thanks

@arihantparsoya
Copy link
Author

arihantparsoya commented Jul 11, 2017

It would be nice to have API something like this:

result, applied_rule = replacer.replace(expression, showsteps=True)

Otherwise we would have to compute the result and applied_rule seperately.

@wheerd wheerd self-assigned this Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants