Beispiel #1
0
 def save_from_origin(self, labeled_comments: LabeledComments, origin_name):
     path = fileutils.join(self._folderpath, labeled_comments.name)
     path_origin = fileutils.join(self._folderpath, origin_name)
     ids = []
     with open(path_origin, "r") as f:
         reader = csv.DictReader(f)
         for row in reader:
             ids.append(row["id"]),
     with open(path, "w") as f:
         writer = csv.DictWriter(f, fieldnames=["id", "text", "polarity"])
         for id, comment, label in zip(ids, labeled_comments.comments,
                                       labeled_comments.labels):
             row = {"id": id, "text": comment, "polarity": label}
             writer.writerow(row)
Beispiel #2
0
 def save(self, labeled_comments: LabeledComments):
     path = fileutils.join(self._folderpath, labeled_comments.name)
     with open(path, "w") as f:
         writer = csv.DictWriter(f)
         for comment, label in zip(labeled_comments.comments,
                                   labeled_comments.labels):
             row = {"text": comment, "polarity": label}
             writer.writerow(row)
Beispiel #3
0
 def get(self, name: str) -> LabeledComments:
     path = fileutils.join(self._folderpath, name)
     comments = []
     labels = []
     with open(path, "r") as f:
         reader = csv.DictReader(f)
         for row in reader:
             comments.append(self._cleaner.clean(row["text"])),
             labels.append(row["polarity"])
     return LabeledComments(name, comments, labels)
Beispiel #4
0
 def save_sklearn(self, name:str, model:SVC):
     name = f"{name}.joblib"
     fullpath = fileutils.join(self._folderpath, name)
     joblib.dump(model, fullpath) 
Beispiel #5
0
 def get_sklearn(self, name:str) -> SVC:
     name = f"{name}.joblib"
     fullpath = fileutils.join(self._folderpath, name)
     model = joblib.load(fullpath)
     return model
Beispiel #6
0
 def get_keras_weights(self, name:str, model:Model):
     name = f"{name}.hdf5"
     fullpath = fileutils.join(self._folderpath, name)
     model.load_weights(fullpath)
     return model
Beispiel #7
0
 def save_keras_weights(self, name:str, model:Model):
     name = f"{name}.hdf5"
     fullpath = fileutils.join(self._folderpath, name)
     model.save_weights(fullpath, overwrite=True)
Beispiel #8
0
 def get_keras(self, name:str) -> Model:
     name = f"{name}.h5"
     fullpath = fileutils.join(self._folderpath, name)
     model = load_model(fullpath, compile=True)
     return model
Beispiel #9
0
 def __init__(self, folderpath, filename, cleaner:SentenceCleaner):
     self._name = filename
     self._xml = et.parse(fileutils.join(folderpath, filename))
     self._cleaner = cleaner
Beispiel #10
0
 def save(self, folderpath, filename, xml):
     path = fileutils.join(folderpath, filename)
     xml.write(path)