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

[#75] Schema.org mapping #108

Merged
merged 26 commits into from Feb 16, 2018

Conversation

Projects
None yet
2 participants
@metaodi
Copy link
Member

metaodi commented Jan 16, 2018

Add schema.org mapping (see #75 for details)

This PR provides:

  • Mapping from DCAT to schema.org/Dataset
  • New parameter profiles to the catalog and dataset endpoints to be able to change the profiles when requesting the metadata (this allows to server DCAT and schema.org on the same instance), example /dataset/my-dataset.jsonld?profiles=schemaorg

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch 3 times, most recently from 88bd3a6 to fbe19aa Jan 18, 2018

@@ -32,10 +32,15 @@ def read_catalog(self, _format=None):
if not _format:
return HomeController().index()

_profiles = toolkit.request.params.get('profiles')

This comment has been minimized.

@amercader

amercader Jan 22, 2018

Member

Does it really make sense to ask for more than one profile at the time? Can you give an example? IIRC profiles used inheritance to extend them.

This comment has been minimized.

@amercader

amercader Jan 22, 2018

Member

Turns out I implemented it exactly like this at the lower level 🙃 Ignore me!

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch 3 times, most recently from e7f2b92 to 98774fb Jan 23, 2018

@metaodi

This comment has been minimized.

Copy link
Member Author

metaodi commented Jan 23, 2018

I found a way to check if a helper function is defined.

In ckan/ckan#3042 an excpetion was added to the helper dictionary, so it's no longer possible to simply use {% if h.structured_data %} in jinja, as this triggers an exception. But calling h.get() seems to do the trick:

{% if helper_dict.get('structured_data') %}
{{ h.structured_data()|safe }}
{% endif %}

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch 2 times, most recently from 3ea181c to 38cc5b3 Jan 23, 2018

@metaodi metaodi changed the title WIP: [#75] Schema.org mapping [#75] Schema.org mapping Jan 23, 2018

@metaodi

This comment has been minimized.

Copy link
Member Author

metaodi commented Jan 24, 2018

Unfortunately the approach I described above does not work in older versions of CKAN (<2.6), because earlier versions of jinja do not support the use of dict(). Therefore I added another template helper to check if a helper is available or not.

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch from 3f2f10e to eb4f4d7 Jan 31, 2018

except ImportError:
# CKAN < 2.6
class HelperError(Exception):
pass

This comment has been minimized.

@metaodi

metaodi Jan 31, 2018

Author Member

I already added the HelperError to ckantoolkit to avoid this "hack" (ckan/ckantoolkit#6)

@metaodi

This comment has been minimized.

Copy link
Member Author

metaodi commented Jan 31, 2018

I rebased this PR to master to fix the merge conflicts.

@metaodi

This comment has been minimized.

Copy link
Member Author

metaodi commented Feb 12, 2018

@amercader ping, can you review this PR?

@amercader

This comment has been minimized.

Copy link
Member

amercader commented Feb 12, 2018

sorry @metaodi, I'm a bit swamped right now but it's definitely on my list. Will try to review it this week.

README.md Outdated
@@ -788,6 +799,88 @@ To disable this behavior, you can set the following config value in your ini fil
ckanext.dcat.translate_keys = False
## Structured data
To add [structured data](https://developers.google.com/search/docs/guides/intro-structured-data) to dataset pages, activate the `structured_data` plugin in your ini file.

This comment has been minimized.

@amercader

amercader Feb 15, 2018

Member

I took me quite a while to discover why I wasn't seeing the structured data json-ld after activating the structured_data plugin. Here we should mention that you need in structured_data in addition to the dcat plugin.

This basically means that if someone wants the schema.org support they also need to enable the links to RDF representation for datasets and catalog, as these are automatically added by the dcat plugin. This is probably fine, but we might want to add a config option to disable this for people that just want the schema.org support.

@amercader

This comment has been minimized.

Copy link
Member

amercader commented Feb 15, 2018

This looks good @metaodi . Only one minor change in the README and we can merge.

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch from ad91776 to d2bff78 Feb 15, 2018

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch 2 times, most recently from 39fe8e2 to b2ce7d1 Feb 15, 2018

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch from b2ce7d1 to f172e84 Feb 16, 2018

metaodi added some commits Feb 16, 2018

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch from 77c69e2 to 5225e57 Feb 16, 2018

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch from adde42b to b2ec8a6 Feb 16, 2018

@metaodi metaodi force-pushed the opendata-swiss:75-schema-org-profile branch from b2ec8a6 to 71a9728 Feb 16, 2018

@metaodi

This comment has been minimized.

Copy link
Member Author

metaodi commented Feb 16, 2018

@amercader I made the changes to the README and added the new config option for the RDF endpoints (+tests)

@amercader amercader merged commit d1756dc into ckan:master Feb 16, 2018

4 checks passed

codecov/patch 97.22% of diff hit (target 90.46%)
Details
codecov/project 91.26% (+0.8%) compared to 7a2abfe
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
security/snyk No new issues
Details
@amercader

This comment has been minimized.

Copy link
Member

amercader commented Feb 16, 2018

Thanks @metaodi, fantastic work as usual

@amercader

This comment has been minimized.

Copy link
Member

amercader commented Feb 16, 2018

This is worth a new release, I've released 0.0.7

@metaodi metaodi deleted the opendata-swiss:75-schema-org-profile branch Feb 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.