|
1 |
| -# MIT License |
2 |
| -# |
3 |
| -# Copyright (c) 2022 mmb L (Python port) |
4 |
| -# Copyright (c) 2021 Wolf Garbe (Original C# implementation) |
5 |
| -# |
6 |
| -# Permission is hereby granted, free of charge, to any person obtaining a copy |
7 |
| -# of this software and associated documentation files (the "Software"), to deal |
8 |
| -# in the Software without restriction, including without limitation the rights |
9 |
| -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 |
| -# copies of the Software, and to permit persons to whom the Software is |
11 |
| -# furnished to do so, subject to the following conditions: |
12 |
| -# |
13 |
| -# The above copyright notice and this permission notice shall be included in all |
14 |
| -# copies or substantial portions of the Software. |
15 |
| - |
16 |
| -""" |
17 |
| -.. module:: compostiion |
18 |
| - :synopsis: Data class for :meth:`symspellpy.symspellpy.word_segmentation`. |
19 |
| -""" |
20 |
| - |
21 |
| -from typing import NamedTuple |
22 |
| - |
23 |
| - |
24 |
| -class Composition(NamedTuple): |
25 |
| - """Used by :meth:`word_segmentation`. |
26 |
| -
|
27 |
| - Attributes: |
28 |
| - segmented_string: The word segmented string. |
29 |
| - corrected_string: The spelling corrected string. |
30 |
| - distance_sum: The sum of edit distance between input string and |
31 |
| - corrected string |
32 |
| - log_prob_sum: The sum of word occurrence probabilities in log |
33 |
| - scale (a measure of how common and probable the corrected |
34 |
| - segmentation is). |
35 |
| - """ |
36 |
| - |
37 |
| - segmented_string: str = "" |
38 |
| - corrected_string: str = "" |
39 |
| - distance_sum: int = 0 |
40 |
| - log_prob_sum: float = 0 |
41 |
| - |
42 |
| - @classmethod |
43 |
| - def create( |
44 |
| - cls, |
45 |
| - composition: "Composition", |
46 |
| - segmented_part: str, |
47 |
| - corrected_part: str, |
48 |
| - distance: int, |
49 |
| - log_prob: float, |
50 |
| - ) -> "Composition": |
51 |
| - """Creates a Composition by appending to an existing Composition.""" |
52 |
| - return cls( |
53 |
| - composition.segmented_string + segmented_part, |
54 |
| - composition.corrected_string + corrected_part, |
55 |
| - composition.distance_sum + distance, |
56 |
| - composition.log_prob_sum + log_prob, |
57 |
| - ) |
| 1 | +# MIT License |
| 2 | +# |
| 3 | +# Copyright (c) 2022 mmb L (Python port) |
| 4 | +# Copyright (c) 2021 Wolf Garbe (Original C# implementation) |
| 5 | +# |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files (the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions: |
| 12 | +# |
| 13 | +# The above copyright notice and this permission notice shall be included in all |
| 14 | +# copies or substantial portions of the Software. |
| 15 | + |
| 16 | +""" |
| 17 | +.. module:: compostiion |
| 18 | + :synopsis: Data class for :meth:`symspellpy.symspellpy.word_segmentation`. |
| 19 | +""" |
| 20 | + |
| 21 | +from typing import NamedTuple |
| 22 | + |
| 23 | + |
| 24 | +class Composition(NamedTuple): |
| 25 | + """Used by :meth:`word_segmentation`. |
| 26 | +
|
| 27 | + Attributes: |
| 28 | + segmented_string: The word segmented string. |
| 29 | + corrected_string: The spelling corrected string. |
| 30 | + distance_sum: The sum of edit distance between input string and |
| 31 | + corrected string |
| 32 | + log_prob_sum: The sum of word occurrence probabilities in log |
| 33 | + scale (a measure of how common and probable the corrected |
| 34 | + segmentation is). |
| 35 | + """ |
| 36 | + |
| 37 | + segmented_string: str = "" |
| 38 | + corrected_string: str = "" |
| 39 | + distance_sum: int = 0 |
| 40 | + log_prob_sum: float = 0 |
| 41 | + |
| 42 | + @classmethod |
| 43 | + def create( |
| 44 | + cls, |
| 45 | + composition: "Composition", |
| 46 | + segmented_part: str, |
| 47 | + corrected_part: str, |
| 48 | + distance: int, |
| 49 | + log_prob: float, |
| 50 | + ) -> "Composition": |
| 51 | + """Creates a Composition by appending to an existing Composition.""" |
| 52 | + return cls( |
| 53 | + composition.segmented_string + segmented_part, |
| 54 | + composition.corrected_string + corrected_part, |
| 55 | + composition.distance_sum + distance, |
| 56 | + composition.log_prob_sum + log_prob, |
| 57 | + ) |
0 commit comments