Skip to content

Commit

Permalink
feat: use QueryParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Dec 8, 2024
1 parent a3bc139 commit c83613f
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 127 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Kevin Stadler <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.12"
rdfproxy = {git = "https://github.com/acdh-oeaw/rdfproxy.git", branch = "lupl/model-bool-feature"}
rdfproxy = {git = "https://github.com/acdh-oeaw/rdfproxy.git", branch = "lupl/ungrouped-ordering"}
fastapi = {extras = ["standard"], version = "^0.115.4"}
gitpython = "^3.1.43"

Expand Down
27 changes: 15 additions & 12 deletions releven.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from git import Repo
from rdfproxy import Page, SPARQLModelAdapter
from rdfproxy import Page, QueryParameters, SPARQLModelAdapter
from releven_location import Location
from releven_person import Person
from releven_written_work import WrittenWork
Expand Down Expand Up @@ -36,28 +36,31 @@ def location(page: int = 1, size: int = 10) -> Page[Location]:
.replace("\n ", " "),
model=Location,
)
return adapter.query(page=page, size=size)
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]:
@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_written_work.rq")
query=open(f"{path.dirname(path.realpath(__file__))}/releven_person.rq")
.read()
.replace("\n ", " "),
model=WrittenWork,
model=Person,
)
return adapter.query(page=page, size=size)
parameters = QueryParameters(page=page, size=size)
return adapter.query(parameters)


@app.get("/person")
def person(page: int = 1, size: int = 10) -> Page[Person]:
@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_person.rq")
query=open(f"{path.dirname(path.realpath(__file__))}/releven_written_work.rq")
.read()
.replace("\n ", " "),
model=Person,
model=WrittenWork,
)
return adapter.query(page=page, size=size)
parameters = QueryParameters(page=page, size=size)
return adapter.query(parameters)
16 changes: 9 additions & 7 deletions releven_location.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from typing import Annotated

from pydantic import AnyUrl, BaseModel
from rdfproxy import SPARQLBinding
from pydantic import AnyUrl, BaseModel, Field # noqa: F401
from rdfproxy import ConfigDict, SPARQLBinding


class Location(BaseModel):
class Config:
title = "Location"
model_bool = "id"

id: Annotated[AnyUrl | None, SPARQLBinding("location")] = None
model_config = ConfigDict(
title="Location",
model_bool="id",
)
id: Annotated[AnyUrl | None, SPARQLBinding("location")] = Field(
default=None, exclude=True
)
location_descriptive_name: Annotated[
str | None, SPARQLBinding("location__location_descriptive_name")
] = None
61 changes: 48 additions & 13 deletions releven_person.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
from typing import Annotated

from pydantic import AnyUrl, BaseModel
from rdfproxy import SPARQLBinding
from pydantic import AnyUrl, BaseModel, Field # noqa: F401
from rdfproxy import ConfigDict, SPARQLBinding


class Person_PersonAppellationAssertion(BaseModel):
class Config:
title = "Name(s) in the sources"
model_bool = "id"

model_config = ConfigDict(
title="Name(s) in the sources",
model_bool="id",
)
id: Annotated[
AnyUrl | None, SPARQLBinding("person__person_appellation_assertion")
] = None
] = Field(default=None, exclude=True)
person_appellation_is: Annotated[
str | None,
SPARQLBinding("person__person_appellation_assertion__person_appellation_is"),
] = None


class Person(BaseModel):
class Config:
title = "Person"
model_bool = "id"
group_by = "person"

id: Annotated[AnyUrl | None, SPARQLBinding("person")] = None
model_config = ConfigDict(
title="Person",
model_bool="id",
group_by="id",
)
id: Annotated[AnyUrl | None, SPARQLBinding("person")] = Field(
default=None, exclude=True
)
person_id_assignment: Annotated[
list[AnyUrl], SPARQLBinding("person__person_id_assignment")
]
person_appellation_assertion: Annotated[
list[Person_PersonAppellationAssertion],
SPARQLBinding("person__person_appellation_assertion"),
]
person_gender_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_gender_assertion")
]
person_ethnicity_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_ethnicity_assertion")
]
person_descriptive_name: Annotated[
list[str], SPARQLBinding("person__person_descriptive_name")
]
person_possession_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_possession_assertion")
]
person_status_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_status_assertion")
]
person_religion_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_religion_assertion")
]
person_occupation_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_occupation_assertion")
]
person_language_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_language_assertion")
]
person_kinship_assertion: Annotated[
list[AnyUrl], SPARQLBinding("person__person_kinship_assertion")
]
birth_circumstances_claim: Annotated[
AnyUrl | None, SPARQLBinding("person__birth_circumstances_claim")
] = None
person_death_assertion: Annotated[
AnyUrl | None, SPARQLBinding("person__person_death_assertion")
] = None
69 changes: 65 additions & 4 deletions releven_person.rq
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,85 @@ PREFIX r11pros: <https://r11.eu/ns/prosopography/>

