Home>

Dp matching is created by referring to the following contents.
I want to use two csv files for comparison, is there only one? Doesn't it work because it's a number rather than a string? .. I'm sorry I don't understand. I would appreciate it if you could teach me. I look forward to working with you.

import difflib
import Levenshtein
from pprint import pprint
text_filepath ='../Desktop/m122.csv'
results = []
# File reading/similarity calculation processing
with open (../Desktop/m1.csv,'r') as fr:
    # # Header creation
    header = fr.readline ()
    header = header.strip ()
    columns = header.split ('\ t')
    columns.extend (['Gestalt_1','Gestalt_2','Levenshtein','Jaro_Winkler'])
    results.append (columns)
    for line in fr.readlines ():
        line = line.strip ()
        data = line.split ('\ t')
        str1 = data [0]
        str2 = data [1]
        # 1. Gestalt pattern matching
        gestalt1 = difflib.SequenceMatcher (None, str1, str2) .ratio ()
        gestalt2 = difflib.SequenceMatcher (None, str2, str1) .ratio ()
        data.append (gestalt1)
        data.append (gestalt2)
        # 2. Levenshtein distance
        lev_dist = Levenshtein.distance (str1, str2)
        ## Standardization
        divider = len (str1) if len (str1)>len (str2) else len (str2)
        lev_dist = lev_dist/divider
        lev_dist = 1 --lev_dist
        data.append (lev_dist)
        # 3. Jaro Winkler Distance
        jaro_dist = Levenshtein.jaro_winkler (str1, str2)
        data.append (jaro_dist)
        # Rounded to 4 decimal places for display
        data [2:] = [round (x, 4) for x in data [2:]]
        results.append (data)
# Export results
result_filepath ='../Desktop/mmm.txt'
with open (result_filepath,'w') as fw:
    for result in results:
        print ('\ t'. join (map (str, result)), file = fw)
File "<ipython-input-11-06fb6b37c5de>", line 10
    with open (/Desktop/m1.csv,'r') as fr:
              ^ ^
SyntaxError: invalid syntax