from rdflib import Namespace, RDF, RDFS, ConjunctiveGraph from semantics import schema, statements SKOS = Namespace('http://www.w3.org/2008/04/skos/core#') OWL = Namespace('http://www.w3.org/2002/07/owl#') DC = Namespace('http://purl.org/dc/elements/1.1/') DCT = Namespace('http://purl.org/dc/terms/') f = file('summary-tables.html','w') ############################################# header = """ SKOS Simple Knowledge Organization System Reference
""" ############################################# f.write(header) f.write("""

Appendix A. SKOS Quick Reference

""") ############################################# begin classes f.write("""

Classes in the SKOS Data Model

""") classes = list(schema().subjects(RDF.type, OWL['Class'])) classes.sort() for c in classes : # local name ln = c.rpartition('#')[2] print ln f.write(''' ''') # uri uri = c print uri f.write(''' ''') # definition f.write(''' ''') # super classes supers = list(schema().objects(c, RDFS.subClassOf)) supers.sort() f.write(''' ''') # disjoint classes disjoints = list(schema().objects(c, OWL['disjointWith'])) disjoints.extend(list(schema().subjects(OWL['disjointWith'],c))) f.write(''' ''') f.write("""
skos:'''+ln+'''
URI: '''+uri+'''
Definition: @@TODO
Super-classes: ''') for s in supers : if s.startswith(SKOS) : # TODO sln = s.rpartition('#')[2] f.write('''skos:'''+sln+'''
''') else : # TODO f.write(''+s+'
') if len(supers) == 0 : f.write('None asserted.''') f.write('''
Disjoint classes: ''') for d in disjoints : if d.startswith(SKOS) : # TODO dln = d.rpartition('#')[2] f.write('''skos:'''+dln+'''
''') else : # TODO f.write(''+d+'
') if len(disjoints) == 0 : f.write('None asserted.''') f.write('''
""") ############################################# end classes ############################################# begin properties f.write("""

Properties in the SKOS Data Model

""") props = list(schema().subjects(RDF.type, OWL['ObjectProperty'])) props.extend(list(schema().subjects(RDF.type, OWL['DatatypeProperty']))) props.sort() for p in props : # local name ln = p.rpartition('#')[2] print ln f.write(''' ''') # uri uri = p print uri f.write(''' ''') # definition f.write(''' ''') # super props supers = list(schema().objects(p, RDFS.subPropertyOf)) supers.sort() f.write(''' ''') # disjoint properties f.write(''' ''') # domain f.write(''' ''') # range f.write(''' ''') inverses = list(schema().objects(p, OWL['inverseOf'])) # inverses.extend(list(schema().subjects(OWL['inverseOf'], p))) inverses.sort() f.write(''' ''') # other characteristics f.write(''' ''') f.write("""
skos:'''+ln+'''
URI: '''+uri+'''
Definition: @@TODO
Super-properties: ''') for s in supers : if s.startswith(SKOS) : # TODO sln = s.rpartition('#')[2] f.write('''skos:'''+sln+'''
''') else : # TODO f.write(''+s+'
') if len(supers) == 0 : f.write('None asserted.''') f.write('''
Disjoint properties: @@TODO
Domain: ''') domain = list(schema().objects(p, RDFS.domain)) domain.sort() for d in domain : if d.startswith(SKOS) : # TODO dln = d.rpartition('#')[2] f.write('''skos:'''+dln+'''
''') else : # TODO f.write(''+d+'
') if len(domain) == 0 : f.write('None asserted.''') f.write('''
Range: ''') range = list(schema().objects(p, RDFS.range)) range.sort() for r in range : if r.startswith(SKOS) : # TODO rln = r.rpartition('#')[2] f.write('''skos:'''+rln+'''
''') else : # TODO f.write(''+r+'
') if len(range) == 0 : f.write('None asserted.''') f.write('''
Inverse of: ''') for i in inverses : if i.startswith(SKOS) : # TODO iln = i.rpartition('#')[2] f.write('''skos:'''+iln+'''
''') else : # TODO f.write(''+i+'
') if len(inverses) == 0 : f.write('None asserted.''') f.write('''
Other characteristics: @@TODO
""") ############################################# ############################################# footer="""
""" ############################################# f.write(footer) f.flush() f.close()