Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDF frequencies improvements #1752

Merged
merged 3 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Improve/fix validation error formatting on harvesting [#1745](https://github.com/opendatateam/udata/pull/1745)
- Ensure daterange can be parsed from full iso datetime [#1748](https://github.com/opendatateam/udata/pull/1748)
- API: enforce application/json content-type for forms [#1751](https://github.com/opendatateam/udata/pull/1751)
- RDF parser can now process [european frequencies](https://publications.europa.eu/en/web/eu-vocabularies/at-dataset/-/resource/dataset/frequency) [#1752](https://github.com/opendatateam/udata/pull/1752)

## 1.4.0 (2018-06-06)

Expand Down
43 changes: 41 additions & 2 deletions udata/core/dataset/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
from rdflib.resource import Resource as RdfResource
from rdflib.namespace import RDF

from udata import i18n
from udata import i18n, uris
from udata.frontend.markdown import parse_html
from udata.models import db
from udata.core.organization.rdf import organization_to_rdf
from udata.core.user.rdf import user_to_rdf
from udata.rdf import (
DCAT, DCT, FREQ, SCV, SKOS, SPDX, SCHEMA, namespace_manager, url_from_rdf
DCAT, DCT, FREQ, SCV, SKOS, SPDX, SCHEMA, EUFREQ,
namespace_manager, url_from_rdf
)
from udata.utils import get_by

Expand All @@ -40,6 +41,37 @@
'unknown': None,
}

# Map european frequencies to their closest equivalent
# See:
# - http://publications.europa.eu/mdr/resource/authority/frequency/html/frequencies-eng.html # noqa: E501
# - https://publications.europa.eu/en/web/eu-vocabularies/at-dataset/-/resource/dataset/frequency # noqa: E501
EU_RDF_REQUENCIES = {
# Match Dublin Core name
EUFREQ.ANNUAL: 'annual',
EUFREQ.BIENNIAL: 'biennial',
EUFREQ.TRIENNIAL: 'triennial',
EUFREQ.QUARTERLY: 'quarterly',
EUFREQ.MONTHLY: 'monthly',
EUFREQ.BIMONTHLY: 'bimonthly',
EUFREQ.WEEKLY: 'weekly',
EUFREQ.BIWEEKLY: 'biweekly',
EUFREQ.DAILY: 'daily',
# Name differs from Dublin Core
EUFREQ.ANNUAL_2: 'semiannual',
EUFREQ.ANNUAL_3: 'threeTimesAYear',
EUFREQ.MONTHLY_2: 'semimonthly',
EUFREQ.MONTHLY_3: 'threeTimesAMonth',
EUFREQ.WEEKLY_2: 'semiweekly',
EUFREQ.WEEKLY_3: 'threeTimesAWeek',
EUFREQ.DAILY_2: 'semidaily',
EUFREQ.CONT: 'continuous',
EUFREQ.UPDATE_CONT: 'continuous',
EUFREQ.IRREG: 'irregular',
EUFREQ.UNKNOWN: 'unknown',
EUFREQ.OTHER: 'unknown',
EUFREQ.NEVER: 'punctual',
}


Dataset.extras.register('uri', db.StringField)
Dataset.extras.register('dct:identifier', db.StringField)
Expand Down Expand Up @@ -264,9 +296,16 @@ def temporal_from_rdf(period_of_time):


def frequency_from_rdf(term):
if isinstance(term, basestring):
try:
term = URIRef(uris.validate(term))
except uris.ValidationError:
pass
if isinstance(term, RdfResource):
term = term.identifier
if isinstance(term, URIRef):
if EUFREQ in term:
return EU_RDF_REQUENCIES.get(term)
_, _, freq = namespace_manager.compute_qname(term)
return freq

Expand Down
1 change: 1 addition & 0 deletions udata/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SPDX = Namespace('http://spdx.org/rdf/terms#')
VCARD = Namespace('http://www.w3.org/2006/vcard/ns#')
FREQ = Namespace('http://purl.org/cld/freq/')
EUFREQ = Namespace('http://publications.europa.eu/resource/authority/frequency/') # noqa: E501
DCT = DCTERMS # More common usage

namespace_manager = NamespaceManager(Graph())
Expand Down