SELECT
?person
?person__person_id_assignment
?person__person_appellation_assertion
?person__person_appellation_assertion__person_appellation_is
?person__person_gender_assertion
?person__person_ethnicity_assertion
?person__person_descriptive_name
?person__person_possession_assertion
?person__person_status_assertion
?person__person_religion_assertion
?person__person_occupation_assertion
?person__person_language_assertion
?person__person_kinship_assertion
?person__birth_circumstances_claim
?person__person_death_assertion

WHERE {
?person a crm:E21_Person.

OPTIONAL {
?person__person_id_assignment a crm:E15_Identifier_Assignment.
?person ^crm:P140_assigned_attribute_to ?person__person_id_assignment.
}

OPTIONAL {
?person__person_appellation_assertion a star:E13_crm_P1.
?person__person_appellation_assertion crm:P140_assigned_attribute_to ?person.
?person ^crm:P140_assigned_attribute_to ?person__person_appellation_assertion.

?person__person_appellation_assertion___pai crm:P140_assigned_attribute_to ?person__person_appellation_assertion.
?person__person_appellation_assertion___pai crm:P141_assigned ?person__person_appellation_assertion___pai___pai.
?person__person_appellation_assertion___pai___pai crm:P190_has_symbolic_content ?person__person_appellation_assertion__person_appellation_is.
?person__person_appellation_assertion crm:P141_assigned ?person__person_appellation_assertion___pai.
?person__person_appellation_assertion___pai crm:P190_has_symbolic_content ?person__person_appellation_assertion__person_appellation_is.
}

OPTIONAL {
?person__person_gender_assertion a star:E13_crm_P41.
?person ^crm:P141_assigned ?person__person_gender_assertion.
}

OPTIONAL {
?person__person_ethnicity_assertion a star:E13_crm_P107.
?person ^crm:P141_assigned ?person__person_ethnicity_assertion.
}

OPTIONAL {
?person crm:P3_has_note ?person__person_descriptive_name.
}

OPTIONAL {
?person__person_possession_assertion a star:E13_crm_P51.
?person ^crm:P141_assigned ?person__person_possession_assertion.
}

OPTIONAL {
?person__person_status_assertion a star:E13_sdhss_P26.
?person ^crm:P141_assigned ?person__person_status_assertion.
}

OPTIONAL {
?person__person_religion_assertion a star:E13_sdhss_P36.
?person ^crm:P141_assigned ?person__person_religion_assertion.
}

OPTIONAL {
?person__person_occupation_assertion a star:E13_sdhss_P13.
?person ^crm:P141_assigned ?person__person_occupation_assertion.
}

OPTIONAL {
?person__person_language_assertion a star:E13_sdhss_P38.
?person ^crm:P140_assigned_attribute_to ?person__person_language_assertion.
}

OPTIONAL {
?person__person_kinship_assertion a star:E13_sdhss_P17.
?person ^crm:P141_assigned ?person__person_kinship_assertion.
}

?person__birth_circumstances_claim a star:E13_crm_P98.
?person ^crm:P141_assigned ?person__birth_circumstances_claim.

?person__person_death_assertion a star:E13_crm_P100.
?person ^crm:P141_assigned ?person__person_death_assertion.
}

71 changes: 11 additions & 60 deletions releven_written_work.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,21 @@
from typing import Annotated

from pydantic import AnyUrl, BaseModel
from rdfproxy import SPARQLBinding


class WrittenWork_WorkCreationAssertion_WorkCreation(BaseModel):
class Config:
title = "text_creation"
model_bool = "id"
group_by = "written_work__work_creation_assertion__work_creation"

id: Annotated[
AnyUrl | None,
SPARQLBinding("written_work__work_creation_assertion__work_creation"),
] = None
work_creation_6464e7f7408f5: Annotated[
list[AnyUrl],
SPARQLBinding(
"written_work__work_creation_assertion__work_creation__work_creation_6464e7f7408f5"
),
]
text_creation_timeframe_assertio: Annotated[
AnyUrl | None,
SPARQLBinding(
"written_work__work_creation_assertion__work_creation__text_creation_timeframe_assertio"
),
] = None


class WrittenWork_WorkCreationAssertion(BaseModel):
class Config:
title = "text_creation_assertion"
model_bool = "id"

