Oct-10-2018, 08:27 PM
Hi, I am getting error in 'TEXTS' that 'too many blank lines, and 'missing white space around operator' and also I am not able to run that program. Please help.
from __future__ import unicode_literals, print_function import plac import spacy TEXTS ='Microsoft was founded by Bill Gates and Paul Allen on April 4 1975 to develop and sell BASIC interpreters for the Altair 8800. Since the 1990, it has increasingly diversified from the operating system market and has made a number of corporate acquisitions. ', @plac.annotations(model=("Model to load (needs parser and NER)", "positional", None, str)) def main(model='en_core_web_sm'): nlp = spacy.load(model) print("Loaded model '%s'" % model) print("Processing %d texts" % len(TEXTS)) for text in TEXTS: doc = nlp(text) relations = extract_currency_relations(doc) for r1, r2 in relations: print('{:<10}\t{}\t{}'.format(r1.text, r2.ent_type_, r2.text)) def extract_currency_relations(doc): # merge entities and noun chunks into one token spans = list(doc.ents) + list(doc.noun_chunks) for span in spans: span.merge() relations = [] for money in filter(lambda w : w.ent_type_ == 'PERSON', doc): if money.dep_ in ('attr', 'dobj'): subject = [w for w in money.head.lefts if w.dep_ == 'nsubj'] if subject: subject = subject[0] relations.append((subject, money)) elif money.dep_ == 'pobj' and money.head.dep_ == 'prep': relations.append((money.head.head, money)) return relations if __name__ == '__main__': plac.call(main)