def __init__(self, lexPath, docPath): self.lexicon = util.LoadLexiconFromCSV(lexPath) self.docPath = docPath if docPath.endswith("json"): self.docType = "json" elif docPath.endswith("xml"): self.docType = "xml" else: self.docType = "json" self.iterator = self.GetIter()
def predict(self, filePath): #PREDICT lexicon = util.LoadLexiconFromCSV( "../files/lexicons/SentiWordNet_Lexicon_concise.csv") angel = Angel(lexicon, True) parsedReviewsPath = os.path.join(os.path.dirname(filePath), "YelpParsedReviews.json") with open(parsedReviewsPath, 'r') as file: TrainingFile = file.read() classificationData = json.loads(TrainingFile) for k in range(len(classificationData["ClassificationModel"])): current = classificationData["ClassificationModel"][str(k + 1)] notCount = current["NotCount"] if "Sentences" in current: if not isinstance(current["Sentences"], list): current["Sentences"] = [current["Sentences"]] sentences = current["Sentences"] else: continue current["Label"] = Sentiment.GetSentimentClass( angel.PredictReviewScore(sentences, notCount), 1) angel.DumpDetails(sentences, current["Label"]) return classificationData