~jplacerda/zeitgeist/784850

« back to all changes in this revision

Viewing changes to extra/PythonSerializer.py

  • Committer: Markus Korn
  • Date: 2010-04-25 15:02:24 UTC
  • mto: This revision was merged to the branch mainline in revision 1447.
  • Revision ID: thekorn@gmx.de-20100425150224-3dhno40i965oww24
* updated README.Ontology
* cleaned up some code in the ontology serializer

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
NIENS = Namespace("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#")
25
25
 
26
 
import sys, pprint
27
 
 
28
26
def escape_chars(text, strip=True):
29
27
        text = text.replace("'", "\\'")
30
28
        text = text.replace('"', '\\"')
47
45
 
48
46
 
49
47
class PythonSerializer(RecursiveSerializer):
50
 
 
51
 
        #~ def _get_all_classes(self):
52
 
                #~ return self.store.subjects(RDF.type, RDFS.Class)
53
48
                
54
49
        def _get_all_subclasses(self, *super_classes):
55
50
                for cls in super_classes:
77
72
                
78
73
 
79
74
        def serialize(self, stream, base=None, encoding=None, **args):
80
 
                #~ # this is not working yet, and does not do anything
81
 
                #~ for resource in self.store.subjects(RDFS.subClassOf, RDFS.Resource):
82
 
                        #~ #stream.write("""class %s(RDFSResource):\n\tpass\n\n""" %str(resource).split("#")[-1])
83
 
#~ 
84
 
                        #~ for member in self.store.subjects(RDFS.domain, resource):
85
 
                                #~ attributes = dict(self.store.predicate_objects(member))
86
 
                                #~ if attributes.pop(RDF.type) == RDFS.RDFSNS["Property"]:
87
 
                                        #~ # ok, it is a property
88
 
                                        #~ name = attributes.pop(RDFS.label)
89
 
                                        #~ print name
90
 
                                        #~ print attributes
91
 
                                #~ else:
92
 
                                        #~ raise ValueError
93
 
                                #~ break
94
 
                #~ all_classes = set(self._get_all_classes())
95
75
                symbol_classes = set(self._get_all_subclasses(NIENS["InformationElement"], NIENS["DataObject"]))
96
 
                #~ ignore_classes = all_classes - symbol_classes
97
 
                #~ pprint.pprint(ignore_classes, stream=sys.stderr)
98
 
                #~ pprint.pprint(sorted(symbol_classes), stream=sys.stderr)
99
76
                
100
77
                for symbol in sorted(symbol_classes):
101
78
                        self._create_symbol(