I want to extract only organization from a string or column.
I am using this code:
def ent(doc):
for x in (nlp(doc)).ents:
if x.label_ != "ORG": continue
else:
return (x.text)
d= ("Brock Group (American Industrial Partners) acquires Aegion's Energy Services Businesses")
ent(d)
However, this code only extract only one organization not all; like in this case only gives:
'Brock Group'
CodePudding user response:
Your code only extracts the first organization name because it returns when the condition is met. You can use list comprehension
def ent(doc):
return [x for x in (nlp(doc)).ents if x.label_ == "ORG"]