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

[#31] Add transform and search_all #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

SoluMilken
Copy link
Contributor

@SoluMilken SoluMilken commented Oct 9, 2018

  • search_all: Recursively search the substring that matches the given regular expression pattern. Meanwhile, collect the start and end positions of the matched substring.

  • transform: Transform the string according to the provided annotations. A pair of annotations contains the forward and backward part. An annotation has format (start position, end position, substring). This method would extract the substring based on the positions provided by forward annotation and replace it with the substring provided by backward annotation.

@absolutelyNoWarranty absolutelyNoWarranty changed the title Transfrom n search all [#31] Add transform and search_all Oct 9, 2018
@stegben
Copy link
Contributor

stegben commented Oct 9, 2018

Please provide a detailed description of this PR. Ain't nobody got time for guessing what you try to do

@absolutelyNoWarranty
Copy link
Contributor

forward_annotations and backward_annotations are 1-to-1 mapping?

@SoluMilken
Copy link
Contributor Author

forward_annotations and backward_annotations are 1-to-1 mapping? YES
forward and backward annotations should contain the same number of annotation with the format (int, int ,str).

@SoluMilken
Copy link
Contributor Author

Def: An annotation is a tuple contains two integers and a string. Two integers indicate the start and end positions of string to be transformed. The string in this repo must be the same as that original_string[start: end].

@SoluMilken
Copy link
Contributor Author

I hope that this method (annotation) can be used in "list of string" for recording the process of transformation by only changing the last part.

@absolutelyNoWarranty
Copy link
Contributor

absolutelyNoWarranty commented Oct 9, 2018

transform should check that forward/backward are valid

  • list must be same lengths
  • forward annotations must actually be present in the input when present
  • len of b-a must be same len as chunk
  • no overlaps

cls.test_cases = [
{
"input_str": " 買5 - 80年 五門車~ ",
"reg_pattern": re.compile(r"\A\s+.{0,1}|.{0,1}\s+\Z"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the regex mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

開頭 抓\s 和 0個或1個隨便的字元
結尾 也如此

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants