code: def test_attributeruler_score(nlp, pattern_dicts):
      # initialize with patterns
      ruler = nlp.add_pipe("attribute_ruler")
      ruler.initialize(lambda: [], patterns=pattern_dicts)
      doc = nlp("This is a test.")
      assert doc[2].lemma_ == "the"
      assert str(doc[2].morph) == "Case=Nom|Number=Plur"
      assert doc[3].lemma_ == "cat"
      assert str(doc[3].morph) == "Case=Nom|Number=Sing"
      doc = nlp.make_doc("This is a test.")
      dev_examples = [
          Example.from_dict(
              doc, {"lemmas": ["this", "is", "a", "cat", "."]}
          )
      ]
      scores = nlp.evaluate(dev_examples)
      # "cat" is the only correct lemma
      assert scores["lemma_acc"] == pytest.approx(0.2)
      # no morphs are set
      assert scores["morph_acc"] is None
      nlp.remove_pipe("attribute_ruler")
  
      # test with custom scorer
      @registry.misc("weird_scorer.v1")
      def make_weird_scorer():
          def weird_scorer(examples, weird_score, **kwargs):
              return {"weird_score": weird_score}
  
          return weird_scorer
  
      ruler = nlp.add_pipe(
          "attribute_ruler",
          config={"scorer": {"@misc": "weird_scorer.v1"}},
      )
      ruler.initialize(lambda: [], patterns=pattern_dicts)
      scores = nlp.evaluate(
          dev_examples, scorer_cfg={"weird_score": 0.12345}
      )
      assert scores["weird_score"] == 0.12345
      assert "token_acc" in scores
      assert "lemma_acc" not in scores
      scores = nlp.evaluate(
          dev_examples, scorer_cfg={"weird_score": 0.23456}
      )
      assert scores["weird_score"] == 0.23456
  
imports: import numpy
  import pytest
  from spacy import registry, util
  from spacy.lang.en import English
  from spacy.pipeline import AttributeRuler
  from spacy.tokens import Doc
  from spacy.training import Example
  from ..util import make_tempdir
label_desc: Use image node_id 10 for calling a global function with example usage: test_attributeruler_score(nlp, pattern_dicts) and returns: weird_scorer, dict