OKKAM Community Portal

 
  • Increase font size
  • Default font size
  • Decrease font size
Home -> Documentation -> APIs -> Entity Search in Python (Code Example)

Entity Search in Python (Code Example)

E-mail Print PDF

This is example code in python on how to access the ENS search API. You can download the examples in the attached ZIP file.

 

 

ENS ID Search in 10 LOC 


query = "QUERY{Paolo Bouquet}METADATA{entityType=person}" 
from suds.client import Client
import EnsClientEntity
endpoint = "http://api.okkam.org/okkam-core/WebServices?wsdl"
client = Client(endpoint)
result = client.service.findEntity(query)
for candidate in result:
xml = candidate["XML"].encode('utf-8')
entity = EnsClientEntity.parseString(xml)
print entity.get_oid(),". sim:",candidate["sim"] 
 
 

Detailed comments inline 

 
#query = "Yosemite National Park"
query = "QUERY{Paolo Bouquet}METADATA{entityType=person}"


#------ ENS ID Search in 10 LOC --------

# you'll need the suds package to use our SOAP service
# see the suds docu if you are behind a proxy server
from suds.client import Client

# the EnsClientEntity class was auto-generated by generateDS.py
# http://www.rexx.com/~dkuhlman/generateDS.html
# this is our main data structure containing the entity description
import EnsClientEntity

# this is the WSDL file of the okkam ENS
endpoint = "http://api.okkam.org/okkam-core/WebServices?wsdl"

# this you'd probably do only once and then re-use the connection
client = Client(endpoint)

# now you send your query to the ENS
result = client.service.findEntity(query)

# result is a list of objects containing 
# okkamid, similarity and XML string with the complety entity data
for candidate in result:
# make sure no garbage characters bother us
xml = candidate["XML"].encode('utf-8')
# parse XML data from server into EnsClientEntity
entity = EnsClientEntity.parseString(xml)
# here you see how to access the data
# maybe you want to use DataDumper to inspect the object
print entity.get_oid(),". sim:",candidate["sim"]

Attachments:
Download this file (ensquery.zip)ensquery.zip[ ]8 Kb04/03/10 13:56
Last Updated on Thursday, 04 March 2010 14:00