Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
E
ES Subset Generator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ChEMBL
C
ChEMBL
Main Web Interface
ES Subset Generator
Commits
bcf192ec
Commit
bcf192ec
authored
Aug 18, 2020
by
David Mendez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement mapping_to_apply generation for nested properties
parent
f07d8524
Pipeline
#93046
passed with stages
in 3 minutes and 33 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
17 deletions
+99
-17
app/es_subset_generator/mappings.py
app/es_subset_generator/mappings.py
+42
-5
app/es_subset_generator/test/data/mappings_to_apply_must_be_1json
...ubset_generator/test/data/mappings_to_apply_must_be_1json
+51
-0
app/es_subset_generator/test/test_mappings_handling.py
app/es_subset_generator/test/test_mappings_handling.py
+6
-12
No files found.
app/es_subset_generator/mappings.py
View file @
bcf192ec
...
...
@@ -27,15 +27,52 @@ def parse_mapping_from_es_response(index_mapping, required_source):
:param required_source: source (list of properties) to get from the mapping
:return: the mapping ready to be applied to the subset index
"""
mappings_to_apply
=
{
all_
mappings_to_apply
=
{
'properties'
:
{}
}
for
current_property
in
required_source
:
mapping_to_apply
=
get_mapping_to_apply_in_subset_index
(
index_mapping
,
current_property
)
mappings_to_apply
[
'properties'
][
current_property
]
=
mapping_to_apply
for
current_property_path
in
required_source
:
mapping_to_apply
=
get_mapping_to_apply_in_subset_index
(
index_mapping
,
current_property_path
)
add_mapping_to_property_path
(
mapping_to_apply
,
all_mappings_to_apply
,
current_property_path
)
return
all_mappings_to_apply
def
add_mapping_to_property_path
(
mapping_to_apply
,
all_mappings_to_apply
,
property_path
):
"""
Adds the mapping to all the mappings to apply to the path indicated as parameter
:param mapping_to_apply: mapping to add to the dict
:param all_mappings_to_apply: a dict with all the mappings to apply
:param property_path: path to the property
"""
print
(
'property_path: '
,
property_path
)
prop_path_parts
=
property_path
.
split
(
'.'
)
current_prop
=
prop_path_parts
[
0
]
print
(
'prop_path_parts: '
,
prop_path_parts
)
if
len
(
prop_path_parts
)
==
1
:
all_mappings_to_apply
[
'properties'
][
current_prop
]
=
mapping_to_apply
else
:
container_dict
=
all_mappings_to_apply
[
'properties'
].
get
(
current_prop
)
if
container_dict
is
None
:
all_mappings_to_apply
[
'properties'
][
current_prop
]
=
{
'properties'
:
{}
}
rest_of_the_path_parts
=
prop_path_parts
[
1
:]
rest_of_the_path
=
'.'
.
join
(
rest_of_the_path_parts
)
inside_mappings_to_apply
=
all_mappings_to_apply
[
'properties'
][
current_prop
]
add_mapping_to_property_path
(
mapping_to_apply
,
inside_mappings_to_apply
,
rest_of_the_path
)
return
mappings_to_apply
def
get_mapping_to_apply_in_subset_index
(
index_mapping
,
property_path
):
...
...
app/es_subset_generator/test/data/mappings_to_apply_must_be_1json
0 → 100644
View file @
bcf192ec
{
"properties": {
"molecule_properties": {
"properties": {
"hba": {
"type": "integer"
},
"psa": {
"type": "double"
},
"molecular_species": {
"type": "keyword"
}
}
},
"molecule_synonyms": {
"properties": {
"molecule_synonym": {
"type": "keyword"
},
"syn_type": {
"type": "keyword"
},
"synonyms": {
"type": "keyword"
}
}
},
"_metadata": {
"properties": {
"drug": {
"properties": {
"drug_data": {
"properties": {
"withdrawn_year": {
"type": "short"
},
"prodrug": {
"type": "boolean"
}
}
}
}
}
}
},
"helm_notation": {
"type": "keyword"
}
}
}
\ No newline at end of file
app/es_subset_generator/test/test_mappings_handling.py
View file @
bcf192ec
...
...
@@ -54,25 +54,19 @@ class TestMappingsHandling(unittest.TestCase):
]
mappings_to_apply_got
=
mappings
.
parse_mapping_from_es_response
(
mapping_from_base_index
,
source
)
print
(
'mappings_to_apply_got:'
)
print
(
json
.
dumps
(
mappings_to_apply_got
,
indent
=
4
))
mappings_to_apply_must_be
=
{
"properties"
:
{
'pref_name'
:
{
'type'
:
'keyword'
},
}
}
mappings_to_apply_must_be_path
=
'app/es_subset_generator/test/data/mappings_to_apply_must_be_1json'
# self.assertEqual(mappings_to_apply_got, mappings_to_apply_must_be,
# msg='The mappings were not produced correctly!')
with
open
(
mappings_to_apply_must_be_path
,
'rt'
)
as
mappings_to_apply_must_be_file
:
mappings_to_apply_must_be
=
json
.
load
(
mappings_to_apply_must_be_file
)
self
.
assertEqual
(
mappings_to_apply_got
,
mappings_to_apply_must_be
,
msg
=
'The mappings were not produced correctly!'
)
def
test_locates_source_config_of_property
(
self
):
"""
Test that it locates the config of a property
"""
sample_mapping_path
=
'app/es_subset_generator/test/data/sample_mapping_1.json'
with
open
(
sample_mapping_path
,
'rt'
)
as
sample_mapping_file
:
...
...
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