class_docstr: Text classification service
class_docstr_tok: ["Text","classification","service"]
docstr: Compute metrics for a given rule. It's not necessary that query rule
  is created in dataset. Basic computed rules are:
  
  coverage, correct[*], incorrect[*], precision[*]
  
  [*]: computed metrics only if label is provided or rule already created in dataset
  
  Parameters
  ----------
  dataset:
      The dataset
  rule_query:
      The provided rule query. If already created in dataset, the ``label``
      param will be omitted
  labels:
      Label used for the rule metrics. If not provided and no rule was stored with the
      provided query, no precision will be computed.
      Otherwise, the labels from the stored rule will be used to compute the metrics.
  
  Returns
  -------
  
      Metrics summary for rule and labels
docstr_tok: ["Compute","metrics","for","a","given","rule",".","It","'s","not","necessary","that","query","rule","is","created","in","dataset",".","Basic","computed","rules","are",":","coverage",",","correct","[","*","]",",","incorrect","[","*","]",",","precision","[","*","]","[","*","]",":","computed","metrics","only","if","label","is","provided","or","rule","already","created","in","dataset","Parameters","--","--","--","--","--","dataset",":","The","dataset","rule_query",":","The","provided","rule","query",".","If","already","created","in","dataset",",","the","``","label","``","param","will","be","omitted","labels",":","Label","used","for","the","rule","metrics",".","If","not","provided","and","no","rule","was","stored","with","the","provided","query",",","no","precision","will","be","computed",".","Otherwise",",","the","labels","from","the","stored","rule","will","be","used","to","compute","the","metrics",".","Returns","--","--","--","-","Metrics","summary","for","rule","and","labels"]
code: def compute_labeling_rule(
      self,
      dataset: ServiceTextClassificationDataset,
      rule_query: str,
      labels: Optional[List[str]] = None,
  ) -> LabelingRuleMetricsSummary:
      """
      Compute metrics for a given rule. It's not necessary that query rule
      is created in dataset. Basic computed rules are:
  
      coverage, correct[*], incorrect[*], precision[*]
  
      [*]: computed metrics only if label is provided or rule already created in dataset
  
      Parameters
      ----------
      dataset:
          The dataset
      rule_query:
          The provided rule query. If already created in dataset, the ``label``
          param will be omitted
      labels:
          Label used for the rule metrics. If not provided and no rule was stored with the
          provided query, no precision will be computed.
          Otherwise, the labels from the stored rule will be used to compute the metrics.
  
      Returns
      -------
  
          Metrics summary for rule and labels
  
      """
  
      rule_query = rule_query.strip()
  
      if labels is None:
          rule = self.find_labeling_rule(
              dataset, rule_query=rule_query, error_on_missing=False
          )
          if rule:
              labels = rule.labels
  
      metric_data = self.__metrics__.summarize_metric(
          dataset=dataset,
          metric=TextClassificationMetrics.find_metric("labeling_rule"),
          rule_query=rule_query,
          labels=labels,
      )
      annotated = self.__metrics__.annotated_records(dataset)
      total = self.__metrics__.total_records(dataset)
  
      metrics = LabelingRuleSummary.parse_obj(metric_data)
  
      coverage = metrics.covered_records / total if total > 0 else None
      coverage_annotated = (
          metrics.annotated_covered_records / annotated
          if annotated > 0
          else None
      )
  
      return LabelingRuleMetricsSummary(
          total_records=total,
          annotated_records=annotated,
          coverage=coverage,
          coverage_annotated=coverage_annotated,
          correct=metrics.correct_records if annotated > 0 else None,
          incorrect=metrics.incorrect_records
          if annotated > 0
          else None,
          precision=metrics.precision if annotated > 0 else None,
      )
  
imports: from typing import Iterable, List, Optional, Tuple
  from fastapi import Depends
  from argilla.server.errors.base_errors import EntityAlreadyExistsError, EntityNotFoundError, MissingDatasetRecordsError
  from argilla.server.services.datasets import DatasetsService
  from argilla.server.services.metrics import MetricsService
  from argilla.server.services.search.model import ServiceSearchResults, ServiceSortableField, ServiceSortConfig
  from argilla.server.services.search.service import SearchRecordsService
  from argilla.server.services.storage.service import RecordsStorageService
  from argilla.server.services.tasks.commons import BulkResponse
  from argilla.server.services.tasks.text_classification.metrics import TextClassificationMetrics
  from argilla.server.services.tasks.text_classification.model import DatasetLabelingRulesMetricsSummary, DatasetLabelingRulesSummary, LabelingRuleMetricsSummary, LabelingRuleSummary, ServiceLabelingRule, ServiceTextClassificationDataset, ServiceTextClassificationQuery, ServiceTextClassificationRecord
label_desc: Use image node_id 12 for calling the TextClassificationService obj's underlying member method code with example usage: obj.compute_labeling_rule(dataset, rule_query, labels) and returns: LabelingRuleMetricsSummary