Skip to content

Commit b3886d3

Browse files
qinzzzqinzzzhunterhector
authored andcommitted
Issue 644 (#645)
* change tyoe_id to type_name in DataStore for compatablility * fix mypy error * Update batch_processor.py * Update bert_based_query_creator.py * Update converter.py * Update converter.py List is invariant so we have to update the function return type annotation a bit: python/mypy#3351 * Update converter.py * Update converter.py * Update converter.py * Update converter.py * Update converter.py * Update converter.py * Update converter.py * Update forte/data/data_store.py * Update converter.py Co-authored-by: qinzzz <[email protected]> Co-authored-by: Hector <[email protected]>
1 parent 90c181a commit b3886d3

9 files changed

Lines changed: 129 additions & 155 deletions

File tree

‎forte/data/base_store.py‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def __init__(self):
3333
"""
3434

3535
@abstractmethod
36-
def add_annotation_raw(self, type_id: int, begin: int, end: int) -> int:
36+
def add_annotation_raw(self, type_name: str, begin: int, end: int) -> int:
3737
r"""This function adds an annotation entry with `begin` and `end`
38-
indices to the (`type_id`)th sortedlist in `self.__elements`,
38+
indices to the `type_name` sortedlist in `self.__elements`,
3939
returns the `tid` for the inserted entry.
4040
4141
Args:
42-
type_id (int): The index of Annotation sortedlist in `self.__elements`.
42+
type_name (str): The index of Annotation sortedlist in `self.__elements`.
4343
begin (int): Begin index of the entry.
4444
end (int): End index of the entry.
4545
Returns:
@@ -49,37 +49,39 @@ def add_annotation_raw(self, type_id: int, begin: int, end: int) -> int:
4949

5050
@abstractmethod
5151
def add_link_raw(
52-
self, type_id: int, parent_tid: int, child_tid: int
52+
self, type_name: str, parent_tid: int, child_tid: int
5353
) -> Tuple[int, int]:
5454
r"""This function adds a link entry with `parent_tid` and `child_tid`
55-
to the (`type_id`)th list in `self.__elements`, returns the `tid` and the
55+
to the `type_name` list in `self.__elements`, returns the `tid` and the
5656
`index_id` for the inserted entry in the list. This `index_id` is the
57-
index of the entry in the (`type_id`)th list.
57+
index of the entry in the `type_name` list.
5858
5959
Args:
60-
type_id (int): The index of Link list in `self.__elements`.
60+
type_name (str): The index of Link list in `self.__elements`.
6161
parent_tid (int): `tid` of the parent entry.
6262
child_tid (int): `tid` of the child entry.
6363
6464
Returns:
65-
`tid` of the entry and its index in the (`type_id`)th list.
65+
`tid` of the entry and its index in the `type_name` list.
6666
6767
"""
6868
raise NotImplementedError
6969

7070
@abstractmethod
71-
def add_group_raw(self, type_id: int, member_type: str) -> Tuple[int, int]:
71+
def add_group_raw(
72+
self, type_name: str, member_type: str
73+
) -> Tuple[int, int]:
7274
r"""This function adds a group entry with `member_type` to the
73-
(`type_id`)th list in `self.__elements`, returns the `tid` and the
75+
`type_name` list in `self.__elements`, returns the `tid` and the
7476
`index_id` for the inserted entry in the list. This `index_id` is the
75-
index of the entry in the (`type_id`)th list.
77+
index of the entry in the `type_name` list.
7678
7779
Args:
78-
type_id (int): The index of Group list in `self.__elements`.
80+
type_name (str): The index of Group list in `self.__elements`.
7981
member_type (str): Fully qualified name of its members.
8082
8183
Returns:
82-
`tid` of the entry and its index in the (`type_id`)th list.
84+
`tid` of the entry and its index in the `type_name` list.
8385
8486
"""
8587
raise NotImplementedError
@@ -154,25 +156,25 @@ def delete_entry(self, tid: int):
154156
@abstractmethod
155157
def get_entry(self, tid: int) -> Tuple[List, int, int]:
156158
r"""Look up the entry_dict with key `tid`. Return the entry,
157-
its `type_id`, and its `index_id` in the `entry_type` list.
159+
its `type_name`, and its `index_id` in the `entry_type` list.
158160
159161
Args:
160162
tid (int): Unique id of the entry.
161163
162164
Returns:
163-
The entry which `tid` corresponds to, its `type_id` and its index
165+
The entry which `tid` corresponds to, its `type_name` and its index
164166
in the `entry_type` list.
165167
166168
"""
167169
raise NotImplementedError
168170

169171
@abstractmethod
170-
def get(self, type_id: int, include_sub_type: bool) -> Iterator[List]:
172+
def get(self, type_name: str, include_sub_type: bool) -> Iterator[List]:
171173
r"""This function fetches entries from the data store of
172-
type self.__type_dict[`type_id`].
174+
type `type_name`.
173175
174176
Args:
175-
type_id (int)): The index of the list in `self.__elements`.
177+
type_name (str): The index of the list in `self.__elements`.
176178
include_sub_type: A boolean to indicate whether get its subclass.
177179
178180
Returns:

‎forte/data/converter/converter.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import logging
15-
from typing import List, Tuple, Any, Optional, Union, Dict
15+
from typing import List, Tuple, Any, Optional, Union, Dict, Sequence
16+
1617
import numpy as np
1718
import torch
1819

@@ -103,7 +104,7 @@ def load_state(self, state: Dict):
103104

104105
def convert(
105106
self, features: List[Feature]
106-
) -> Tuple[MatrixLike, List[MatrixLike]]:
107+
) -> Tuple[MatrixLike, Sequence[MatrixLike]]:
107108
"""
108109
Convert a list of Features to matrix-like form, where
109110

‎forte/data/data_pack.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def get_span_text(self, begin: int, end: int) -> str:
386386
"""
387387
return self._text[begin:end]
388388

389-
def get_span_audio(self, begin: int, end: int) -> str:
389+
def get_span_audio(self, begin: int, end: int) -> np.ndarray:
390390
r"""Get the audio in the data pack contained in the span.
391391
`begin` and `end` represent the starting and ending indices of the span
392392
in audio payload respectively. Each index corresponds to one sample in

0 commit comments

Comments
 (0)