id: Annotated[
AnyUrl | None, SPARQLBinding("written_work__work_creation_assertion")
] = None
work_creation: Annotated[
WrittenWork_WorkCreationAssertion_WorkCreation | None,
SPARQLBinding("written_work__work_creation_assertion__work_creation"),
] = None
work_creation_assertion_by: Annotated[
AnyUrl | None,
SPARQLBinding(
"written_work__work_creation_assertion__work_creation_assertion_by"
),
] = None
work_creation_assertion_by_64676da87229e: Annotated[
AnyUrl | None,
SPARQLBinding(
"written_work__work_creation_assertion__work_creation_assertion_by_64676da87229e"
),
] = None
from pydantic import AnyUrl, BaseModel, Field # noqa: F401
from rdfproxy import ConfigDict, SPARQLBinding


class WrittenWork(BaseModel):
class Config:
title = "Text Expression"
model_bool = "id"
group_by = "written_work"

id: Annotated[AnyUrl | None, SPARQLBinding("written_work")] = None
model_config = ConfigDict(
title="Text Expression",
model_bool="id",
group_by="id",
)
id: Annotated[AnyUrl | None, SPARQLBinding("written_work")] = Field(
default=None, exclude=True
)
written_work_label: Annotated[
str | None, SPARQLBinding("written_work__written_work_label")
] = None
work_creation_assertion: Annotated[
list[WrittenWork_WorkCreationAssertion],
SPARQLBinding("written_work__work_creation_assertion"),
list[AnyUrl], SPARQLBinding("written_work__work_creation_assertion")
]
31 changes: 1 addition & 30 deletions releven_written_work.rq
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ SELECT
?written_work
?written_work__written_work_label
?written_work__work_creation_assertion
?written_work__work_creation_assertion__work_creation
?written_work__work_creation_assertion__work_creation__work_creation_6464e7f7408f5
?written_work__work_creation_assertion__work_creation__text_creation_timeframe_assertio
?written_work__work_creation_assertion__work_creation_assertion_by
?written_work__work_creation_assertion__work_creation_assertion_by_64676da87229e

WHERE {
?written_work a r11:Text_Expression.
Expand All @@ -22,31 +17,7 @@ WHERE {

OPTIONAL {
?written_work__work_creation_assertion a star:E13_lrmoo_R17.
?written_work__work_creation_assertion crm:P141_assigned ?written_work.

?written_work__work_creation_assertion__work_creation a lrmoo:F28_Expression_Creation.
?written_work__work_creation_assertion___wc crm:P141_assigned ?written_work__work_creation_assertion.
?written_work__work_creation_assertion___wc crm:P140_assigned_attribute_to ?written_work__work_creation_assertion__work_creation.

OPTIONAL {
?written_work__work_creation_assertion__work_creation__work_creation_6464e7f7408f5 a star:E13_crm_P14.
?written_work__work_creation_assertion__work_creation___wc6 crm:P141_assigned ?written_work__work_creation_assertion__work_creation.
?written_work__work_creation_assertion__work_creation___wc6 crm:P140_assigned_attribute_to ?written_work__work_creation_assertion__work_creation___wc6___wc6.
?written_work__work_creation_assertion__work_creation__work_creation_6464e7f7408f5 crm:P140_assigned_attribute_to ?written_work__work_creation_assertion__work_creation___wc6___wc6.
}

?written_work__work_creation_assertion__work_creation__text_creation_timeframe_assertio a star:E13_crm_P4.
?written_work__work_creation_assertion__work_creation___tcta crm:P141_assigned ?written_work__work_creation_assertion__work_creation.
?written_work__work_creation_assertion__work_creation___tcta crm:P140_assigned_attribute_to ?written_work__work_creation_assertion__work_creation___tcta___tcta.
?written_work__work_creation_assertion__work_creation__text_creation_timeframe_assertio crm:P140_assigned_attribute_to ?written_work__work_creation_assertion__work_creation___tcta___tcta.

?written_work__work_creation_assertion__work_creation_assertion_by a crm:E21_Person.
?written_work__work_creation_assertion___wcab crm:P141_assigned ?written_work__work_creation_assertion.
?written_work__work_creation_assertion___wcab crm:P14_carried_out_by ?written_work__work_creation_assertion__work_creation_assertion_by.

?written_work__work_creation_assertion__work_creation_assertion_by_64676da87229e a r11:Author_Group.
?written_work__work_creation_assertion___wcab6 crm:P141_assigned ?written_work__work_creation_assertion.
?written_work__work_creation_assertion___wcab6 crm:P14_carried_out_by ?written_work__work_creation_assertion__work_creation_assertion_by_64676da87229e.
?written_work ^crm:P141_assigned ?written_work__work_creation_assertion.
}
}

0 comments on commit c83613f

Please sign in to comment.