def getServerAddress(self):
return self.serverAddress
-
def setServerAddress(self, serverAddress):
print "setting address", self, serverAddress
self.serverAddress = serverAddress
-
def debugMode(self):
return self.debug
-
def setDebugMode(self, mode):
self.debug = mode
import datetime
from pytz import timezone
from urlparse import urlparse
+from SmartAPI.agents.Agent import Agent
from SmartAPI.model.Entity import Entity
from SmartAPI.model.Activity import Activity
from SmartAPI.model.Coordinates import Coordinates
from rdflib.term import URIRef
-class SearchAgent(object):
+class SearchAgent(Agent):
remoteURL = FIND_URI
debug = False
def __init__(self, myUri=''):
+ Agent.__init__(self)
self.generatedBy = myUri
self.entity = Entity()
#self.entity.clearTypes()
@classmethod
def setRegistrationServiceUri(cls, serverURI):
cls.setServerAddress(serverURI)
-
+
+ def setEntity(self, e):
+ self.entity = e
+
+ def doSearch(self):
+ return self.search()
+
def search(self):
from SmartAPI.model.Response import Response
return agent.search()
@classmethod
- def fetchBySmartAPIId(cls, myId, idToFetch):
+ def fetchBySmartAPIId(cls, myId, idToFetch):
'''
only return one entity if there is.
'''
agent.entity = e
res = agent.search()
if res is not None and len(res) > 0:
- return res[0]
+ return res[0]
@classmethod
def searchByPoint(cls, myId, latitude, longitude, distanceInKm, entityType=None):
condition.addOr(Obj(type))
self.entity.clearTypes()
self.entity.addType(condition)
-
+
def daysOldData(self, days):
'''
Define how many days old data will be searched.
'''
duration = Duration(days=days)
self.entity.add(URIRef(PROPERTY.FRESHNESS), duration)
-
+
def monthsOldData(self, months):
'''
Define how many months old data will be searched.
duration = Duration(minutes=minutes)
self.entity.add(URIRef(PROPERTY.FRESHNESS), duration)
-
def anyOfNames(self, searchStrings):
'''
Define multiple search strings for the entity name (label). Will return also partial hits
self.methods.append(m)
def _parseStatement(self, statement, custom_classes = None):
+ from SmartAPI.model.Person import Person
self.parse_property(statement, PROPERTY.PERSON, self.setPerson, Person, custom_classes = custom_classes)
self.parse_property(statement, PROPERTY.METHOD, self.addMethod, Variant, custom_classes = custom_classes)
super(Authorization, self)._parseStatement(statement, custom_classes = custom_classes)
myIdentity = "http://adapt.asema.com/demos/python/datasource/"
adaptServiceIdentity = "http://adapt.asema.com"
#registrationServerUri = "http://find.smart-api.io/smart/v1.0e1.0/access"
+#registrationServerKeyUri = "http://find.smart-api.io/smart/v1.0e1.0/key"
registrationServerUri = "http://192.168.2.96:8080/smartapifind-core/smart/v1.0e1.0/access"
registrationServerKeyUri = "http://192.168.2.96:8080/smartapifind-core/smart/v1.0e1.0/key"
--- /dev/null
+#!/usr/bin/python
+
+from SmartAPI.agents.SearchAgent import SearchAgent
+
+from SmartAPI.common.Tools import Tools
+from SmartAPI.common.RESOURCE import RESOURCE
+
+from SmartAPI.model.Activity import Activity
+from SmartAPI.model.Condition import Condition
+from SmartAPI.model.Entity import Entity
+
+
+myIdentity = "http://adapt.asema.com/demos/python/datasourcesearch/"
+adaptServiceIdentity = "http://adapt.asema.com"
+registrationServerUri = "http://find.smart-api.io/smart/v1.0e1.0/access"
+#registrationServerUri = "http://192.168.2.96:8080/smartapifind-core/smart/v1.0e1.0/access"
+
+
+class SampleSearch(object):
+
+ def __init__(self):
+ pass
+
+ def do(self):
+ agent = SearchAgent(myIdentity)
+ agent.setServerAddress(registrationServerUri)
+ agent.setDebugMode(True)
+
+ e = Entity()
+ e.setServedBy(adaptServiceIdentity)
+ agent.setEntity(e)
+
+ result = agent.doSearch()
+
+ if len(result) > 0:
+ print "FOUND THE FOLLOWING:"
+ for r in result:
+ r.turtlePrint()
+ else:
+ print "No results found."
+
+def main():
+ s = SampleSearch()
+ s.do()
+
+
+if __name__ == '__main__':
+ main()
+