From 20be469a317e3de493e19103fe2690855d84984f Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 22 May 2020 01:56:22 +0200 Subject: Exact matching --- dicofr.py | 30 +++++++++++++++++++++++++----- 1 file 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) + -- cgit v1.2.3