class_docstr: Implements conditional random fields (CRF) to do named entity recognition.
class_docstr_tok: ["Implements","conditional","random","fields","(","CRF",")","to","do","named","entity","recognition","."]
docstr: Convert a token into discrete features including words before and after.
docstr_tok: ["Convert","a","token","into","discrete","features","including","words","before","and","after","."]
code: def _create_features_for_token(
      self,
      crf_tokens: List[CRFToken],
      token_idx: int,
      half_window_size: int,
      window_range: range,
      include_tag_features: bool,
  ) -> Dict[Text, Any]:
      """Convert a token into discrete features including words before and after."""
      configured_features = self.component_config[self.CONFIG_FEATURES]
      prefixes = [str(i) for i in window_range]
  
      token_features = {}
  
      # iterate over the tokens in the window range (-1, 0, +1) to collect the
      # features for the token at token_idx
      for pointer_position in window_range:
          current_token_idx = token_idx + pointer_position
  
          if current_token_idx >= len(crf_tokens):
              # token is at the end of the sentence
              token_features["EOS"] = True
          elif current_token_idx < 0:
              # token is at the beginning of the sentence
              token_features["BOS"] = True
          else:
              token = crf_tokens[current_token_idx]
  
              # get the features to extract for the token we are currently looking at
              current_feature_idx = pointer_position + half_window_size
              features = configured_features[current_feature_idx]
  
              prefix = prefixes[current_feature_idx]
  
              # we add the 'entity' feature to include the entity type as features
              # for the role and group CRFs
              # (do not modify features, otherwise we will end up adding 'entity'
              # over and over again, making training very slow)
              additional_features = []
              if include_tag_features:
                  additional_features.append(
                      CRFEntityExtractorOptions.ENTITY
                  )
  
              for feature in features + additional_features:
                  if feature == CRFEntityExtractorOptions.PATTERN:
                      # add all regexes extracted from the 'RegexFeaturizer' as a
                      # feature: 'pattern_name' is the name of the pattern the user
                      # set in the training data, 'matched' is either 'True' or
                      # 'False' depending on whether the token actually matches the
                      # pattern or not
                      regex_patterns = self.function_dict[feature](
                          token
                      )
                      for (
                          pattern_name,
                          matched,
                      ) in regex_patterns.items():
                          token_features[
                              f"{prefix}:{feature}:{pattern_name}"
                          ] = matched
                  else:
                      value = self.function_dict[feature](token)
                      token_features[f"{prefix}:{feature}"] = value
  
      return token_features
  
imports: from __future__ import annotations
  from collections import OrderedDict
  from enum import Enum
  import logging
  import typing
  import numpy
  from typing import Any, Dict, List, Optional, Text, Tuple, Callable, Type
  import rasa.nlu.utils.bilou_utils
  import rasa.shared.utils.io
  import rasa.utils.train_utils
  from rasa.engine.graph import GraphComponent, ExecutionContext
  from rasa.engine.recipes.default_recipe import DefaultV1Recipe
  from rasa.engine.storage.resource import Resource
  from rasa.engine.storage.storage import ModelStorage
  from rasa.nlu.test import determine_token_labels
  from rasa.nlu.tokenizers.spacy_tokenizer import POS_TAG_KEY
  from rasa.nlu.extractors.extractor import EntityExtractorMixin
  from rasa.nlu.tokenizers.tokenizer import Token, Tokenizer
  from rasa.shared.nlu.training_data.training_data import TrainingData
  from rasa.shared.nlu.training_data.message import Message
  from rasa.nlu.constants import TOKENS_NAMES
  from rasa.shared.nlu.constants import TEXT, ENTITIES, ENTITY_ATTRIBUTE_TYPE, ENTITY_ATTRIBUTE_GROUP, ENTITY_ATTRIBUTE_ROLE, NO_ENTITY_TAG, SPLIT_ENTITIES_BY_COMMA, SPLIT_ENTITIES_BY_COMMA_DEFAULT_VALUE
  from rasa.shared.constants import DOCS_URL_COMPONENTS
  from rasa.utils.tensorflow.constants import BILOU_FLAG, FEATURIZERS
label_desc: Use image node_id 17 for calling the CRFEntityExtractor obj's underlying member method code with example usage: obj._create_features_for_token(crf_tokens, token_idx, half_window_size, window_range, include_tag_features) and returns: token_features