Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import numpy
  2. from numpy import matrix
  3. from numpy import linalg
  4.  
  5. import itertools
  6. from pprint import pprint
  7. import random
  8.  
  9.  
  10. m = matrix( [
  11. ['Robot','Cyborg','Andoid', 'Bot', 'Droid'],
  12. ['Character','Concept','Mechanical Person', 'Artificial Intelligence', 'Mascot'],
  13. ['Downloadable','Stock','3d', 'Digital', 'Robotics'],
  14. ['Clipart','Illustration','Render', 'Image', 'Graphic'],
  15. ])
  16.  
  17. used = []
  18.  
  19. i = 0
  20.  
  21. def make_sentence(m, used):
  22. sentence = []
  23. i = 0
  24. while i <= 3:
  25. word = m[i,random.randrange(0,4)]
  26. sentence.append(word)
  27. i = i+1
  28. return ' '.join(sentence)
  29.  
  30. def is_used(sentence, used):
  31. if sentence not in used:
  32. return False
  33. else:
  34. return True
  35.  
  36. sentences = []
  37. i = 0
  38. while i <= 1000:
  39. sentence = make_sentence(m, used)
  40. if(is_used(sentence, used)):
  41. continue
  42. else:
  43. sentences.append(sentence)
  44. print str(i) + ' ' +sentence
  45. used.append(sentence)
  46. i = i+1
  47.  
  48. import itertools
  49. mx = [
  50. ['Robot','Cyborg','Andoid', 'Bot', 'Droid'],
  51. ['Character','Concept','Mechanical Person', 'Artificial Intelligence', 'Mascot'],
  52. ['Downloadable','Stock','3d', 'Digital', 'Robotics'],
  53. ['Clipart','Illustration','Render', 'Image', 'Graphic'],
  54. ]
  55. for combination in itertools.product(*mx):
  56. print combination
  57.  
  58. def make_sentences(m, choices = []):
  59. output = []
  60. if len(choices) == 4:
  61. sentence = ""
  62. i = 0
  63. #Go through the four rows of the matrix
  64. #and choose words for the sentence
  65. for j in choices:
  66. sentence += " " + m[i][j]
  67. i += 1
  68. return [sentence] #must be returned as a list
  69. for i in range(0,4):
  70. output += make_sentences(m, choices+[i])
  71. return output #this could be changed to a yield statement
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement