Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. # DOCUMENTS
  2. doc1 = "My sister likes to have sugar, but not my father."
  3. doc2 = "Doctors suggest that driving may cause increased stress."
  4.  
  5. documents = [doc1, doc2]
  6.  
  7. # DICTIONARY
  8. dictionary = ["doctors", "sister", "like"]
  9.  
  10. # CHECK DOCUMENT WORDS WITHIN DICTIONARY
  11. for word in dictionary:
  12. for doc in documents:
  13. if word in doc:
  14. print "nnnWord:",
  15. print word,
  16. print "in document:",
  17. print doc
  18.  
  19. doc1 = "My sister likes to have sugar, but not my father.".split()
  20. doc2 = "Doctors suggest that driving may cause increased stress.".split()
  21.  
  22. import string
  23. doc1 = "My sister likes to have sugar, but not my father.".translate(None, string.punctuation).split()
  24. doc2 = "Doctors suggest that driving may cause increased stress.".translate(None, string.punctuation).split()
  25.  
  26. documents = map(set, [doc1, doc2])
  27.  
  28. # DICTIONARY
  29. dictionary = ["doctors", "sister", "like"]
  30.  
  31. for word in dictionary:
  32. for doc in documents:
  33. if word in doc:
  34. print "nnnWord:",
  35. print word,
  36. print "in document:",
  37. print doc
  38.  
  39. Word: sister in document: set(['sister', 'my', 'father', 'but', 'sugar', 'to', 'likes', 'have', 'not', 'My'])
  40.  
  41. import string
  42.  
  43. def get_words(text):
  44. return set(text.translate(None, string.punctuation).split())
  45.  
  46. if __name__ == "__main__":
  47. documents = ["My sister likes to have sugar, but not my father.",
  48. "Doctors suggest that driving may cause increased stress."]
  49.  
  50. words_in_documents = map(get_words, documents)
  51.  
  52. for word in ["doctors", "sister", "like"]:
  53. for doc, words in zip(documents, words_in_documents):
  54. if word in words:
  55. print "nnnWord: {} in document: {}".format(word, doc)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement