generate_owl.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/usr/bin/env python3
  2. # author: Harshvardhan Pandit
  3. # Creates the OWL ontology for GDPRtEXT
  4. # NOTE: EDIT LATER WITH PROTEGE
  5. ##############################################################################
  6. from rdflib import Graph, RDF, RDFS, XSD, OWL, Literal, URIRef, BNode
  7. from rdflib import Namespace
  8. graph = Graph()
  9. DC = Namespace('http://purl.org/dc/elements/1.1/')
  10. graph.namespace_manager.bind('dc', DC)
  11. graph.namespace_manager.bind('owl', OWL)
  12. GDPRtEXT_URI = URIRef('http://purl.org/adaptcentre/ontologies/GDPRtEXT#')
  13. GDPRtEXT = Namespace('http://purl.org/adaptcentre/ontologies/GDPRtEXT#')
  14. graph.namespace_manager.bind('GDPRtext', GDPRtEXT)
  15. graph.add((GDPRtEXT_URI, RDF.type, OWL.Ontology))
  16. graph.add((GDPRtEXT_URI, RDFS.label, Literal(
  17. 'GDPR text EXTensions', datatype=XSD.string)))
  18. graph.add((GDPRtEXT_URI, DC.title, Literal(
  19. 'GDPRtEXT', datatype=XSD.string)))
  20. graph.add((GDPRtEXT_URI, OWL.versionInfo, Literal(
  21. '0.1', datatype=XSD.string)))
  22. graph.add((GDPRtEXT_URI, DC.creator, Literal(
  23. 'Harshvardhan J. Pandit', datatype=XSD.string)))
  24. graph.add((GDPRtEXT_URI, DC.description, Literal((
  25. 'This ontology extends the canonical (official) GDPR text '
  26. 'with additional annotations'), datatype=XSD.string)))
  27. graph.add((GDPRtEXT_URI, RDFS.comment, Literal(
  28. 'This is an ontology to represent GDPR text as a set of RDF resources',
  29. datatype=XSD.string)))
  30. # This is the ELI namespace, used as the legal vocabulary for EU text
  31. ELI = Namespace("http://data.europa.eu/eli/ontology#")
  32. graph.namespace_manager.bind('eli', ELI)
  33. # bind ELI items to names that are easier to access (argumentative)
  34. LRS = ELI.LegalResourceSubdivision
  35. TITLE = ELI.title
  36. NOS = ELI.number
  37. TITLE_ALT = ELI.title_alternative
  38. PART_OF = ELI.is_part_of
  39. graph.add((PART_OF, RDF.type, OWL.TransitiveProperty))
  40. HAS_PART = ELI.has_part
  41. graph.add((HAS_PART, RDF.type, OWL.TransitiveProperty))
  42. DESC = ELI.description
  43. # declare chapters, etc. as subclasses of LRS
  44. class_Chapter = GDPRtEXT['Chapter']
  45. graph.add((class_Chapter, RDF.type, OWL.Class))
  46. graph.add((class_Chapter, RDFS.subClassOf, LRS))
  47. graph.add((class_Chapter, RDFS.label, Literal('Chapter', datatype=XSD.string)))
  48. graph.add((class_Chapter, RDFS.comment, Literal(
  49. 'Chapter in GDPR text', datatype=XSD.string)))
  50. # declare section, etc. as subclasses of LRS
  51. class_Section = GDPRtEXT['Section']
  52. graph.add((class_Section, RDF.type, OWL.Class))
  53. graph.add((class_Section, RDFS.subClassOf, LRS))
  54. graph.add((class_Section, RDFS.label, Literal('Section', datatype=XSD.string)))
  55. graph.add((class_Section, RDFS.comment, Literal(
  56. 'Section in GDPR text', datatype=XSD.string)))
  57. # declare article, etc. as subclasses of LRS
  58. class_Article = GDPRtEXT['Article']
  59. graph.add((class_Article, RDF.type, OWL.Class))
  60. graph.add((class_Article, RDFS.subClassOf, LRS))
  61. graph.add((class_Article, RDFS.label, Literal('Article', datatype=XSD.string)))
  62. graph.add((class_Article, RDFS.comment, Literal(
  63. 'Article in GDPR text', datatype=XSD.string)))
  64. # declare point, etc. as subclasses of LRS
  65. class_Point = GDPRtEXT['Point']
  66. graph.add((class_Point, RDF.type, OWL.Class))
  67. graph.add((class_Point, RDFS.subClassOf, LRS))
  68. graph.add((class_Point, RDFS.label, Literal('Point', datatype=XSD.string)))
  69. graph.add((class_Point, RDFS.comment, Literal(
  70. 'Point in GDPR text', datatype=XSD.string)))
  71. # declare subpoint, etc. as subclasses of LRS
  72. class_SubPoint = GDPRtEXT['SubPoint']
  73. graph.add((class_SubPoint, RDF.type, OWL.Class))
  74. graph.add((class_SubPoint, RDFS.subClassOf, LRS))
  75. graph.add((class_SubPoint, RDFS.label, Literal(
  76. 'SubPoint', datatype=XSD.string)))
  77. graph.add((class_SubPoint, RDFS.comment, Literal(
  78. 'SubPoint in GDPR text', datatype=XSD.string)))
  79. # Regulation
  80. class_Recital = GDPRtEXT['Recital']
  81. graph.add((class_Recital, RDF.type, OWL.Class))
  82. graph.add((class_Recital, RDFS.subClassOf, LRS))
  83. graph.add((class_Recital, RDFS.label, Literal(
  84. 'Regulation', datatype=XSD.string)))
  85. graph.add((class_Recital, RDFS.comment, Literal(
  86. 'Regulation in GDPR text', datatype=XSD.string)))
  87. # Citation
  88. class_Citation = GDPRtEXT['Citation']
  89. graph.add((class_Citation, RDF.type, OWL.Class))
  90. graph.add((class_Citation, RDFS.subClassOf, LRS))
  91. graph.add((class_Citation, RDFS.label, Literal(
  92. 'Citation', datatype=XSD.string)))
  93. graph.add((class_Citation, RDFS.comment, Literal(
  94. 'Citation in GDPR text', datatype=XSD.string)))
  95. # PROPERTIES
  96. property_partof_chapter = GDPRtEXT['isPartOfChapter']
  97. graph.add((property_partof_chapter, RDF.type, OWL.ObjectProperty))
  98. graph.add((property_partof_chapter, RDF.type, OWL.FunctionalProperty))
  99. graph.add((property_partof_chapter, RDFS.subPropertyOf, PART_OF))
  100. graph.add((property_partof_chapter, RDFS.domain, LRS))
  101. graph.add((property_partof_chapter, RDFS.range, class_Chapter))
  102. graph.add((property_partof_chapter, RDFS.label, Literal(
  103. 'is part of Chapter', datatype=XSD.string)))
  104. graph.add((property_partof_chapter, RDFS.comment, Literal(
  105. 'represents a legal resource subdivision to be part of a chapter',
  106. datatype=XSD.string)))
  107. property_partof_section = GDPRtEXT['isPartOfSection']
  108. graph.add((property_partof_section, RDF.type, OWL.ObjectProperty))
  109. graph.add((property_partof_section, RDF.type, OWL.FunctionalProperty))
  110. graph.add((property_partof_section, RDFS.subPropertyOf, PART_OF))
  111. graph.add((property_partof_section, RDFS.domain, LRS))
  112. graph.add((property_partof_section, RDFS.range, class_Section))
  113. graph.add((property_partof_section, RDFS.label, Literal(
  114. 'is part of Section', datatype=XSD.string)))
  115. graph.add((property_partof_section, RDFS.comment, Literal(
  116. 'represents a legal resource subdivision to be part of a section',
  117. datatype=XSD.string)))
  118. property_partof_article = GDPRtEXT['isPartOfArticle']
  119. graph.add((property_partof_article, RDF.type, OWL.ObjectProperty))
  120. graph.add((property_partof_article, RDF.type, OWL.FunctionalProperty))
  121. graph.add((property_partof_article, RDFS.subPropertyOf, PART_OF))
  122. graph.add((property_partof_article, RDFS.domain, LRS))
  123. graph.add((property_partof_article, RDFS.range, class_Article))
  124. graph.add((property_partof_article, RDFS.label, Literal(
  125. 'is part of Article', datatype=XSD.string)))
  126. graph.add((property_partof_article, RDFS.comment, Literal(
  127. 'represents a legal resource subdivision to be part of a article',
  128. datatype=XSD.string)))
  129. property_partof_point = GDPRtEXT['isPartOfPoint']
  130. graph.add((property_partof_point, RDF.type, OWL.ObjectProperty))
  131. graph.add((property_partof_point, RDF.type, OWL.FunctionalProperty))
  132. graph.add((property_partof_point, RDFS.subPropertyOf, PART_OF))
  133. graph.add((property_partof_point, RDFS.domain, LRS))
  134. graph.add((property_partof_point, RDFS.range, class_Point))
  135. graph.add((property_partof_point, RDFS.label, Literal(
  136. 'is part of Point', datatype=XSD.string)))
  137. graph.add((property_partof_point, RDFS.comment, Literal(
  138. 'represents a legal resource subdivision to be part of a point',
  139. datatype=XSD.string)))
  140. property_has_chapter = GDPRtEXT['hasChapter']
  141. graph.add((property_has_chapter, RDF.type, OWL.ObjectProperty))
  142. graph.add((property_has_chapter, RDF.type, OWL.FunctionalProperty))
  143. graph.add((property_has_chapter, RDFS.subPropertyOf, HAS_PART))
  144. graph.add((property_has_chapter, RDFS.domain, ELI.LegalResource))
  145. graph.add((property_has_chapter, RDFS.range, class_Chapter))
  146. graph.add((property_has_chapter, RDFS.label, Literal(
  147. 'has Chapter', datatype=XSD.string)))
  148. graph.add((property_has_chapter, RDFS.comment, Literal(
  149. 'indicates the legal resource has the Chapter', datatype=XSD.string)))
  150. property_has_section = GDPRtEXT['hasSection']
  151. graph.add((property_has_section, RDF.type, OWL.ObjectProperty))
  152. graph.add((property_has_section, RDF.type, OWL.FunctionalProperty))
  153. graph.add((property_has_section, RDFS.subPropertyOf, HAS_PART))
  154. graph.add((property_has_section, RDFS.domain, LRS))
  155. graph.add((property_has_section, RDFS.range, class_Section))
  156. graph.add((property_has_section, RDFS.label, Literal(
  157. 'has Section', datatype=XSD.string)))
  158. graph.add((property_has_section, RDFS.comment, Literal(
  159. 'indicates the legal resource has the Section', datatype=XSD.string)))
  160. property_has_article = GDPRtEXT['hasArticle']
  161. graph.add((property_has_article, RDF.type, OWL.ObjectProperty))
  162. graph.add((property_has_article, RDF.type, OWL.FunctionalProperty))
  163. graph.add((property_has_article, RDFS.subPropertyOf, HAS_PART))
  164. graph.add((property_has_article, RDFS.domain, LRS))
  165. graph.add((property_has_article, RDFS.range, class_Article))
  166. graph.add((property_has_article, RDFS.label, Literal(
  167. 'has Article', datatype=XSD.string)))
  168. graph.add((property_has_article, RDFS.comment, Literal(
  169. 'indicates the legal resource has the Article', datatype=XSD.string)))
  170. property_has_point = GDPRtEXT['hasPoint']
  171. graph.add((property_has_point, RDF.type, OWL.ObjectProperty))
  172. graph.add((property_has_point, RDF.type, OWL.FunctionalProperty))
  173. graph.add((property_has_point, RDFS.subPropertyOf, HAS_PART))
  174. graph.add((property_has_point, RDFS.domain, LRS))
  175. graph.add((property_has_point, RDFS.range, class_Point))
  176. graph.add((property_has_point, RDFS.label, Literal(
  177. 'has Point', datatype=XSD.string)))
  178. graph.add((property_has_point, RDFS.comment, Literal(
  179. 'indicates the legal resource has the Point', datatype=XSD.string)))
  180. property_has_subpoint = GDPRtEXT['hasSubPoint']
  181. graph.add((property_has_subpoint, RDF.type, OWL.ObjectProperty))
  182. graph.add((property_has_subpoint, RDF.type, OWL.FunctionalProperty))
  183. graph.add((property_has_subpoint, RDFS.subPropertyOf, HAS_PART))
  184. graph.add((property_has_subpoint, RDFS.domain, LRS))
  185. graph.add((property_has_subpoint, RDFS.range, class_SubPoint))
  186. graph.add((property_has_subpoint, RDFS.label, Literal(
  187. 'has SubPoint', datatype=XSD.string)))
  188. graph.add((property_has_subpoint, RDFS.comment, Literal(
  189. 'indicates the legal resource has the SubPoint', datatype=XSD.string)))
  190. property_has_recital = GDPRtEXT['hasRecital']
  191. graph.add((property_has_recital, RDF.type, OWL.ObjectProperty))
  192. graph.add((property_has_recital, RDF.type, OWL.FunctionalProperty))
  193. graph.add((property_has_recital, RDFS.subPropertyOf, HAS_PART))
  194. graph.add((property_has_recital, RDFS.domain, LRS))
  195. graph.add((property_has_recital, RDFS.range, class_Recital))
  196. graph.add((property_has_recital, RDFS.label, Literal(
  197. 'has Recital', datatype=XSD.string)))
  198. graph.add((property_has_recital, RDFS.comment, Literal(
  199. 'indicates the legal resource has the Recital', datatype=XSD.string)))
  200. graph.serialize(destination='../deliverables/gdpr.owl', format='xml')