Coretex
transcription.py
1 # Copyright (C) 2023 Coretex LLC
2 
3 # This file is part of Coretex.ai
4 
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 
18 # from typing import List, Dict
19 # from typing_extensions import Self
20 # from pathlib import Path
21 # from zipfile import ZipFile
22 
23 # import json
24 
25 # from .token import Token
26 # from ..codable import Codable, KeyDescriptor
27 
28 
29 # class Transcription(Codable):
30 
31 # """
32 # Represents a result of a single transcription
33 
34 # Properties:
35 # text: str -> transcribed text
36 # tokens: List[Token] -> tokens of transcribed text
37 # """
38 
39 # text: str
40 # tokens: List[Token]
41 
42 # @classmethod
43 # def create(cls, text: str, tokens: List[Token]) -> Self:
44 # obj = cls()
45 
46 # obj.text = text
47 # obj.tokens = tokens
48 
49 # return obj
50 
51 # @classmethod
52 # def load(cls, filePath: Path) -> Self:
53  # """
54  # Loads saved transcription from a json file
55 
56  # Parameters
57  # ----------
58  # filePath : Path
59  # path to json file
60 
61  # Returns
62  # -------
63  # Self -> loaded transcription
64  # """
65 
66 # with filePath.open("r") as file:
67 # return cls.decode(json.load(file))
68 
69 # @classmethod
70 # def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
71 # descriptors = super()._keyDescriptors()
72 # descriptors["tokens"] = KeyDescriptor("tokens", Token, list)
73 
74 # return descriptors
75 
76 # def save(self, path: Path) -> Path:
77  # """
78  # Saves transcription to a zipped json file
79 
80  # Parameters
81  # ----------
82  # path : Path
83  # path to json file
84 
85  # Returns
86  # -------
87  # Path -> path to zip file
88  # """
89 
90 # with path.open("w") as file:
91 # json.dump(self.encode(), file, indent = 4)
92 
93 # zipPath = path.parent / f"{path.stem}.zip"
94 
95 # with ZipFile(zipPath, "w") as zipFile:
96 # zipFile.write(str(path), path.name)
97 
98 # return zipPath