Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#1365): create rules with regex queries #1369

Merged
merged 2 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/rubrix/server/tasks/text_classification/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async def create_rule(


@router.get(
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query}}/metrics",
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query:path}}/metrics",
operation_id="compute_rule_metrics",
description="Computes dataset labeling rule metrics",
response_model=LabelingRuleMetricsSummary,
Expand Down Expand Up @@ -386,7 +386,7 @@ async def compute_dataset_rules_metrics(


@router.delete(
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query}}",
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query:path}}",
operation_id="delete_labeling_rule",
description="Deletes a labeling rule from dataset",
)
Expand All @@ -412,7 +412,7 @@ async def delete_labeling_rule(


@router.get(
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query}}",
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query:path}}",
operation_id="get_rule",
description="Get the dataset labeling rule",
response_model=LabelingRule,
Expand Down Expand Up @@ -444,7 +444,7 @@ async def get_rule(


@router.patch(
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query}}",
f"{NEW_BASE_ENDPOINT}/labeling/rules/{{query:path}}",
operation_id="update_rule",
description="Update dataset labeling rule attributes",
response_model=LabelingRule,
Expand Down
23 changes: 19 additions & 4 deletions tests/server/text_classification/test_api_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from rubrix.server.tasks.text_classification import (
CreateLabelingRule,
DatasetLabelingRulesMetricsSummary,
LabelingRule,
LabelingRuleMetricsSummary,
TextClassificationBulkData,
Expand Down Expand Up @@ -96,6 +95,7 @@ def test_dataset_update_rule(mocked_client):
"rule",
[
CreateLabelingRule(query="a query", description="Description", label="LALA"),
CreateLabelingRule(query="/a qu?ry/", description="Description", label="LALA"),
CreateLabelingRule(
query="another query", description="Description", labels=["A", "B", "C"]
),
Expand Down Expand Up @@ -130,6 +130,9 @@ def test_dataset_with_rules(mocked_client, rule):
"rule",
[
CreateLabelingRule(query="a query", description="Description", label="LALA"),
CreateLabelingRule(
query="/a qu(e|E)ry/", description="Description", label="LALA"
),
CreateLabelingRule(
query="another query", description="Description", labels=["A", "B", "C"]
),
Expand Down Expand Up @@ -163,13 +166,13 @@ def test_delete_dataset_rules(mocked_client):
response = mocked_client.post(
f"/api/datasets/TextClassification/{dataset}/labeling/rules",
json=CreateLabelingRule(
query="a query", label="TEST", description="Description"
query="/a query/", label="TEST", description="Description"
).dict(),
)
assert response.status_code == 200

response = mocked_client.delete(
f"/api/datasets/TextClassification/{dataset}/labeling/rules/{'a query'}"
f"/api/datasets/TextClassification/{dataset}/labeling/rules//a query/"
)
assert response.status_code == 200

Expand Down Expand Up @@ -314,6 +317,18 @@ def test_rule_metrics_with_missing_label(mocked_client):
"total_records": 1,
},
),
(
CreateLabelingRule(query="/eje.*o/", labels=["A", "o.k."]),
{
"annotated_records": 1,
"correct": 1.0,
"coverage": 1.0,
"coverage_annotated": 1.0,
"incorrect": 1.0,
"precision": 0.5,
"total_records": 1,
},
),
],
)
def test_rule_metrics_with_missing_label_for_stored_rule(
Expand Down Expand Up @@ -376,7 +391,7 @@ def test_create_rules_and_then_log(mocked_client):
),
(
[
CreateLabelingRule(query="ejemplo", label="TEST"),
CreateLabelingRule(query="/eje.?plo/", label="TEST"),
CreateLabelingRule(query="bad request", label="TEST"),
CreateLabelingRule(query="other", labels=["A", "B"]),
],
Expand Down