diff --git a/dqgen/resources/asciidoc_templates/instance.jinja2 b/dqgen/resources/asciidoc_templates/instance.jinja2 new file mode 100644 index 0000000..f7a668f --- /dev/null +++ b/dqgen/resources/asciidoc_templates/instance.jinja2 @@ -0,0 +1,21 @@ +{% raw %} +{% import "macros.adoc" as mc %} +{% endraw %} + {{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }} + {% raw %} +{% if not content.empty %} + {% call mc.render_fetch_results(content, error) %} + {% set compress_uris = simplify_uri_columns_in_tabular(data_frame=content,namespace_inventory=namespaces,error_fail=False) %} + {% endraw %} +== {{ operation|title }} {{ class_name }}s + +The table below lists the {{ operation }} *{{ cls }}* + +*Query identifier:* {{ query_file }} + + {{ "{{" }} mc.pandas_table(content, "{{ operation|title }} {{ class_name }}s") {{ "}}" }} + {% raw %} + {% endcall %} +{% endif %} + {% endraw %} + diff --git a/dqgen/resources/asciidoc_templates/main.jinja2 b/dqgen/resources/asciidoc_templates/main.jinja2 new file mode 100644 index 0000000..7abb31b --- /dev/null +++ b/dqgen/resources/asciidoc_templates/main.jinja2 @@ -0,0 +1,49 @@ +{% raw %} +{% extends "layout.adoc" %} +{% import "macros.adoc" as mc %} +{% block content %} +{% endraw %} + +This report is automatically generated from the {% raw %}{{ conf.dataset_name }}{% endraw %} RDF dataset on {% raw %}{{ conf.timestamp }}{% endraw %} +and aims at presenting the difference between two versions of an RDFS/OWL vocabulary following the {% raw %}{{ conf.application_profile }}{% endraw %} application profile. + +== Report details + +*Dataset ID:* {% raw %}{{ conf.dataset_name }}{% endraw %} + +*Dataset name:* {% raw %}{{ conf.original_name }}{% endraw %} + +*Old version file:* {% raw %}{{ conf.old_version_file }}{% endraw %} + +*New version file:* {% raw %}{{ conf.new_version_file }}{% endraw %} + +*Time:* {% raw %}{{ conf.timestamp }}{% endraw %} + +*Application profile:* {% raw %}{{ conf.application_profile }}{% endraw %} + +{% raw %} +{% set namespaces = namespace_inventory({}) %} +{% include "statistics.adoc" %} +{% endraw %} +{% for class_key , class_data in data_source.items() %} +== {{ class_data.label }} + {% if class_data.description is not undefined %} +{{ class_data.description }} + {% endif %} + {% for instance_change_file in class_data.instance_changes.files %} + {{ "{% include " }}"{{ instance_change_file }}"{{ " with context %}" }} + {% endfor %} + {% for prop_group, prop_group_data in class_data.prop_groups.items() %} +=== {{ prop_group_data.label }} + {% for prop_file in prop_group_data.query_template_file_paths %} + {{ "{% include " }}"{{ prop_file }}"{{ " with context %}" }} + {% endfor %} + {% endfor %} +{% endfor %} +{% raw %} +== Prefixes + +{{ mc.render_namespaces(namespaces.namespaces_as_dict()) }} +{% endblock %} +{% endraw %} + diff --git a/dqgen/resources/asciidoc_templates/property.jinja2 b/dqgen/resources/asciidoc_templates/property.jinja2 new file mode 100644 index 0000000..85a0ba4 --- /dev/null +++ b/dqgen/resources/asciidoc_templates/property.jinja2 @@ -0,0 +1,21 @@ +{% raw %} +{% import "macros.adoc" as mc %} +{% endraw %} + {{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }} + {% raw %} +{% if not content.empty %} + {% call mc.render_fetch_results(content, error) %} + {% set compress_uris = simplify_uri_columns_in_tabular(data_frame=content,namespace_inventory=namespaces,error_fail=False) %} + {% endraw %} +=== {{ operation|title }} {{ property_name }} + +The table below lists the {{ operation }} *{{ property }}* + +*Query identifier:* {{ query_file }} + + {{ "{{" }} mc.pandas_table(content, "{{ operation|title }} {{ property_name }}") {{ "}}" }} + {% raw %} + {% endcall %} +{% endif %} + {% endraw %} + diff --git a/dqgen/resources/asciidoc_templates/reified_property.jinja2 b/dqgen/resources/asciidoc_templates/reified_property.jinja2 new file mode 100644 index 0000000..6177bd7 --- /dev/null +++ b/dqgen/resources/asciidoc_templates/reified_property.jinja2 @@ -0,0 +1,21 @@ +{% raw %} +{% import "macros.adoc" as mc %} +{% endraw %} + {{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }} + {% raw %} +{% if not content.empty %} + {% call mc.render_fetch_results(content, error) %} + {% set compress_uris = simplify_uri_columns_in_tabular(data_frame=content,namespace_inventory=namespaces,error_fail=False) %} + {% endraw %} +=== {{ operation|title }} reified {{ property_name }} + +The table below lists the {{ operation }} *{{ property }} / {{ object_property }}* + +*Query identifier:* {{ query_file }} + + {{ "{{" }} mc.pandas_table(content, "{{ operation|title }} reified {{ property_name }}") {{ "}}" }} + {% raw %} + {% endcall %} +{% endif %} + {% endraw %} + diff --git a/dqgen/resources/asciidoc_templates/static/layout.adoc b/dqgen/resources/asciidoc_templates/static/layout.adoc new file mode 100644 index 0000000..05417bd --- /dev/null +++ b/dqgen/resources/asciidoc_templates/static/layout.adoc @@ -0,0 +1,7 @@ +{% raw %} += {{ conf.title }} + +{% block content %} +{% endblock %} +{% endraw %} + diff --git a/dqgen/resources/asciidoc_templates/static/macros.adoc b/dqgen/resources/asciidoc_templates/static/macros.adoc new file mode 100644 index 0000000..6019175 --- /dev/null +++ b/dqgen/resources/asciidoc_templates/static/macros.adoc @@ -0,0 +1,80 @@ +{# Default way of showing errors #} +{% macro render_error(message) -%} +[NOTE] +==== +*Error* + +{{ message|e }} +==== +{%- endmacro %} + +{# Default macro for showing/wrapping the fetch results #} +{% macro render_fetch_results(content, error) -%} + {% if error %} + {{ render_error(error) }} + {% else %} + {% if content is undefined %} + {{ render_error("Some content expected but none was found.") }} + {% else %} + {{ caller() }} + {% endif %} + {% endif %} +{%- endmacro %} + + +{% macro pandas_table(df, caption, column_labels={}) -%} + {% if (df is defined) and (df is not none) %} + {% set df = df.fillna(value="") %} +[cols="{{ df.columns|length }}*", options="header"] +|=== + {% for column in df.columns %} + {% if column in column_labels %} +|{{ column_labels[column] }} + {% else %} +|{{ column }} + {% endif %} + {% endfor %} + + {% for idx, row in df.iterrows() %} + {% for colname in df.columns %} + {# handle decimal format: float, float64, float32 #} + {% if 'float' in (df.dtypes[colname] | string) %} +|{{ row[colname] | round(precision=2) }} + {% else %} +|{{ row[colname] }} + {% endif %} + {% endfor %} + + {% endfor %} +|=== + +.{{ caption }} + {% else %} + {{ render_error("How did you get here? did you forget to use 'render_fetch_results' macro?") }} + {% endif %} +{%- endmacro %} + +{% macro count_value(df) %} + {% for idx, row in df.iterrows() %} + {% for colname in df.columns %} +|{{ row[colname] }} + {% endfor %} + {% endfor %} +{% endmacro %} + +{% macro render_namespaces(namesapces_dist) %} +[cols="1,3", options="header"] +|=== +|Namespace +|URI + + {% for prefix, uri in namesapces_dist|dictsort %} +|{{ prefix }} +|{{ uri }} + + {% endfor %} +|=== + +.Prefixes +{% endmacro %} + diff --git a/dqgen/resources/asciidoc_templates/statistics.jinja2 b/dqgen/resources/asciidoc_templates/statistics.jinja2 new file mode 100644 index 0000000..36ad493 --- /dev/null +++ b/dqgen/resources/asciidoc_templates/statistics.jinja2 @@ -0,0 +1,57 @@ +{% raw %} +{% import "macros.adoc" as mc %} +{% endraw %} +== Statistics + + {% for class_key , class_data in data_source.items() %} +=== {{ class_data.label }} + {% if class_data.description is not undefined %} +{{ class_data.description }} + {% endif %} + +[cols="1,1,1", options="header"] +|=== +|Instance +|Added +|Deleted + +|{{ class_data.label }} + {% for count_query in class_data.instance_changes.count_queries %} + {{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ count_query }}"]).fetch_tabular() {{ "%}" }} + {% raw %} + {% call mc.render_fetch_results(content, error) %} + {{ mc.count_value(content) }} + {% endcall %} + {% endraw %} + {% endfor %} +|=== + +[cols="1,1,1,1,1,1,1", options="header"] +|=== +|Property group +|Property +|Added +|Deleted +|Updated +|Moved +|Changed + {% for prop_group, prop_group_data in class_data.prop_groups.items() %} + {% set prop_group_name = prop_group_data.label %} + {% for index ,count_prop_section in prop_group_data.count_queries.items() %} + +|{{ prop_group_name }} +|{{ count_prop_section.label }} + {% for query_file in count_prop_section.files %} + {{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }} + {% raw %} + {% call mc.render_fetch_results(content, error) %} + {{ mc.count_value(content) }} + {% endcall %} + {% endraw %} + {% endfor %} + {% endfor %} + {% endfor %} +|=== + + {% endfor %} +