class_docstr: Class for linking of entity substrings in the document to entities in Wikidata
class_docstr_tok: ["Class","for","linking","of","entity","substrings","in","the","document","to","entities","in","Wikidata"]
code: def match_tokens(self, entity_substr_split, label_tokens):
      cnt = 0.0
      if not (
          len(entity_substr_split) > 1
          and len(label_tokens) > 1
          and set(entity_substr_split) != set(label_tokens)
          and label_tokens[0] != label_tokens[-1]
          and (
              (entity_substr_split[0] == label_tokens[-1])
              or (entity_substr_split[-1] == label_tokens[0])
          )
      ):
          for ent_tok in entity_substr_split:
              found = False
              for label_tok in label_tokens:
                  if label_tok == ent_tok:
                      found = True
                      break
              if found:
                  cnt += 1.0
              else:
                  for label_tok in label_tokens:
                      if label_tok[:2] == ent_tok[:2]:
                          fuzz_score = fuzz.ratio(label_tok, ent_tok)
                          c_long_toks = (
                              len(label_tok) >= 8
                              and label_tok[:6] == ent_tok[:6]
                              and fuzz_score > 70.0
                          )
                          c_shrt_toks = (
                              len(label_tokens) > 2
                              and len(label_tok) > 3
                              and label_tok[:4] == ent_tok[:4]
                          )
                          if (
                              fuzz_score >= 75.0
                              or c_long_toks
                              or c_shrt_toks
                          ) and not found:
                              cnt += fuzz_score * 0.01
                              break
      substr_score = round(
          cnt / max(len(label_tokens), len(entity_substr_split)), 3
      )
      if len(label_tokens) == 2 and len(entity_substr_split) == 1:
          if entity_substr_split[0] == label_tokens[1]:
              substr_score = 0.5
          elif entity_substr_split[0] == label_tokens[0]:
              substr_score = 0.3
      return substr_score
  
imports: import re
  import sqlite3
  from logging import getLogger
  from typing import List, Dict, Tuple, Any, Union
  from collections import defaultdict
  import nltk
  import spacy
  from hdt import HDTDocument
  from nltk.corpus import stopwords
  from rapidfuzz import fuzz
  from deeppavlov.core.commands.utils import expand_path
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.models.component import Component
  from deeppavlov.core.models.serializable import Serializable
  from deeppavlov.models.entity_extraction.find_word import WordSearcher
label_desc: Use image node_id 13 for calling the EntityLinker obj's underlying member method code with example usage: obj.match_tokens(entity_substr_split, label_tokens) and returns: substr_score