class_docstr: Parse BCP-47 composite language tags
  
  Supports all the main subtags, and the 'u-sd' extension:
  
  >>> from nltk.corpus import bcp47
  >>> bcp47.name('oc-gascon-u-sd-fr64')
  'Occitan (post 1500): Gascon: Pyrénées-Atlantiques'
  
  Can load a conversion table to Wikidata Q-codes:
  >>> bcp47.load_wiki_q()
  >>> bcp47.wiki_q['en-GI-spanglis']
  'Q79388'
docstr: Convert a BCP-47 tag to a dictionary of labelled subtags
docstr_tok: ["Convert","a","BCP-47","tag","to","a","dictionary","of","labelled","subtags"]
code: def parse_tag(self, tag):
      """Convert a BCP-47 tag to a dictionary of labelled subtags"""
      subtags = tag.split("-")
      lang = {}
      labels = [
          "language",
          "extlang",
          "script",
          "region",
          "variant",
          "variant",
      ]
      while subtags and labels:
          subtag = subtags.pop(0)
          found = False
          while labels:
              label = labels.pop(0)
              subtag = self.casing[label](subtag)
              if self.format[label].fullmatch(subtag):
                  if subtag in self.db[label]:
                      found = True
                      valstr = self.val2str(
                          self.db[label][subtag]["Description"]
                      )
                      if label == "variant" and label in lang:
                          lang[label] += ": " + valstr
                      else:
                          lang[label] = valstr
                      break
                  elif subtag in self.db["deprecated"][label]:
                      found = True
                      note = (
                          f"The {subtag!r} {label} code is deprecated"
                      )
                      if (
                          "Preferred-Value"
                          in self.db["deprecated"][label][subtag]
                      ):
                          prefer = self.db["deprecated"][label][subtag][
                              "Preferred-Value"
                          ]
                          note += f"', prefer '{self.val2str(prefer)}'"
                      lang[label] = self.val2str(
                          self.db["deprecated"][label][subtag][
                              "Description"
                          ]
                      )
                      warn(note)
                      break
          if not found:
              if (
                  subtag == "u" and subtags[0] == "sd"
              ):  # CLDR regional subdivisions
                  sd = subtags[1]
                  if sd in self.subdiv:
                      ext = self.subdiv[sd]
                  else:
                      ext = f"<Unknown subdivision: {ext}>"
              else:  # other extension subtags are not supported yet
                  ext = f"{subtag}{''.join(['-'+ext for ext in subtags])}".lower()
                  if not self.format["singleton"].fullmatch(subtag):
                      ext = f"<Invalid extension: {ext}>"
                      warn(ext)
              lang["extension"] = ext
              subtags = []
      return lang
  
file_path: nltk/nltk/corpus/reader/bcp47.py
imports: import re
  from warnings import warn
  from xml.etree import ElementTree
  from nltk.corpus.reader import CorpusReader
label_desc: Use image node_id 9 for calling the BCP47CorpusReader obj's underlying member method code with example usage: obj.parse_tag(tag) and returns: lang