decode
Code to detect and fix semi official and unofficial encodings.
(Northern) sami character eight bit encodings have been semi or non official standards and have been converted to the various systems' internal encodings. This module has functions that revert the damage done.
decode_para(position, text)
Decode the text given to this function.
Replace letters in text with the ones from the dict at position position in CTYPES
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position |
str
|
an encoding name |
required |
text |
str
|
the text to decode |
required |
Returns:
Type | Description |
---|---|
str
|
The decoded text |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
default_decoder(position, text)
The default decoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position |
str
|
required | |
text |
str
|
The string that should be decoded. |
required |
Returns:
Type | Description |
---|---|
str
|
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
fix_macsami_cp1252(instring)
Fix instring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instring |
str
|
A bytestring that originally was encoded as macsami but has been decoded to unicode as if it was cp1252. |
required |
Returns:
Type | Description |
---|---|
str
|
str with fixed encoding. |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
fix_macsami_latin1(instring)
Fix instring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instring |
str
|
A bytestring that originally was encoded as macsami but has been decoded to unicode as if it was latin1. |
required |
Returns:
Type | Description |
---|---|
str
|
a string with fixed encoding. |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
52 53 54 55 56 57 58 59 60 61 62 63 |
|
fix_macsami_mac(instring)
Fix instring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instring |
str
|
A bytestring that originally was encoded as macsami but has been decoded to unicode as if it was macroman. |
required |
Returns:
Type | Description |
---|---|
str
|
a string with fixed encoding. |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
fix_meadowmari_cp1252(instring)
Fix instring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instring |
str
|
A bytestring that originally was encoded as meadowmari but has been decoded to unicode as if it was cp1252. |
required |
Returns:
Type | Description |
---|---|
str
|
a string with fixed encoding. |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
fix_winsami2_cp1252(instring)
Fix instring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instring |
str
|
A bytestring that originally was encoded as winsami2 but has been decoded to unicode as if it was cp1252. |
required |
Returns:
Type | Description |
---|---|
str
|
a string with fixed encoding. |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
83 84 85 86 87 88 89 90 91 92 93 94 |
|
guess_body_encoding(content, mainlang)
Guess the encoding of the string content.
First get the frequencies of the "sami letters" Then get the frequencies of the letters in the encodings in CTYPES
If "sami letters" that the encoding tries to fix exist in "content", disregard the encoding
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
str
|
the content |
required |
mainlang |
str
|
Three-letter language code |
required |
Returns:
Type | Description |
---|---|
str
|
A codec name, as given in the keys of CTYPES, or None if no codec could be determined |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
guess_file_encoding(filename, mainlang)
Guess the encoding of a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
the file to open |
required |
Returns:
Type | Description |
---|---|
str
|
A codec name, as given in the keys of CTYPES, or None if no codec could be determined |
Source code in /home/anders/projects/CorpusTools/corpustools/decode.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|