Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FOR PYTHON ------> In the following, we say things like t.j. should not match. This means that the full string t.j. wil not appear in

FOR PYTHON ------>

In the following, we say things like t.j. should not match. This means that the full string t.j. wil not appear in the set of answers returned by finditer. Sub-parts of it might (e.g., t.j may match), but t.j.wont.

image text in transcribedimage text in transcribed

import regexs text = ''' CS1110-001/smile ! hi there "hi there" but not " hi there" or "hi there " or "I said "hi" just now" 3,4, 3.0, 4.5 and -3.14159265 1110 but not 3.4.5, 1 or 1 2 or 3 - 4 Thomas Jefferson and Edmund Jennings Randolph and J. Pierpont Finch and T. Jefferson but not T Jefferson or Thomas J. or Flannery O'Connor ''' def full_match(regex, text): '''Gives a list of all complete matches''' ans = [] for match in regex.finditer(text): ans.append(match.group(0)) return ans ns = full_match(regexs.nospace, text) print('nospace:', 'CS1110-001/smile' in ns, '!' in ns, 'hi there' not in ns, '' not in ns) q = full_match(regexs.quotation, text) print('quotation:', '"hi there"' in q, '" hi there"' not in q, '"hi there "' not in q, '"I said "hi" just now"' not in q) tn = full_match(regexs.twonum, text) print('twonum:', '3,4' in tn, '3.0, 4.5' in tn, '-3.14159265 1110' in tn, '3.4.5, 1' not in tn, '1 2' not in tn, '3 - 4' not in tn) for match in regexs.twonum.finditer(text): if match.group(0) == '3,4': print(' match1:', '3' in match.groups(), '4' in match.groups()) if match.group(0) == '-3.14159265 1110': print(' match2:', '-3.14159265' in match.groups(), '1110' in match.groups()) ln = full_match(regexs.likely_name, text) print('likely_name:', 'Thomas Jefferson' in ln, 'Edmund Jennings Randolph' in ln, 'J. Pierpont Finch' in ln, 'T. Jefferson' in ln, 'T Jefferson' not in ln, 'Thomas J.' not in ln, "Flannery O'Connor" not in ln) 

image text in transcribed

PLEASE ANY HELP WOULD BE GREATLY APPRECIATED !

1. What we mean by "match" TABLE OF CONTENTS 1. what we mean by match" 2. Task 3. Testing your code . Troubleshooting In the following, we say things like " t.j. should not match." This means that the full string t.j. wil not appear in the set of answers returned by finditer. Sub-parts of it might (e.g., t.j may match), but t.j won't 2. Task regexs.py that defines several variables containing compiled regular expressions, as Write a python file called follows: nospace = a regular expression that matches one or more non-whitespace characters. CS1110-001/smile should match, as should! hi there should not match, nor should the empty string . quotation a regular expression that matches text beginning and ending with a, with no internal", where the first and last character inside the quotes are not spaces. "hi there should match " hi there" should not match, nor should "hi there or "I said "hi" just now" twonum = a regular expression that matches pairs of numbers, separated by a space, comma, or both (with the space after the comma if both:, but not, ). Accept both numbers with and without decimal places, and allow an optional preceding on each number. If there is a decimal place, there must be at least one digit on each side of it. Additionally, each of the two numbers (with the if present) should be a group after a match. . 3,4, 3.0, 4.5, and -3.14159265 1110 should all match. 3.4.5, 1,1 2, and 3 -4 should not match likely name a regular expression that matches one common full name pattern: two or three consecutive capitalized runs of letters, separated by spaces. A capital letter and a period can serve as a name except in the last position. Thomas Jefferson should match, as should Edmund Jennings Randolph, J. Pierpont Finch, and T. Jefferson T Jefferson, Thomas J. ,and Flannery 0'Connor should not match. 1. What we mean by "match" TABLE OF CONTENTS 1. what we mean by match" 2. Task 3. Testing your code . Troubleshooting In the following, we say things like " t.j. should not match." This means that the full string t.j. wil not appear in the set of answers returned by finditer. Sub-parts of it might (e.g., t.j may match), but t.j won't 2. Task regexs.py that defines several variables containing compiled regular expressions, as Write a python file called follows: nospace = a regular expression that matches one or more non-whitespace characters. CS1110-001/smile should match, as should! hi there should not match, nor should the empty string . quotation a regular expression that matches text beginning and ending with a, with no internal", where the first and last character inside the quotes are not spaces. "hi there should match " hi there" should not match, nor should "hi there or "I said "hi" just now" twonum = a regular expression that matches pairs of numbers, separated by a space, comma, or both (with the space after the comma if both:, but not, ). Accept both numbers with and without decimal places, and allow an optional preceding on each number. If there is a decimal place, there must be at least one digit on each side of it. Additionally, each of the two numbers (with the if present) should be a group after a match. . 3,4, 3.0, 4.5, and -3.14159265 1110 should all match. 3.4.5, 1,1 2, and 3 -4 should not match likely name a regular expression that matches one common full name pattern: two or three consecutive capitalized runs of letters, separated by spaces. A capital letter and a period can serve as a name except in the last position. Thomas Jefferson should match, as should Edmund Jennings Randolph, J. Pierpont Finch, and T. Jefferson T Jefferson, Thomas J. ,and Flannery 0'Connor should not match

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

3. Discuss the process of behavior modeling training.

Answered: 1 week ago