Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ChEMBL
C
ChEMBL
Main Web Interface
Elasticsearch Proxy API
Commits
49d6a58d
Commit
49d6a58d
authored
Jul 01, 2021
by
David Mendez
Browse files
Entities joiner: use a function to generate the join query depending on configuration
parent
f71c8cb2
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
25 deletions
+42
-25
app/entities_joiner/entities_joiner.py
app/entities_joiner/entities_joiner.py
+13
-11
app/entities_joiner/standardisation.py
app/entities_joiner/standardisation.py
+29
-14
No files found.
app/entities_joiner/entities_joiner.py
View file @
49d6a58d
...
...
@@ -36,7 +36,7 @@ def get_tiny_hash_to_related_items(destination_entity_browser_state_template,
app_logging
.
debug
(
f
'entities join cache_key:
{
cache_key
}
'
)
cache_response
=
cache
.
fail_proof_get
(
key
=
cache_key
)
if
cache_response
is
None
:
if
cache_response
is
not
None
:
save_statistics
(
entity_from
,
entity_to
,
None
,
True
)
return
cache_response
...
...
@@ -71,15 +71,17 @@ def get_tiny_hash_to_related_items(destination_entity_browser_state_template,
index_name
=
standardisation
.
get_index_name_for_origin_entity
(
parsed_origin_entity
)
fail_if_null
(
index_name
,
'index name'
,
parsed_origin_entity
,
parsed_destination_entity
)
from
_property
=
standardisation
.
get_
from
_property
(
parsed_origin_entity
,
parsed_destination_entity
)
fail_if_null
(
from
_property
,
'
from
property'
,
parsed_origin_entity
,
parsed_destination_entity
)
origin
_property
=
standardisation
.
get_
origin
_property
(
parsed_origin_entity
,
parsed_destination_entity
)
fail_if_null
(
origin
_property
,
'
origin
property'
,
parsed_origin_entity
,
parsed_destination_entity
)
selection_description
=
json
.
loads
(
raw_selection_description
)
es_query
=
json
.
loads
(
raw_es_query
)
ids
=
ids_loader
.
load_ids_for_query
(
es_query
,
selection_description
,
from
_property
,
index_name
)
ids
=
ids_loader
.
load_ids_for_query
(
es_query
,
selection_description
,
origin
_property
,
index_name
)
to_property
=
standardisation
.
get_to_property
(
parsed_origin_entity
,
parsed_destination_entity
)
fail_if_null
(
to_property
,
'to property'
,
parsed_origin_entity
,
parsed_destination_entity
)
destination_query_generator
=
standardisation
.
get_destination_query_generator
(
parsed_origin_entity
,
parsed_destination_entity
)
fail_if_null
(
destination_query_generator
,
'destination query generator'
,
parsed_origin_entity
,
parsed_destination_entity
)
settings_path
=
standardisation
.
get_settings_path_for_destination_entity
(
parsed_destination_entity
)
fail_if_null
(
settings_path
,
'settings path'
,
parsed_origin_entity
,
parsed_destination_entity
)
...
...
@@ -87,7 +89,7 @@ def get_tiny_hash_to_related_items(destination_entity_browser_state_template,
browser_name
=
standardisation
.
get_browser_names_for_destination_entity
(
parsed_destination_entity
)
fail_if_null
(
browser_name
,
'browser name'
,
parsed_origin_entity
,
parsed_destination_entity
)
join_state_hash
=
get_join_state_hash
(
ids
,
to_property
,
settings_path
,
browser_name
,
join_state_hash
=
get_join_state_hash
(
ids
,
destination_query_generator
,
settings_path
,
browser_name
,
destination_entity_browser_state_template
,
previous_hash
)
...
...
@@ -129,18 +131,18 @@ def fail_if_null(value, value_name, parsed_origin_entity, parsed_destination_ent
f
'to
{
parsed_destination_entity
.
value
}
'
)
def
get_join_state_hash
(
ids
,
to_property
,
settings_path
,
browser_name
,
destination_entity_browser_state_template
,
def
get_join_state_hash
(
ids
,
destination_query_generator
,
settings_path
,
browser_name
,
destination_entity_browser_state_template
,
previous_hash
):
"""
:param ids: list of its for the join
:param
to_property: entity to which to do the join
:param
destination_query_generator: function that generates the join query from a list of ids
:param settings_path: settings path to be used by the user interface
:param browser_name: name of the destination browser used to build the desired url
:param destination_entity_browser_state_template: template to build the url for the destination entity browser
:param previous_hash: hash of the state that originated this join of entities
:return: the hash for the query state used for the join
"""
ids_clauses
=
" OR "
.
join
([
f
'"
{
item_id
}
"'
for
item_id
in
ids
])
desired_state
=
{
'origin'
:
{
'type'
:
'ENTITIES_JOIN'
,
...
...
@@ -148,7 +150,7 @@ def get_join_state_hash(ids, to_property, settings_path, browser_name, destinati
},
'list'
:
{
'settings_path'
:
settings_path
,
'custom_query'
:
f
'
{
to_property
}
(
{
ids_clauses
}
)'
,
'custom_query'
:
destination_query_generator
(
ids
)
,
'use_custom_query'
:
True
,
'search_term'
:
""
,
'at_least_one_facet_is_selected'
:
False
,
...
...
app/entities_joiner/standardisation.py
View file @
49d6a58d
...
...
@@ -65,29 +65,44 @@ def get_index_name_for_origin_entity(parsed_origin_entity):
return
index_name
def
create_simple_query_generator
(
destination_property
):
"""
:param destination_property: property to use to build the query
:return: a function to be used to build the join query
"""
def
join_function
(
ids
):
"""
:param ids: ids of the items matches
:return: query to use for the join
"""
ids_clauses
=
" OR "
.
join
([
f
'"
{
item_id
}
"'
for
item_id
in
ids
])
return
f
'
{
destination_property
}
(
{
ids_clauses
}
)'
return
join_function
JOIN_PROPERTIES
=
{
'from'
:
{
PossibleOriginEntities
.
CHEMBL_DRUG_WARNINGS
:
{
'to'
:
{
PossibleDestinationEntities
.
CHEMBL_ACTIVITIES
:
{
'
from
_property'
:
'drug_warning.molecule_chembl_id'
,
'
to_property'
:
'molecule_chembl_id'
'
origin
_property'
:
'drug_warning.molecule_chembl_id'
,
'
destination_query_generator'
:
create_simple_query_generator
(
'molecule_chembl_id'
)
},
PossibleDestinationEntities
.
CHEMBL_COMPOUNDS
:
{
'
from
_property'
:
'drug_warning.molecule_chembl_id'
,
'
to_property'
:
'molecule_chembl_id'
'
origin
_property'
:
'drug_warning.molecule_chembl_id'
,
'
destination_query_generator'
:
create_simple_query_generator
(
'molecule_chembl_id'
)
},
PossibleDestinationEntities
.
CHEMBL_DRUGS
:
{
'
from
_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'
to_property'
:
'molecule_chembl_id'
'
origin
_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'
destination_query_generator'
:
create_simple_query_generator
(
'molecule_chembl_id'
)
},
PossibleDestinationEntities
.
CHEMBL_DRUG_MECHANISMS
:
{
'
from
_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'
to_property'
:
'molecule_chembl_id'
'
origin
_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'
destination_query_generator'
:
create_simple_query_generator
(
'molecule_chembl_id'
)
},
PossibleDestinationEntities
.
CHEMBL_DRUG_INDICATIONS
:
{
'
from
_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'
to_property'
:
'molecule_chembl_id'
'
origin
_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'
destination_query_generator'
:
create_simple_query_generator
(
'molecule_chembl_id'
)
}
}
}
...
...
@@ -112,7 +127,7 @@ BROWSER_NAMES_FOR_DESTINATION_ENTITIES = {
}
def
get_
from
_property
(
parsed_origin_entity
,
parsed_destination_entity
):
def
get_
origin
_property
(
parsed_origin_entity
,
parsed_destination_entity
):
"""
:param parsed_origin_entity: entity 'from' parsed by the PossibleEntitiesFrom enum
:param parsed_destination_entity: entity 'to' parsed by the PossibleEntitiesTo enum
...
...
@@ -122,10 +137,10 @@ def get_from_property(parsed_origin_entity, parsed_destination_entity):
get
(
'from'
,
{}).
\
get
(
parsed_origin_entity
,
{}).
\
get
(
'to'
,
{}).
\
get
(
parsed_destination_entity
,
{}).
get
(
'
from
_property'
)
get
(
parsed_destination_entity
,
{}).
get
(
'
origin
_property'
)
def
get_
to_property
(
parsed_origin_entity
,
parsed_destination_entity
):
def
get_
destination_query_generator
(
parsed_origin_entity
,
parsed_destination_entity
):
"""
:param parsed_origin_entity: entity 'from' parsed by the PossibleEntitiesFrom enum
:param parsed_destination_entity: entity 'to' parsed by the PossibleEntitiesTo enum
...
...
@@ -135,7 +150,7 @@ def get_to_property(parsed_origin_entity, parsed_destination_entity):
get
(
'from'
,
{}).
\
get
(
parsed_origin_entity
,
{}).
\
get
(
'to'
,
{}).
\
get
(
parsed_destination_entity
,
{}).
get
(
'
to_property
'
)
get
(
parsed_destination_entity
,
{}).
get
(
'
destination_query_generator
'
)
def
get_settings_path_for_destination_entity
(
parsed_destination_entity
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment