Not able to retrieve output from Python code

Hi,

I am trying to pass Body of the email to Python code and retrieve the email, phone number and names as an output from the python code. When I run this code via UiPath, I am getting the same value as what I am passing to the python code as an input. But not able to get the actual output. Not sure where I am going wrong. Can someone please help?

information-extraction.py

import sys
import re
import nltk
nltk.download(‘stopwords’)
nltk.download(‘punkt’)
nltk.download(‘averaged_perceptron_tagger’)
nltk.download(‘maxent_ne_chunker’)
nltk.download(‘words’)
from nltk.corpus import stopwords
stop = set(stopwords.words(‘english’))

def extract_phone_numbers(string):
r = re.compile(r’(\d{3}[-.\s]??\d{3}[-.\s]??\d{4}|(\d{3})\s*\d{3}[-.\s]??\d{4}|\d{3}[-.\s]??\d{4})‘)
phone_numbers = r.findall(string)
return [re.sub(r’\D’, ‘’, number) for number in phone_numbers]

def extract_email_addresses(string):
r = re.compile(r’[\w.-]+@[\w.-]+')
return(r.findall(string))

def ie_preprocess(document):
document = ’ '.join([i for i in document.split() if i not in stop])
sentences = nltk.sent_tokenize(document)
sentences = [nltk.word_tokenize(sent) for sent in sentences]
sentences = [nltk.pos_tag(sent) for sent in sentences]
return(sentences)

def extract_names(document):
names =
sentences = ie_preprocess(document)
for tagged_sentence in sentences:
for chunk in nltk.ne_chunk(tagged_sentence):
if type(chunk) == nltk.tree.Tree:
if chunk.label() == ‘PERSON’:
names.append(’ '.join([c[0] for c in chunk]))
return(names)

if name == ‘main’:
numbers = extract_phone_numbers(NameExtract.xaml (8.7 KB)
BodyContent)
address = extract_email_addresses(BodyContent)
names = extract_names(BodyContent)
print(numbers)
print(emails)
print(names)
robot(numbers, emails, names)

Regards,

PrameelaJ

Hi @prameelaj

See a basic example here:

As well as more forum topics here.

1 Like