Skip to content

Commit

Permalink
feat: adapts SPARQL queries to combine proxies in one entity
Browse files Browse the repository at this point in the history
until now we delivered every proxy as a single entity. given that there is now a flow that creates provided entities where no exist, we can start to deliver combined entities.
  • Loading branch information
sennierer committed Jul 6, 2023
1 parent 68ee2a2 commit 8451d0c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
10 changes: 5 additions & 5 deletions intavia_backend/sparql/entity_type_bindings_v2_1.sparql
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{%- if kind -%}
{%- for k1 in kind -%}
{?entity a {{k1.get_rdf_uri()}}
{?entity_proxy a {{k1.get_rdf_uri()}}
BIND("{{k1}}" AS ?entityTypeLabel)}
{% if not loop.last %}UNION{% endif %}
{%- endfor -%}
{%- else -%}
{?entity a idmcore:Person_Proxy
{?entity_proxy a idmcore:Person_Proxy
BIND("person" AS ?entityTypeLabel)
} UNION {
?entity a crm:E74_Group
?entity_proxy a crm:E74_Group
BIND("group" AS ?entityTypeLabel)
} UNION {
?entity a crm:E53_Place
?entity_proxy a crm:E53_Place
BIND("place" AS ?entityTypeLabel)
} UNION {
?entity a idm:CHO_Proxy
?entity_proxy a idm:CHO_Proxy
BIND("cultural-heritage-object" AS ?entityTypeLabel)
}
{%- endif -%}
28 changes: 15 additions & 13 deletions intavia_backend/sparql/query_entities_v2_1.sparql
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
?entity (crm:P1_is_identified_by/rdfs:label)|rdfs:label ?entityLabel .
?entity_proxy (crm:P1_is_identified_by/rdfs:label)|rdfs:label ?entityLabel .
GRAPH <http://www.intavia.eu/graphs/provided_persons>
{?entity_proxy idmcore:person_proxy_for ?entity .}
{%- if q -%}
?entityLabel bds:search "{{q}}" .
?entityLabel bds:rank ?score .
{%- endif -%}
{%- if occupation -%}
?entity bioc:has_occupation ?occupation1 .
?entity_proxy bioc:has_occupation ?occupation1 .
?occupation1 rdfs:label ?occupationLabel1 .
?occupationLabel1 bds:search "{{occupation}}" .
?occupationLabel1 bds:matchAllTerms "true" .
{%- endif -%}
{%- if occupations_id -%}
{%- for occ in occupations_id -%}
{?entity bioc:has_occupation <{{occ}}>}
{?entity_proxy bioc:has_occupation <{{occ}}>}
{% if not loop.last %}UNION{% endif %}
{%- endfor -%}
{%- endif -%}
{%- if born_before -%}
?bornBeforeEvent a crm:E67_Birth .
?bornBeforeEvent crm:P98_brought_into_life ?entity .
?bornBeforeEvent crm:P98_brought_into_life ?entity_proxy .
?bornBeforeEvent crm:P4_has_time-span/(crm:P82a_begin_of_the_begin|crm:P82b_end_of_the_end) ?bornBeforeFilter .
FILTER(?bornBeforeFilter < xsd:dateTime("{{born_before}}"))
{%- endif -%}
{%- if born_after -%}
?bornAfterEvent a crm:E67_Birth .
?bornAfterEvent crm:P98_brought_into_life ?entity .
?bornAfterEvent crm:P98_brought_into_life ?entity_proxy .
?bornAfterEvent crm:P4_has_time-span/(crm:P82a_begin_of_the_begin|crm:P82b_end_of_the_end) ?bornAfterFilter .
FILTER(?bornAfterFilter > xsd:dateTime("{{born_after}}"))
{%- endif -%}
{%- if died_before -%}
?diedBeforeEvent a crm:E69_Death .
?diedBeforeEvent crm:P100_was_death_of ?entity .
?diedBeforeEvent crm:P100_was_death_of ?entity_proxy .
?diedBeforeEvent crm:P4_has_time-span/(crm:P82a_begin_of_the_begin|crm:P82b_end_of_the_end) ?diedBeforeFilter .
FILTER(?diedBeforeFilter < xsd:dateTime("{{died_before}}"))
{%- endif -%}
{%- if died_after -%}
?diedAfterEvent a crm:E69_Death .
?diedAfterEvent crm:P100_was_death_of ?entity .
?diedAfterEvent crm:P100_was_death_of ?entity_proxy .
?diedAfterEvent crm:P4_has_time-span/(crm:P82a_begin_of_the_begin|crm:P82b_end_of_the_end) ?diedAfterFilter .
FILTER(?diedAfterFilter > xsd:dateTime("{{died_after}}"))
{%- endif -%}
{%- if gender -%}
?entity bioc:has_gender|bioc:gender bioc:{{gender.name}} .
?entity_proxy bioc:has_gender|bioc:gender bioc:{{gender.name}} .
{%- endif -%}
{%- if gender_id -%}
?entity bioc:has_gender|bioc:gender <{{gender_id}}> .
?entity_proxy bioc:has_gender|bioc:gender <{{gender_id}}> .
{%- endif -%}
{%- if related_entity -%}
?entity bioc:bearer_of ?role . ?role ^bioc:had_participant_in_role ?event .
?entity_proxy bioc:bearer_of ?role . ?role ^bioc:had_participant_in_role ?event .
?event (crm:P7_took_place_at|(bioc:had_participant_in_role/^bioc:bearer_of)) ?evEntity .
{?evEntity crm:P1_is_identified_by ?evEntityAppelation .
?evEntityAppelation a crm:E33_E41_Linguistic_Appellation .
Expand All @@ -55,20 +57,20 @@
?evEntityLabel bds:search "{{related_entity}}" .
{%- endif -%}
{%- if related_entities_id -%}
?entity bioc:bearer_of ?role . ?role ^bioc:had_participant_in_role|^bioc:occured_in_the_presence_of_in_role ?event .
?entity_proxy bioc:bearer_of ?role . ?role ^bioc:had_participant_in_role|^bioc:occured_in_the_presence_of_in_role ?event .
{%- for entity in related_entities_id -%}
{?event crm:P7_took_place_at|((bioc:had_participant_in_role|bioc:occured_in_the_presence_of_in_role)/^bioc:bearer_of) <{{entity}}>}
{% if not loop.last %}UNION{% endif %}
{%- endfor -%}
{%- endif -%}
{%- if event_role -%}
?entity bioc:bearer_of ?role .
?entity_proxy bioc:bearer_of ?role .
?role a/rdfs:label ?roleLabel .
?roleLabel bds:search "{{event_role}}" .
?roleLabel bds:matchAllTerms "true" .
{%- endif -%}
{%- if event_roles_id -%}
?entity bioc:bearer_of ?role .
?entity_proxy bioc:bearer_of ?role .
{%- for role in event_roles_id -%}
{?role a <{{role}}>}
{% if not loop.last %}UNION{% endif %}
Expand Down
18 changes: 9 additions & 9 deletions intavia_backend/sparql/retrieve_entities_v2_1.sparql
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
BIND("no label provided" AS ?defaultEntityLabel)
OPTIONAL {?entity crm:P1_is_identified_by ?appellation .
OPTIONAL {?entity_proxy crm:P1_is_identified_by ?appellation .
{?appellation a crm:E33_E41_Linguistic_Appellation .} UNION {?appellation a crm:E35_Title}
?appellation rdfs:label ?entityLabelPre .}
OPTIONAL {?entity bioc:has_occupation ?occupation . ?occupation rdfs:label ?occupationLabel .}
OPTIONAL {?entity owl:sameAs ?linkedIds}
OPTIONAL {?entity bioc:has_gender ?gender
OPTIONAL {?entity_proxy bioc:has_occupation ?occupation . ?occupation rdfs:label ?occupationLabel .}
OPTIONAL {?entity_proxy owl:sameAs ?linkedIds}
OPTIONAL {?entity_proxy bioc:has_gender ?gender
OPTIONAL {?gender rdfs:label ?genderLabel }}
OPTIONAL {?entity bioc:has_nationality ?nationality . ?nationality rdfs:label ?nationalityLabel .}
OPTIONAL {?entity bioc:bearer_of ?role .
OPTIONAL {?entity_proxy bioc:has_nationality ?nationality . ?nationality rdfs:label ?nationalityLabel .}
OPTIONAL {?entity_proxy bioc:bearer_of ?role .
?role ^bioc:had_participant_in_role|^bioc:occured_in_the_presence_of_in_role ?event .
?role a ?role_type
}
OPTIONAL {?entity crm:P168_place_is_defined_by/crm:P168_place_is_defined_by ?geometry}
OPTIONAL {?entity ^crm:P70_documents ?mediaObject }
OPTIONAL {?entity idmcore:bio_link ?biographyObject }
OPTIONAL {?entity_proxy crm:P168_place_is_defined_by/crm:P168_place_is_defined_by ?geometry}
OPTIONAL {?entity_proxy ^crm:P70_documents ?mediaObject }
OPTIONAL {?entity_proxy idmcore:bio_link ?biographyObject }
BIND(COALESCE(?entityLabelPre, ?defaultEntityLabel) AS ?entityLabel)
2 changes: 1 addition & 1 deletion intavia_backend/sparql/search_v2_1.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SELECT ?entity ?entityType ?entityTypeLabel ?entityLabel ?gender ?genderLabel ?n
{% include 'add_datasets_v2_1.sparql' %}

WITH {
SELECT DISTINCT ?entity ?entityTypeLabel ?score
SELECT DISTINCT ?entity ?entityTypeLabel ?score ?entity_proxy

{% include 'add_datasets_v2_1.sparql' %}

Expand Down

0 comments on commit 8451d0c

Please sign in to comment.