From 649e5d1327e778fc50c9485a13c455f33bc33382 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 16 Aug 2021 16:33:43 -0700 Subject: [PATCH] Allow reuse of get_absolute_path, is_none_or_empty methods - Move them to utils.helper.py for reuse - Import those modules where required - Delete duplicate methods defined in org_to_jsonl.py, asymmetric.py --- processor/org_mode/org_to_jsonl.py | 9 +-------- search_type/asymmetric.py | 6 +----- utils/__init__.py | 0 utils/helpers.py | 9 +++++++++ 4 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 utils/__init__.py create mode 100644 utils/helpers.py diff --git a/processor/org_mode/org_to_jsonl.py b/processor/org_mode/org_to_jsonl.py index 016435d3..9e786abb 100644 --- a/processor/org_mode/org_to_jsonl.py +++ b/processor/org_mode/org_to_jsonl.py @@ -2,6 +2,7 @@ # Import Modules import processor.org_mode.orgnode +from utils.helpers import get_absolute_path, is_none_or_empty import json import argparse import pathlib @@ -119,14 +120,6 @@ def convert_org_entries_to_jsonl(entries, verbose=0): return jsonl -def is_none_or_empty(item): - return item == None or (hasattr(item, '__iter__') and len(item) == 0) - - -def get_absolute_path(filepath): - return str(pathlib.Path(filepath).expanduser().absolute()) - - if __name__ == '__main__': # Setup Argument Parser parser = argparse.ArgumentParser(description="Map Org-Mode notes into (compressed) JSONL format") diff --git a/search_type/asymmetric.py b/search_type/asymmetric.py index ddcd526e..74078563 100644 --- a/search_type/asymmetric.py +++ b/search_type/asymmetric.py @@ -10,7 +10,7 @@ import re import torch import argparse import pathlib - +from utils.helpers import get_absolute_path def initialize_model(): "Initialize model for assymetric semantic search. That is, where query smaller than results" @@ -140,10 +140,6 @@ def collate_results(hits, entries, count=5): in hits[0:count]] -def get_absolute_path(filepath): - return str(pathlib.Path(filepath).expanduser().absolute()) - - if __name__ == '__main__': # Setup Argument Parser parser = argparse.ArgumentParser(description="Map Org-Mode notes into (compressed) JSONL format") diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/utils/helpers.py b/utils/helpers.py new file mode 100644 index 00000000..64902835 --- /dev/null +++ b/utils/helpers.py @@ -0,0 +1,9 @@ +import pathlib + + +def is_none_or_empty(item): + return item == None or (hasattr(item, '__iter__') and len(item) == 0) + + +def get_absolute_path(filepath): + return str(pathlib.Path(filepath).expanduser().absolute())