{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Install rapidfuzz","metadata":{}},{"cell_type":"code","source":"!pip install rapidfuzz -qq","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-09-16T22:57:38.953646Z","iopub.execute_input":"2021-09-16T22:57:38.953995Z","iopub.status.idle":"2021-09-16T22:57:46.662883Z","shell.execute_reply.started":"2021-09-16T22:57:38.953963Z","shell.execute_reply":"2021-09-16T22:57:46.661857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# rapidfuzz process module","metadata":{}},{"cell_type":"markdown","source":"The process module makes it compare strings to lists of strings. This is generally more performant than using the scorers directly from Python. Here are some examples on the usage of processors in RapidFuzz:","metadata":{}},{"cell_type":"markdown","source":"# Example1","metadata":{}},{"cell_type":"code","source":"from rapidfuzz import process, fuzz\nchoices = [\"Atlanta Falcons\", \"New York Jets\", \"New York Giants\", \"Dallas Cowboys\"]","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.665347Z","iopub.execute_input":"2021-09-16T22:57:46.665721Z","iopub.status.idle":"2021-09-16T22:57:46.673397Z","shell.execute_reply.started":"2021-09-16T22:57:46.665658Z","shell.execute_reply":"2021-09-16T22:57:46.672587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"process.extract(\"new york jets\", choices, scorer=fuzz.WRatio, limit=2)","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.674826Z","iopub.execute_input":"2021-09-16T22:57:46.675065Z","iopub.status.idle":"2021-09-16T22:57:46.686473Z","shell.execute_reply.started":"2021-09-16T22:57:46.675037Z","shell.execute_reply":"2021-09-16T22:57:46.685647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"process.extractOne(\"cowboys\", choices, scorer=fuzz.WRatio)","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.688476Z","iopub.execute_input":"2021-09-16T22:57:46.688824Z","iopub.status.idle":"2021-09-16T22:57:46.698892Z","shell.execute_reply.started":"2021-09-16T22:57:46.688787Z","shell.execute_reply":"2021-09-16T22:57:46.698048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Example2","metadata":{}},{"cell_type":"code","source":"import pandas as pd\ncaptions = pd.read_csv('../input/wikipedia-image-caption/test_caption_list.csv')\nprint(len(captions))\ncaptions.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.699880Z","iopub.execute_input":"2021-09-16T22:57:46.700224Z","iopub.status.idle":"2021-09-16T22:57:46.895921Z","shell.execute_reply.started":"2021-09-16T22:57:46.700196Z","shell.execute_reply":"2021-09-16T22:57:46.895048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CAPTIONS = captions.caption_title_and_reference_description.values.tolist()\nprint(len(CAPTIONS))\nCAPTIONS[:10]","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.897252Z","iopub.execute_input":"2021-09-16T22:57:46.897508Z","iopub.status.idle":"2021-09-16T22:57:46.912927Z","shell.execute_reply.started":"2021-09-16T22:57:46.897479Z","shell.execute_reply":"2021-09-16T22:57:46.912021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from rapidfuzz import process, fuzz","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.914317Z","iopub.execute_input":"2021-09-16T22:57:46.914538Z","iopub.status.idle":"2021-09-16T22:57:46.923673Z","shell.execute_reply.started":"2021-09-16T22:57:46.914513Z","shell.execute_reply":"2021-09-16T22:57:46.923010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s = \"Albert Pike Albert Pike\"","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.924794Z","iopub.execute_input":"2021-09-16T22:57:46.925007Z","iopub.status.idle":"2021-09-16T22:57:46.936067Z","shell.execute_reply.started":"2021-09-16T22:57:46.924982Z","shell.execute_reply":"2021-09-16T22:57:46.935247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = process.extract(s, CAPTIONS, scorer=fuzz.ratio, processor=None, limit=1)","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.937125Z","iopub.execute_input":"2021-09-16T22:57:46.937714Z","iopub.status.idle":"2021-09-16T22:57:46.967561Z","shell.execute_reply.started":"2021-09-16T22:57:46.937623Z","shell.execute_reply":"2021-09-16T22:57:46.966717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.970036Z","iopub.execute_input":"2021-09-16T22:57:46.970275Z","iopub.status.idle":"2021-09-16T22:57:46.980487Z","shell.execute_reply.started":"2021-09-16T22:57:46.970248Z","shell.execute_reply":"2021-09-16T22:57:46.979622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result[0][0]","metadata":{"execution":{"iopub.status.busy":"2021-09-16T22:57:46.981549Z","iopub.execute_input":"2021-09-16T22:57:46.981888Z","iopub.status.idle":"2021-09-16T22:57:46.992920Z","shell.execute_reply.started":"2021-09-16T22:57:46.981850Z","shell.execute_reply":"2021-09-16T22:57:46.991915Z"},"trusted":true},"execution_count":null,"outputs":[]}]}