def _resolve_tags(self, tag): try: if urlparse(tag).scheme in ('http', 'https'): resolved = label_list_yso(tag) if resolved: return resolved except: pass return [tag]
def _future_keywords_to_labels_urls_implementation(): ''' This old code is kept here for now if needed in future ''' # JuhoL: extract, process and save keywords # JuhoL: keywords, match elements <keyword> <topClass> keywords = stdy_dscr.stdyInfo.subject(re.compile('keyword|topcClas')) keywords = list(set(keywords)) # JuhoL: For what? Transforming, filtering? idx = 0 for kw in keywords: if not kw: continue #vocab = None #if 'vocab' in kw.attrs: # vocab = kw.attrs.get("vocab", None) if not kw.string: continue tag = kw.string.strip() if tag.startswith('http://www.yso.fi'): tags = utils.label_list_yso(tag) pkg.extras['tag_source_%i' % idx] = tag idx += 1 elif tag.startswith('http://') or tag.startswith('https://'): pkg.extras['tag_source_%i' % idx] = tag idx += 1 tags = [] # URL tags break links in UI. else: tags = [tag] for tagi in tags: #pkg.add_tag_by_name(t[:100]) tagi = tagi[:100] # 100 char limit in DB. tag_obj = model.Tag.by_name(tagi) if not tag_obj: tag_obj = model.Tag(name=tagi) tag_obj.save() pkgtag = model.Session.query(model.PackageTag).filter( model.PackageTag.package_id==pkg.id).filter( model.PackageTag.tag_id==tag_obj.id).limit(1).first() if not pkgtag: pkgtag = model.PackageTag(tag=tag_obj, package=pkg) pkgtag.save() # Avoids duplicates if tags has duplicates.