I need to extract a name and a quote for a given text such as:
Homer Simpson said: "Okay, here we go..."
The returned values:
- extracted_person_name - The extracted person name, as appearing in the patterns explained above
- extracted_quotation - The extracted quoted text (withot the surrounding quotation marks).
- Important Note: if the pattern is not found, return None values for both the
extracted person name and the extracted text.
You could expect the input text to look similar to the following pattern:
Person name said: "quoted text"
Variations of the above pattern:
The colon punctuation mark (:) is optional, and and might not appear in the input sentence. Instead of the word said you could also expect the words:
answered, responded, replied
this is what I got so far:
def person_quotation_pattern_extraction(raw_text):
name_pattern = "\w+\s\w+"
quote_pattern = "["]\w+["]"
quote = re.search(quote_pattern, raw_text)
name = re.search(name_pattern, raw_text)
if re.search(quote_pattern,raw_text):
extracted_quotation = quote.group(0)
else:
extracted_quotation=None
if re.search(name_pattern,raw_text):
extracted_person_name = name.group(0)
else:
extracted_person_name=None
return extracted_person_name, extracted_quotation
problem is it returns Null. I'm assuming the patterns are incorrect can you tell me what's wrong with them?