Skip to content

Commit 1ff9375

Browse files
committed
wip
1 parent 3a9af0c commit 1ff9375

7 files changed

Lines changed: 141 additions & 22 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
prefix rr: <http://www.w3.org/ns/r2rml#>
2+
prefix rml: <http://semweb.mmlab.be/ns/rml#>
3+
4+
SELECT distinct ?tmLabel ?tmComment
5+
WHERE {
6+
values (?tripleMap){
7+
(<$tripleMapUri>)
8+
}
9+
?tripleMap a rr:TriplesMap;
10+
optional{?tripleMap rdfs:label ?tmLabel}
11+
optional{?tripleMap rdfs:comment ?tmComment}
12+
13+
}
14+

ted_sws/rml_to_html/resources/queries/get_predicate_object_map.rq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
prefix rml: <http://semweb.mmlab.be/ns/rml#>
22
prefix rr: <http://www.w3.org/ns/r2rml#>
33

4-
SELECT ?predicate ?reference ?referenceLanguageMap ?parentTripleMap ?joinConditionChild ?joinConditionParent ?template ?templateTermType
4+
SELECT distinct ?predicate ?reference ?referenceLanguageMap ?parentTripleMap ?joinConditionChild ?joinConditionParent ?template ?templateTermType
55
WHERE {
66
values (?tripleMap){
77
(<$tripleMapUri>)
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
prefix rr: <http://www.w3.org/ns/r2rml#>
22

3-
SELECT ?tripleMap ?tmLabel ?tmComment
3+
SELECT ?tripleMap
44

55
{
66
?tripleMap a rr:TriplesMap .
7-
optional{?tripleMap rdfs:label ?tmLabel}
8-
optional{?tripleMap rdfs:comment ?tmComment}
9-
107
}

ted_sws/rml_to_html/resources/query_registry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ def SUBJECT_MAP(self):
1717

1818
@property
1919
def PREDICATE_OBJECT_MAP(self):
20-
return get_sparql_query(query_file_name="get_predicate_object_map.rq")
20+
return get_sparql_query(query_file_name="get_predicate_object_map.rq") \
21+
22+
@property
23+
def TRIPLE_MAP_COMMENT_LABEL(self):
24+
return get_sparql_query(query_file_name="get_label_comment.rq")
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{% macro display_element(key,dict_to_check,label,list_element=True,link=False) -%}
2+
{% if key in dict_to_check.keys() %}
3+
{% if list_element %}
4+
<dd><strong><em>{{ label }}:</em></strong>
5+
{% if link %}
6+
<a href="#{{ dict_to_check[key].value }}">{{ dict_to_check[key].value }}</a>
7+
{% else %}
8+
{{ dict_to_check[key].value }}
9+
{% endif %}
10+
</dd>
11+
{% else %}
12+
<p>{{ dict_to_check[key].value }}</p>
13+
{% endif %}
14+
{% endif %}
15+
{% endmacro -%}
16+
17+
<!DOCTYPE html>
18+
<html lang="en">
19+
<head>
20+
<meta charset="UTF-8">
21+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
22+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
23+
<title>HTML report for RML</title>
24+
<style type="text/css">
25+
body {
26+
font-family: Arial, sans-serif;
27+
margin: 25px auto;
28+
width: 80%;
29+
}
30+
31+
dt {
32+
font-weight: bold;
33+
text-decoration: underline;
34+
}
35+
36+
dd {
37+
padding: 0 0 0.5em 0;
38+
}
39+
</style>
40+
</head>
41+
<body>
42+
<h1>RML report </h1>
43+
<hr>
44+
{% for triple_map in triple_maps_details %}
45+
<h2 id="{{ triple_map }}">{{ triple_maps_details[triple_map].triple_map_uri }}</h2>
46+
{% for detail in triple_maps_details[triple_map].details %}
47+
{{ display_element("tmLabel", detail,"tmLabel",False) }}
48+
{{ display_element("tmComment", detail,"tmComment",False) }}
49+
{% endfor %}
50+
<dl>
51+
<dt>Logical Source</dt>
52+
{% for logical_source in triple_maps_details[triple_map].logical_source %}
53+
<dd>{{ logical_source.source.value }}</dd>
54+
{% endfor %}
55+
</dl>
56+
57+
<dl>
58+
<dt>Subject map</dt>
59+
{% for subject_map in triple_maps_details[triple_map].subject_map %}
60+
<dd>
61+
<strong><em>Class:</em></strong> {{ subject_map.cls.value }}<br>
62+
<strong><em>Template:</em></strong> {{ subject_map.template.value }}
63+
</dd>
64+
{% endfor %}
65+
</dl>
66+
67+
<dl>
68+
<dt>Predicate object maps</dt>
69+
<dd>
70+
{% for object_map in triple_maps_details[triple_map].predicate_object_map %}
71+
{% if "predicate" in object_map.keys() %}
72+
<dl>
73+
<dt>{{ object_map.predicate.value }}</dt>
74+
75+
{{ display_element("reference",object_map,"Reference") }}
76+
{{ display_element("referenceLanguageMap",object_map,"Reference Language Map") }}
77+
{{ display_element("parentTripleMap",object_map,"Parent Triple Map",True, True) }}
78+
{{ display_element("joinConditionChild",object_map,"Join condition Child") }}
79+
{{ display_element("joinConditionParent",object_map,"Join condition Parent") }}
80+
{{ display_element("template",object_map,"Template") }}
81+
{{ display_element("templateTermType",object_map,"Template term type") }}
82+
83+
</dl>
84+
{% endif %}
85+
{% endfor %}
86+
</dd>
87+
</dl>
88+
89+
{% endfor %}
90+
91+
</body>
92+
</html>
93+

ted_sws/rml_to_html/services/rml_to_html.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import json
22
from string import Template
33

4+
from jinja2 import Environment, PackageLoader
5+
46
from ted_sws.data_manager.adapters.repository_abc import MappingSuiteRepositoryABC
57
from ted_sws.notice_validator.adapters.sparql_runner import SPARQLRunner
68
from ted_sws.rml_to_html.resources.query_registry import QueryRegistry
79

10+
TEMPLATES = Environment(loader=PackageLoader("ted_sws.rml_to_html.resources", "templates"))
11+
RML_TO_HTML_REPORT_TEMPLATE = "rml_to_html_report.jinja2"
812

913
def query_uri_substitution(query: str, triple_map_uri: str) -> str:
1014
"""
@@ -24,7 +28,10 @@ def get_query_results(query: str, sparql_runner: SPARQLRunner) -> dict:
2428

2529
def run_queries_for_triple_map(triple_map_uri: str, query_registry: QueryRegistry, sparql_runner: SPARQLRunner) -> dict:
2630
return {
27-
"triple_map_uri":triple_map_uri,
31+
"triple_map_uri": triple_map_uri,
32+
"details": get_query_results(
33+
query=query_uri_substitution(query=query_registry.TRIPLE_MAP_COMMENT_LABEL, triple_map_uri=triple_map_uri),
34+
sparql_runner=sparql_runner),
2835
"logical_source": get_query_results(
2936
query=query_uri_substitution(query=query_registry.LOGICAL_SOURCE, triple_map_uri=triple_map_uri),
3037
sparql_runner=sparql_runner),
@@ -37,7 +44,8 @@ def run_queries_for_triple_map(triple_map_uri: str, query_registry: QueryRegistr
3744

3845
}
3946

40-
def rml_files_to_html_report(mapping_suite_identifier: str,mapping_suite_repository: MappingSuiteRepositoryABC):
47+
48+
def rml_files_to_html_report(mapping_suite_identifier: str, mapping_suite_repository: MappingSuiteRepositoryABC):
4149
mapping_suite_package = mapping_suite_repository.get(reference=mapping_suite_identifier)
4250
if mapping_suite_package is None:
4351
raise ValueError(f'Mapping suite package, with {mapping_suite_identifier} id, was not found')
@@ -46,20 +54,19 @@ def rml_files_to_html_report(mapping_suite_identifier: str,mapping_suite_reposit
4654

4755
sparql_runner = SPARQLRunner(files=rml_files)
4856
triple_maps = json.loads(sparql_runner.query(query_object=query_registry.TRIPLE_MAP).serialize(
49-
format="json").decode("utf-8"))
57+
format="json").decode("utf-8"))
5058
triple_maps_uris = [triple_map['tripleMap']["value"] for triple_map in triple_maps["results"]["bindings"]]
51-
list_of_triple_maps = {}
52-
for triple_map_uri in triple_maps_uris[:2]:
53-
triple_map_details = {}
54-
55-
query = query_uri_substitution(query=query_registry.LOGICAL_SOURCE, triple_map_uri=triple_map_uri)
56-
logical_source = json.loads(
57-
sparql_runner.query(query_object=query).serialize(
58-
format="json").decode("utf-8"))
59-
triple_map_details["logical_source"] = logical_source["results"]["bindings"]
60-
list_of_triple_maps[triple_map_uri] = triple_map_details
59+
print(triple_maps_uris)
60+
triple_maps_details = {}
61+
for triple_map_uri in triple_maps_uris:
62+
triple_maps_details[triple_map_uri] = run_queries_for_triple_map(triple_map_uri=triple_map_uri,
63+
query_registry=query_registry,
64+
sparql_runner=sparql_runner)
6165

66+
html_report = TEMPLATES.get_template(RML_TO_HTML_REPORT_TEMPLATE).render(triple_maps_details=triple_maps_details)
67+
with open("rml-report.html", "w") as file:
68+
file.write(html_report)
6269

70+
return triple_maps_details
6371

6472

65-
return list_of_triple_maps
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import json
2+
13
from ted_sws.data_manager.adapters.mapping_suite_repository import MappingSuiteRepositoryInFileSystem
24
from ted_sws.rml_to_html.services.rml_to_html import rml_files_to_html_report
35

46

57
def test_rml_files_to_html_report(file_system_repository_path):
68
mapping_suite_repository = MappingSuiteRepositoryInFileSystem(repository_path=file_system_repository_path)
7-
triple_maps = rml_files_to_html_report(mapping_suite_identifier="test_package",mapping_suite_repository=mapping_suite_repository)
9+
triple_maps=rml_files_to_html_report(mapping_suite_identifier="test_package",mapping_suite_repository=mapping_suite_repository)
810

911
# triple_maps_uris = [triple_map['tripleMap']["value"] for triple_map in triple_maps["results"]["bindings"]]
10-
print(triple_maps)
12+
# #
13+
# with open("triple-maps.json", "w") as file:
14+
# file.write(json.dumps(triple_maps))

0 commit comments

Comments
 (0)