def __init__(self, manager, uri=None, isBlank=False, blankNodeId=None): PASSProcessModelElement.__init__(self, manager, uri, isBlank, blankNodeId) self.hasModelComponent = ListenerList([], self, "hasModelComponent") self._fireChangeEvents = True self.fireChangeEvent()
def __init__(self, manager, uri=None, isBlank=False, blankNodeId=None): """ Constructor - Should never be called directly from outside the model framwork. @param ModelManager manger : The parent element (if one exists). @param string uri : @param bool isBlank : @param string blankNodeId : @return : @author """ PASSProcessModelElement.__init__(self, manager, uri, isBlank, blankNodeId) self.hasEdge = ListenerList([], self, "hasEdge") self.hasState = ListenerList([], self, "hasState") self._fireChangeEvents = True self.fireChangeEvent()
def serialize(self): """ Serializes the given resource to triple statements from the Redland RDF library. This is done by using the model manager and its attribute wrapper. @return : @author """ #First set yourself the class type if it is not Resource or already set if(type(self).__name__ != "Resource"): if(not hasattr(self, "type")): self.type = ListenerList([], self, "type") ownClassUri = self.modelManager.classMapper.getClassResource(type(self).__name__) #Do this typing stuff and check if the type is not a resource found = False for r in self.type: try: if(r.uri == ownClassUri): found = True break except: #Do nothing pass if(not found): #Add your own class type self.type.append(Resource(self.modelManager, uri = ownClassUri)) #Initialize an array to store the results in results = [] #Iterate over all variables and store the values for (key, value) in list(self.__dict__.items()): #Only store the values of "public" variables if(not key.startswith("_")): #Subject and attribute are always the of normal type resource if(not self.isBlank): subjectNode = RDF.Uri(self.uri) else: subjectNode = RDF.Node(blank=self.blankIdentifier) attributeNode = RDF.Uri(self.modelManager.attrMapper.getAttributeUri(key)) #Object node might be a list or a skalar if(value is None): #Do nothing pass elif(isinstance(value, list)): for subValue in value: results.append(self._generateStatement(subjectNode, attributeNode, subValue)) else: results.append(Resource._generateStatement(subjectNode, attributeNode, value)) #Now return the results return results
def __init__(self, manager, uri = None, isBlank = False, blankNodeId = None): """ Constructor including the parent element @param ModelManager manger : The parent element (if one exists). @param string uri : @param bool isBlank : @param string blankNodeId : @param PASSProcessModelElement : The hierarchical parent of this process element. @return : @author """ #Call super constructor Resource.__init__(self, manager, uri, isBlank, blankNodeId) #Generate the component id and the empty array for the meta content self.hasComponentID = randomXMLName() self.hasMetaContent = ListenerList([], self, "hasMetaContent") self.hasAbstractVisualRepresentation = None self.hasVisualRepresentation = None self.label = ListenerList([], self, "label")
def __init__(self, manager, uri = None, isBlank = False, blankNodeId = None, parentModel = None): """ Constructor - Should never be called directly from outside the model framwork. @param ModelManager manger : The parent element (if one exists). @param string uri : @param bool isBlank : @param string blankNodeId : @return : @author """ PASSProcessModelElement.__init__(self, manager, uri, isBlank, blankNodeId) if((parentModel is not None) and (not isinstance(parentModel, PASSProcessModel))): raise Exception("ParentModel parameter must be of type PASSProcessModel!") self.belongsTo = parentModel self.hasModelComponent = ListenerList([], self, "hasModelComponent")
def __init__(self, manager, uri = None, isBlank = False, blankNodeId = None): """ Constructor - defines whether this instance represents a blank node or not. - This cannot be changed later on! @param ModelManager manager : The manager that is responsible for this resource. @param string uri : The uri this Resource should represent. @param bool isBlank : Boolean to dertermine whether the node is a blank node @param string blankNodeId : The identifier for the blank node if this resource is a blank node. @return : @author """ #By default a resource does not fire change events self._fireChangeEvents = False #Import it just here because it is not needed before from ModelManager import * #Check the type of the manager object if(not isinstance(manager, ModelManager)): raise Exception("Paramter \"manager\" has to be of type ModelManager!") self._modelManager = manager self._modelManager.registerResource(self) self.type = ListenerList([], self, "type") #Now check whether to create a normal or a blank resource self._isBlank = isBlank if(not self._isBlank): #Create a normal resource if(uri is not None): self.uri = uri else: self._uri = None else: #Create a blank resource if(blankNodeId is not None): self._blankIdentifier = blankNodeId else: raise Exception("If a Resource is defined as a blank node it must also define the \"blankNodeId\" parameter")
def _convertTriples(self, result, ownClasses, alternativeAttrUri=None): """ Internal method to make loading from file easier! @return : @author """ #Rest subject string subjectString = None #Attribute is always a node with uris => Automatically get the attribute name if (("a" in result) and (result["a"] is not None)): attrName = self.attrMapper.getAttributeName(str(result["a"].uri)) else: attrName = self.attrMapper.getAttributeName(alternativeAttrUri) #Now check of what type the subject is if (result["s"].is_resource()): subjectString = str(result["s"].uri) elif (result["s"].is_blank()): subjectString = str(result["s"].blank_identifier) else: raise Exception( "Received a RDFNode that is a subject and neither of type normal nor blank!" ) #Insert the subject if not already in class list if (not (subjectString in ownClasses)): #Do a dynamic import of the missing class exec(str("from " + ClassMapper.DEFAULT_CLASS + " import *")) classConstructor = globals()[ClassMapper.DEFAULT_CLASS] if (subjectString.startswith("http://")): ownClasses[subjectString] = classConstructor(self, uri=subjectString) else: ownClasses[subjectString] = classConstructor( self, isBlank=True, blankNodeId=subjectString) #Get the subject class subjectClass = ownClasses[subjectString] #Now check of what type the object is objectIsLiteral = False if (result["o"].is_resource()): objectString = str(result["o"].uri) elif (result["o"].is_blank()): objectString = str(result["o"].blank_identifier) else: #It is a literal objectIsLiteral = True literalValues = result["o"].literal_value if (literalValues["datatype"] is not None): dt = str(literalValues["datatype"]) else: dt = None objectClass = Resource.castLiteralToType(literalValues["string"], dt) #Now go on depending the object type if (not objectIsLiteral): #Insert the object if not already in class list if (not (objectString in ownClasses)): #Do a dynamic import of the missing class exec(str("from " + ClassMapper.DEFAULT_CLASS + " import *")) classConstructor = globals()[ClassMapper.DEFAULT_CLASS] if (objectString.startswith("http://")): ownClasses[objectString] = classConstructor( self, uri=objectString) else: ownClasses[objectString] = classConstructor( self, isBlank=True, blankNodeId=objectString) #Get the object class objectClass = ownClasses[objectString] #Now take the classes and reference the object in the subjects attribute depending on the multiplicity multiplicity = subjectClass.getAttrMultiplicity(attrName) if (multiplicity == AttributeMultiplicity.UNKNOWN): if (not hasattr(subjectClass, attrName)): setattr(subjectClass, attrName, ListenerList([], subjectClass, str(attrName))) getattr(subjectClass, attrName).append(objectClass) elif (multiplicity == AttributeMultiplicity.UNIQUE): setattr(subjectClass, attrName, objectClass) else: raise Exception( "Unknown attribute multiplicity set to attribute " + attrName)