Example #1
0
 def setLabelsFromExperiment(self, experiment):
     num_instances = self.numInstances()
     self.labels = [None] * num_instances
     self.families = [None] * num_instances
     self.annotations = [None] * num_instances
     self.true_labels = [None] * num_instances
     self.true_families = [None] * num_instances
     ## Labels/Families
     benign_ids = labels_tools.getLabelIds(
         experiment.cursor,
         'benign',
         experiment_label_id=experiment.experiment_label_id)
     malicious_ids = labels_tools.getLabelIds(
         experiment.cursor,
         'malicious',
         experiment_label_id=experiment.experiment_label_id)
     for instance_id in benign_ids + malicious_ids:
         label, family, method, annotation = labels_tools.getLabelDetails(
             experiment.cursor, instance_id, experiment.experiment_label_id)
         self.setLabel(instance_id, label == 'malicious')
         self.setFamily(instance_id, family)
         self.setAnnotation(instance_id, annotation)
     ## True Labels
     if labels_tools.hasTrueLabels(experiment.cursor):
         labels, families = labels_tools.getExperimentLabelsFamilies(
             experiment.cursor, experiment_label_id=1)
         self.true_labels = labels
         self.true_families = families
Example #2
0
 def getManualAnnotation(self, iteration):
     details = labels_tools.getLabelDetails(iteration.experiment,
                                            self.instance_id)
     if details is None:
         warnings.warn('Instance %s has not been annotated.' % (str(self.instance_id)))
     else:
         label, family, _, _ = details
         self.updateDatasets(iteration, label, family)
Example #3
0
 def getManualAnnotation(self, iteration):
     try:
         label, family, _, _ = labels_tools.getLabelDetails(
             iteration.experiment.cursor, self.instance_id,
             iteration.experiment.experiment_label_id)
         self.updateDatasets(iteration, label, family)
     except labels_tools.NoLabel:
         warnings.warn('Instance %s has not been annotated.' %
                       (str(self.instance_id)))
Example #4
0
 def checkLabelsWithDB(self, cursor, experiment_label_id):
     for instance_id in self.getAnnotatedIds():
         label = self.getLabel(instance_id)
         family = self.getFamily(instance_id)
         try:
             DB_label, DB_family, m, annotation = labels_tools.getLabelDetails(
                 cursor, instance_id, experiment_label_id)
             DB_label = labels_tools.labelStringToBoolean(DB_label)
             if DB_label != label or DB_family != family:
                 self.setLabel(instance_id, DB_label)
                 self.setFamily(instance_id, DB_family)
                 self.setAnnotation(instance_id, annotation)
         except labels_tools.NoLabel:
             ## The instance is not annotated anymore
             self.setLabel(instance_id, None)
             self.setFamily(instance_id, None)
             self.setAnnotation(instance_id, None)
Example #5
0
 def getLabels(self, num_instances):
     labels = [None] * num_instances
     families = [None] * num_instances
     annotations = [False] * num_instances
     true_labels = [None] * num_instances
     true_families = [None] * num_instances
     ## Labels/Families
     benign_ids = labels_tools.getLabelIds(self.experiment, 'benign')
     malicious_ids = labels_tools.getLabelIds(self.experiment, 'malicious')
     for instance_id in benign_ids + malicious_ids:
         label, family, method, annotation = labels_tools.getLabelDetails(
             self.experiment, instance_id)
         labels[self.indexes[instance_id]] = label == 'malicious'
         families[self.indexes[instance_id]] = family
         annotations[self.indexes[instance_id]] = annotation
     ## True Labels
     has_true_labels = db_tables.hasTrueLabels(self.experiment)
     if has_true_labels:
         true_labels, true_families = labels_tools.getTrueLabelsFamilies(
             self.experiment)
     return labels, families, annotations, true_labels, true_families
Example #6
0
 def checkAnswered(self, iteration):
     details = labels_tools.getLabelDetails(
         iteration.experiment.session, self.instance_id,
         iteration.experiment.oldest_parent)
     return details is not None