Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 regex for addresses, dates, and times
#1
I am trying to come up with a way to get a hit for any facebook post that contains key words relating to a yard sale and extract the address, date, and time if there is one available. However an example below shows the vast styles of posts. For example using the word 'sale' by itself will give false hits for things like 'i have X for sale'. But yard sales come in a variety (yard, garage, rummage, porch, inside, estate, craft, flea market, (etc.) sale. As well as curb alerts, town wide trash collections, and community sales).

As if that is not difficult, i am wondering how to extract an address? This leaves me blank as sometimes it could be PA, P.A., Penn, Pennsylvania as well as NY, N.Y., New York, etc. Sometimes the state or even the town is not even listed. And then the actual street address. Which that could be anything really.

The dates and time doesnt seem as difficult to extract as i have done that before.

I think i am going to have to apply regex multiple times as all the content is not within one string, but sometimes the title of the post, as well as the rest in the post itself. As well as some of the content in responses to the post. For example of searching; search out whether its a yard sale or not first. If it is then check the time. If its a valid time, then check the address. So it would not be a one shot regex to get it all at once.

But i am assuming that with address at least would need a regex. I am just downright horrible at it. Does anyone have an idea on how to extract each example (each one is on a different line)? Or any ideas?

'''
MOVING SALE FRI & SAT 8-4. 669 Anderson hill candor
Large family garage sale June 28th and 29th 9 am to 4pm a lot of different items available. Something for everyone! First come first sale basis so stop in and see what we have. Dont PM just stop by 28 ferncrest drive tunkhannock pa in the west gate development
821 cedar street Elmira 1 hour left no reasonable offer refused!
Multi-family yard sale. Fri. & Sat. June 28 & 29. 8am-4pm 575 Joyce Road, Rome, PA. 
Garage sale 106 Thompson Ave Little Valley NY.
YARD SALE Friday 8-? and Saturday 8-12!! 210 S River St Athens.
A lot of good stuff, 1009 Fountain Lane, Lawman where the old flee market off I86 you should she my signs up
Yard sale! Located in Herrickville. Here today until 5. Tomorrow 9-? Come check it out!
Stop by Friday 6/28 and Saturday 6/29 from 8am-2pm! 3628 Pinecrest Rd, Vestal
Annual multi family yard sale just outside of Monroeton at 12050 Rt. 220S (going toward New Albany). 
Garage sale!!$1Endicott, NY
Garage sale on east main St Montour falls this weekend
Sale Friday 6/21 and Saturday 6/22. Antiques, brand new items, clothes, toys, housewares, etc....to much to list, great quality stuff. 5 Speer Drive, corning. 9-3pm
 2360 COUNTY ROAD 16 WATKINS GLEN 14891
'''
I have attempted to use CommonRegex but it only grabs a portion of hits. And it fails to grab things like 8-12 to identify as a time. or calculates 8-12p as only 12p time. OR fails to grab dates as 6/21 as a date..
>>> from commonregex import CommonRegex as CR
>>> text = '''
... MOVING SALE FRI & SAT 8-4. 669 Anderson hill candor
... Large family garage sale June 28th and 29th 9 am to 4pm a lot of different items available. Something for everyone! First come first sale basis so stop in and see what we have. Dont PM just stop by 28 ferncrest drive tunkhannock pa in the west gate development
... 821 cedar street Elmira 1 hour left no reasonable offer refused!
... Multi-family yard sale. Fri. & Sat. June 28 & 29. 8am-4pm 575 Joyce Road, Rome, PA. 
... Garage sale 106 Thompson Ave Little Valley NY.
... YARD SALE Friday 8-? and Saturday 8-12!! 210 S River St Athens.
... A lot of good stuff, 1009 Fountain Lane, Lawman where the old flee market off I86 you should she my signs up
... Yard sale! Located in Herrickville. Here today until 5. Tomorrow 9-? Come check it out!
... Stop by Friday 6/28 and Saturday 6/29 from 8am-2pm! 3628 Pinecrest Rd, Vestal
... Annual multi family yard sale just outside of Monroeton at 12050 Rt. 220S (going toward New Albany). 
... Garage sale!!$1Endicott, NY
... Garage sale on east main St Montour falls this weekend
... Sale Friday 6/21 and Saturday 6/22. Antiques, brand new items, clothes, toys, housewares, etc....to much to list, great quality stuff. 5 Speer Drive, corning. 9-3pm
...  2360 COUNTY ROAD 16 WATKINS GLEN 14891
... '''
>>>
>>> parsed_text = CR(text)
>>> parsed_text.times
['4pm', '8am', '4pm', '8am', '2pm', '3pm']
>>> parsed_text.dates
['June 28th', 'June 28']
>>> parsed_text.street_addresses
['28 ferncrest drive', '821 cedar street', '575 Joyce Road,', '106 Thompson Ave', '210 S River St', '3628 Pinecrest Rd,', '5 Speer Drive,', '2360 COUNTY ROAD']
Quote
#2
would something like https://pypi.org/project/Fuzzy/ help?
Quote
#3
Having worked on something like this, it's going to take a fair bit of work, and it won't catch everything. Go for the low hanging fruit. See what it misses. Analyze the misses and come up with a second regex. Rinse and repeat, but watch the false positives. Eventually you will get to a point where you are getting too much junk for the good stuff you are getting to be worth it. That's when you have to accept not getting everything.
metulburr likes this post
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  extracting embedded IP addresses Skaperen 3 131 Aug-30-2019, 08:09 PM
Last Post: Skaperen
  ipv6 addresses Skaperen 0 186 May-16-2019, 05:37 AM
Last Post: Skaperen

Forum Jump:


Users browsing this thread: 1 Guest(s)