diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-04-08 16:00:43 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-04-08 16:00:43 +0200 |
| commit | ba69ff0a4d01921a61f06c9867662e2c76b0346f (patch) | |
| tree | 4b9fa6f8208863fcdd815f30df359307f103da1c | |
| parent | 9b41cb5b704279c62e058aba10bc0e4d664ceb6d (diff) | |
scots flag
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | cli/commands/bridge/words.py | 16 |
2 files changed, 13 insertions, 4 deletions
@@ -43,6 +43,7 @@ python cli.py bridge words --a light --b dark | --b TEXT | Ending word | (required) | | --include_oe | Include OE/archaic words | (off) | | --include_slang | Include slang/colloquial words | (off) | +| --include_scots | Include Scots words | (off) | | --words_per_step INTEGER | Number of words to check per step | 20 | | --categories_per_word INTEGER | Number of categories to check per word | 3 | | --min_depth INTEGER | Minimum depth of matches | 10 | diff --git a/cli/commands/bridge/words.py b/cli/commands/bridge/words.py index 0bbf3a5..4bc0982 100644 --- a/cli/commands/bridge/words.py +++ b/cli/commands/bridge/words.py @@ -20,6 +20,8 @@ from app.thesaurus.api import Thesaurus help='Whether to include OE/archaic words') @click.option('-sl', '--include_slang', 'opt_include_slang', is_flag=True, help='Whether to include slang/colloquial words') +@click.option('-sc', '--include_scots', 'opt_include_scots', is_flag=True, + help='Whether to include Scots words') @click.option('-w', '--words_per_step', 'opt_words_per_step', default=20, help='Number of words to check per step') @click.option('-c', '--categories_per_word', 'opt_categories_per_word', default=3, @@ -29,12 +31,12 @@ from app.thesaurus.api import Thesaurus @click.option('-sh', '--use_shortest_path', 'opt_use_shortest_path', is_flag=True, help='Use shortest path between words') @click.pass_context -def cli(ctx, opt_word_a, opt_word_b, opt_include_oe, opt_include_slang, opt_words_per_step, opt_categories_per_word, opt_min_depth, opt_use_shortest_path): +def cli(ctx, opt_word_a, opt_word_b, opt_include_oe, opt_include_slang, opt_include_scots, opt_words_per_step, opt_categories_per_word, opt_min_depth, opt_use_shortest_path): """ Find connections between two words """ thesaurus = Thesaurus() - solver = TreeSolver(thesaurus, opt_word_a, opt_word_b, opt_include_oe, opt_include_slang, opt_words_per_step, opt_categories_per_word, opt_min_depth, opt_use_shortest_path) + solver = TreeSolver(thesaurus, opt_word_a, opt_word_b, opt_include_oe, opt_include_slang, opt_include_scots, opt_words_per_step, opt_categories_per_word, opt_min_depth, opt_use_shortest_path) print(f"Starting word: {opt_word_a}") print(f"Ending word: {opt_word_b}") @@ -56,12 +58,13 @@ def cli(ctx, opt_word_a, opt_word_b, opt_include_oe, opt_include_slang, opt_word # print(solver.skips) class TreeSolver: - def __init__(self, thesaurus, word_a, word_b, include_oe, include_slang, words_per_step, categories_per_word, min_depth, use_shortest_path): + def __init__(self, thesaurus, word_a, word_b, include_oe, include_slang, include_scots, words_per_step, categories_per_word, min_depth, use_shortest_path): self.thesaurus = thesaurus self.word_a = word_a self.word_b = word_b self.include_oe = include_oe self.include_slang = include_slang + self.include_scots = include_scots self.words_per_step = words_per_step self.categories_per_word = categories_per_word self.skips = [] @@ -123,6 +126,8 @@ class TreeSolver: return None if not self.include_slang and self.is_slang(years): return None + if not self.include_scots and self.is_scots(years): + return None if word not in tree: tree[word] = tree[catid] + 1 self.max_dist = max(self.max_dist, tree[word]) @@ -240,7 +245,10 @@ class TreeSolver: return (('oe' in years and 'oe-' not in years) or 'arch' in years) def is_slang(self, years): - return 'slang' in years or 'colloq' in years or 'Scots' in years + return 'slang' in years or 'colloq' in years + + def is_scots(self, years): + return 'Scots' in years def fix_word(self, word): if '<' in word or '/' in word or ',' in word: |
