-
Notifications
You must be signed in to change notification settings - Fork 7
FAqT Service for CKAN Datasets
Tim L edited this page Jul 6, 2014
·
14 revisions
- Getting Started
- CKAN - an introduction to using CKAN.
- FAqT Service - how to create one.
This page describes how to use the ckanclient within a FAqT Service to talk to a varying number of CKAN instances.
The following services implement how to communicate to a CKAN instance for every resource processed:
- by-ckan-installation.py parses the URI to get the base:
print 'processing ' + input.subject
base = input.subject.replace('/$','')
api = base
ckan = ckanclient.CkanClient(input.subject+'/api')
- lift-ckan.py uses the default ckanclient, but will change it if the dataset is attributed to a CKAN instance:
ckan = self.ckan
if len(input.prov_wasAttributedTo) > 0:
agent = input.prov_wasAttributedTo.first
print 'CKAN: ' + agent.subject
if ns.DATAFAQS['CKAN'] in agent.rdf_type:
ckan = ckanclient.CkanClient(input.prov_wasAttributedTo.first.subject+'/api')
For example, the following input will lead the FAqT Service to call http://hub.healthdata.gov/api
(the /api
is appended to the URI of the CKAN):
<http://hub.healthdata.gov/dataset/hospital-compare>
a datafaqs:CKANDataset;
rdfs:comment "Omitting datafaqs:ckan_identifier will fall back to parsing the URI.";
prov:wasAttributedTo <http://hub.healthdata.gov>;
.
<http://hub.healthdata.gov>
a datafaqs:CKAN;
rdfs:comment "If the CKANDataset was attributed to a CKAN, ask that CKAN about it.";
.
-
faqt.py encapsulates both of these in the method
getCKANAPI
; it's used like:
def process(self, input, output):
print 'processing ' + input.subject
ckan = self.getCKANAPI(input) # returns a ckanclient.CkanClient
ckan_id = self.getCKANIdentiifer(input) # returns the dataset identifier within CKAN's URI for the dataset.
try:
ckan.package_entity_get(ckan_id)
...
Java FAqT services can extend edu.rpi.tw.data.ckan.CKANReader.