docstr: Instantiates a Dataset from a OCR-Json format.
  
  The folder is structured with a "images" folder and a "tagged" folder.
  Those folders contain respectively .jpg and .json files with matching file name.
  The json contains 3 fields "words", "bbox", "labels" which are lists of equal length
  "words" is a list of strings, containing the ocr texts,
  "bbox" is a list of int-Tuples, containing left, top, right, bottom
  "labels" is a BIO-tagging of the sentences
  :param path_to_split_directory: base folder with the task data
  :param label_type: the label_type to add the ocr labels to
  :param encoding: the encoding to load the .json files with
  :param normalize_coords_to_thousands: if True, the coordinates will be ranged from 0 to 1000
  :param load_images: if True, the pillow images will be added as metadata
  :param in_memory: If set to True, the dataset is kept in memory as Sentence objects, otherwise does disk reads
  :param label_name_map: Optionally map tag names to different schema.
  :return: a Dataset with Sentences that contain OCR information
docstr_tok: ["Instantiates","a","Dataset","from","a","OCR-Json","format",".","The","folder","is","structured","with","a","``","images","''","folder","and","a","``","tagged","''","folder",".","Those","folders","contain","respectively",".jpg","and",".json","files","with","matching","file","name",".","The","json","contains","3","fields","``","words","''",",","``","bbox","''",",","``","labels","''","which","are","lists","of","equal","length","''","words","''","is","a","list","of","strings",",","containing","the","ocr","texts",",","''","bbox","''","is","a","list","of","int-Tuples",",","containing","left",",","top",",","right",",","bottom","''","labels","''","is","a","BIO-tagging","of","the","sentences",":","param","path_to_split_directory",":","base","folder","with","the","task","data",":","param","label_type",":","the","label_type","to","add","the","ocr","labels","to",":","param","encoding",":","the","encoding","to","load","the",".json","files","with",":","param","normalize_coords_to_thousands",":","if","True",",","the","coordinates","will","be","ranged","from","0","to","1000",":","param","load_images",":","if","True",",","the","pillow","images","will","be","added","as","metadata",":","param","in_memory",":","If","set","to","True",",","the","dataset","is","kept","in","memory","as","Sentence","objects",",","otherwise","does","disk","reads",":","param","label_name_map",":","Optionally","map","tag","names","to","different","schema",".",":","return",":","a","Dataset","with","Sentences","that","contain","OCR","information"]
code: def __init__(
      self,
      path_to_split_directory: Union[str, Path],
      label_type: str = "ner",
      in_memory: bool = True,
      encoding: str = "utf-8",
      load_images: bool = False,
      normalize_coords_to_thousands: bool = True,
      label_name_map: Optional[Dict[str, str]] = None,
  ) -> None:
      """Instantiates a Dataset from a OCR-Json format.
  
      The folder is structured with a "images" folder and a "tagged" folder.
      Those folders contain respectively .jpg and .json files with matching file name.
      The json contains 3 fields "words", "bbox", "labels" which are lists of equal length
      "words" is a list of strings, containing the ocr texts,
      "bbox" is a list of int-Tuples, containing left, top, right, bottom
      "labels" is a BIO-tagging of the sentences
      :param path_to_split_directory: base folder with the task data
      :param label_type: the label_type to add the ocr labels to
      :param encoding: the encoding to load the .json files with
      :param normalize_coords_to_thousands: if True, the coordinates will be ranged from 0 to 1000
      :param load_images: if True, the pillow images will be added as metadata
      :param in_memory: If set to True, the dataset is kept in memory as Sentence objects, otherwise does disk reads
      :param label_name_map: Optionally map tag names to different schema.
      :return: a Dataset with Sentences that contain OCR information
      """
      self.in_memory = in_memory
      path_to_split_directory = Path(path_to_split_directory)
      assert path_to_split_directory.exists()
  
      image_dir = path_to_split_directory / "images"
      tagged_dir = path_to_split_directory / "tagged"
      self.base_path = path_to_split_directory
      assert tagged_dir.exists()
      assert image_dir.exists()
      self.file_names = sorted(
          {p.stem for p in image_dir.iterdir() if p.is_file()}
          & {p.stem for p in tagged_dir.iterdir() if p.is_file()}
      )
  
      self.total_sentence_count: int = len(self.file_names)
      self.load_images = load_images
      self.label_type = label_type
      self.encoding = encoding
      self.label_name_map = label_name_map
      self.normalize_coords_to_thousands = normalize_coords_to_thousands
      if in_memory:
          self.sentences = [
              self._load_example(file_name)
              for file_name in self.file_names
          ]
  
imports: import json
  from pathlib import Path
  from typing import Dict, Optional, Union
  import gdown.download_folder
  import PIL
  from torch.utils.data import Dataset
  import flair
  from flair.data import BoundingBox, Corpus, FlairDataset, Sentence, get_spans_from_bio
  from flair.datasets.base import find_train_dev_test_files
label_desc: Use image node_id 1 to create a new OcrJsonDataset object from inherited base classes: FlairDataset with example: obj = OcrJsonDataset(path_to_split_directory, label_type, in_memory, encoding, load_images, normalize_coords_to_thousands, label_name_map)