13 from cubicweb.common.view import StartupView |
13 from cubicweb.common.view import StartupView |
14 from cubicweb.web.httpcache import EtagHTTPCacheManager |
14 from cubicweb.web.httpcache import EtagHTTPCacheManager |
15 |
15 |
16 _ = unicode |
16 _ = unicode |
17 |
17 |
18 OWL_CARD_MAP = {'1': '''<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality> |
18 OWL_CARD_MAP = {'1': '<rdf:type rdf:resource="&owl;FunctionalProperty"/>', |
19 <owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>''', |
19 '?': '<owl:maxCardinality rdf:datatype="&xsd;int">1</owl:maxCardinality>', |
20 '?': '<owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>', |
20 '+': '<owl:minCardinality rdf:datatype="&xsd;int">1</owl:minCardinality>', |
21 '+': '<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>', |
21 '*': '' |
22 '*': '<owl:cardinality rdf:datatype="&xsd;nonNegativeInteger">n</owl:cardinality>' |
|
23 } |
22 } |
24 |
23 |
25 OWL_CARD_MAP_DATA = {'String': 'xsd:string', |
24 OWL_CARD_MAP_DATA = {'String': 'xsd:string', |
26 'Datetime': 'xsd:dateTime', |
25 'Datetime': 'xsd:dateTime', |
27 'Bytes': 'xsd:byte', |
26 'Bytes': 'xsd:byte', |
239 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
238 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
240 xmlns:xsd="http://www.w3.org/2001/XMLSchema#" |
239 xmlns:xsd="http://www.w3.org/2001/XMLSchema#" |
241 xmlns:owl="http://www.w3.org/2002/07/owl#" |
240 xmlns:owl="http://www.w3.org/2002/07/owl#" |
242 xmlns="http://logilab.org/owl/ontologies/%s#" |
241 xmlns="http://logilab.org/owl/ontologies/%s#" |
243 xmlns:%s="http://logilab.org/owl/ontologies/%s#" |
242 xmlns:%s="http://logilab.org/owl/ontologies/%s#" |
244 xml:base="http://logilab.org/owl/ontologies/%s#"> |
243 xml:base="http://logilab.org/owl/ontologies/%s"> |
245 |
244 |
246 <owl:Ontology rdf:about=""> |
245 <owl:Ontology rdf:about=""> |
247 <rdfs:comment> |
246 <rdfs:comment> |
248 %s Cubicweb OWL Ontology |
247 %s Cubicweb OWL Ontology |
249 |
248 |
250 </rdfs:comment> |
249 </rdfs:comment> |
|
250 </owl:Ontology> |
251 ''' % (self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name)) |
251 ''' % (self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name)) |
252 entities = [eschema for eschema in self.schema.entities() |
252 entities = [eschema for eschema in self.schema.entities() |
253 if not eschema.is_final()] |
253 if not eschema.is_final()] |
254 if skipmeta: |
254 if skipmeta: |
255 entities = [eschema for eschema in entities |
255 entities = [eschema for eschema in entities |
263 for key, eschema in sorted(keys): |
263 for key, eschema in sorted(keys): |
264 self.visit_property_schemaOWL(eschema, skiprels) |
264 self.visit_property_schemaOWL(eschema, skiprels) |
265 self.w(u'<!-- datatype property -->') |
265 self.w(u'<!-- datatype property -->') |
266 for key, eschema in sorted(keys): |
266 for key, eschema in sorted(keys): |
267 self.visit_property_object_schemaOWL(eschema, skiprels) |
267 self.visit_property_object_schemaOWL(eschema, skiprels) |
268 self.w(u' </owl:Ontology></rdf:RDF>') |
268 self.w(u'</rdf:RDF>') |
269 |
269 |
270 def eschema_link_url(self, eschema): |
270 def eschema_link_url(self, eschema): |
271 return self.req.build_url('eetype/%s?vid=eschema' % eschema) |
271 return self.req.build_url('eetype/%s?vid=eschema' % eschema) |
272 |
272 |
273 def rschema_link_url(self, rschema): |
273 def rschema_link_url(self, rschema): |
322 if aname == 'eid': |
322 if aname == 'eid': |
323 continue |
323 continue |
324 card_data = aschema.type |
324 card_data = aschema.type |
325 self.w(u'''<rdfs:subClassOf> |
325 self.w(u'''<rdfs:subClassOf> |
326 <owl:Restriction> |
326 <owl:Restriction> |
327 <owl:onProperty rdf:resource="#%s"/> |
327 <owl:onProperty rdf:resource="#%s"/> |
328 <owl:cardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:cardinality> |
328 <rdf:type rdf:resource="&owl;FunctionalProperty"/> |
329 </owl:Restriction> |
329 </owl:Restriction> |
330 </rdfs:subClassOf>''' |
330 </rdfs:subClassOf>''' |
331 |
331 |
332 % aname) |
332 % aname) |
333 self.w(u'</owl:Class>') |
333 self.w(u'</owl:Class>') |
334 |
334 |
335 def visit_property_schemaOWL(self, eschema, skiprels=()): |
335 def visit_property_schemaOWL(self, eschema, skiprels=()): |
336 """get a layout for property entity OWL schema""" |
336 """get a layout for property entity OWL schema""" |
337 etype = eschema.type |
337 etype = eschema.type |
338 |
338 |
339 for rschema, targetschemas, role in eschema.relation_definitions(): |
339 for rschema, targetschemas, role in eschema.relation_definitions(): |
363 self.w(u'''<owl:DatatypeProperty rdf:ID="%s"> |
363 self.w(u'''<owl:DatatypeProperty rdf:ID="%s"> |
364 <rdfs:domain rdf:resource="#%s"/> |
364 <rdfs:domain rdf:resource="#%s"/> |
365 <rdfs:range rdf:resource="%s"/> |
365 <rdfs:range rdf:resource="%s"/> |
366 </owl:DatatypeProperty>''' |
366 </owl:DatatypeProperty>''' |
367 % (aname, eschema, OWL_CARD_MAP_DATA[card_data])) |
367 % (aname, eschema, OWL_CARD_MAP_DATA[card_data])) |
368 # <owl:DatatypeProperty rdf:ID="%s"/> |
368 |
369 # </owl:DatatypeProperty> |
|
370 |
|
371 |
|
372 |
369 |