Skip to content

Commit

Permalink
Deduce tags from INSPIRE keywords when importing a dataset.
Browse files Browse the repository at this point in the history
This addresses #135 (partially, covers only the import case).
  • Loading branch information
drmalex07 committed Jun 8, 2015
1 parent 66db577 commit ae9cda7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ckanext/publicamundi/lib/metadata/schemata/thesaurus.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class IThesaurusTerms(IObject):
min_length = 1,
max_length = 8)

def iter_terms():
'''Provide an iterator on terms.
'''

@zope.interface.invariant
def check_terms(obj):
unexpected_terms = []
Expand Down
27 changes: 25 additions & 2 deletions ckanext/publicamundi/lib/metadata/types/inspire_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ class InspireMetadata(BaseMetadata):
responsible_party = list

def deduce_basic_fields(self):
'''Deduce basic (i.e. core CKAN) fields from self.
'''

data = super(InspireMetadata, self).deduce_basic_fields()

data['notes'] = self.abstract
# id (applicable only for imported/harvested)

identifier = None
try:
identifier = uuid.UUID(self.identifier)
Expand All @@ -100,6 +103,26 @@ def deduce_basic_fields(self):
else:
data['id'] = str(identifier)

# notes

data['notes'] = self.abstract

# Todo version

# tags: Collect free keywords and thesauri terms (see #135)

tags = []

for kw in self.free_keywords:
tags.append(dict(name=kw.value, display_name=kw.value))

for thes_name, thes_terms in self.keywords.items():
for term in thes_terms.iter_terms():
tags.append(dict(name=term.value, display_name=term.title))

if tags:
data['tags'] = tags

return data

# XML serialization
Expand Down
10 changes: 9 additions & 1 deletion ckanext/publicamundi/lib/metadata/types/thesaurus.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ class ThesaurusTerms(Object):

zope.interface.implements(IThesaurusTerms)

# Fixme: Maybe point here to a factory for named Thesaurus objects
thesaurus = Thesaurus

terms = list

def iter_terms(self):
vocabulary = self.thesaurus.vocabulary.by_value
for t in self.terms:
yield vocabulary.get(t)

__iter__ = iter_terms



0 comments on commit ae9cda7

Please sign in to comment.