Skip to content

Commit

Permalink
whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
oktaal committed Aug 28, 2023
1 parent 8cceb2e commit 07f5c2f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions compound_splitter/api_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
'''

Expand Down
17 changes: 9 additions & 8 deletions compound_splitter/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
If the test set is larger, a random sample will be evaluated.
'''


class MisalignedError(Exception):
pass

Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion compound_splitter/socket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def cleanup():
Run the `stop` function of each method
'''

for method in started_methods.values():
method.stop()

Expand Down
8 changes: 4 additions & 4 deletions compound_splitter/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from setuptools import setup

setup()
setup()

0 comments on commit 07f5c2f

Please sign in to comment.