1
- from rdflib import Graph , BNode , Literal , Namespace
1
+ from rdflib import Graph , BNode , Literal
2
2
from rdflib .namespace import XSD
3
3
4
- odml = Namespace ( "http://g-node/odml#" )
4
+ from odml . tools . rdf_converter import ODML_NS
5
5
6
6
g = Graph ()
7
7
8
8
doc = BNode ("d1" )
9
9
s1 = BNode ("s1" )
10
10
p12 = BNode ("p1" )
11
11
12
- g .add ((doc , odml .version , Literal (1.1 )))
13
- g .add ((doc , odml .docversion , Literal (42 )))
14
- g .add ((doc , odml .author , Literal ('D. N. Adams' )))
15
- g .add ((doc , odml .date , Literal ('1979-10-12' , datatype = XSD .date )))
16
- g .add ((doc , odml .hasSection , s1 ))
12
+ g .add ((doc , ODML_NS .version , Literal (1.1 )))
13
+ g .add ((doc , ODML_NS .docversion , Literal (42 )))
14
+ g .add ((doc , ODML_NS .author , Literal ('D. N. Adams' )))
15
+ g .add ((doc , ODML_NS .date , Literal ('1979-10-12' , datatype = XSD .date )))
16
+ g .add ((doc , ODML_NS .hasSection , s1 ))
17
17
18
- g .add ((s1 , odml .property , p12 ))
19
- g .add ((s1 , odml .type , Literal ('crew' )))
20
- g .add ((s1 , odml .description , Literal ('Information on the crew' )))
21
- g .add ((s1 , odml .name , Literal ('TheCrew' )))
18
+ g .add ((s1 , ODML_NS .property , p12 ))
19
+ g .add ((s1 , ODML_NS .type , Literal ('crew' )))
20
+ g .add ((s1 , ODML_NS .description , Literal ('Information on the crew' )))
21
+ g .add ((s1 , ODML_NS .name , Literal ('TheCrew' )))
22
22
23
- g .add ((p12 , odml .hasValue , Literal ('[Arthur Philip Dent,Zaphod Beeblebrox,Tricia Marie McMillan,Ford Prefect]' )))
24
- g .add ((p12 , odml .description , Literal ('List of crew members names' )))
25
- g .add ((p12 , odml .dtype , Literal ('person' )))
26
- g .add ((p12 , odml .name , Literal ('NameCrewMembers' )))
23
+ content = '[Arthur Philip Dent,Zaphod Beeblebrox,Tricia Marie McMillan,Ford Prefect]'
24
+ g .add ((p12 , ODML_NS .hasValue , Literal (content )))
25
+ g .add ((p12 , ODML_NS .description , Literal ('List of crew members names' )))
26
+ g .add ((p12 , ODML_NS .dtype , Literal ('person' )))
27
+ g .add ((p12 , ODML_NS .name , Literal ('NameCrewMembers' )))
27
28
28
29
res = g .serialize (format = 'application/rdf+xml' ).decode ("utf-8" )
29
30
print (res )
30
31
31
- f = open ("generated_ex1.xml" , "w" )
32
- f .write (res )
33
- f .close ()
32
+ with open ("generated_odml_rdf.xml" , "w" ) as f :
33
+ f .write (res )
0 commit comments