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

HW try #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions textminer/extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import re

text = """Dear Mr. Davis,

I got to know of your company through our mutual friend Fiona Williams and the
training you offer to graduate students in Advertising.

I am a graduate student of Mass Communications with specialization in
Advertising. I am currently pursuing the last year of my course.
I would very much like to see firsthand the work environment in an advertising
agency.

If you would like a reference, my advisor can be reached at (454) 999-1212.

You can contact me at (919) 123-4569 at your convenience."""



def phone_numbers(text):
phone_book = re.findall(r"\(?(\d{3})\)?[\.\-]?\s*(\d{3})[\.\-]?(\d{4})", text)
return phone_book

print(phone_numbers(text))
12 changes: 6 additions & 6 deletions textminer/tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import textminer.validator as v


@xfail
# @xfail
def test_binary_numbers():
assert v.binary("0")
assert v.binary("1")
Expand All @@ -15,7 +15,7 @@ def test_binary_numbers():
assert not v.binary("911")


@xfail
# @xfail
def test_binary_even():
"""String must be a binary number and be even."""

Expand All @@ -24,7 +24,7 @@ def test_binary_even():
assert not v.binary_even("1011")


@xfail
# @xfail
def test_hexadecimal():
assert v.hex("CAFE")
assert v.hex("9F9")
Expand All @@ -34,7 +34,7 @@ def test_hexadecimal():
assert not v.hex("COFFEE")


@xfail
# @xfail
def test_word():
assert v.word("hello")
assert v.word("wonderful")
Expand All @@ -47,7 +47,7 @@ def test_word():
assert not v.word("bar*us")


@xfail
# @xfail
def test_words():
"""words can take an optional count argument. In case it exists, the text
must match that number of words."""
Expand All @@ -69,7 +69,7 @@ def test_words():
assert not v.words("18-wheeler tarbox", count=3)


@xfail
# @xfail
def test_phone_numbers():
"""US phone numbers only."""

Expand Down
22 changes: 22 additions & 0 deletions textminer/validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import re
import collections

def binary(string):
return re.findall(r"(\A[01]+)", string)

def binary_even(string):
if binary(string):
return re.findall(r"[0]\Z", string)

def hex(string):
return re.findall(r"(\b[A-Fa-f0-9]{1,}\b)", string)

def word(string):
return re.findall(r"[\w-]+\w[^\*!]$", string)
#
# def words(string, count=None):
# if word(string) != []:
# return (word(string), count)

def phone_number(string):
return re.findall(r"\b\(?\d{,3}\)?[-.\s]?\d{,3}[-.]?\d{,4}\b", string)