Exemplo n.º 1
0
    def parseStatement(self, statement):

        # get predicate
        predicate = str(statement.getPredicate())

        # pitch
        if predicate == PROPERTY.PITCH:
            try:
                self.setPitch(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:pitch value as literal double."
                traceback.print_exc()
            return

        # yaw
        if predicate == PROPERTY.YAW:
            try:
                self.setYaw(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:yaw value as literal double."
                traceback.print_exc()
            return

        # roll
        if predicate == PROPERTY.ROLL:
            try:
                self.setRoll(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:roll value as literal double."
                traceback.print_exc()
            return

        # pass on to Object
        super(Orientation, self).parseStatement(statement)
Exemplo n.º 2
0
	def parseStatement(self, statement):
		
			# get predicate
			predicate = str(statement.getPredicate())
	
			# width
			if predicate == PROPERTY.WIDTH:
				try:
					self.setWidth(ValueObject().parse(statement.getResource()))
				except:
					print "Unable to interpret seas:width value as literal double."
					traceback.print_exc()
				return
	
			# height
			if predicate == PROPERTY.HEIGHT:
				try:
					self.setHeight(ValueObject().parse(statement.getResource()))
				except:
					print "Unable to interpret seas:height value as literal double."
					traceback.print_exc()
				return
			
			# depth
			if predicate == PROPERTY.DEPTH:
				try:
					self.setDepth(ValueObject().parse(statement.getResource()))
				except:
					print "Unable to interpret seas:depth value as literal double."
					traceback.print_exc()
				return
				
			# pass on to Object
			super(Size, self).parseStatement(statement)
Exemplo n.º 3
0
    def parseStatement(self, statement):

        # get predicate
        predicate = str(statement.getPredicate())

        # latitude
        if predicate == PROPERTY.LOCATION:
            try:
                self.setCoordinates(Coordinates().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:coordinates value as coordinates."
                traceback.print_exc()
            return

        if predicate == PROPERTY.MINRADIUS:
            try:
                self.setMinRadius(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:minradius value."
                traceback.print_exc()
            return

        if predicate == PROPERTY.MAXRADIUS:
            try:
                self.setMaxRadius(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:maxradius value."
                traceback.print_exc()
            return

        # pass on to Object
        super(Ring, self).parseStatement(statement)
Exemplo n.º 4
0
    def parseStatement(self, statement):
        from SmartAPI.model.Velocity import Velocity
        from SmartAPI.model.ValueObject import ValueObject
        from SmartAPI.model.TemporalContext import TemporalContext

        # get predicate
        predicate = str(statement.getPredicate())

        # route points
        if predicate == PROPERTY.LIST:
            try:
                self.setRoutePoints(
                    statement.getResource().toList(Coordinates))
            except:
                print "Unable to interpret seas:list value as a resource for Route."
                traceback.print_exc()
            return

        if predicate == PROPERTY.LENGTH:
            try:
                self.setLength(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:length value as a resource for Route."
                traceback.print_exc()
            return

        if predicate == PROPERTY.ENERGYCONSUMPTION:
            try:
                self.setEnergyConsumption(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:energyconsumption value as a resource for Route."
                traceback.print_exc()
            return

        if predicate == PROPERTY.AVERAGEVELOCITY:
            try:
                self.setAverageVelocity(Velocity().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:averageSpeed value as a resource for Route."
                traceback.print_exc()
            return

        if predicate == PROPERTY.DURATION:
            try:
                self.setDuration(TemporalContext().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:duration value as a resource for Route."
                traceback.print_exc()
            return

        # pass on to Object
        super(Route, self).parseStatement(statement)
Exemplo n.º 5
0
 def __init__(self, uri=None):
     ValueObject.__init__(self, uri)
     self.setType(RESOURCE.EVALUATION)
     self.categories = []
     self.entities = []
     self.timeSeries = []
     self.systemOfInterest = None
     self.value = None
     self.valueObjects = []
     self.inputs = []
     self.outputs = []
     self.interfaces = []
     self.activities = []
     self.list = None
     self.map = Map()
Exemplo n.º 6
0
 def pointSearchArea(self, center, kilometers):
     ring = Ring()
     ring.add(URIRef(PROPERTY.LAT), center.getLatitude())
     ring.add(URIRef(PROPERTY.LONG), center.getLongitude())
     maxR = ValueObject()
     maxR.setQuantity(RESOURCE.LENGTH)
     maxR.setUnit(RESOURCE.KILOMETER)
     maxR.setValue(Variant(kilometers))
     ring.setMaxRadius(maxR)
     self.entity.add(URIRef(NS.SMARTAPI + "ring"), ring)
Exemplo n.º 7
0
    def parseStatement(self, statement):
        from SmartAPI.model.Size import Size
        from SmartAPI.model.Orientation import Orientation
        from SmartAPI.model.Direction import Direction
        from SmartAPI.model.Velocity import Velocity
        from SmartAPI.model.ValueObject import ValueObject

        # get predicate
        predicate = str(statement.getPredicate())

        # status
        if predicate == PROPERTY.VELOCITY:
            try:
                self.setVelocity(Velocity().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:velocity value as resource."
                traceback.print_exc()
            return

        # status
        if predicate == PROPERTY.ORIENTATION:
            try:
                self.setOrientation(Orientation().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:orientation value."
                traceback.print_exc()
            return

        # status
        if predicate == PROPERTY.SIZE:
            try:
                self.setSize(Size().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:size value as resource."
                traceback.print_exc()
            return

        # errors
        if predicate == PROPERTY.DIRECTION:
            try:
                self.setDirection(Direction().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:direction value as resource."
                traceback.print_exc()
            return

        if predicate == PROPERTY.WEIGHT:
            try:
                self.setWeight(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:weight value as resource."
                traceback.print_exc()
            return

        # pass on to Evaluation
        super(PhysicalEntity, self).parseStatement(statement)
Exemplo n.º 8
0
    def parseStatement(self, statement):

        # get predicate
        predicate = str(statement.getPredicate())

        # bearing
        if predicate == PROPERTY.BEARING:
            try:
                self.setBearing(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:bearing value as ValueObject."
                traceback.print_exc()
            return

        # heading
        if predicate == PROPERTY.HEADING:
            try:
                self.setHeading(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:heading value as ValueObject."
                traceback.print_exc()
            return

        # tracking
        if predicate == PROPERTY.TRACKING:
            try:
                self.setTracking(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:tracking value as ValueObject."
                traceback.print_exc()
            return

            # tracking
        if predicate == PROPERTY.COURSE:
            try:
                self.setCourse(ValueObject().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:course value as ValueObject."
                traceback.print_exc()
            return

        # pass on to Object
        super(Direction, self).parseStatement(statement)
Exemplo n.º 9
0
    def newValueObject(self, quantity, unit, dataType, description, types):
        '''
		@param types: a list of string, or one single string representing Type; 
		all the others are string types  
		'''
        from SmartAPI.model.ValueObject import ValueObject

        valueObject = ValueObject(quantity=quantity,
                                  unit=unit,
                                  dataType=dataType,
                                  description=description,
                                  types=types)
        self.addValueObject(valueObject)
        return valueObject
Exemplo n.º 10
0
    def _parse_list_entry(self, entry, klass=None, from_nude=False):
        from SmartAPI.model.ValueObject import ValueObject
        from SmartAPI.rdf.Variant import Variant
        from SmartAPI.common.Tools import Tools

        if from_nude and klass is not None:
            item = klass()
            item.fromNude(entry)
            return item

        if isinstance(entry, Literal):
            return Variant(entry.toPython())
        elif isinstance(entry, URIRef):
            if entry == RDF.nil:
                return None
            return Variant(entry)
        else:
            if klass is None:
                types = []
                sl = self.listStatements(subject=entry,
                                         predicate=URIRef(PROPERTY.RDF_TYPE),
                                         object=None)
                for s in sl:
                    types.append(s.getResource().toString())
                klass = Tools().mapper.getClass(types, default=Variant)

            item = klass()
            for s in self.find_statements_for_node(entry):
                if s.predicate == NS.SMARTAPI + "valueObject":
                    itemv = ValueObject()
                    for sv in self.find_statements_for_node(s.object):
                        itemv.parse(sv)
                    item.addValueObject(itemv)
                else:
                    item.parseStatement(s)
            return item
Exemplo n.º 11
0
    def parseStatement(self, statement):
        from SmartAPI.model.ValueObject import ValueObject

        predicate = str(statement.getPredicate())

        # output vals
        if predicate == PROPERTY.OUTPUTVALUES:
            try:
                self.addOutputValue(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:outputValues value as resource."
                traceback.print_exc()
            return

        super(Input, self).parseStatement(statement)
Exemplo n.º 12
0
	def __init__(self, uri = None, quantity = None, unit = None, value = None, maximum = None, system_of_interest = None):
		ValueObject.__init__(self, uri = uri, quantity = quantity, unit = unit, value = value, maximum = maximum)
		self.automatic_percentage_calculation = True
		self.system_of_interest = system_of_interest
		self.percentage = None
		self.setType(RESOURCE.CAPACITY)
Exemplo n.º 13
0
    def parseStatement(self, statement):
        from SmartAPI.model.Address import Address
        from SmartAPI.model.Coordinates import Coordinates
        from SmartAPI.model.Zone import Zone
        from SmartAPI.model.Controllability import Controllability
        from SmartAPI.model.Availability import Availability
        from SmartAPI.model.Activity import Activity
        from SmartAPI.model.Evaluation import Evaluation
        from SmartAPI.model.InterfaceAddress import InterfaceAddress
        from SmartAPI.model.ValueObject import ValueObject

        # get predicate
        predicate = str(statement.getPredicate())

        # zone
        if predicate == PROPERTY.ZONE:
            try:
                self.setZone(Zone().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:zone value as resource."
                print sys.exc_info()[1]
                traceback.print_exc()
            return

        # coordinates
        if predicate == PROPERTY.LOCATION:
            try:
                self.setCoordinates(Coordinates().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret geo:location value as resource."
                print sys.exc_info()[1]
                traceback.print_exc()
            return

            # coordinates
        if predicate == PROPERTY.HASADDRESS:
            try:
                self.setAddress(Address().parse(statement.getResource()))
            except:
                print "Unable to interpret vcard:hasAddress value as resource."
                print sys.exc_info()[1]
                traceback.print_exc()
            return

        if predicate == PROPERTY.ISMANAGEDBY:
            try:
                self.setManagedBy(Entity().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:isManagedBy value as resource."
                print sys.exc_info()[1]
                traceback.print_exc()
            return

        # controllability
        if predicate == PROPERTY.HASEVALUATION:
            try:
                self.addControllability(Controllability().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:hasEvaluation value as resource."
                traceback.print_exc()
            return

        # availability
        if predicate == PROPERTY.HASAVAILABILITY:
            try:
                self.addAvailability(Availability().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:hasAvailability value as resource."
                traceback.print_exc()
            return

        # data availability
        if predicate == PROPERTY.HASDATAAVAILABILITY:
            try:
                self.addDataAvailability(Availability().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:hasDataAvailability value as resource."
                traceback.print_exc()
            return

        # hascapability
        if predicate == PROPERTY.HASCAPABILITY:
            try:
                self.addCapability(Activity().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:hasCapability value as resource."
                traceback.print_exc()
            return

        # hascapability
        if predicate == PROPERTY.MANAGES:
            try:
                self.addManagedEntity(Entity().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:hasCapability value as resource."
                traceback.print_exc()
            return

        # capacity
        if predicate == PROPERTY.CAPACITY:
            try:
                self.addCapacity(Evaluation().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:capacity value as resource."
                traceback.print_exc()
            return

        # interfaceaddress
        if predicate == PROPERTY.INTERFACE:
            try:
                self.addInterface(InterfaceAddress().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:interface value as resource."
                traceback.print_exc()
            return

        # creators
        if predicate == PROPERTY.CREATOR:
            try:
                self.addCreator(Entity().parse(statement.getResource()))
            except:
                print "Unable to interpret dc:creator value as resource."
                traceback.print_exc()
            return

        # owner
        if predicate == PROPERTY.OWNER:
            try:
                self.addOwner(Entity().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:owner value as resource."
                traceback.print_exc()
            return

            # website
        if predicate == PROPERTY.HASURL:
            try:
                self.addWebsite(statement.getString())
            except:
                print "Unable to interpret vcard:hasURL value as string literal."
                traceback.print_exc()
            return

        # logo
        if predicate == PROPERTY.HASLOGO:
            try:
                self.addLogo(statement.getString())
            except:
                print "Unable to interpret vcard:hasLogo value as string literal."
                traceback.print_exc()
            return

        # photo
        if predicate == PROPERTY.HASPHOTO:
            try:
                self.addPhoto(statement.getString())
            except:
                print "Unable to interpret vcard:hasPhoto value as string literal."
                traceback.print_exc()
            return

        # sound
        if predicate == PROPERTY.HASSOUND:
            try:
                self.addSound(statement.getString())
            except:
                print "Unable to interpret vcard:hasSound value as string literal."
                traceback.print_exc()
            return

        # valueobject
        if predicate == PROPERTY.VALUEOBJECT:
            try:
                self.addValueObject(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:valueObject value as resource."
                traceback.print_exc()
            return

        # pass on to Object
        super(Entity, self).parseStatement(statement)
Exemplo n.º 14
0
    def parseStatement(self, statement):

        # get predicate
        predicate = str(statement.getPredicate())

        # angularVelocityX
        if predicate == PROPERTY.ANGULARVELOCITYX:
            try:
                self.setAngularVelocityX(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:angularVelocityX value as literal double."
                traceback.print_exc()
            return

        # angularVelocityY
        if predicate == PROPERTY.ANGULARVELOCITYY:
            try:
                self.setAngularVelocityY(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:angularVelocityY value as literal double."
                traceback.print_exc()
            return

        # angularVelocityZ
        if predicate == PROPERTY.ANGULARVELOCITYZ:
            try:
                self.setAngularVelocityZ(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:angularVelocityZ value as literal double."
                traceback.print_exc()
            return

        # linearVelocityX
        if predicate == PROPERTY.LINEARVELOCITYX:
            try:
                self.setLinearVelocityX(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:linearVelocityX value as literal double."
                traceback.print_exc()
            return

        # linearVelocityY
        if predicate == PROPERTY.LINEARVELOCITYY:
            try:
                self.setLinearVelocityY(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:linearVelocityY value as literal double."
                traceback.print_exc()
            return

        # linearVelocityZ
        if predicate == PROPERTY.LINEARVELOCITYZ:
            try:
                self.setLinearVelocityZ(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:linearVelocityZ value as literal double."
                traceback.print_exc()
            return
        # groundSpeedX
        if predicate == PROPERTY.GROUNDSPEED:
            try:
                self.setGroundSpeed(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:groundSpeed value as literal double."
                traceback.print_exc()
            return

        # pass on to Object
        super(Velocity, self).parseStatement(statement)
Exemplo n.º 15
0
    def createValueObject(self,
                          name=None,
                          unit=None,
                          quantity=None,
                          description=None,
                          datatype=None):
        from SmartAPI.model.ValueObject import ValueObject
        from SmartAPI.rdf.Variant import Variant

        vo = None
        try:
            vo = ValueObject()
            if name is not None: vo.setName(name)
            if quantity is not None: vo.setQuantity(quantity)
            if unit is not None: vo.setUnit(unit)
            if description is not None: vo.setDescription(description)
            if datatype is not None: vo.setValue(Variant(datatype))
        except:
            print "Exception while creating a ValueObject"
            print sys.exc_info()[1]
            vo = None
        return vo
Exemplo n.º 16
0
    def parseStatement(self, statement):
        from SmartAPI.rdf.Variant import Variant
        from SmartAPI.model.Activity import Activity
        from SmartAPI.model.Device import Device
        from SmartAPI.model.Entity import Entity
        from SmartAPI.model.Input import Input
        from SmartAPI.model.Output import Output
        from SmartAPI.model.Parameter import Parameter
        from SmartAPI.model.SystemOfInterest import SystemOfInterest
        from SmartAPI.model.TemporalContext import TemporalContext
        from SmartAPI.model.InterfaceAddress import InterfaceAddress
        from SmartAPI.model.TimeSeries import TimeSeries
        from SmartAPI.common.Tools import Tools

        if statement is None:
            raise NonePointerException("Unable to parse None to Evaluation.")
            return

        # get predicate
        predicate = str(statement.getPredicate())

        # category
        if predicate == PROPERTY.CATEGORY:
            try:
                self.addCategory(str(statement.getResource().toString()))
            except:
                print "Unable to interpret seas:category value as resource."
                traceback.print_exc()
            return

        # systemofinterest
        if predicate == PROPERTY.SYSTEMOFINTEREST:
            try:
                self.setSystemOfInterest(SystemOfInterest().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:systemOhInterest value as resource."
                traceback.print_exc()
            return

        # interfaceaddress
        if predicate == PROPERTY.INTERFACE:
            try:
                self.addInterface(InterfaceAddress().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:interface value as resource."
                traceback.print_exc()
            return

        # timeserie
        if predicate == PROPERTY.TIMESERIES:
            try:
                self.addTimeSerie(TimeSeries().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:timeSeries value as resource."
                traceback.print_exc()
            return

        # value
        if predicate == PROPERTY.RDF_VALUE:
            self.setValue(Variant().parse(statement))
            return

        # valueobject
        if predicate == PROPERTY.VALUEOBJECT:
            try:
                self.addValueObject(ValueObject().parse(
                    statement.getResource()))
            except:
                print "Unable to interpret seas:valueObject value as resource."
                traceback.print_exc()
            return

        # input data
        if predicate == PROPERTY.HASINPUT:
            try:
                self.addInput(Input().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:hasInput value as resource."
                traceback.print_exc()
            return

        # input reference
        if predicate == PROPERTY.HASREFINPUT:
            try:
                input = Input().parse(statement.getResource())
                input.setInputType(Input.TYPE_REFERENCE)
                self.addInput(input)
            except:
                print "Unable to interpret seas:hasRefInput value as resource."
                traceback.print_exc()
            return

        # output
        if predicate == PROPERTY.HASOUTPUT:
            try:
                self.addOutput(Output().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:hasOutput value as resource."
                traceback.print_exc()
            return

        # activities
        if predicate == PROPERTY.ACTIVITY:
            try:
                self.addActivity(Activity().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:activity value as resource."
                print statement
                print "------------------------"
                traceback.print_exc()
                raise
            return
        """"
        if predicate == PROPERTY.PARAMETER:
            try:
                self.addParameter(Parameter().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:parameter value as resource."
                traceback.print_exc()
            return
        """

        # entity
        if predicate == PROPERTY.ENTITY:
            try:
                self.addEntity(Entity().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:entity value (of type seas:Entity) as resource."
                traceback.print_exc()
            return

#       # entity
#       if predicate == PROPERTY.ENTITY:
#           types = None
#           try:
#               types = Tools().getResourceTypes(statement.getResource())
#           except:
#               print "Unable to interpret seas:entity value as resource."
#               traceback.print_exc()
#
#           # service
#           if types is not None and RESOURCE.SERVICE in types:
#               try:
#                   self.addEntity(Service().parse(statement.getResource()))
#               except:
#                   print "Unable to interpret seas:entity value (of type seas:Service) as resource."
#                   traceback.print_exc()
#               return
#
#           # device
#           if types is not None and RESOURCE.DEVICE in types:
#               try:
#                   self.addEntity(Device().parse(statement.getResource()))
#               except:
#                   print "Unable to interpret seas:entity value (of type seas:Device) as resource."
#                   traceback.print_exc()
#               return
#
#
#           # serviceprovider
#
#           # weatherserviceprovider
#
#           # could not match with any entity subtype
#           try:
#               self.addEntity(Entity().parse(statement.getResource()))
#           except:
#               print "Unable to interpret seas:entity value (of type seas:Entity) as resource."
#               traceback.print_exc()
#           return

# generatedat
        if predicate == PROPERTY.LIST:
            try:
                list_python, listType = statement.getResource().toList(
                    Evaluation)
                self.setList(list_python, listType)
            except:
                print "Unable to interpret seas:list value as list."
                traceback.print_exc()
            return

        # generatedat
        if predicate == PROPERTY.MAP:
            try:
                self.setMap(Map().parse(statement.getResource()))
            except:
                print "Unable to interpret seas:map value as resource."
                traceback.print_exc()
            return

        # pass on to Obj
        super(Evaluation, self).parseStatement(statement)