def runTraining(folderName): trainingFiles = [] #Liste des fichiers d'entrainement trainingData = [] #données étudiées pos = 0 neg = 0 for dir in os.walk(folderName): dir = dir[1] #get directory list for i, f in enumerate(dir): actualFolder = os.path.join(folderName, f) for files in os.walk( actualFolder): #Parcourir liste dossier dans training trainingFiles.append(files[2]) for j, tf in enumerate( files[2]): #Parcourir liste des fichiers dans *star tempP, tempN = (an.analyzeFile( os.path.join(actualFolder, tf))) pos = (pos + tempP) / 2 neg = (neg + tempN) / 2 trainingData.append([pos, neg]) return trainingData
help="Folder with training examples") argparser.add_argument("-f", "--fileName", help="File to analyze") args = argparser.parse_args() print("Analyzing training files... Please wait ... ") data = td.runTraining(args.directoryName) #Analyse des fichiers de test if args.fileName: print( "You chose to analyze a new file to determine how many stars it should have." ) print("Analyzing " + str(args.fileName) + ". Please wait...") filename = os.path.join( "tests", args.fileName ) #le fichier que l'on veut analyser doit se trouver dans le dossier "tests" pos, neg = an.analyzeFile(filename) #Analyse du fichier print("RESULTS :") if (max(pos, neg) == pos): print("This review is more positive than negative") else: print("This review is more negative than positive") # METHODE 1 - Non Concluante (Précision à ~0,6 étoiles) # res=an.getBestMatch1(data,pos,neg) # print("Method 1 : This review should have "+str(res)+" star(s)") #METHODE 2 - MEILLEURE (Précision à ~0,5 étoiles) res = an.getBestMatch2(data, pos, neg) print("This review should have " + str(res) + " star(s)") # print("Method 2 : This review should have "+str(res)+" star(s)")