diff --git a/retailtree/retailtree.py b/retailtree/retailtree.py index 0f20514..6da7460 100644 --- a/retailtree/retailtree.py +++ b/retailtree/retailtree.py @@ -28,12 +28,12 @@ def add_annotation(self, annotation): self.annotations[annotation.id] = annotation def get(self, id): - # type:(int) -> Annotation + # type:(int|str) -> Annotation """ Retrieve an annotation by its ID. Args: - id (int): The ID of the annotation to retrieve. + id (int|str): The ID of the annotation to retrieve. Returns: The annotation corresponding to the provided ID. @@ -76,7 +76,7 @@ def __get_neighbors_radius(self): return radius def __fetch_neighbors(self, id, radius=1): - # type:(int, int) -> list[tuple[float, Annotation]] + # type:(int|str, int) -> list[tuple[float, Annotation]] radius = radius*self.__get_neighbors_radius() neighbors = self.tree.get_all_in_range( (self.annotations[id].x_mid, self.annotations[id].y_mid), radius) @@ -116,12 +116,12 @@ def __fetching_ann_in_range(self, result_dict, min_angle, max_angle, result_lst) return result_lst def neighbors_wa(self, id, radius=1, amin=None, amax=None): - # type:(int, int, float, float) -> list[dict] + # type:(int|str, int, float, float) -> list[dict] """ Retrieves neighboring elements within a specified angle range around a given element. Args: - id (int): The identifier of the central element. + id (int|str): The identifier of the central element. radius (float, optional): The radius within which to search for neighbors. Defaults to 1. amin (min_angle) (float, optional): The minimum angle in degree. Defaults to None. amax (max_angle) (float, optional): The maximum angle in degree. Defaults to None. @@ -150,14 +150,14 @@ def neighbors_wa(self, id, radius=1, amin=None, amax=None): return result_lst def neighbors(self, id, radius=1): - # type:(int, int) -> list[dict] + # type:(int|str, int) -> list[dict] """ Finds neighboring annotations within a specified radius of a given annotation.(Radius specified is taken as a square rather than a circle) Uses a Vantage Point Tree (VPTree) to efficiently find annotations within the specified radius. Args: - id (int): The ID of the annotation. + id (int|str): The ID of the annotation. radius (float, optional): The relative radius within which to search. Defaults to 1. If a value less than 1 is provided, it's multiplied by an internal factor. @@ -189,14 +189,14 @@ def neighbors(self, id, radius=1): return result_lst def TBLR(self, id, radius=1, overlap=0.5): - # type:(int, int, float) -> (dict[str, int | bool] | str) + # type:(int|str, int, float) -> (dict[str, int | bool] | str) """ Computes top, bottom, left, and right connections for a given annotation within a specified radius. Finds neighboring annotations within the radius, calculates connections based on overlap percentage, and returns the connections as a dictionary. Args: - - id (int): The ID of the annotation. + - id (int|str): The ID of the annotation. - radius (float, optional): The radius within which to search for neighboring annotations. Defaults to 1. - overlap (float, optional): The overlap percentage used to compute connections. Defaults to 0.5. diff --git a/retailtree/structs/annotation_struct.py b/retailtree/structs/annotation_struct.py index f4de548..0e1d6ba 100644 --- a/retailtree/structs/annotation_struct.py +++ b/retailtree/structs/annotation_struct.py @@ -9,7 +9,7 @@ class Annotation: Parameters ---------- - id: - Int. Id of the Annotation. + Int|Str. Id of the Annotation. - x_min: Float. Left-most coordinate of rectangular annotation. - x_max: @@ -26,8 +26,8 @@ class Annotation: """ def __init__(self, id, x_min, y_min, x_max, y_max, label=None, metadata=None): - # type:(int, float, float, float, float, Any , dict[Any, Any]) -> None - self.__id = int(id) + # type:(int|str, float, float, float, float, Any , dict[Any, Any]) -> None + self.__id = id if isinstance(id, str) else int(id) self.__x_min = float(x_min) self.__x_max = float(x_max) self.__y_min = float(y_min) diff --git a/setup.py b/setup.py index 7273f8c..edeb149 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read(fname): setup( name="retailtree", - version="1.3.2", + version="1.3.3", long_description=read("README.md"), long_description_content_type='text/markdown', packages=find_packages(),