Skip to content

Commit

Permalink
capture concept-scheme structure in database field (#812)
Browse files Browse the repository at this point in the history
* proposal to capture full concept-scheme structure in database field, to facilitate inclusion of themes in ogcapi-records

* use the new structure of ogcapi-records for themes

uses identification.keywords2 and keyword_object awaiting release of owslib
  • Loading branch information
pvgenuchten authored Dec 7, 2022
1 parent 2b94076 commit 817c7df
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions etc/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'pycsw:Abstract': 'abstract',
'pycsw:Keywords': 'keywords',
'pycsw:KeywordType': 'keywordstype',
'pycsw:Themes': 'themes',
'pycsw:Format': 'format',
'pycsw:Source': 'source',
'pycsw:Date': 'date',
Expand Down
1 change: 1 addition & 0 deletions pycsw/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def setup_db(database, table, home, create_sfsql_tables=True, create_plpythonu_f
Column('edition', Text, index=True),
Column('keywords', Text, index=True),
Column('keywordstype', Text, index=True),
Column('themes', Text, index=True),
Column('parentidentifier', Text, index=True),
Column('relation', Text, index=True),
Column('time_begin', Text, index=True),
Expand Down
1 change: 1 addition & 0 deletions pycsw/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def __init__(self, prefix='csw30'):
'pycsw:Edition': 'edition',
'pycsw:Keywords': 'keywords',
'pycsw:KeywordType': 'keywordstype',
'pycsw:Themes': 'themes',
'pycsw:Format': 'format',
'pycsw:Source': 'source',
'pycsw:Date': 'date',
Expand Down
4 changes: 4 additions & 0 deletions pycsw/core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,10 @@ def _parse_iso(context, repos, exml):
all_keywords = [item for sublist in md.identification.keywords for item in sublist['keywords'] if item is not None]
_set(context, recobj, 'pycsw:Keywords', ','.join(all_keywords))
_set(context, recobj, 'pycsw:KeywordType', md.identification.keywords[0]['type'])
_set(context, recobj, 'pycsw:Themes',
# OWSlib currently stores keywords extended with thesaurus in keywords2, see https://github.com/geopython/OWSLib/issues/301
json.dumps([t for t in md.identification.keywords2 if t.thesaurus is not None],
default=lambda o: o.__dict__))

if (hasattr(md.identification, 'creator') and
len(md.identification.creator) > 0):
Expand Down
11 changes: 11 additions & 0 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,17 @@ def record2json(record, url, collection, stac_item=False):
})
record_dict['properties']['providers'] = rcnt

if record.themes:
ogcapiThemes = []
# For a scheme, prefer uri over label
# OWSlib currently uses .keywords_object for keywords with url, see https://github.com/geopython/OWSLib/pull/765
for theme in json.loads(record.themes):
ogcapiThemes.append({
'scheme': theme['thesaurus'].get('url',theme['thesaurus'].get('title','')),
'concepts': [c for c in theme.get('keywords_object',[]) if c not in [None,""]]
})
record_dict['properties']['themes'] = ogcapiThemes

if record.links:
rdl = record_dict['links']

Expand Down
26 changes: 17 additions & 9 deletions pycsw/ogc/api/templates/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,24 @@ <h2>{{ data['id'] }}</h2>
{% endfor %}
</ul>
</td>
{% elif key == 'themes' %}
<td>
{% for theme in value %}
<b>{{ theme['scheme'] }}</b>
<ul>
{% for concept in theme['concepts'] %}
<li>{{ concept }}</li>
{% endfor %}
</ul>

{% elif key == 'themes' %}
<td>
{% for theme in value %}

<b>{{ theme['scheme'] }}</b>
<ul>
{% for concept in theme['concepts'] %}
<li>
{% if concept['url'] %}
<a href="{{ concept['url'] }}">{{ concept['name'] or concept['url'] }}</a>
{% else %}
{{ concept['name'] }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endfor %}
</td>
{% elif key == 'externalIds' %}
<td>
Expand Down
Binary file not shown.
Binary file modified tests/functionaltests/suites/cite/data/cite.db
Binary file not shown.

0 comments on commit 817c7df

Please sign in to comment.