source: exist/trunk/python/ndgUtils/vocabtermdata.py @ 4248

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgUtils/vocabtermdata.py@4248
Revision 4248, 21.2 KB checked in by cbyrom, 11 years ago (diff)

Add online reference terms data to the vocabtermdata class + extend the
utility methods to allow the retrieval of this data.

Line 
1#!/usr/bin/env python
2'''
3 Class to store and access the various vocab term data
4 
5 @author: C Byrom, Tessella Jul 2008
6'''
7import sys, logging, commands, string, os, time, re
8import urllib
9
10class VocabTermItem(object):
11    '''
12    Class representing single vocab term item
13    '''
14    def __init__(self, vocabURL, termID, title=None):
15        self.vocabURL = vocabURL
16        self.termID = termID
17        self.title = title
18
19
20class VocabTermData(object):
21    '''
22    Class representing vocab term data - including
23    methods to look these up to ensure they are current
24    '''
25
26    OBJECT_PAGE_TERM = 'ObjectPage'
27    DATA_URL_TERM = 'DataURL'
28    DATA_PAGE_TERM = 'DataPage'
29    CURATOR_PAGE_TERM = 'CuratorPage'
30    EXT_METADATA_TERM = 'ExtMetadata'
31    METADATA_SOURCE_TERM = 'MetadataSource'
32    URI_TERM = 'URI'
33    LOGO_TERM = 'LOGO'
34    NUM_SIM_TERM = 'NumSim'
35    OPENDAP_TERM = 'OPENDAP'
36    THREDDS_TERM = 'THREDDS'
37    WMS_TERM = 'WMS'
38    WCS_TERM = 'WCS'
39    WFS_TERM = 'WFS'
40    LAS_TERM = 'LAS'
41    DATA_EXTRACTOR_TERM = 'DataExtractor' 
42    FILE_BROWSER_TERM = 'FileBrowser'   
43    CSML_TERM = 'CSML'
44   
45    ACTIVITY_TERM = 'ACTIVITY'
46    DPT_TERM = 'DPT'
47    OBS_TERM = 'OBS'
48    GRANULE_TERM = 'GRANULE'
49    DE_TERM = "DE"
50   
51    # dpt subtypes
52    LIDAR_TERM = "dgLidar"
53    RADAR_TERM = "dgRadar"
54    SONDE_TERM = "dgSonde"
55    NAVIGATION_TERM = "dgNavigation"
56    GAS_CHROMATOGRAPH_TERM = "dgGasChromatograph"
57    SPECTROMETER_TERM = "dgSpectrometer"
58    MASS_SPECTROMETER_TERM = "dgMassSpectrometer"
59    MET_SENSOR_TERM = "dgMetSensor"
60    DOAS_TERM = "dgDOAS"
61    ASOZ_TERM = "dgASOZ"
62    RADIOMETER_TERM = "dgRadiometer"
63    FAGE_TERM = "dgFAGE"
64    IMAGER_TERM = "dgImager"
65    FILTER_TERM = "dgFilter"
66    PARTICLE_COUNTER_TERM = "dgParticleCounter"
67    SAMPLER_TERM = "dgSampler"
68    OTHER_INSTRUMENT_TYPE_TERM = "dgOtherInstrumentType"
69    MODEL_TERM = "dgModel"
70    INSTRUMENT_TERM = "dgInstrument"
71   
72    # de subtypes
73    SIMULATION_TERM = "dgSimulation"
74    ANALYSIS_TERM = "dgAnalysis"
75    MEASUREMENT_TERM = "dgMeasurement"
76   
77    # activity subtypes
78    DATA_COLLECTION_TERM = "dgActivityDataCollection"
79    DATA_PROJECT_TERM = "dgActivityDataProject"
80    DATA_CAMPAIGN_TERM = "dgActivityDataCampaign"
81    DATA_INVESTIGATION_TERM = "dgActivityDataInvestigation"
82    FLIGHT_TERM = "dgFlight"
83    CRUISE_TERM = "dgCruise"
84    FUNDING_PROGRAM_TERM = "dgFundingProgram"
85   
86    # obs subtypes
87    STATIONARY_PLATFORM_TERM = "dgStationaryPlatform"
88    MOVING_PLATFORM_TERM = "dgMovingPlatform"
89    LAND_STATION_TERM = "dgLandStation"
90    MOORING_TERM = "dgMooring"
91    STATION_GROUP_TERM = "dgStationGroup"
92    SHIP_TERM = "dgShip"
93    AIRCRAFT_TERM = "dgAircraft"
94    SATELLITE_TERM = "dgSatellite"
95    COMPUTER_TERM = "dgComputer"
96
97    # provider types
98    BADC_TERM = 'badc.nerc.ac.uk'
99    NEODC_TERM = 'neodc.nerc.ac.uk'
100   
101    TERM_DATA = {
102                 OBJECT_PAGE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '1', title = 'Object Home Page'),
103                 DATA_URL_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '2', title = 'Data URL'),
104                 DATA_PAGE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '3', title = 'Data Home Page'),
105                 CURATOR_PAGE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '4', title = 'Curator Home Page'),
106                 EXT_METADATA_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '5', title = 'Extended Metadata'),
107                 METADATA_SOURCE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '6', title = 'Original Metadata Source'),
108                 #URI_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '3URI', title = 'Data Home Page'),
109                 BADC_TERM:VocabTermItem('NOT YET SET UP', BADC_TERM, title = 'British Atomspheric Data Centre'),
110                 NEODC_TERM:VocabTermItem('NOT YET SET UP', NEODC_TERM, title = 'NERC Earth Observation Data Centre'),
111                 LOGO_TERM:VocabTermItem('LOGO', 'LOGO', title = 'Logo'),
112                 NUM_SIM_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '7', title = 'NumSim description'),
113                 OPENDAP_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/P201', 'GCMDU010', title = 'GET DATA > OPENDAP DATA (DODS)'),
114                 THREDDS_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/P201', 'GCMDU013', title = 'GET DATA > THREDDS DATA'),
115                 WMS_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/P201', 'GCMDU026', title = 'GET SERVICE > GET WEB MAP SERVICE (WMS)'),
116                 WCS_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/P201', 'GCMDU024', title = 'GET SERVICE > GET WEB COVERAGE SERVICE (WCS)'),
117                 WFS_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/P201', 'GCMDU025', title = 'GET SERVICE > GET WEB FEATURE SERVICE (WFS)'),
118                 LAS_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/P201', 'GCMDU006', title = 'GET DATA > LAS'),
119                 DATA_EXTRACTOR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '8', title = 'NDG DataExtractor'),
120                 FILE_BROWSER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '9', title = 'File Browser'),
121                 CSML_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N021', '1'),
122                 ACTIVITY_TERM:VocabTermItem('Activity - NOT YET SET UP', ACTIVITY_TERM, title = 'Activity'),
123                 DPT_TERM:VocabTermItem('DPT - NOT YET SET UP', DPT_TERM, title = 'Data Production Tool'),
124                 OBS_TERM:VocabTermItem('OBS - NOT YET SET UP', OBS_TERM, title = 'Observation Station'),
125                 GRANULE_TERM:VocabTermItem('GRAN - NOT YET SET UP', GRANULE_TERM, title = 'Data Granule'),
126                 DE_TERM:VocabTermItem('DE - NOT YET SET UP', DE_TERM, title = 'Data Entity'),
127                 
128                 LIDAR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG02', title = LIDAR_TERM),
129                 RADAR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG03', title = RADAR_TERM),
130                 SONDE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG04', title = SONDE_TERM),
131                 NAVIGATION_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG05', title = NAVIGATION_TERM),
132                 GAS_CHROMATOGRAPH_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG06', title = GAS_CHROMATOGRAPH_TERM),
133                 SPECTROMETER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG07', title = SPECTROMETER_TERM),
134                 MASS_SPECTROMETER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG08', title = MASS_SPECTROMETER_TERM),
135                 MET_SENSOR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG09', title = MET_SENSOR_TERM),
136                 DOAS_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG10', title = DOAS_TERM),
137                 ASOZ_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG11', title = ASOZ_TERM),
138                 RADIOMETER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG12', title = RADIOMETER_TERM),
139                 FAGE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG13', title = FAGE_TERM),
140                 IMAGER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG14', title = IMAGER_TERM),
141                 FILTER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG15', title = FILTER_TERM),
142                 PARTICLE_COUNTER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG16', title = PARTICLE_COUNTER_TERM),
143                 SAMPLER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG17', title = SAMPLER_TERM),
144                 OTHER_INSTRUMENT_TYPE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG99', title = OTHER_INSTRUMENT_TYPE_TERM),
145                 MODEL_TERM:VocabTermItem('dgModel - NOT YET SET UP', MODEL_TERM, title = MODEL_TERM),
146                 INSTRUMENT_TERM:VocabTermItem('dgInstrument - NOT YET SET UP', INSTRUMENT_TERM, title = INSTRUMENT_TERM),
147                 
148                 SIMULATION_TERM:VocabTermItem('NOT YET SET UP', SIMULATION_TERM, title = SIMULATION_TERM),
149                 ANALYSIS_TERM:VocabTermItem('NOT YET SET UP', ANALYSIS_TERM, title = ANALYSIS_TERM),
150                 MEASUREMENT_TERM:VocabTermItem('NOT YET SET UP', MEASUREMENT_TERM, title = MEASUREMENT_TERM),
151                 DATA_COLLECTION_TERM:VocabTermItem('NOT YET SET UP', DATA_COLLECTION_TERM, title = DATA_COLLECTION_TERM),
152                 DATA_PROJECT_TERM:VocabTermItem('NOT YET SET UP', DATA_PROJECT_TERM, title = DATA_PROJECT_TERM),
153                 DATA_CAMPAIGN_TERM:VocabTermItem('NOT YET SET UP', DATA_CAMPAIGN_TERM, title = DATA_CAMPAIGN_TERM),
154                 DATA_INVESTIGATION_TERM:VocabTermItem('NOT YET SET UP', DATA_INVESTIGATION_TERM, title = DATA_INVESTIGATION_TERM),
155                 FLIGHT_TERM:VocabTermItem('NOT YET SET UP', FLIGHT_TERM, title = FLIGHT_TERM),
156                 CRUISE_TERM:VocabTermItem('NOT YET SET UP', CRUISE_TERM, title = CRUISE_TERM),
157                 FUNDING_PROGRAM_TERM:VocabTermItem('NOT YET SET UP', FUNDING_PROGRAM_TERM, title = FUNDING_PROGRAM_TERM),
158                 
159                 STATIONARY_PLATFORM_TERM:VocabTermItem('NOT YET SET UP', STATIONARY_PLATFORM_TERM, title = STATIONARY_PLATFORM_TERM),
160                 MOVING_PLATFORM_TERM:VocabTermItem('NOT YET SET UP', MOVING_PLATFORM_TERM, title = MOVING_PLATFORM_TERM),
161                 LAND_STATION_TERM:VocabTermItem('NOT YET SET UP', LAND_STATION_TERM, title = LAND_STATION_TERM),
162                 MOORING_TERM:VocabTermItem('NOT YET SET UP', MOORING_TERM, title = MOORING_TERM),
163                 STATION_GROUP_TERM:VocabTermItem('NOT YET SET UP', STATION_GROUP_TERM, title = STATION_GROUP_TERM),
164                 SHIP_TERM:VocabTermItem('NOT YET SET UP', SHIP_TERM, title = SHIP_TERM),
165                 AIRCRAFT_TERM:VocabTermItem('NOT YET SET UP', AIRCRAFT_TERM, title = AIRCRAFT_TERM),
166                 SATELLITE_TERM:VocabTermItem('NOT YET SET UP', SATELLITE_TERM, title = SATELLITE_TERM),
167                 COMPUTER_TERM:VocabTermItem('NOT YET SET UP', COMPUTER_TERM, title = COMPUTER_TERM)
168                 }
169
170    ATOM_TYPES = [ACTIVITY_TERM, DE_TERM, DPT_TERM, GRANULE_TERM, OBS_TERM]
171
172    PROVIDER_TYPES = [BADC_TERM, NEODC_TERM]
173
174    ONLINE_REF_TYPES = [ OBJECT_PAGE_TERM, DATA_URL_TERM, DATA_PAGE_TERM, \
175                         CURATOR_PAGE_TERM, EXT_METADATA_TERM, METADATA_SOURCE_TERM, \
176                         NUM_SIM_TERM, \
177                         OPENDAP_TERM, THREDDS_TERM, WMS_TERM, WCS_TERM, WFS_TERM, \
178                         DATA_EXTRACTOR_TERM, FILE_BROWSER_TERM, LAS_TERM, LOGO_TERM]
179#URI_TERM, \
180
181    ATOM_CATEGORY = "atom"
182    ONLINE_REF_CATEGORY = "onlineref"
183    PROVIDER_CATEGORY = "provider"
184   
185    # A dictionary to group the various valid subtypes of atoms - grouped by their
186    # main type
187    SUBTYPE_TERMS = {
188                     DPT_TERM: [
189                        LIDAR_TERM, RADAR_TERM, \
190                        SONDE_TERM, NAVIGATION_TERM, \
191                        GAS_CHROMATOGRAPH_TERM, SPECTROMETER_TERM, \
192                        MASS_SPECTROMETER_TERM,
193                        MET_SENSOR_TERM, DOAS_TERM,
194                        ASOZ_TERM, RADIOMETER_TERM,
195                        FAGE_TERM, IMAGER_TERM,
196                        FILTER_TERM, PARTICLE_COUNTER_TERM,
197                        SAMPLER_TERM, OTHER_INSTRUMENT_TYPE_TERM,
198                        MODEL_TERM, INSTRUMENT_TERM
199                        ],
200                     DE_TERM: [
201                        SIMULATION_TERM, ANALYSIS_TERM, \
202                        MEASUREMENT_TERM       
203                        ],
204                     ACTIVITY_TERM: [
205                        DATA_COLLECTION_TERM, DATA_PROJECT_TERM, \
206                        DATA_CAMPAIGN_TERM, DATA_INVESTIGATION_TERM, \
207                        FLIGHT_TERM, CRUISE_TERM, \
208                        FUNDING_PROGRAM_TERM,
209                        ],
210                     OBS_TERM: [
211                        STATIONARY_PLATFORM_TERM, MOVING_PLATFORM_TERM, \
212                        LAND_STATION_TERM, MOORING_TERM, \
213                        STATION_GROUP_TERM, SHIP_TERM, \
214                        AIRCRAFT_TERM, SATELLITE_TERM, \
215                        COMPUTER_TERM
216                        ]
217                     }
218             
219   
220    ONE_HOUR = 3600.0
221   
222    VOCAB_SERVER_URL = 'http://vocab.ndg.nerc.ac.uk/clients/whatLists'
223
224    BROWSE_ROOT_URL = "http://localhost:5000/view/"
225
226    def __init__(self):
227        logging.info("Setting up VocabTermData object")
228        self.VOCAB_DATA_PAGE = None
229        self.REFRESH_TIME = time.time()
230        self.latestTermVersion = {}
231        logging.info("VocabTermData object set up")
232
233
234    def isValidSubType(self, mainType, subType):
235        '''
236        Determine whether a specified subtype is valid for a particular
237        main type
238        @param mainType: term ID of the main type of the data
239        @param subType: term ID of the subtype of the data
240        @return: True if the subtype is valid
241        @raise ValueError: if the mainType is not recognised or the subType is not valid
242        '''
243        if not self.SUBTYPE_TERMS.has_key(mainType):
244            errorMessage = "Error: unrecognised data type: '%s'" %mainType
245            logging.error(errorMessage)
246            raise ValueError(errorMessage)
247
248        if subType in self.SUBTYPE_TERMS[mainType]:
249            return True
250           
251        errorMessage = "Error: subtype, '%s' is not valid for data type, '%s'" \
252            %(subType, mainType)
253        logging.error(errorMessage)
254        raise ValueError(errorMessage)
255
256
257    def getValidTypes(self, category):
258        '''
259        Return a list of the valid types available for a particular data category
260        @param category: type of term info to look up - e.g. atoms or providers
261        - this should be specified using the ..._CATEGORY instance variables
262        defined above
263        @return list of VocabTermInfo objects for the specified category
264        '''
265        logging.debug("Lookup up list of valid %s types" %category)
266        catList = []
267        if category == self.ATOM_CATEGORY:
268            catList = self.ATOM_TYPES
269        elif category == self.PROVIDER_CATEGORY:
270            catList = self.PROVIDER_TYPES
271        elif category == self.ONLINE_REF_CATEGORY:
272            catList = self.ONLINE_REF_TYPES
273        else:
274            errorMessage = "Unrecognised data category, '%s'" %category
275            logging.info(errorMessage)
276            raise ValueError(errorMessage)
277           
278        types = []
279        for st in catList:
280            types.append(self.TERM_DATA[st])
281        return types
282
283
284    def getValidSubTypes(self, atomType):
285        '''
286        Get list of subtypes that are valid wrt a specified atom type
287        @param atomType: term ID for the atom type whose subtypes need to
288        be looked up
289        @return: list of valid subtypes
290        '''
291        logging.debug("Lookup up subtypes for atom type, '%s'" %atomType)
292        subTypes = self.SUBTYPE_TERMS.get(atomType) or []
293        types = []
294        for st in subTypes:
295            item = self.TERM_DATA[st]
296            # tidy up the title slightly, if need be
297            if item.title and item.title.startswith('dg'):
298                item.title = item.title[2:]
299                # and fix any camelcase - putting into words
300                item.title = re.sub('([A-Z])', r" \1", item.title).strip()
301            types.append(item)
302        logging.debug("Found subtypes: %s" %subTypes)
303        return types
304
305       
306    def getTermFromTitle(self, title):
307        '''
308        Given a term title/label, get back the related term id
309        @param title: title/label of term id to retrieve
310        @raise ValueError: if more than one title or no title is returned 
311        '''
312        termID = []
313        for val in self.TERM_DATA.itervalues():
314            if val.title == title:
315                termID.append(val.termID)
316       
317        if len(termID) != 1:
318            errorMessage = "Error: could not accurately determine the vocab term \
319                ID for the label, '%s' - %s values returned" %(title, len(termID))
320            logging.error(errorMessage)
321            raise ValueError(errorMessage)
322
323        return termID[0]
324       
325
326    def _getVocabDataPage(self):
327        '''
328        Getter method to allow regular refreshing of data
329        '''
330        if self.REFRESH_TIME < time.time():
331            self.getVocabServerData()
332       
333        return self.VOCAB_DATA_PAGE
334
335   
336    def getVocabServerData(self):
337        '''
338        Retrieve the web page containing the versioning info for the various vocab terms
339        '''
340        logging.info("Retrieving vocab server data page")
341        f = urllib.urlopen(self.VOCAB_SERVER_URL)
342        self.VOCAB_DATA_PAGE = f.read()
343        f.close()
344        self.REFRESH_TIME = time.time() + self.ONE_HOUR
345        logging.info("Vocab server data retrieved")
346
347
348    def getLatestTermVersions(self):
349        '''
350        Retrieve the latest versions of the vocab terms required
351        - NB, refreshes the data on an hourly basis, if necessary
352        '''
353        # now need to parse the returned data to get the current version number
354        for termName in self.TERM_DATA:
355            if termName not in self.latestTermVersion:
356                self.getLatestTermVersion(termName)
357
358                   
359    def getLatestTermVersion(self, termName):
360        '''
361        Parse the vocab server data and determine the latest version number of the term with the specified name
362        @param termName: name of term whose current version needs to be established
363        '''
364        logging.info("Getting latest term version for term, '%s'" %termName)
365        # check for recent data - NB, the term will probably share a base url with other terms
366        # so may have already have the correct URL set up
367        if termName not in self.latestTermVersion or self.REFRESH_TIME < time.time():
368   
369            uri = self.TERM_DATA[termName].vocabURL
370            currentVersion = self._getURIVersion(uri)
371   
372            self.latestTermVersion[termName] = str(currentVersion)
373        logging.info("Latest term version for term, '%s' retrieved" %termName)
374
375
376    def _getURIVersion(self, uri):
377        '''
378        Parse the server data for a specified uri and return the latest version number of it
379        @param uri: uri to look for
380        @raise ValueError: if specified uri not found in vocab server
381        @return version of vocab uri, '' if uri contains latest version and None if uri not found
382        '''
383        # allow the data to be refreshed on an hourly basis
384        pageData = self._getVocabDataPage()
385       
386        uri = uri.replace('/term/','/list/')
387        if uri.endswith('/'):
388            uri = uri.rstrip('/')
389        # NB, the uri may already have a version number included in it - so allow this in the search
390        regExp = re.compile(r'(' + uri + '(/(\d{1,}))?)')
391        currentVersion = None
392        foundTerm = False
393        for termVals in regExp.findall(pageData):
394            foundTerm = True
395            version = termVals[2]
396            # version number must be included in original uri, if match found without a version number
397            # being split out - so ignore this - since the original uri is already specified in full
398            if not version:
399                currentVersion = ''
400                break
401
402            # TODO: check how the versioning system will be done - i.e. 3.2.4 type versioning will cause this to break
403            if not currentVersion:
404                currentVersion = int(version)
405            elif int(version) > currentVersion:
406                currentVersion = int(version)
407
408        if currentVersion == None:
409            errorMessage = "Could not find information in vocab server for uri, '%s' - exiting" %uri
410            logging.error(errorMessage)
411            # TODO: uncomment the ValueError once all the vocab terms have been defined
412            #raise ValueError(errorMessage)
413
414        return currentVersion
415
416       
417    def getTermCurrentVocabURL(self, termName):
418        '''
419        Get the current URL on the vocab server to the specified term
420        @param termName: name of term whose URL to return
421        '''
422        logging.debug("Looking up vocab data for term: '%s'" %termName)
423       
424        if termName not in self.TERM_DATA:
425            errorMessage = "Could not find term, '%s' in defined list of valid vocab terms - exiting" %termName
426            logging.error(errorMessage)
427            raise ValueError(errorMessage)
428       
429        if termName not in self.latestTermVersion:
430            self.getLatestTermVersion(termName)
431
432        uri = self.TERM_DATA[termName].vocabURL + \
433            "/" + self.latestTermVersion[termName] + "/" + \
434            self.TERM_DATA[termName].termID
435        logging.debug("Returning vocab URL: '%s'" %uri)
436        return  uri
437   
438   
439    def getCurrentVocabURI(self, uri):
440        '''
441        Look up a specified URI and return the current version of it
442        '''
443        logging.debug("Looking up current version of uri: '%s'" %uri)
444        currentVersion = self._getURIVersion(uri)
445        logging.debug("URI version looked up")
446        if currentVersion:
447            if not uri.endswith('/'):
448                uri += '/'
449            return uri + str(currentVersion)
450        return uri
Note: See TracBrowser for help on using the repository browser.