Skip to content

Commit 240e7f3

Browse files
committed
Cleanup
1 parent adafdb1 commit 240e7f3

File tree

10 files changed

+52
-102
lines changed

10 files changed

+52
-102
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ package-lock.json
1616
# local files
1717
config.yaml
1818
stage
19+
queries

README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,9 @@ A local file `config.yaml` is needed with configuration. See [`config.example.ya
6464

6565
In addition the following environment variables can be used:
6666

67+
- `SPARQL`: backend API endpoint. Default: `http://localhost:3030/n4o/`
6768
- `STAGE`: readable stage directory. Default: `stage`
68-
69-
### SPARQL
70-
71-
The default configuration expects a SPARL endpoint at <http://localhost:3030/n4o/>. This can be provided with Fuseki triple store and a database `n4o` locally created like this:
72-
73-
~~~sh
74-
curl --data "dbName=n4o&dbType=tdb2" http://localhost:3030/$/datasets
75-
~~~
76-
77-
Alternatively use the preconfigured Docker container [n4o-fuseki](https://github.com/nfdi4objects/n4o-fuseki#readme).
69+
- `QUERIES`: directory with sample SPARQL queries with file extension `.rq`. Default: `queries`
7870

7971
The RDF database is expected to be grouped in named graphs:
8072

@@ -84,7 +76,7 @@ The RDF database is expected to be grouped in named graphs:
8476
- Graphs `http://bartoc.org/en/node/X` where X is an integer contain information from individual terminologies
8577
- The default graph must be configured as union graph.
8678

87-
See [n4o-graph-importer](https://github.com/nfdi4objects/n4o-graph-importer#readme) for a component to ensure RDF data is only imported into the triple store as expected.
79+
See [n4o-fuseki](https://github.com/nfdi4objects/n4o-fuseki#readme) for preconfigured Triple store and [n4o-graph-importer](https://github.com/nfdi4objects/n4o-graph-importer#readme) for a component to ensure RDF data is only imported into the triple store as expected.
8880

8981
### Tools
9082

@@ -140,6 +132,8 @@ To locally build the Docker image run `make docker`. The container is named `n4o
140132
docker run --rm --net=host -p 8000:8000 -v ./config.yaml:/app/config.yaml:ro n4o-graph-apis
141133
~~~
142134

135+
To use custom queries, mount your local directory to `/app/queries`
136+
143137
## License
144138

145139
MIT License

app.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def jsonify(data, status=200, indent=3, sort_keys=False):
3737
def render(template, **vars):
3838
# TODO: better title?
3939
title = template.split(".")[0]
40-
return render_template(template, title=title, githash=app.config["githash"], **vars)
40+
return render_template(template, title=title, **vars)
4141

4242

4343
@app.errorhandler(ApiError)
@@ -95,10 +95,10 @@ def terminology():
9595
return render('terminologies.html')
9696

9797

98-
@app.route('/repository')
99-
@app.route('/repository/')
100-
def repository():
101-
return render('repositories.html')
98+
@app.route('/mappings')
99+
@app.route('/mappings/')
100+
def mappings():
101+
return render('mappings.html')
102102

103103

104104
@app.route('/collection', defaults={'id': None, 'path': None})
@@ -156,9 +156,6 @@ def collection(id, path):
156156
format = "turtle"
157157
mimetype = "text/turtle"
158158

159-
print("Format, mimetype")
160-
print(format, mimetype)
161-
162159
response = make_response("Not found", 404)
163160
response.mimetype = "text/plain"
164161
if len(graph) > 0:
@@ -175,7 +172,7 @@ def sparql_api():
175172

176173
@app.route('/sparql')
177174
def sparql_form():
178-
return render('sparql.html', **config["sparql"])
175+
return render('sparql.html', **config)
179176

180177

181178
@app.route('/tools')
@@ -192,7 +189,7 @@ def init(**config):
192189
for key in config.keys():
193190
app.config[key] = config[key]
194191

195-
endpoint = config["sparql"]["endpoint"]
192+
endpoint = config["sparql"]
196193
app.config["sparql-proxy"] = SparqlProxy(endpoint, config["debug"])
197194

198195
stage = config.get("stage")

config.example.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
# run in debug mode to emit more debugging information
22
debug: false
33

4-
# SPARQL endpoint and examples (required)
5-
sparql:
6-
endpoint: http://localhost:3030/n4o
7-
examples:
8-
# examples given in files
9-
- queries/*.rq
10-
# example given in config file
11-
- name: List all classes
12-
query: |
13-
SELECT DISTINCT ?class WHERE { [] a ?class } examples:
14-
154
# Links to tools and references (optional)
165
tools:
176
- name: LIDO-Schulung

lib/config.py

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
from collections import UserDict
22
import yaml
3+
from pathlib import Path
34
import glob
45
import re
56
import os
67
import subprocess
78

89

9-
def extend_examples(api):
10-
if "examples" in api:
11-
extended = []
12-
for ex in api["examples"]:
13-
if isinstance(ex, str):
14-
for file in glob.glob(ex):
15-
lines = open(file).read().split("\n")
16-
name = re.sub(r"^#\s*", "", lines[0])
17-
extended.append({"name": name, "query": "\n".join(lines)})
18-
else:
19-
extended.append(ex)
20-
api["examples"] = extended
21-
else:
22-
api["examples"] = []
10+
def get_queries(path):
11+
path = Path(path)
12+
queries = []
13+
if path.is_dir():
14+
for file in path.glob('*.rq'):
15+
lines = open(file).read().split("\n")
16+
name = re.sub(r"^#\s*", "", lines[0])
17+
queries.append({"name": name, "query": "\n".join(lines)})
18+
return queries
2319

2420

2521
class Config(UserDict):
@@ -38,35 +34,15 @@ def __init__(self, file=None, debug=False):
3834
else:
3935
self.data = {}
4036

41-
if not self.get("stage", None):
42-
self.data["stage"] = os.getenv('STAGE', 'stage')
43-
if not self.data.get("sparql", None):
44-
self.data["sparql"] = {
45-
"endpoint": os.getenv('SPARQL', "http://localhost:3030/n4o")
46-
}
37+
self.data["stage"] = os.getenv('STAGE', 'stage')
38+
self.data["sparql"] = os.getenv('SPARQL', "http://localhost:3030/n4o")
4739

4840
if debug:
4941
self.data["debug"] = True
5042
elif "debug" not in self.data:
5143
self.data["debug"] = False
5244

53-
if "import" in self.data:
54-
for name in ["collections", "terminologies"]:
55-
if name in self.data["import"]:
56-
path = self.data["import"][name]
57-
if not os.path.isdir(path):
58-
raise Exception(f"Missing {name} path: {path}")
59-
else:
60-
self.data["import"] = {}
61-
62-
extend_examples(self.data["sparql"])
45+
self.data["queries"] = get_queries(os.getenv('QUERIES', 'queries'))
6346

6447
if "tools" not in self.data:
6548
self.data["tools"] = []
66-
67-
try:
68-
self.data["githash"] = subprocess.run(['git', 'rev-parse', '--short=8', 'HEAD'],
69-
stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
70-
except Exception:
71-
self.data["githash"] = None
72-
pass

templates/base.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<script src="{{url_for('static',filename='codemirror/codemirror.js')}}"></script>
1414
<script src="{{url_for('static',filename='codemirror/runmode.js')}}"></script>
1515
<script src="{{url_for('static',filename='codemirror/javascript.js')}}"></script>
16-
<script src="{{url_for('static',filename='codemirror/pg.js')}}"></script>
1716
<script src="{{url_for('static',filename='common.js')}}"></script>
1817
<meta name="msapplication-TileImage" content="{{url_for('static',filename='nfdi4objects-logo.png')}}" />
1918
<title>N4O Graph: {{title}}</title>
@@ -50,10 +49,10 @@
5049
{% endif %}
5150
</li>
5251
<li>
53-
{% if request.path.startswith("/repository") %}
54-
<a href="{{url_for('repository')}}"><span><strong>Repositories</strong></span></a>
52+
{% if request.path.startswith("/mappings") %}
53+
<a href="{{url_for('mappings')}}"><span><strong>Mappings</strong></span></a>
5554
{% else %}
56-
<a href="{{url_for('repository')}}"><span>Repositories</span></a>
55+
<a href="{{url_for('mappings')}}"><span>Mappings</span></a>
5756
{% endif %}
5857
</li>
5958
{% if config.tools %}
@@ -80,9 +79,6 @@
8079
<div style="float:right;">
8180
web interface:
8281
<a href="https://github.com/nfdi4objects/n4o-graph-apis">sources</a>
83-
{% if githash %}
84-
(<a href="https://github.com/nfdi4objects/n4o-graph-apis/commit/{{ githash }}">{{ githash }}</a>)
85-
{% endif %}
8682
|
8783
<a href="https://github.com/nfdi4objects/n4o-graph-apis/issues">issues</a>
8884
</div>

templates/examples.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

templates/license.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
{% block content %}
44
<p>
5-
Data about <a href="/collection/">collections</a> and
6-
<a href="/repository/">repositories</a> can be used freely without
5+
Data about <a href="/collection/">collections</a> and can be used freely without
76
any restrictions (<a href="https://creativecommons.org/publicdomain/zero/1.0/">CC Zero</a>).
87
</p>
98
<p>
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
<script src="{{url_for('static',filename='yasr.min.js')}}"></script>
66

7-
<p>
7+
<p>This page needs to be filled.</p>
8+
9+
<!--p>
810
All research data in the knowledge graph must be published in a trusted
911
research data repository. These include selected repositories listed in
1012
<a href="https://www.re3data.org/">re3data</a> and some repositories of
@@ -24,6 +26,6 @@
2426
OPTIONAL { ?repo foaf:homepage ?url }
2527
}
2628
}
27-
} GROUP BY ?repo ?url"></div>
29+
} GROUP BY ?repo ?url"></div-->
2830

2931
{% endblock %}

templates/sparql.html

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
{% extends 'base.html' %}
22

33
{% block content %}
4-
<script src="{{url_for('static',filename='yasr.min.js')}}"></script>
5-
<script src="{{url_for('static',filename='yasqe.min.js')}}"></script>
6-
<script src="{{url_for('static',filename='sparql-gui.js')}}"></script>
4+
<script src="{{url_for('static',filename='yasr.min.js')}}"></script>
5+
<script src="{{url_for('static',filename='yasqe.min.js')}}"></script>
6+
<script src="{{url_for('static',filename='sparql-gui.js')}}"></script>
77

8-
{% if 'examples' in config.sparql %}
9-
{% set examples = config.sparql.examples %}
10-
{% include 'examples.html' %}
11-
{% endif %}
8+
<div style="float:right;">
9+
<label for="examples">Example queries:</label>
10+
<select id="examples">
11+
<option value="">Please select!</option>
12+
{% for q in config.queries %}
13+
<option value="{{q.query}}">{{q.name}}</option>
14+
{% endfor %}
15+
</select>
16+
</div>
1217

13-
<p>
14-
SPARQL endpoint <code>/api/sparql</code>
15-
(see <a href="https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/#query-operation">documentation</a>)
16-
</p>
18+
<p>
19+
SPARQL endpoint <code>/api/sparql</code>
20+
(see <a href="https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/#query-operation">documentation</a>)
21+
</p>
1722

18-
<div id="yasqe"></div>
19-
<div id="yasr"></div>
23+
<div id="yasqe"></div>
24+
<div id="yasr"></div>
2025
{% endblock %}

0 commit comments

Comments
 (0)