Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update utils.py #62

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions src/scribe_data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,22 @@ def _load_json(package_path: str, file_name: str, root: str):


def _find(source_key: str, source_value: str, target_key: str, error_msg: str):
"""
Each 'language', (english, german,..., etc) is a dictionary of key/value pairs:

entry = {
"language": "english",
"iso": "en",
"qid": "Q1860",
"remove-words": [...],
"ignore-words": [...]
}
"""Loads a JSON resource from a package into a python entity.

Given a key/value pair, the 'source', and the 'target' key, get the 'target' value.
Parameters
----------
package_path : str
The fully qualified package that contains the resource.

Args:
source_value (str): e.g. 'english'.
source_key (str): e.g. 'language'.
target_key (str): e.g. 'iso'.
error_msg (str): for when a value cannot be found.
file_name : str
The name of the file (resource) that contains the JSON data.

Raises:
ValueError: when a source_value is not supported.
root : str
The root node of the JSON document.

Returns:
The 'target' value given the passed arguments.
Returns
-------
A python entity starting at 'root'.
"""
norm_source_value = source_value.lower()

Expand Down
Loading