123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- # -*- coding: utf-8 -*-
- """
- Created on Thu Mar 20 08:58:56 2014
- Script to generate intro-example.odml
- @author: zehl
- """
- import odml
- import datetime
- odmlrepo = 'http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml'
- # CREATE A DOCUMENT
- doc = odml.Document(author="D. N. Adams",
- date=datetime.date(1979, 10, 12),
- version=42)
- # repository=odmlrepo)
- # CREATE AND APPEND THE MAIN SECTIONs
- doc.append(odml.Section(name="TheCrew",
- definition="Information on the crew",
- type="crew"))
- doc.append(odml.Section(name="TheStarship",
- definition="Information on the crew",
- type="crew"))
- # SET NEW PARENT NODE
- parent = doc['TheCrew']
- # APPEND SUBSECTIONS
- parent.append(odml.Section(name="Arthur Philip Dent",
- type="crew/person",
- definition="Information on Arthur Dent"))
- parent.append(odml.Section(name="Zaphod Beeblebrox",
- type="crew/person",
- definition="Information on Zaphod Beeblebrox"))
- parent.append(odml.Section(name="Tricia Marie McMillan",
- type="crew/person",
- definition="Information on Trillian Astra"))
- parent.append(odml.Section(name="Ford Prefect",
- type="crew/person",
- definition="Information on Ford Prefect"))
- # APPEND PROPERTIES WITH VALUES
- parent.append(odml.Property(name="NameCrewMembers",
- value=[odml.Value(data="Arthur Philip Dent",
- dtype=odml.DType.person),
- odml.Value(data="Zaphod Beeblebrox",
- dtype=odml.DType.person),
- odml.Value(data="Tricia Marie McMillan",
- dtype=odml.DType.person),
- odml.Value(data="Ford Prefect",
- dtype=odml.DType.person)],
- definition="List of crew members names"))
- parent.append(odml.Property(name="NoCrewMembers",
- value=odml.Value(data=4,
- dtype=odml.DType.int),
- definition="Number of crew members"))
- # SET NEW PARENT NODE
- parent = doc['TheCrew']['Arthur Philip Dent']
- # APPEND SUBSECTIONS
- # APPEND PROPERTIES WITH VALUES
- parent.append(odml.Property(name="Species",
- value=odml.Value(data="Human",
- dtype=odml.DType.string),
- definition="Species to which subject belongs to"))
- parent.append(odml.Property(name="Nickname",
- value=odml.Value(data="The sandwich-maker",
- dtype=odml.DType.string),
- definition="Nickname(s) of the subject"))
- parent.append(odml.Property(name="Occupation",
- value=odml.Value(data="-",
- dtype=odml.DType.string),
- definition="Occupation of the subject"))
- parent.append(odml.Property(name="Gender",
- value=odml.Value(data="male",
- dtype=odml.DType.string),
- definition="Sex of the subject"))
- parent.append(odml.Property(name="HomePlanet",
- value=odml.Value(data="Earth",
- dtype=odml.DType.string),
- definition="Home planet of the subject"))
- # SET NEW PARENT NODE
- parent = doc['TheCrew']['Zaphod Beeblebrox']
- # APPEND SUBSECTIONS
- # APPEND PROPERTIES WITH VALUES
- parent.append(odml.Property(name="Species",
- value=odml.Value(data="Betelgeusian",
- dtype=odml.DType.string),
- definition="Species to which subject belongs to"))
- parent.append(odml.Property(name="Nickname",
- value=odml.Value(data="-",
- dtype=odml.DType.string),
- definition="Nickname(s) of the subject"))
- parent.append(odml.Property(name="Occupation",
- value=odml.Value(data="Ex-Galactic President",
- dtype=odml.DType.string),
- definition="Occupation of the subject"))
- parent.append(odml.Property(name="Gender",
- value=odml.Value(data="male",
- dtype=odml.DType.string),
- definition="Sex of the subject"))
- parent.append(odml.Property(name="HomePlanet",
- value=odml.Value(data="A planet in the vicinity "
- "of Betelgeuse",
- dtype=odml.DType.string),
- definition="Home planet of the subject"))
- # SET NEW PARENT NODE
- parent = doc['TheCrew']['Tricia Marie McMillan']
- # APPEND SUBSECTIONS
- # APPEND PROPERTIES WITH VALUES
- parent.append(odml.Property(name="Species",
- value=odml.Value(data="Betelgeusian",
- dtype=odml.DType.string),
- definition="Species to which subject belongs to"))
- parent.append(odml.Property(name="Nickname",
- value=odml.Value(data="Trillian Astra",
- dtype=odml.DType.string),
- definition="Nickname(s) of the subject"))
- parent.append(odml.Property(name="Occupation",
- value=odml.Value(data="-",
- dtype=odml.DType.string),
- definition="Occupation of the subject"))
- parent.append(odml.Property(name="Gender",
- value=odml.Value(data="female",
- dtype=odml.DType.string),
- definition="Sex of the subject"))
- parent.append(odml.Property(name="HomePlanet",
- value=odml.Value(data="Earth",
- dtype=odml.DType.string),
- definition="Home planet of the subject"))
- # SET NEW PARENT NODE
- parent = doc['TheCrew']['Ford Prefect']
- # APPEND SUBSECTIONS
- # APPEND PROPERTIES WITH VALUES
- parent.append(odml.Property(name="Species",
- value=odml.Value(data="Betelgeusian",
- dtype=odml.DType.string),
- definition="Species to which subject belongs to"))
- parent.append(odml.Property(name="Nickname",
- value=odml.Value(data="Ix",
- dtype=odml.DType.string),
- definition="Nickname(s) of the subject"))
- parent.append(odml.Property(name="Occupation",
- value=odml.Value(data="Researcher for the "
- "Hitchhiker's Guide to the "
- "Galaxy",
- dtype=odml.DType.string),
- definition="Occupation of the subject"))
- parent.append(odml.Property(name="Gender",
- value=odml.Value(data="male",
- dtype=odml.DType.string),
- definition="Sex of the subject"))
- parent.append(odml.Property(name="HomePlanet",
- value=odml.Value(data="A planet in the vicinity "
- "of Betelgeuse",
- dtype=odml.DType.string),
- definition="Home planet of the subject"))
- # SET NEW PARENT NODE
- parent = doc['TheStarship']
- # APPEND SUBSECTIONS
- parent.append(odml.Section(name='Cybernetics',
- type="starship/cybernetics",
- definition="Information on cybernetics present on "
- "the ship"))
- # APPEND PROPERTIES WITH VALUES
- parent.append(odml.Property(name="Name",
- value=odml.Value(data="Heart of Gold",
- dtype=odml.DType.string),
- definition="Name of person/device"))
- parent.append(odml.Property(name="OwnerStatus",
- value=odml.Value(data="stolen",
- dtype=odml.DType.string),
- definition="Owner status of device"))
- parent.append(odml.Property(name="DriveType",
- value=odml.Value(data="Infinite Propability Drive",
- dtype=odml.DType.string),
- definition="Type of drive"))
- parent.append(odml.Property(name="Technology",
- value=odml.Value(data="secret",
- dtype=odml.DType.string),
- definition="Technology used to built device"))
- parent.append(odml.Property(name="Length",
- value=odml.Value(data=150.00,
- dtype=odml.DType.float,
- unit='m'),
- definition="Length of device"))
- parent.append(odml.Property(name="Shape",
- value=odml.Value(data="various",
- dtype=odml.DType.string),
- definition="Shape of device"))
- parent.append(odml.Property(name="FactoryPlanet",
- value=odml.Value(data="Damogran",
- dtype=odml.DType.string),
- definition="Planet where device was constructed"))
- # SET NEW PARENT NODE
- parent = doc['TheStarship']['Cybernetics']
- # APPEND SUBSECTIONS
- parent.append(odml.Section(name='Marvin',
- type="starship/cybernetics",
- definition="Information on Marvin"))
- parent.append(odml.Section(name='Eddie',
- type="starship/cybernetics",
- definition="Information on Eddie"))
- # APPEND PROPERTIES WITH VALUES
- parent.append(odml.Property(name="RobotType",
- value=odml.Value(data="Genuine People "
- "Personalities",
- dtype=odml.DType.string),
- definition="Type of robots"))
- parent.append(odml.Property(name="Manufacturer",
- value=odml.Value(data="Sirius Cybernetics "
- "Corporation",
- dtype=odml.DType.string),
- definition="Manufacturer of robots"))
- parent.append(odml.Property(name="NoOfCybernetics",
- value=odml.Value(data=2,
- dtype=odml.DType.int),
- definition="Number of cybernetic robots on the "
- "ship"))
- homedir = "/home/zehl/Projects/toolbox/"
- save_to = homedir + "/python-odml/doc/example_odMLs/THGTTG.odml"
- odml.tools.xmlparser.XMLWriter(doc).write_file(save_to)
|