feature extraction in python for nlp

import re
test_string = "The New York Police, New Delhi police and other police departments are fighting crime".lower()
cities = ['new delhi', 'new york']
regex = "(("+"|".join(cities)+") police)"
regex = regex.lower()
results = re.findall(regex, test_string)
print([res[0] for res in results])
#['new york police', 'new delhi police']

Leave a Comment