@@ -66,6 +66,27 @@ def _escape_oewn_sense_key(sense_key: str) -> str:
66
66
67
67
68
68
def sense_key_getter (lexicon : str ) -> SensekeyGetter :
69
+ """Return a function that gets sense keys from senses.
70
+
71
+ The *lexicon* argument determines how the function will retrieve
72
+ the sense key. For OMW and EWN 2019/2020 lexicons, the sense key
73
+ is in the ``identifier`` metadata. For OEWN 2021+ lexicons, the
74
+ sense ID is an escaped form of the sense key. For any unsupported
75
+ lexicon, an error is raised.
76
+
77
+ The function that is returned accepts one argument, a
78
+ :class:`wn.Sense` (ideally from the same lexicon specified in the
79
+ *lexicon* argument), and returns a :class:`str` if the sense key
80
+ exists in the lexicon or :data:`None` otherwise.
81
+
82
+ >>> import wn
83
+ >>> from wn.compat import sensekey
84
+ >>> oewn = wn.Wordnet("oewn:2024")
85
+ >>> get_sense_key = sensekey.sense_key_getter("oewn:2024")
86
+ >>> get_sense_key(oewn.senses("alabaster")[0])
87
+ 'alabaster%3:01:00::'
88
+
89
+ """
69
90
if lexicon in METADATA_LEXICONS :
70
91
71
92
def getter (sense : wn .Sense ) -> Optional [str ]:
@@ -89,6 +110,32 @@ def getter(sense: wn.Sense) -> Optional[str]:
89
110
90
111
91
112
def sense_getter (lexicon : str , wordnet : Optional [wn .Wordnet ] = None ) -> SenseGetter :
113
+ """Return a function that gets the sense for a sense key.
114
+
115
+ The *lexicon* argument determines how the function will retrieve
116
+ the sense. For OMW and EWN 2019/2020 lexicons, the sense key is in
117
+ the ``identifier`` metadata and a mapping of sense keys to senses
118
+ will be created internally. For OEWN 2021+ lexicons the sense ID
119
+ is an escaped form of the sense key, so the given sense key is
120
+ escaped, then the sense is retrieved by :meth:`wn.Wordnet.sense`.
121
+ For any unsupported lexicon, an error is raised.
122
+
123
+ The optional *wordnet* object is used as the source of the
124
+ returned :class:`wn.Sense` objects. If none is provided, a new
125
+ :class:`wn.Wordnet` object is created using the *lexicon*
126
+ argument.
127
+
128
+ The function that is returned accepts one argument, a :class:`str`
129
+ of the sense key, and returns a :class:`wn.Sense` if the sense key
130
+ exists in the lexicon or :data:`None` otherwise.
131
+
132
+ >>> import wn
133
+ >>> from wn.compat import sensekey
134
+ >>> get_sense = sensekey.sense_getter("oewn:2024")
135
+ >>> get_sense("alabaster%3:01:00::")
136
+ Sense('oewn-alabaster__3.01.00..')
137
+
138
+ """
92
139
if wordnet is None :
93
140
wordnet = wn .Wordnet (lexicon )
94
141
0 commit comments