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

[290-p4] Q6 & Q7 understanding #66

Closed
ymzhang-neo opened this issue Sep 9, 2020 · 3 comments
Closed

[290-p4] Q6 & Q7 understanding #66

ymzhang-neo opened this issue Sep 9, 2020 · 3 comments

Comments

@ymzhang-neo
Copy link
Collaborator

Hi @kevinamstutz , this will be one of the last two posts about 290 Project 4. The two posts will be about my understanding of the code: The questions are well designed, and it's just about my misunderstanding of the code. Thanks in advance for helping me to learn!

Q6 is to identify dialogue directions enclosed in "[" and "]". and Q7 is about identifying multiple directions in one line. The solution says:

# Q6 (2a in solution)
dat$has_direction <- grepl("(\\[.*\\])+", dat$text_w_direction)

# Q7 (2b in solution)
length(grep("(\\[.*\\].*){3,}", dat$text_w_direction))
length(grep("(\\[.*\\].*){6,}", dat$text_w_direction))

It seems that the pattern "\\[.*\\]" will get the same results as "(\\[.*\\])+" in the Q6 solution. Is it a general recommendation/good practice to use quantifier. or is there some important difference that I may neglect?

I would also like to share three mistakes I made about Q7, which motivated me to suggest more notes or hints on, for example, the parentheses and quantifiers.

# Mistake 1: Not using parentheses
sum(grepl('\\[.*\\]{2,}', dat$text_w_direction)) # 1
# Mistake 2: Checking consecutive pairs of "[...]"
sum(grepl('(\\[.*\\]){2,}', dat$text_w_direction)) # 10
# Mistake 3: Mis-using quantifiers
sum(grepl('(\\[.*\\]+){2,}', dat$text_w_direction)) # 10

I am not sure how to best help the students to learn such details. While I can compare my code with the solution, it could be difficult to debug such mistakes on the students' side as manually checking the data may or may not reveal all the patterns. Do you think there are any online resources or examples that may be relevant to be included in the project?

@kevinamstutz
Copy link
Member

Dear @ymzhang-neo,

I can't think of any reason I'd add that quantifier. My guess is I took some previous regular expression I was working with and modified it and didn't think to remove the quantifier. I can't think of a reason to include it now.

I think the best way is to make very similar examples and add them to the grep section in the book! I'll work on some and push them out. Thank you for providing the specific attempts, it's very helpful!

@ymzhang-neo
Copy link
Collaborator Author

Thank you @kevinamstutz for the clarification! I asked about the quantifiers just to make sure that I did not miss something. As to the additional examples, they would be helpful to illustrate regex in action - Thanks so much for drafting them!

@ymzhang-neo
Copy link
Collaborator Author

With Project 4 deadline on yesterday, I think we can close this issue. Thanks!

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

No branches or pull requests

2 participants