Skip to content

Commit

Permalink
fix(rules): store single-label rules with a comp. format for old vers…
Browse files Browse the repository at this point in the history
…ions (#1334)

(cherry picked from commit d5044df)
  • Loading branch information
frascuchon committed Mar 29, 2022
1 parent bf999df commit 117fe3a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/rubrix/server/tasks/text_classification/service/service.py
Expand Up @@ -250,6 +250,7 @@ def add_labeling_rule(
rule:
The rule
"""
self.__normalized_rule__(rule)
self.__labeling__.add_rule(dataset, rule)

def update_labeling_rule(
Expand Down Expand Up @@ -278,6 +279,8 @@ def update_labeling_rule(
found_rule.label = labels[0] if len(labels) == 1 else None
if description is not None:
found_rule.description = description

self.__normalized_rule__(found_rule)
self.__labeling__.replace_rule(dataset, found_rule)
return found_rule

Expand Down Expand Up @@ -387,3 +390,12 @@ def compute_overall_rules_metrics(self, dataset: TextClassificationDatasetDB):
total_records=total,
annotated_records=annotated,
)

@staticmethod
def __normalized_rule__(rule: LabelingRule) -> LabelingRule:
if rule.labels and len(rule.labels) == 1:
rule.label = rule.labels[0]
elif rule.label and not rule.labels:
rule.labels = [rule.label]

return rule

0 comments on commit 117fe3a

Please sign in to comment.