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
Merged

Conversation

metaodi
Copy link
Member

@metaodi 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 75-schema-org-profile branch 3 times, most recently from 88bd3a6 to fbe19aa Compare January 19, 2018 13:20
@@ -32,10 +32,15 @@ def read_catalog(self, _format=None):
if not _format:
return HomeController().index()

_profiles = toolkit.request.params.get('profiles')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@metaodi metaodi force-pushed the 75-schema-org-profile branch 3 times, most recently from e7f2b92 to 98774fb Compare January 23, 2018 21:50
@metaodi
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 75-schema-org-profile branch 2 times, most recently from 3ea181c to 38cc5b3 Compare January 23, 2018 22:21
@metaodi metaodi changed the title WIP: [#75] Schema.org mapping [#75] Schema.org mapping Jan 23, 2018
@metaodi
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.

Stefan Oderbolz added 17 commits January 31, 2018 11:19
The SchemaOrg schema provides a number of methods that could be
overriden by subclasses if they need a slightly different mapping to
schema.org (e.g. from one of the DCAT AP standards).

With those methods in place it should be relatively easy to implement a
schema.org mapping for different standards.
- This new plugin contains a template helper method to print structured
  data of a dataset, which is printed on a dataset detail page
  (typically JSON-LD)
except ImportError:
# CKAN < 2.6
class HelperError(Exception):
pass
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@metaodi
Copy link
Member Author

metaodi commented Jan 31, 2018

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

@metaodi
Copy link
Member Author

metaodi commented Feb 12, 2018

@amercader ping, can you review this PR?

@amercader
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

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

@metaodi metaodi force-pushed the 75-schema-org-profile branch 2 times, most recently from 39fe8e2 to b2ce7d1 Compare February 16, 2018 06:48
@metaodi
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
@amercader
Copy link
Member

Thanks @metaodi, fantastic work as usual

@amercader
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants