1- from rdflib import Graph , BNode , Literal , Namespace
1+ from rdflib import Graph , BNode , Literal
22from rdflib .namespace import XSD
33
4- odml = Namespace ( "http://g-node/odml#" )
4+ from odml . tools . rdf_converter import ODML_NS
55
66g = Graph ()
77
88doc = BNode ("d1" )
99s1 = BNode ("s1" )
1010p12 = BNode ("p1" )
1111
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 ))
1717
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' )))
2222
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' )))
2728
2829res = g .serialize (format = 'application/rdf+xml' ).decode ("utf-8" )
2930print (res )
3031
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