Guest User

Untitled

a guest
Oct 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import spacy
  2. nlp = spacy.load('en')
  3.  
  4. text_list = []
  5. text_list.append("I have spent 5+ years developing bug-tracking systems and creating data managing systems.")
  6. text_list.append("I have spent 2+ years in analysis and implementation of complex, custom-built applications.")
  7.  
  8. for content in text_list:
  9. document = nlp(content)
  10. sentences = [sent for sent in document.sents if('year') in sent.string.lower()]
  11. for s in sentences:
  12. for ent in nlp(s.text).ents:
  13. if ent.label_ == "DATE":
  14. if('year' in ent.text):
  15. s_text = nlp(ent.text)
  16. num_list = []
  17. print("nText with Number::", s_text)
  18. for word in s_text:
  19. print("Word :", word, " Pos :", word.pos_, " Tag :", word.tag_, " Like Num? :", word.like_num)
  20.  
  21. Text with Number:: 5+ years
  22. Word : 5 Pos : NUM Tag : CD Like Num? : True
  23. Word : + Pos : SYM Tag : SYM Like Num? : False
  24. Word : years Pos : NOUN Tag : NNS Like Num? : False
  25.  
  26. Text with Number:: 2+ years
  27. Word : 2 Pos : PUNCT Tag : LS Like Num? : True
  28. Word : + Pos : SYM Tag : SYM Like Num? : False
  29. Word : years Pos : NOUN Tag : NNS Like Num? : False
Add Comment
Please, Sign In to add comment