Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
taxonomy-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Global Dynamic Exposure
Libraries
taxonomy-lib
Commits
d71fa9c3
Commit
d71fa9c3
authored
1 month ago
by
Danijel Schorlemmer
Browse files
Options
Downloads
Patches
Plain Diff
Implement the JSON import and export of taxonomy data
parent
070e9d4e
Branches
39-implement-open-interval-for-tag-ybet
v25.01
Tags
v25.01-alpha.0
2 merge requests
!37
Resolve "Implement the JSON import and export of taxonomy data"
,
!35
Draft: Resolve "[Epic] Changes to taxonomy-lib for the 25.01 release"
Pipeline
#83399
passed
1 month ago
Stage: tests
Changes
2
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
taxonomylib/taxonomylib.py
+47
-1
47 additions, 1 deletion
taxonomylib/taxonomylib.py
tests/test_taxonomylib.py
+33
-0
33 additions, 0 deletions
tests/test_taxonomylib.py
with
80 additions
and
1 deletion
taxonomylib/taxonomylib.py
+
47
−
1
View file @
d71fa9c3
...
...
@@ -19,6 +19,8 @@
from
__future__
import
annotations
import
re
import
json
from
copy
import
deepcopy
from
math
import
floor
from
taxonomylib.constants
import
(
...
...
@@ -77,6 +79,46 @@ class Taxonomy:
else
:
self
.
_taxonomy_dict
=
taxonomy_dict
def
get_dict
(
self
)
->
dict
[
str
,
str
]:
"""
Returns the internal dictionary with taxonomy data.
Returns:
dict [str, str]:
Copy of internal dictionary with taxonomy data.
"""
return
deepcopy
(
self
.
_taxonomy_dict
)
@classmethod
def
load_json
(
cls
,
json_taxonomy
:
str
)
->
Taxonomy
:
"""
Initializes a `Taxonomy` object with reading the provided taxonomy data from a JSON
string into the `_taxonomy_dict` dictionary.
Args:
json_taxonomy (str):
Taxonomy data in JSON format.
Returns:
A `Taxonomy` object with taxonomy data from the taxonomy string.
"""
taxonomy
=
cls
(
json
.
loads
(
json_taxonomy
))
taxonomy
.
is_valid
()
return
taxonomy
def
get_json
(
self
)
->
str
:
"""
Creates a JSON string from the internal taxonomy dictionary.
Returns:
str:
A representation of the internal taxonomy dictionary as JSON string.
"""
return
json
.
dumps
(
self
.
_taxonomy_dict
,
indent
=
4
)
@classmethod
def
load_taxonomy_string
(
cls
,
taxonomy_string
:
str
)
->
Taxonomy
:
"""
...
...
@@ -249,7 +291,11 @@ class Taxonomy:
"""
Checks if the taxonomy data is valid. Checks for the following attributes are
implemented:
- height attribute.
- `HEI` attribute.
- `HIM` attribute.
- `HEB` attribute.
- date attribute.
- roof attribute.
"""
self
.
_is_valid_hei_attribute
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_taxonomylib.py
+
33
−
0
View file @
d71fa9c3
...
...
@@ -470,3 +470,36 @@ def test_check_for_occupancy_match():
f
"
The resulting tag of
{
test_dataset
[
0
]
}
and
{
test_dataset
[
1
]
}
should be
"
f
"
{
test_dataset
[
2
][
1
]
}
but
{
result
}
was returned.
"
)
def
test_load_get_json
():
"""
Tests if the `load_json()` and `get_json()` functions correctly export a JSON string from
the dictionary of taxonomy data and read it back in correctly. For this the taxonomy data is
provided as a standard taxonomy string, read into the internal dictionary, exported to JSON,
read back in from JSON and exported again to the standard string. If the string is recreated
identically, the test passes.
"""
test_datasets
=
[
"
CR+CIP/LFINF+CDL+LFC:15.0/HBET:4-7/BPD/EWMA/RSH1/FC
"
,
"
CR/LDUAL+CDN/HBET:3-5/SOS
"
,
"
CR/LWAL+CDM+DUL/HBET:31-/RES
"
,
"
MUR+STRUB+MOM/LWAL+CDN/HBET:3-6/COM
"
,
"
S/LFBR/HBET:1-3/YBET:1976-1978/SOS
"
,
"
W+WLI/LWAL+CDM/HBET:1-2/RES1/RWO3
"
,
"
MUR/LWAL+CDL/HBET:1-2/RES2A/EWMA
"
,
"
CR+CIP/LWAL+CDN/HBET:1-3/RES4
"
,
"
CR+CIP/LFM+CDM/HBET:1-3/RES2D
"
,
"
CR+PC/LWAL+CDM/COM3
"
,
"
S+SL/LFM+CDM/COM2
"
,
"
MUR/LWAL+CDN/HBET:1-2/COM5/EWMA
"
,
"
CR+CIP/LWAL+CDM/HBET:1-3/IND2
"
,
"
S+SL/LFM+CDN/IND2
"
,
]
for
test_dataset
in
test_datasets
:
taxonomy
=
Taxonomy
.
load_taxonomy_string
(
test_dataset
)
json_string
=
taxonomy
.
get_json
()
taxonomy
=
Taxonomy
.
load_json
(
json_string
)
taxonomy_string
=
taxonomy
.
get_standard_string
()
assert
taxonomy_string
==
test_dataset
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment