Commit 824bd7c
committed
Replace
When the spelling dictionaries are loaded, previously the correction
line was just stored in memory as a simple text. Through out the code,
callers would then have to deal with the `data` attribute, correctly
`split()` + `strip()` it. With this change, the dictionary parsing
code now encapsulates this problem.
The auto-correction works from the assumption that there is only one
candidate. This assumption is invariant and seem to be properly
maintained in the code. Therefore, we can just pick the first
candidate word when doing a correction.
In the code, the following name changes are performed:
* `Misspelling.data` -> `Misspelling.candidates`
* `fixword` -> `candidates` when used for multiple candidates
(`fixword` remains for when it is a correction)
On performance:
Performance-wise, this change moves computation from "checking" time
to "startup" time. The performance cost does not appear to be
noticeable in my baseline (#3419). Though, keep the corpus weakness on
the ratio of cased vs. non-cased corrections with multiple candidates
in mind.
The all lowercase typo is now slightly more expensive (it was passed
throughout `fix_case` and fed directly into the `print` in the
original code. In the new code, it will always need a `join`). There
are still an overweight of lower-case only corrections in general, so
the unconditional `.join` alone is not sufficient to affect the
performance noticeably.data: str with candidates: Sequence[str]
1 parent b28a5a3 commit 824bd7c
3 files changed
+34
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | | - | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
716 | 719 | | |
717 | 720 | | |
718 | 721 | | |
719 | | - | |
| 722 | + | |
720 | 723 | | |
721 | 724 | | |
722 | | - | |
| 725 | + | |
723 | 726 | | |
724 | 727 | | |
725 | 728 | | |
| |||
729 | 732 | | |
730 | 733 | | |
731 | 734 | | |
732 | | - | |
| 735 | + | |
| 736 | + | |
733 | 737 | | |
734 | 738 | | |
735 | 739 | | |
| |||
747 | 751 | | |
748 | 752 | | |
749 | 753 | | |
750 | | - | |
| 754 | + | |
751 | 755 | | |
752 | 756 | | |
753 | | - | |
754 | | - | |
755 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
756 | 760 | | |
757 | 761 | | |
758 | 762 | | |
| |||
767 | 771 | | |
768 | 772 | | |
769 | 773 | | |
770 | | - | |
| 774 | + | |
771 | 775 | | |
772 | | - | |
| 776 | + | |
773 | 777 | | |
774 | 778 | | |
775 | 779 | | |
| |||
861 | 865 | | |
862 | 866 | | |
863 | 867 | | |
864 | | - | |
| 868 | + | |
865 | 869 | | |
866 | 870 | | |
867 | 871 | | |
868 | 872 | | |
869 | 873 | | |
870 | 874 | | |
871 | | - | |
| 875 | + | |
872 | 876 | | |
873 | 877 | | |
874 | 878 | | |
| |||
958 | 962 | | |
959 | 963 | | |
960 | 964 | | |
961 | | - | |
| 965 | + | |
962 | 966 | | |
963 | 967 | | |
964 | 968 | | |
965 | 969 | | |
966 | 970 | | |
967 | | - | |
| 971 | + | |
968 | 972 | | |
969 | 973 | | |
970 | 974 | | |
| |||
981 | 985 | | |
982 | 986 | | |
983 | 987 | | |
984 | | - | |
| 988 | + | |
985 | 989 | | |
986 | 990 | | |
987 | 991 | | |
| |||
996 | 1000 | | |
997 | 1001 | | |
998 | 1002 | | |
999 | | - | |
| 1003 | + | |
1000 | 1004 | | |
1001 | 1005 | | |
1002 | 1006 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | | - | |
| 24 | + | |
23 | 25 | | |
24 | | - | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | | - | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
31 | | - | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
52 | 57 | | |
53 | 58 | | |
54 | 59 | | |
| |||
0 commit comments