import csvFile import os import sys import re #open csv file f = open('training.csv','r') reader = csv.reader(f) for row in reader: q1 = row[3] #first question q2 = row[4] #second question #Preprocess function num = re.sub(r'abc', 'def', input) # Replace pattern abc -> def #Overlapping Compute, assume preprocess done q1 = q1.strip().split(' ') m = len(q1) q2 = q2.strip().split(' ') n = len(q2) only_in_q1 = [word for word in q1 if word not in set(q2)] only_in_q2 = [word for word in q2 if word not in set(q1)] diff_len1 = len(only_in_q1) diff_len2 = len(only_in_q2) w1_olap = m - diff_len1 w2_olap = n - diff_len2 return(w1_olap + w2_olap) / (m+n) #main should be at the end def main(filePath,thr): print(ComputeAccuracy(filePath, thr)) print(AccuracyRemoveStops(filePath, thr)) if __name__ == '__main__': #then call the functions\ filePath = sys.argv[1] thr = float(sys.argv[2]) main(filePath, thr)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question