-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreleven.py
66 lines (54 loc) · 1.97 KB
/
releven.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from os import path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from git import Repo
from rdfproxy import Page, QueryParameters, SPARQLModelAdapter
from releven_location import Location
from releven_person import Person
from releven_written_work import WrittenWork
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# The automatic health check endpoint is /. The return code has to be 200 or 30x.
@app.get("/")
def version():
repo = Repo(search_parent_directories=True)
return {"version": repo.git.describe(tags=True, dirty=True, always=True)}
@app.get("/location")
def location(page: int = 1, size: int = 10) -> Page[Location]:
adapter = SPARQLModelAdapter(
target="https://graphdb.r11.eu/repositories/RELEVEN",
query=open(f"{path.dirname(path.realpath(__file__))}/releven_location.rq")
.read()
.replace("\n ", " "),
model=Location,
)
parameters = QueryParameters(page=page, size=size)
return adapter.query(parameters)
@app.get("/person")
def person(page: int = 1, size: int = 10) -> Page[Person]:
adapter = SPARQLModelAdapter(
target="https://graphdb.r11.eu/repositories/RELEVEN",
query=open(f"{path.dirname(path.realpath(__file__))}/releven_person.rq")
.read()
.replace("\n ", " "),
model=Person,
)
parameters = QueryParameters(page=page, size=size)
return adapter.query(parameters)
@app.get("/written_work")
def written_work(page: int = 1, size: int = 10) -> Page[WrittenWork]:
adapter = SPARQLModelAdapter(
target="https://graphdb.r11.eu/repositories/RELEVEN",
query=open(f"{path.dirname(path.realpath(__file__))}/releven_written_work.rq")
.read()
.replace("\n ", " "),
model=WrittenWork,
)
parameters = QueryParameters(page=page, size=size)
return adapter.query(parameters)