aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2020-05-22 01:56:22 +0200
committerache <ache@ache.one>2020-05-22 01:56:22 +0200
commit20be469a317e3de493e19103fe2690855d84984f (patch)
tree521695e9cdff0ccdc456d7f2ba40b17e0d28304e
parentAdd Makefile install (diff)
Exact matching
-rwxr-xr-xdicofr.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/dicofr.py b/dicofr.py
index b41f658..6ae3d3e 100755
--- a/dicofr.py
+++ b/dicofr.py
@@ -53,8 +53,21 @@ def matching(word):
"""
Find matching words in the list of words
"""
- print("Error: Not implemented yet", file=sys.stderr)
- pass
+
+ matchingWord = []
+
+ with open('list_word.msgpk', 'rb') as f:
+ msgpackList = f.read()
+ listWord = msgpack.unpackb(msgpackList, raw=False)
+
+ if word[0] != '/':
+ for w in listWord:
+ if word == w:
+ matchingWord.append(w)
+ else:
+ print("Error: Not implemented yet", file=sys.stderr)
+
+ return matchingWord
if __name__ == '__main__':
@@ -69,12 +82,12 @@ if __name__ == '__main__':
else:
dico = f'{DIR_PATH}/{dico}'
- parser = argparse.ArgumentParser(description='Get a french word\'s definition.')
+ parser = argparse.ArgumentParser(description='Get a french word\'s definition')
parser.add_argument('--sql', dest='action', action='store_const',
const=get_def_sql_reg, default=get_def_sql,
help='search a definition using SQL regex, '
'_ to match a letter, %% to match a group of letters')
- parser.add_argument('--matching', dest='matching', action='store_true',
+ parser.add_argument('-m', '--matching', dest='matching', action='store_true',
help='search the french words that match the regex')
parser.add_argument('word', metavar='PATTERN', type=str,
help='the word or the pattern to match')
@@ -82,7 +95,14 @@ if __name__ == '__main__':
arg = parser.parse_args()
if arg.matching:
- matching(arg.word)
+ ret = matching(arg.word)
+ for word in ret:
+ print(word)
+ if not ret:
+ exit(1)
else:
for w in arg.action(arg.word):
ui.show_terminal(w)
+ if not ret:
+ exit(1)
+