thgttg.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Mar 20 08:58:56 2014
  4. Script to generate intro-example.odml
  5. @author: zehl
  6. """
  7. import datetime
  8. import os
  9. import odml
  10. import sys
  11. if len(sys.argv) != 2:
  12. print("Please provide an existing directory for the example odml file.")
  13. quit()
  14. output_directory = sys.argv[-1]
  15. if not os.path.isdir(output_directory):
  16. print("Please provide an existing directory for the example odml file.")
  17. quit()
  18. save_to = os.path.join(output_directory, "THGTTG.odml")
  19. odmlrepo = 'http://portal.g-node.org/odml/terminologies/v1.1/terminologies.xml'
  20. # CREATE A DOCUMENT
  21. doc = odml.Document(author="D. N. Adams",
  22. date=datetime.date(1979, 10, 12),
  23. version=42,
  24. repository=odmlrepo)
  25. # CREATE AND APPEND THE MAIN SECTIONs
  26. doc.append(odml.Section(name="TheCrew",
  27. definition="Information on the crew",
  28. type="crew"))
  29. doc.append(odml.Section(name="TheStarship",
  30. type="starship",
  31. definition="Information on the starship"))
  32. # SET NEW PARENT NODE
  33. parent = doc['TheCrew']
  34. # APPEND SUBSECTIONS
  35. parent.append(odml.Section(name="Arthur Philip Dent",
  36. type="crew/person",
  37. definition="Information on Arthur Dent"))
  38. parent.append(odml.Section(name="Zaphod Beeblebrox",
  39. type="crew/person",
  40. definition="Information on Zaphod Beeblebrox"))
  41. parent.append(odml.Section(name="Tricia Marie McMillan",
  42. type="crew/person",
  43. definition="Information on Trillian Astra"))
  44. parent.append(odml.Section(name="Ford Prefect",
  45. type="crew/person",
  46. definition="Information on Ford Prefect"))
  47. # APPEND PROPERTIES WITH VALUES
  48. parent.append(odml.Property(name="NameCrewMembers",
  49. value=["Arthur Philip Dent",
  50. "Zaphod Beeblebrox",
  51. "Tricia Marie McMillan",
  52. "Ford Prefect"],
  53. dtype=odml.DType.person,
  54. definition="List of crew members names"))
  55. parent.append(odml.Property(name="NoCrewMembers",
  56. value=4,
  57. dtype=odml.DType.int,
  58. definition="Number of crew members",
  59. uncertainty=1,
  60. reference="The Hitchhiker's guide to the Galaxy (novel)"))
  61. # SET NEW PARENT NODE
  62. parent = doc['TheCrew']['Arthur Philip Dent']
  63. # APPEND SUBSECTIONS
  64. # APPEND PROPERTIES WITH VALUES
  65. parent.append(odml.Property(name="Species",
  66. value="Human",
  67. dtype=odml.DType.string,
  68. definition="Species to which subject belongs to"))
  69. parent.append(odml.Property(name="Nickname",
  70. value="The sandwich-maker",
  71. dtype=odml.DType.string,
  72. definition="Nickname(s) of the subject"))
  73. parent.append(odml.Property(name="Occupation",
  74. value=None,
  75. dtype=odml.DType.string,
  76. definition="Occupation of the subject"))
  77. parent.append(odml.Property(name="Gender",
  78. value="male",
  79. dtype=odml.DType.string,
  80. definition="Sex of the subject"))
  81. parent.append(odml.Property(name="HomePlanet",
  82. value="Earth",
  83. dtype=odml.DType.string,
  84. definition="Home planet of the subject"))
  85. # SET NEW PARENT NODE
  86. parent = doc['TheCrew']['Zaphod Beeblebrox']
  87. # APPEND SUBSECTIONS
  88. # APPEND PROPERTIES WITH VALUES
  89. parent.append(odml.Property(name="Species",
  90. value="Betelgeusian",
  91. dtype=odml.DType.string,
  92. definition="Species to which subject belongs to"))
  93. parent.append(odml.Property(name="Nickname",
  94. value=None,
  95. dtype=odml.DType.string,
  96. definition="Nickname(s) of the subject"))
  97. parent.append(odml.Property(name="Occupation",
  98. value="Ex-Galactic President",
  99. dtype=odml.DType.string,
  100. definition="Occupation of the subject"))
  101. parent.append(odml.Property(name="Gender",
  102. value="male",
  103. dtype=odml.DType.string,
  104. definition="Sex of the subject"))
  105. parent.append(odml.Property(name="HomePlanet",
  106. value="A planet in the vicinity of Betelgeuse",
  107. dtype=odml.DType.string,
  108. definition="Home planet of the subject"))
  109. # SET NEW PARENT NODE
  110. parent = doc['TheCrew']['Tricia Marie McMillan']
  111. # APPEND SUBSECTIONS
  112. # APPEND PROPERTIES WITH VALUES
  113. parent.append(odml.Property(name="Species",
  114. value="Human",
  115. dtype=odml.DType.string,
  116. definition="Species to which subject belongs to"))
  117. parent.append(odml.Property(name="Nickname",
  118. value="Trillian Astra",
  119. dtype=odml.DType.string,
  120. definition="Nickname(s) of the subject"))
  121. parent.append(odml.Property(name="Occupation",
  122. value=None,
  123. dtype=odml.DType.string,
  124. definition="Occupation of the subject"))
  125. parent.append(odml.Property(name="Gender",
  126. value="female",
  127. dtype=odml.DType.string,
  128. definition="Sex of the subject"))
  129. parent.append(odml.Property(name="HomePlanet",
  130. value="Earth",
  131. dtype=odml.DType.string,
  132. definition="Home planet of the subject"))
  133. # SET NEW PARENT NODE
  134. parent = doc['TheCrew']['Ford Prefect']
  135. # APPEND SUBSECTIONS
  136. # APPEND PROPERTIES WITH VALUES
  137. parent.append(odml.Property(name="Species",
  138. value="Betelgeusian",
  139. dtype=odml.DType.string,
  140. definition="Species to which subject belongs to"))
  141. parent.append(odml.Property(name="Nickname",
  142. value="Ix",
  143. dtype=odml.DType.string,
  144. definition="Nickname(s) of the subject"))
  145. parent.append(odml.Property(name="Occupation",
  146. value="Researcher/Reporter",
  147. dtype=odml.DType.string,
  148. definition="Occupation of the subject"))
  149. parent.append(odml.Property(name="Gender",
  150. value="male",
  151. dtype=odml.DType.string,
  152. definition="Sex of the subject"))
  153. parent.append(odml.Property(name="HomePlanet",
  154. value="A planet in the vicinity of Betelgeuse",
  155. dtype=odml.DType.string,
  156. definition="Home planet of the subject"))
  157. # SET NEW PARENT NODE
  158. parent = doc['TheStarship']
  159. # APPEND SUBSECTIONS
  160. parent.append(odml.Section(name='Cybernetics',
  161. type="starship/cybernetics",
  162. definition="Information on cybernetics present on "
  163. "the ship"))
  164. # APPEND PROPERTIES WITH VALUES
  165. parent.append(odml.Property(name="Name",
  166. value="Heart of Gold",
  167. dtype=odml.DType.string,
  168. definition="Name of person/device"))
  169. parent.append(odml.Property(name="OwnerStatus",
  170. value="stolen",
  171. dtype=odml.DType.string,
  172. definition="Owner status of device"))
  173. parent.append(odml.Property(name="DriveType",
  174. value="Infinite Propability Drive",
  175. dtype=odml.DType.string,
  176. definition="Type of drive"))
  177. parent.append(odml.Property(name="Technology",
  178. value="secret",
  179. dtype=odml.DType.string,
  180. definition="Technology used to built device"))
  181. parent.append(odml.Property(name="Length",
  182. value=150.00,
  183. dtype=odml.DType.float,
  184. unit='m',
  185. definition="Length of device"))
  186. parent.append(odml.Property(name="Shape",
  187. value="various",
  188. dtype=odml.DType.string,
  189. definition="Shape of device"))
  190. parent.append(odml.Property(name="FactoryPlanet",
  191. value="Damogran",
  192. dtype=odml.DType.string,
  193. definition="Planet where device was constructed"))
  194. # SET NEW PARENT NODE
  195. parent = doc['TheStarship']['Cybernetics']
  196. # APPEND SUBSECTIONS
  197. parent.append(odml.Section(name='Marvin',
  198. type="starship/cybernetics",
  199. definition="Information on Marvin"))
  200. parent.append(odml.Section(name='Eddie',
  201. type="starship/cybernetics",
  202. definition="Information on Eddie"))
  203. # APPEND PROPERTIES WITH VALUES
  204. parent.append(odml.Property(name="NoOfCybernetics",
  205. value=2,
  206. dtype=odml.DType.int,
  207. definition="Number of cybernetic robots on the ship"))
  208. parent.append(odml.Property(name="NamesOfCybernetics",
  209. value=["Marvin",
  210. "Eddie"],
  211. dtype=odml.DType.string,
  212. definition="Names of cybernetic robots on the ship"))
  213. # SET NEW PARENT NODE
  214. parent = doc['TheStarship']['Cybernetics']['Marvin']
  215. # APPEND SUBSECTIONS
  216. # APPEND PROPERTIES WIHT VALUES
  217. parent.append(odml.Property(name="Type",
  218. value="Genuine People Personality",
  219. dtype=odml.DType.string,
  220. definition="Type of robot"))
  221. parent.append(odml.Property(name="Manufacturer",
  222. value="Sirius Cybernetics Corporation",
  223. dtype=odml.DType.string,
  224. definition="Manufacturer of robots"))
  225. # SET NEW PARENT NODE
  226. parent = doc['TheStarship']['Cybernetics']['Eddie']
  227. # APPEND SUBSECTIONS
  228. # APPEND PROPERTIES WIHT VALUES
  229. parent.append(odml.Property(name="Type",
  230. value="Genuine People Personality",
  231. dtype=odml.DType.string,
  232. definition="Type of robot"))
  233. parent.append(odml.Property(name="Manufacturer",
  234. value="Sirius Cybernetics Corporation",
  235. dtype=odml.DType.string,
  236. definition="Manufacturer of robots"))
  237. odml.save(doc, save_to)