diff --git a/doc/example_odMLs/THGTTG.odml b/doc/example_odMLs/THGTTG.odml
index bbed197b..baf2ba0d 100644
--- a/doc/example_odMLs/THGTTG.odml
+++ b/doc/example_odMLs/THGTTG.odml
@@ -3,244 +3,309 @@
42
- D. N. Adams
- 1979-10-12
+ TheCrew
+
+ person
+ NameCrewMembers
+ [Arthur Philip Dent,Zaphod Beeblebrox,Tricia Marie McMillan,Ford Prefect]
+ 77cdad5c-5d74-4e9f-9d74-c1ce8e79e951
+ List of crew members names
+
+
+ int
+ 1
+ NoCrewMembers
+ The Hitchhiker's guide to the Galaxy (novel)
+ [4]
+ 05e14adf-1ca2-4b2d-984d-6c84814a84de
+ Number of crew members
+
+ Arthur Philip Dent
- [Human]
- Species to which subject belongs to
string
Species
+ [Human]
+ f64e9d6a-e38d-499e-a03f-fe59b91ad6ba
+ Species to which subject belongs to
- [The sandwich-maker]
- Nickname(s) of the subject
string
Nickname
+ [The sandwich-maker]
+ c9dd7ae6-66a1-49f0-9853-80f2cdf6b574
+ Nickname(s) of the subject
- [-]
- Occupation of the subject
string
Occupation
+ []
+ 76941971-132a-4b3a-94db-e3cf356ea429
+ Occupation of the subject
- [male]
- Sex of the subject
string
Gender
+ [male]
+ 5f1a5e56-d893-47bd-989a-9d3a596bc29e
+ Sex of the subject
- [Earth]
- Home planet of the subject
string
HomePlanet
+ [Earth]
+ 6470acca-5457-4a43-a61c-6744372dff3b
+ Home planet of the subject
Information on Arthur Dent
+ e547c987-4beb-4250-bcb3-1991c535e7e8
crew/person
- Arthur Philip Dent
+ Zaphod Beeblebrox
- [Betelgeusian]
- Species to which subject belongs to
string
Species
+ [Betelgeusian]
+ 861a8469-708e-4950-be71-12c640d7e7d6
+ Species to which subject belongs to
- [-]
- Nickname(s) of the subject
string
Nickname
+ []
+ ba06784b-d323-45c8-bb52-918b727f2ef1
+ Nickname(s) of the subject
- [Ex-Galactic President]
- Occupation of the subject
string
Occupation
+ [Ex-Galactic President]
+ 09b96b49-7bf3-4449-9e43-62d87bb23f16
+ Occupation of the subject
- [male]
- Sex of the subject
string
Gender
+ [male]
+ 41f4ab65-afda-43c9-aa08-a384c9fba585
+ Sex of the subject
- [A planet in the vicinity of Betelgeuse]
- Home planet of the subject
string
HomePlanet
+ [A planet in the vicinity of Betelgeuse]
+ c81063a1-4727-4d51-bdfd-574923f387ab
+ Home planet of the subject
Information on Zaphod Beeblebrox
+ 5d22732f-ebfd-494d-9fb0-0e938fc83291
crew/person
- Zaphod Beeblebrox
+ Tricia Marie McMillan
- [Betelgeusian]
- Species to which subject belongs to
string
Species
+ [Human]
+ 087d4862-50a5-4764-a2b5-01dded29ccab
+ Species to which subject belongs to
- [Trillian Astra]
- Nickname(s) of the subject
string
Nickname
+ [Trillian Astra]
+ 15fef4d3-a9ed-4fc2-95db-7f7c90d85a8c
+ Nickname(s) of the subject
- [-]
- Occupation of the subject
string
Occupation
+ []
+ 4ab85d8a-f884-4ef7-bf33-0d42044d95bb
+ Occupation of the subject
- [female]
- Sex of the subject
string
Gender
+ [female]
+ dd553e39-b3b1-4ef2-9b21-6145a3222d15
+ Sex of the subject
- [Earth]
- Home planet of the subject
string
HomePlanet
+ [Earth]
+ fe2abddf-f2e7-43f3-b3db-0932f94e17e9
+ Home planet of the subject
Information on Trillian Astra
+ b85c4c2d-4722-48fa-a118-5c2f553d7282
crew/person
- Tricia Marie McMillan
+ Ford Prefect
- [Betelgeusian]
- Species to which subject belongs to
string
Species
+ [Betelgeusian]
+ 1493fb9b-6fb2-479e-923c-61242567ffd7
+ Species to which subject belongs to
- [Ix]
- Nickname(s) of the subject
string
Nickname
+ [Ix]
+ 4b6eb605-dbfb-40e0-83c4-acca43e4fdbb
+ Nickname(s) of the subject
- [Researcher for the Hitchhiker's Guide to the Galaxy]
- Occupation of the subject
string
Occupation
+ [Researcher/Reporter]
+ 3a69dba5-c780-447a-b9d9-e8da3cbbd4f4
+ Occupation of the subject
- [male]
- Sex of the subject
string
Gender
+ [male]
+ 01b8b16c-c80b-4432-93a9-0fab8de74e22
+ Sex of the subject
- [A planet in the vicinity of Betelgeuse]
- Home planet of the subject
string
HomePlanet
+ [A planet in the vicinity of Betelgeuse]
+ f47c0d5e-e2b8-425b-83f3-57bcbe44164d
+ Home planet of the subject
Information on Ford Prefect
+ 97cbf33c-5aa8-41af-b158-13247e7481dd
crew/person
- Ford Prefect
-
- [Arthur Philip Dent,Zaphod Beeblebrox,Tricia Marie McMillan,Ford Prefect]
- List of crew members names
- person
- NameCrewMembers
-
-
- [4]
- Number of crew members
- int
- NoCrewMembers
-
Information on the crew
+ 6df940b5-b502-4749-8ad9-33d7432064f3
crew
- TheCrew
-
-
- Information on Marvin
- starship/cybernetics
- Marvin
-
-
- Information on Eddie
- starship/cybernetics
- Eddie
-
-
- [Genuine People Personalities]
- Type of robots
- string
- RobotType
-
-
- [Sirius Cybernetics Corporation]
- Manufacturer of robots
- string
- Manufacturer
-
-
- [2]
- Number of cybernetic robots on the ship
- int
- NoOfCybernetics
-
- Information on cybernetics present on the ship
- starship/cybernetics
- Cybernetics
-
+ TheStarship
- [Heart of Gold]
- Name of person/device
string
Name
+ [Heart of Gold]
+ b0f80f23-e976-4a06-b146-b81e5f565d6b
+ Name of person/device
- [stolen]
- Owner status of device
string
OwnerStatus
+ [stolen]
+ 43b26234-6023-4e7f-8bc4-401b0fd0504a
+ Owner status of device
- [Infinite Propability Drive]
- Type of drive
string
DriveType
+ [Infinite Propability Drive]
+ 828d51ea-f5c8-4525-b2ff-757555449190
+ Type of drive
- [secret]
- Technology used to built device
string
Technology
+ [secret]
+ 0117aaa2-fa5d-4623-a63c-4342733205ec
+ Technology used to built device
+ float
+ Length
m
[150.0]
+ 7e2a3940-833c-407b-9047-918d317af204
Length of device
- float
- Length
- [various]
- Shape of device
string
Shape
+ [various]
+ f34bfcbb-1a57-4905-bc8b-ef953c0e736e
+ Shape of device
- [Damogran]
- Planet where device was constructed
string
FactoryPlanet
+ [Damogran]
+ c39386b4-2023-4dd3-bf03-57bd3c65d5c0
+ Planet where device was constructed
- Information on the crew
- crew
- TheStarship
+
+ Cybernetics
+
+ int
+ NoOfCybernetics
+ [2]
+ 534155a2-8d6a-471d-a7cb-8a950ff5e157
+ Number of cybernetic robots on the ship
+
+
+ string
+ NamesOfCybernetics
+ [Marvin,Eddie]
+ 7c00d7e3-2822-42b5-b5b3-b5c7dc51f67e
+ Names of cybernetic robots on the ship
+
+
+ Marvin
+
+ string
+ Type
+ [Genuine People Personality]
+ 7f74bd80-4d08-43b3-aedc-7e3668b48d34
+ Type of robot
+
+
+ string
+ Manufacturer
+ [Sirius Cybernetics Corporation]
+ 45cb21b1-b0e6-4eb0-a153-2059dd3d3444
+ Manufacturer of robots
+
+ Information on Marvin
+ 2d66ac3e-5d25-45cc-89c1-1cc5890daa7b
+ starship/cybernetics
+
+
+ Eddie
+
+ string
+ Type
+ [Genuine People Personality]
+ 2899d6df-7f15-48f5-aa11-aa368ba75eeb
+ Type of robot
+
+
+ string
+ Manufacturer
+ [Sirius Cybernetics Corporation]
+ dda738bb-47e4-462b-821c-ea900633dbee
+ Manufacturer of robots
+
+ Information on Eddie
+ 953852d6-bbca-44d5-bad1-fb9bbca08655
+ starship/cybernetics
+
+ Information on cybernetics present on the ship
+ 4f6f4994-cc0f-4d10-a643-4cdda5aa8248
+ starship/cybernetics
+
+ Information on the starship
+ 38a36e78-ceca-4045-87a5-53a4dac29f10
+ starship
+ D. N. Adams
+ 1979-10-12
+ cf6d24de-c780-4ad2-91ce-45dd5157d6b8
diff --git a/doc/example_odMLs/ex_1.odml b/doc/example_odMLs/ex_1.odml
new file mode 100644
index 00000000..e95622b9
--- /dev/null
+++ b/doc/example_odMLs/ex_1.odml
@@ -0,0 +1,52 @@
+
+
+
+
+ D. N. Adams
+ http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml
+
+
+ person
+ [Arthur Philip Dent,Zaphod Beeblebrox,Tricia Marie McMillan,Ford Prefect]
+ 7b0572c1-fcfc-4010-aebf-730397ac29af
+ NameCrewMembers
+ List of crew members names
+
+
+ int
+ 1
+ [4]
+ The Hitchhiker's guide to the Galaxy (novel)
+ 298938a6-0996-4a92-982b-837a08a1a220
+ NoCrewMembers
+ Number of crew members
+
+ crew
+ Information on the crew
+ 0f96a050-2d9b-498f-a532-fbfcc6aae55e
+ TheCrew
+
+
+ string
+ [Human]
+ 635035cc-1c05-4e44-a4b7-0fb3d6295abf
+ Species
+ Species to which subject belongs to
+
+
+ string
+ []
+ 0cec018b-20e3-4b13-bb95-b41de12db97f
+ Nickname
+ Nickname(s) of the subject
+
+ crew/person
+ Information on Arthur Dent
+ 1d6469b5-5322-408b-916e-3224b7a22008
+ Arthur Philip Dent
+
+
+ 1979-10-12
+ 79b613eb-a256-46bf-84f6-207df465b8f7
+ 42
+
diff --git a/doc/example_odMLs/ex_1.rdf b/doc/example_odMLs/ex_1.rdf
new file mode 100644
index 00000000..cb7a1e2a
--- /dev/null
+++ b/doc/example_odMLs/ex_1.rdf
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+
+
+
+ 1979-10-12
+
+
+
+ D. N. Adams
+ 1979-10-12
+
+ 42
+
+
+
+
+ 42
+
+
+ D. N. Adams
+
+ 1979-10-12
+ 1979-10-12
+
+
+
+
+
+ crew
+ s11
+ Information on the crew
+
+
+
+
+
+
+
+ Human
+
+
+
+ Species
+ string
+ Species to which subject belongs to
+
+
+ crew/person
+
+
+
+ Nickname(s) of the subject
+ string
+ Nickname
+
+
+ Arthur Philip Dent
+ Information on Arthur Dent
+
+
+ Number of crew members
+ int
+ 1
+ NoCrewMembers
+
+
+
+ 4
+
+
+
+
+ Information on the crew
+
+ crew
+ s21
+
+
+
+ s1
+
+ crew
+
+
+
+ crew
+ Information on the crew
+ s12
+
+
+
+ Information on the crew
+
+
+
+ crew
+
+
+ List of crew members names
+ person
+
+
+
+ Zaphod Beeblebrox
+ Ford Prefect
+ Arthur Philip Dent
+ Tricia Marie McMillan
+
+
+ NameCrewMembers
+
+
+
+ Information on the crew
+ TheCrew
+
+
+
+ crew
+
+ s21
+ s121
+ Information on the crew
+
+
+ s2
+
+ Information on the crew
+
+ crew
+
+
diff --git a/doc/example_odMLs/ex_2.odml b/doc/example_odMLs/ex_2.odml
new file mode 100644
index 00000000..136e9b77
--- /dev/null
+++ b/doc/example_odMLs/ex_2.odml
@@ -0,0 +1,47 @@
+
+
+
+
+ http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml
+
+ Information on the crew
+
+ Information on the crew
+ da908cda-19e1-4df8-b873-d1f6cd1b164d
+ crew
+ s11
+
+
+ Information on the crew
+
+ Information on the crew
+ 18bb5a7e-2097-43f2-a782-e6f612107e93
+ crew
+ s21
+ s121
+
+ 8d68e6fe-8dda-4dfe-a1d8-edaa0f410255
+ crew
+ s12
+
+ d1e70848-5318-4466-82d0-1c3e99a8ba85
+ crew
+ s1
+
+
+ Information on the crew
+
+ Information on the crew
+ 4b2d0e9d-6352-4676-97d7-fc0a795e83a9
+ crew
+ s21
+
+ bc6cc466-5769-4da1-b90e-8e5595903a4a
+ crew
+ s2
+
+ 1979-10-12
+ 9b862019-643a-403f-b5a9-3b46db012961
+ 42
+ D. N. Adams
+
diff --git a/doc/example_odMLs/odml_ex_1_generator.py b/doc/example_odMLs/odml_ex_1_generator.py
new file mode 100644
index 00000000..028de1c8
--- /dev/null
+++ b/doc/example_odMLs/odml_ex_1_generator.py
@@ -0,0 +1,63 @@
+import datetime
+import os
+
+import odml
+
+odml_pythonpath = "./g-node/python-odml"
+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"))
+
+# 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"))
+
+
+# APPEND PROPERTIES WITH VALUES
+parent.append(odml.Property(name="NameCrewMembers",
+ value=["Arthur Philip Dent",
+ "Zaphod Beeblebrox",
+ "Tricia Marie McMillan",
+ "Ford Prefect"],
+ dtype=odml.DType.person,
+ definition="List of crew members names"))
+
+parent.append(odml.Property(name="NoCrewMembers",
+ value=4,
+ dtype=odml.DType.int,
+ definition="Number of crew members",
+ uncertainty=1,
+ reference="The Hitchhiker's guide to the Galaxy (novel)"))
+
+# SET NEW PARENT NODE
+parent = doc['TheCrew']['Arthur Philip Dent']
+
+# APPEND SUBSECTIONS
+
+# APPEND PROPERTIES WITH VALUES
+parent.append(odml.Property(name="Species",
+ value="Human",
+ dtype=odml.DType.string,
+ definition="Species to which subject belongs to"))
+
+parent.append(odml.Property(name="Nickname",
+ value=None,
+ dtype=odml.DType.string,
+ definition="Nickname(s) of the subject"))
+
+save_to = os.path.join(odml_pythonpath, "doc", "example_odMLs", "ex_1.odml")
+
+odml.save(doc, save_to)
diff --git a/odml/tools/__init__.py b/odml/tools/__init__.py
index 4e7194dd..826c03b0 100644
--- a/odml/tools/__init__.py
+++ b/odml/tools/__init__.py
@@ -1,4 +1,5 @@
-
from odml.tools import dumper
-from odml.tools import xmlparser
from odml.tools import jsonparser
+from odml.tools import rdf_converter
+from odml.tools import xmlparser
+
diff --git a/odml/tools/rdf_converter.py b/odml/tools/rdf_converter.py
new file mode 100644
index 00000000..af8ec26f
--- /dev/null
+++ b/odml/tools/rdf_converter.py
@@ -0,0 +1,134 @@
+import sys
+import uuid
+
+from rdflib import Graph, Literal, URIRef
+from rdflib.namespace import XSD, RDF
+
+import odml
+import odml.format
+
+try:
+ unicode = unicode
+except NameError:
+ unicode = str
+
+odmlns = odml.format.Format.namespace()
+
+
+class RDFWriter(object):
+ """
+ Creates the RDF graph storing information about the odML document
+ """
+
+ def __init__(self, odml_documents, hub_id=None):
+ self.docs = odml_documents
+ self.hub_id = hub_id
+ self.hub_root = None
+ self.g = Graph()
+ self.g.bind("odml", odmlns)
+
+ def create_hub_root(self):
+ if self.hub_root is None:
+ if self.hub_id is None:
+ self.hub_root = URIRef(odmlns + str(uuid.uuid4()))
+ else:
+ self.hub_root = URIRef(odmlns + self.hub_id)
+
+ def convert_to_rdf(self, docs):
+ self.create_hub_root()
+ if docs:
+ self.g.add((self.hub_root, odmlns.Hub, URIRef(odmlns.Hub)))
+ for doc in docs:
+ self.save_element(doc)
+ return self.g
+
+ def save_element(self, e, node=None):
+ """
+ Save the current element to the RDF graph
+ :param e: current element
+ :param node: A node to pass the earlier created node to inner elements
+ :return: the RDF graph
+ """
+ fmt = e._format
+
+ if not node:
+ curr_node = URIRef(odmlns + str(e.id))
+ else:
+ curr_node = node
+
+ self.g.add((curr_node, RDF.type, URIRef(fmt.rdf_type())))
+
+ # adding doc to the hub
+ if isinstance(fmt, odml.format.Document.__class__):
+ self.g.add((self.hub_root, odmlns.hasDocument, curr_node))
+
+ for k in fmt._rdf_map:
+ if k == 'id':
+ continue
+ elif (isinstance(fmt, odml.format.Document.__class__) or
+ isinstance(fmt, odml.format.Section.__class__)) and k == "repository":
+ terminology_url = getattr(e, k)
+ if terminology_url is None or not terminology_url:
+ continue
+ terminology_node = self._get_terminology_by_value(terminology_url)
+ if terminology_node:
+ self.g.add((curr_node, fmt.rdf_map(k), terminology_node))
+ else:
+ # adding terminology to the hub and to link with the doc
+ node = URIRef(odmlns + str(uuid.uuid4()))
+ self.g.add((node, odmlns.Terminology, URIRef(terminology_url)))
+ self.g.add((self.hub_root, odmlns.hasTerminology, node))
+ self.g.add((curr_node, fmt.rdf_map(k), node))
+ # generating nodes for entities: sections, properties and bags of values
+ elif (isinstance(fmt, odml.format.Document.__class__) or
+ isinstance(fmt, odml.format.Section.__class__)) and \
+ k == 'sections' and len(getattr(e, k)) > 0:
+ sections = getattr(e, k)
+ for s in sections:
+ node = URIRef(odmlns + str(s.id))
+ self.g.add((curr_node, fmt.rdf_map(k), node))
+ self.save_element(s, node)
+ elif isinstance(fmt, odml.format.Section.__class__) and \
+ k == 'properties' and len(getattr(e, k)) > 0:
+ properties = getattr(e, k)
+ for p in properties:
+ node = URIRef(odmlns + str(p.id))
+ self.g.add((curr_node, fmt.rdf_map(k), node))
+ self.save_element(p, node)
+ elif isinstance(fmt, odml.format.Property.__class__) and \
+ k == 'value' and len(getattr(e, k)) > 0:
+ values = getattr(e, k)
+ bag = URIRef(str(uuid.uuid4()))
+ self.g.add((bag, RDF.type, RDF.Bag))
+ self.g.add((curr_node, fmt.rdf_map(k), bag))
+ for v in values:
+ self.g.add((bag, RDF.li, Literal(v)))
+ # adding entities' properties
+ else:
+ val = getattr(e, k)
+ if val is None or not val:
+ continue
+ elif k == 'date':
+ self.g.add((curr_node, fmt.rdf_map(k), Literal(val, datatype=XSD.date)))
+ else:
+ self.g.add((curr_node, fmt.rdf_map(k), Literal(val)))
+ return self.g
+
+ def _get_terminology_by_value(self, url):
+ return self.g.value(predicate=odmlns.Terminology, object=URIRef(url))
+
+ def __str__(self):
+ return self.convert_to_rdf(self.docs).serialize(format='turtle').decode("utf-8")
+
+ def __unicode__(self):
+ return self.convert_to_rdf(self.docs).serialize(format='turtle').decode("utf-8")
+
+ def write_file(self, filename):
+ if sys.version_info < (3,):
+ data = unicode(self).encode('utf-8')
+ else:
+ data = str(self)
+
+ f = open(filename, "w")
+ f.write(data)
+ f.close()
\ No newline at end of file