Document Converter
Convert documents so that they can be used by Fonduer and Label Studio without beeing changed during the process. This is crucial to reliably map the annotations back to the original documents.
DocumentConverter
Convert documents so that they are natevly supportet by Fonduer and look the same after Fonduer processes them.
Source code in LabelstudioToFonduer/document_converter.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
convert_one(document_path, output_path, encoding=None)
Document converter that prepares HTML documents for interchange between Label Studio and
Fonduer. The document is opened with the given encoding if specified. If the encodimg is not
known, please use the check_conversion
function to check if the conversion succedes.
The document is then parsed with BeautifulSoup and all comments are striped. Further, the
HTML tag ordering is fixed and the document is saved to the output path using utf-8 encoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
document_path |
str
|
Path to the HTML document to be converted. |
required |
output_path |
str
|
Output path where the converted document should be saved. |
required |
encoding |
Optional[str]
|
If necessary, the encoding can be defined manualy. Defaults to None. |
None
|
Source code in LabelstudioToFonduer/document_converter.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
convert(input_, output_path, encoding=None)
Converter wrapper function to convert a single document or a directory of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ |
str
|
Path to the directory of documents or a single document. |
required |
output_path |
str
|
Path or directory where the converted documents should be saved. |
required |
encoding |
Optional[str]
|
If necessary, the encoding can be defined manualy. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the input path does not exist. |
Source code in LabelstudioToFonduer/document_converter.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
ConversionChecker
Compare the different representations Label Studio and Fonduer may create from the same HTML document. This is useful to check if the conversion of the document is correct. The document is first converted to a format that is natively supportecomputerd by Fonduer. Then, the document is imported into Label Studio and Fonduer. The HTML representation of the document in Label Studio and Fonduer is compared. If the HTML representations are the same, the conversion was successful.
Source code in LabelstudioToFonduer/document_converter.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
process_fonduer(docs_path)
Process pipeline for Fonduer.
Import a given document to Fonduer and export the documents back to the computer to compare the results and investigate any changes that might have occured.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs_path |
str
|
Path to the documents. |
required |
Source code in LabelstudioToFonduer/document_converter.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
process_label_studio(docs_path)
Process pipeline for Label Studio.
Import a given document to Label Studio and export the documents back to the computer to compare the results and investigate any changes that might have occured.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs_path |
str
|
Path to the documents. |
required |
Source code in LabelstudioToFonduer/document_converter.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
check(docs_path)
Import the given documents into Label Studio and Fonduer, then export them back and compare the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs_path |
str
|
Path to the documents. |
required |
Source code in LabelstudioToFonduer/document_converter.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|