class_docstr: A rule (labeling function) in form of an ElasticSearch query.
  
  Args:
      query: An ElasticSearch query with the `query string syntax <https://docs.argilla.io/en/latest/practical_guides/filter_dataset.html>`_.
      label: The label associated to the query. Can also be a list of labels.
      name: An optional name for the rule to be used as identifier in the
          `argilla.labeling.text_classification.WeakLabels` class. By default, we will use the ``query`` string.
  
  Examples:
      >>> import argilla as rg
      >>> urgent_rule = Rule(query="inputs.text:(urgent AND immediately)", label="urgent", name="urgent_rule")
      >>> not_urgent_rule = Rule(query="inputs.text:(NOT urgent) AND metadata.title_length>20", label="not urgent")
      >>> not_urgent_rule.apply("my_dataset")
      >>> my_dataset_records = rg.load(name="my_dataset")
      >>> not_urgent_rule(my_dataset_records[0])
      "not urgent"
class_docstr_tok: ["A","rule","(","labeling","function",")","in","form","of","an","ElasticSearch","query",".","Args",":","query",":","An","ElasticSearch","query","with","the","`","query","string","syntax","<","https",":","\/\/docs.argilla.io\/en\/latest\/practical_guides\/filter_dataset.html",">","`","_",".","label",":","The","label","associated","to","the","query",".","Can","also","be","a","list","of","labels",".","name",":","An","optional","name","for","the","rule","to","be","used","as","identifier","in","the","`","argilla.labeling.text_classification.WeakLabels","`","class",".","By","default",",","we","will","use","the","``","query","``","string",".","Examples",":",">",">",">","import","argilla","as","rg",">",">",">","urgent_rule","=","Rule","(","query=","''","inputs.text",":","(","urgent","AND","immediately",")","''",",","label=","''","urgent","''",",","name=","''","urgent_rule","''",")",">",">",">","not_urgent_rule","=","Rule","(","query=","''","inputs.text",":","(","NOT","urgent",")","AND","metadata.title_length",">","20","''",",","label=","''","not","urgent","''",")",">",">",">","not_urgent_rule.apply","(","``","my_dataset","''",")",">",">",">","my_dataset_records","=","rg.load","(","name=","''","my_dataset","''",")",">",">",">","not_urgent_rule","(","my_dataset_records","[","0","]",")","``","not","urgent","''"]
docstr: Compute the rule metrics for a given dataset:
  
  - **coverage**: Fraction of the records labeled by the rule.
  - **annotated_coverage**: Fraction of annotated records labeled by the rule.
  - **correct**: Number of records the rule labeled correctly (if annotations are available).
  - **incorrect**: Number of records the rule labeled incorrectly (if annotations are available).
  - **precision**: Fraction of correct labels given by the rule (if annotations are available). The precision does not penalize the rule for abstains.
  
  Args:
      dataset: Name of the dataset for which to compute the rule metrics.
  
  Returns:
      The rule metrics.
docstr_tok: ["Compute","the","rule","metrics","for","a","given","dataset",":","-","*","*","coverage","*","*",":","Fraction","of","the","records","labeled","by","the","rule",".","-","*","*","annotated_coverage","*","*",":","Fraction","of","annotated","records","labeled","by","the","rule",".","-","*","*","correct","*","*",":","Number","of","records","the","rule","labeled","correctly","(","if","annotations","are","available",")",".","-","*","*","incorrect","*","*",":","Number","of","records","the","rule","labeled","incorrectly","(","if","annotations","are","available",")",".","-","*","*","precision","*","*",":","Fraction","of","correct","labels","given","by","the","rule","(","if","annotations","are","available",")",".","The","precision","does","not","penalize","the","rule","for","abstains",".","Args",":","dataset",":","Name","of","the","dataset","for","which","to","compute","the","rule","metrics",".","Returns",":","The","rule","metrics","."]
code: def metrics(self, dataset: str) -> Dict[str, Union[int, float]]:
      """Compute the rule metrics for a given dataset:
  
      - **coverage**: Fraction of the records labeled by the rule.
      - **annotated_coverage**: Fraction of annotated records labeled by the rule.
      - **correct**: Number of records the rule labeled correctly (if annotations are available).
      - **incorrect**: Number of records the rule labeled incorrectly (if annotations are available).
      - **precision**: Fraction of correct labels given by the rule (if annotations are available). The precision does not penalize the rule for abstains.
  
      Args:
          dataset: Name of the dataset for which to compute the rule metrics.
  
      Returns:
          The rule metrics.
      """
      metrics = singleton.active_api().rule_metrics_for_dataset(
          dataset=dataset,
          rule=LabelingRule(query=self.query, label=self.label),
      )
  
      return {
          "coverage": metrics.coverage,
          "annotated_coverage": metrics.coverage_annotated,
          "correct": int(metrics.correct)
          if metrics.correct is not None
          else None,
          "incorrect": int(metrics.incorrect)
          if metrics.incorrect is not None
          else None,
          "precision": metrics.precision
          if metrics.precision is not None
          else None,
      }
  
imports: from typing import Dict, List, Optional, Union
  import argilla
  from argilla.client import singleton
  from argilla.client.api import load
  from argilla.client.models import TextClassificationRecord
  from argilla.client.sdk.text_classification.models import LabelingRule
label_desc: Use image node_id 12 for calling the Rule obj's underlying member method code with example usage: obj.metrics(dataset) and returns: dict