Skip to content

Commit

Permalink
Simplified DataObject singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
mwatts15 committed Mar 16, 2015
1 parent 2dc368f commit 39abdb1
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions yarom/dataObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,35 @@ def getOwners(self, property_name):
class DataObjectType(DataObject): # This maybe becomes a DataObject later
pass

class RDFSClass(DataObject): # This maybe becomes a DataObject later
class DataObjectSingleton(DataObject):
""" The DataObject corresponding to rdf:Property """
instance = None
def __init__(self):
DataObject.__init__(self, R.RDFS["Class"])
def __init__(self, *args, **kwargs):
if type(self)._gettingInstance:
DataObject.__init__(self, *args, **kwargs)
else:
raise Exception("You must call getInstance to get "+type(self).__name__)

@classmethod
def getInstance(cls):
if cls.instance is None:
cls.instance = RDFSClass()
cls._gettingInstance = True
cls.instance = cls()
cls._gettingInstance = False

return cls.instance

class RDFSClass(DataObjectSingleton): # This maybe becomes a DataObject later
""" The DataObject corresponding to rdfs:Class """
def __init__(self):
super().__init__(R.RDFS["Class"])

class RDFProperty(DataObjectSingleton):
""" The DataObject corresponding to rdf:Property """
def __init__(self):
super().__init__(R.RDF["Property"])


class RDFTypeProperty(SimpleProperty):
link = R.RDF['type']
linkName = "rdf_type_property"
Expand All @@ -369,39 +387,18 @@ class RDFSSubClassOfProperty(SimpleProperty):
multiple = True

class DataObjectProperty(DataObjectType):
""" An represents the property-as-object.
""" A DataObjectProperty represents the property-as-object.
Try not to confuse this with the Property class
"""

class RDFProperty(DataObject):
""" An RDFProperty represents the property-as-object.
Try not to confuse this with the Property class
"""
instance = None
def __init__(self):
if type(self)._gettingInstance:
DataObject.__init__(self, R.RDF["Property"])
else:
raise Exception("You must call getInstance to get RDFProperty")

@classmethod
def getInstance(cls):
if cls.instance is None:
cls._gettingInstance = True
cls.instance = RDFProperty()
cls._gettingInstance = False

return cls.instance

class ObjectCollection(DataObject):
"""
A convenience class for working with a collection of objects
Example::
v = values('unc-13 neurons and muscles')
v = ObjectCollection('unc-13 neurons and muscles')
n = P.Neuron()
m = P.Muscle()
n.receptor('UNC-13')
Expand All @@ -414,7 +411,7 @@ class ObjectCollection(DataObject):
v.save()
...
# get the list back
u = values('unc-13 neurons and muscles')
u = ObjectCollection('unc-13 neurons and muscles')
nm = list(u.value())
Expand Down

0 comments on commit 39abdb1

Please sign in to comment.