From 07f5c2f4cbd6301ac1a899700a4df4e2d5e4fed3 Mon Sep 17 00:00:00 2001 From: Sheean Spoel Date: Mon, 28 Aug 2023 17:03:56 +0200 Subject: [PATCH] whitespace --- compound_splitter/api_web.py | 6 +++--- compound_splitter/evaluate.py | 17 +++++++++-------- compound_splitter/socket_server.py | 2 +- compound_splitter/splitter.py | 8 ++++---- setup.py | 2 +- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/compound_splitter/api_web.py b/compound_splitter/api_web.py index 196422c..34f1f83 100644 --- a/compound_splitter/api_web.py +++ b/compound_splitter/api_web.py @@ -18,7 +18,7 @@ def get_split(method_name: str, compound: str): If this is the first time the method is called during runtime, run its `start` method. ''' - + if method_name in started_methods: method = started_methods[method_name] else: @@ -34,14 +34,14 @@ def get_list(): ''' Return an array of all available methods. ''' - + methods = list_methods() return jsonify(methods) def cleanup(): ''' - Execute teardown for each method that has + Execute teardown for each method that has been started up. ''' diff --git a/compound_splitter/evaluate.py b/compound_splitter/evaluate.py index 8484c8a..d0626c6 100644 --- a/compound_splitter/evaluate.py +++ b/compound_splitter/evaluate.py @@ -25,6 +25,7 @@ If the test set is larger, a random sample will be evaluated. ''' + class MisalignedError(Exception): pass @@ -38,7 +39,7 @@ def compare_methods(): - the data - evaluation statistics ''' - + for test_set_name, test_set in read_test_sets(): stats = list(evaluate_methods(test_set)) stats.sort(key=lambda item: item["accuracy"], reverse=True) @@ -56,10 +57,10 @@ def read_test_sets(): Each test set should be a CSV file in the test_sets directory. If the number of items in the set is greater than 100, a random sample will be used. - + Returns a generator which yields the name and data for each file. ''' - + dirname = os.path.dirname(__file__) test_sets_dir = os.path.join(dirname, "..", "test_sets") for test_set_name in os.listdir(test_sets_dir): @@ -99,7 +100,7 @@ def evaluate_methods(test_set: List[Tuple[str, str]]): Returns a dictionary with evaluation results ''' - + methods = list_methods() main_test_set = list( (compound, only_main(expected)) for (compound, expected) in test_set) @@ -132,7 +133,7 @@ def split(method, compound: str) -> str: result is selected. If the method returns no results, returns the word without splits. ''' - + candidates = method.split(compound)["candidates"] highest_score = 0 best_candidate = None @@ -160,7 +161,7 @@ def evaluate_method(method_name: str, - accuracy (ratio of words that were split correctly) - skipped (number of words with invalid results) ''' - + skipped = 0 # number of correctly passed through words # i.e. words which weren't split and should not have been split @@ -214,7 +215,7 @@ def call_method(method_name: str, test_set: List[Tuple[str, str]]): Call a compound split method and run it for everything in a test set. ''' - + method = get_method(method_name) print("METHOD:", method_name) start = perf_counter() @@ -255,7 +256,7 @@ def score(actual: str, expected: str) -> Tuple[int, int, int]: # noqa: C901 should not have been split, but was) - the number of true positives (correct splits) ''' - + actual_len = len(actual) expected_len = len(expected) diff --git a/compound_splitter/socket_server.py b/compound_splitter/socket_server.py index 865a776..a123f5f 100644 --- a/compound_splitter/socket_server.py +++ b/compound_splitter/socket_server.py @@ -55,7 +55,7 @@ def cleanup(): Run the `stop` function of each method ''' - + for method in started_methods.values(): method.stop() diff --git a/compound_splitter/splitter.py b/compound_splitter/splitter.py index 84f1e68..9f3ae2e 100644 --- a/compound_splitter/splitter.py +++ b/compound_splitter/splitter.py @@ -12,7 +12,7 @@ class Module: ''' Object representing a python module with compound splitting functions. ''' - + def __init__(self, name: str, run_data): self.module = cast(Any, importlib.import_module(f"methods.{name}")) @@ -56,7 +56,7 @@ def get_method_data(name: str): Opens the `run.json` file in the method directory and returns its contents. ''' - + with open(os.path.join(METHODS_DIR, name, 'run.json')) as run_json: return json.load(run_json) @@ -70,7 +70,7 @@ def get_method(name: str): Output is a python object with `split`, `start`, `stop`, and `prepare` methods. ''' - + run_data = get_method_data(name) method = { 'module': Module(name, run_data) @@ -87,7 +87,7 @@ def list_methods(): and read the JSON configuration for each. Returns a dict with metadata for each method. ''' - + methods = [] for name in os.listdir(METHODS_DIR): if name == "__pycache__": diff --git a/setup.py b/setup.py index fc1f76c..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,3 @@ from setuptools import setup -setup() \ No newline at end of file +setup()