You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# file: testing.pyfromtypingimportDict, Generator, Generic, List, Optional, Tuple, TypeVarfromsparv.api.classesimportAnnotation, BaseAnnotation, Output# type: ignore [import-untyped]fromsparv.coreimportlog_handler# type: ignore [import-untyped] # noqa: F401classMockAnnotation(Annotation):
def__init__(
self,
name: str="",
source_file: Optional[str] =None,
values: Optional[List[str]] =None,
children: Optional[Dict[str, List[List[int]]]] =None,
) ->None:
super().__init__(name)
self._values=valuesor []
self._children=childrenor {}
defread(self, allow_newlines: bool=False) ->Generator[str, None, None]:
"""Yield each line from the annotation."""ifnotself._values:
returnyieldfromself._valuesdefget_children(
self,
child: BaseAnnotation,
*,
orphan_alert: bool=False,
preserve_parent_annotation_order: bool=False,
) ->Tuple[List, List]:
"""Return two lists. The first one is a list with n (= total number of parents) elements where every element is a list of indices in the child annotation. The second one is a list of orphans, i.e. containing indices in the child annotation that have no parent. Both parents and children are sorted according to their position in the source file, unless preserve_parent_annotation_order is set to True, in which case the parents keep the order from the parent annotation. """returnself._children[child.name], []
defcreate_empty_attribute(self) ->List:
return [None] *max(len(val) forvalinself._children.values())
T=TypeVar("T")
classMemoryOutput(Output, Generic[T]):
def__init__(self) ->None:
self.values: List[T] = []
defwrite(
self,
values: List[T],
*,
append: bool=False,
allow_newlines: bool=False,
source_file: Optional[str] =None,
) ->None:
"""Write an annotation to file. Existing annotation will be overwritten. 'values' should be a list of values. """ifappend:
self.values.extend(values)
else:
self.values=values
I have written some mock classes to be able to run tests for a annotator function.
Maybe it is interesting to put it in something like
sparv.testing
or shall I put it in a separate repo (maybesparv-testing
) to let i mature there?Update: I have created https://github.com/spraakbanken/sparv-pipeline-testing to use it several plugin repos.
Example usage:
The text was updated successfully, but these errors were encountered: