anndata.ann.annlabel package¶
Submodules¶
anndata.ann.annlabel.label module¶
- filename
sppas.src.anndata.annlabel.label.py
- author
Brigitte Bigi
- contact
- summary
Represent one of labels of an annotation.
- class anndata.ann.annlabel.label.sppasLabel(tag, score=None)[source]¶
Bases:
object
Represent the content of an annotation.
sppasLabel allows to store a set of sppasTags with their scores. This class is using a list of lists, i.e. a list of pairs (tag, score). This is the best compromise between memory usage, speed and readability.
A label is a list of possible sppasTag(), represented as a UNICODE string. A data type can be associated, as sppasTag() can be ‘int’, ‘float’ or ‘bool’.
- __init__(tag, score=None)[source]¶
Create a new sppasLabel instance.
- Parameters
tag – (sppasTag or list of sppasTag or None)
score – (float or list of float or None)
- append(tag, score=None)[source]¶
Add a sppasTag into the list.
Do not add the tag if this alternative is already inside the list, but add the scores.
- Parameters
tag – (sppasTag)
score – (float)
- append_content(content, data_type='str', score=None)[source]¶
Add a text into the list.
- Parameters
content – (str)
data_type – (str): The type of this text content.
One of: (str, int, float, bool) :param score: (float)
- get_best()[source]¶
Return the best sppasTag, i.e. the one with the better score.
- Returns
(sppasTag or None)
- get_score(tag)[source]¶
Return the score of a tag or None if tag is not in the label.
- Parameters
tag – (sppasTag)
- Returns
score: (float)
- match(tag_functions, logic_bool='and')[source]¶
Return True if a tag matches all or any of the functions.
- Parameters
tag_functions – list of (function, value, logical_not)
logic_bool – (str) Apply a logical “and” or a logical “or” between the functions.
- Returns
(bool)
function: a function in python with 2 arguments: tag/value
value: the expected value for the tag
logical_not: boolean
- Example
Search if a tag is exactly matching “R”:
>>> l.match([(exact, "R", False)])
- Example
Search if a tag is starting with “p” or starting with “t”:
>>> l.match([(startswith, "p", False), >>> (startswith, "t", False), ], logic_bool="or")
- remove(tag)[source]¶
Remove a tag of the list.
- Parameters
tag – (sppasTag) the tag to be removed of the list.
anndata.ann.annlabel.tag module¶
- filename
sppas.src.anndata.annlabel.tag.py
- author
Brigitte Bigi
- contact
- summary
Represent one of tags of a label.
- class anndata.ann.annlabel.tag.sppasTag(tag_content, tag_type=None)[source]¶
Bases:
object
Represent one of the possible tags of a label.
A sppasTag is a data content of any type. By default, the type of the data is “str” and the content is empty, but internally the sppasTag stores ‘None’ values because None is 16 bits and an empty string is 37.
A sppasTag() content can be one of the following types:
string/unicode - (str)
integer - (int)
float - (float)
boolean - (bool)
point - (sppasFuzzyPoint)
rect - (sppasFuzzyRect)
Get access to the content with the get_content() method and to the typed content with get_typed_content().
>>> t1 = sppasTag("2") # "2" (str) >>> t2 = sppasTag(2) # "2" (str) >>> t3 = sppasTag(2, tag_type="int") # 2 (int) >>> t4 = sppasTag("2", tag_type="int") # 2 (int) >>> t5 = sppasTag("2", tag_type="float") # 2. (float) >>> t6 = sppasTag("true", tag_type="bool") # True (bool) >>> t7 = sppasTag(0, tag_type="bool") # False (bool) >>> t8 = sppasTag((27, 32), tag_type="point") # x=27, y=32 (point) >>> t9 = sppasTag((27, 32, 320, 200), tag_type="rect")
- TAG_TYPES = ('str', 'float', 'int', 'bool', 'point', 'rect')¶
- __init__(tag_content, tag_type=None)[source]¶
Initialize a new sppasTag instance.
- Parameters
tag_content – (any) Data content
tag_type – (str): The type of this content. One of: (‘str’, ‘int’, ‘float’, ‘bool’, ‘point’, ‘rect’).
‘str’ is the default tag_type.
- get_content()[source]¶
Return an unicode string corresponding to the content.
Also returns a unicode string in case of a list (elements are separated by a whitespace).
- Returns
(unicode)
anndata.ann.annlabel.tagcompare module¶
- filename
sppas.src.anndata.annlabel.tagcompare.py
- author
Brigitte Bigi
- contact
- summary
Comparison methods for a tag, used by the filter system.
- class anndata.ann.annlabel.tagcompare.sppasTagCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
Comparison methods for sppasTag.
Label’tags can be of 3 types in anndata (str, num, bool) so that this class allows to create different comparison methods depending on the type of the tags.
- Example
Three different ways to compare a tag content to a given string
>>> tc = sppasTagCompare() >>> tc.exact(sppasTag("abc"), u("abc")) >>> tc.methods['exact'](sppasTag("abc"), u("abc")) >>> tc.get('exact')(sppasTag("abc"), u("abc"))
- static bool(tag, x)[source]¶
Return True if boolean value of the tag is equal to boolean x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (bool)
- Returns
(bool)
- Raises
AnnDataTypeError
- static contains(tag, text)[source]¶
Test if the first text contains the second text.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static endswith(tag, text)[source]¶
Test if first text ends with the characters of the second text.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static equal(tag, x)[source]¶
Return True if numerical value of the tag is equal to x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (int, float)
- Returns
(bool)
- Raises
AnnDataTypeError
- static exact(tag, text)[source]¶
Test if two texts strictly contain the same characters.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static greater(tag, x)[source]¶
Return True if numerical value of the tag is greater than x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (int, float)
- Returns
(bool)
- Raises
AnnDataTypeError
- static icontains(tag, text)[source]¶
Case-insensitive contains.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static iendswith(tag, text)[source]¶
Case-insensitive endswith.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static iexact(tag, text)[source]¶
Case-insensitive exact.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static istartswith(tag, text)[source]¶
Case-insensitive startswith.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static lower(tag, x)[source]¶
Return True if numerical value of the tag is lower than x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (int, float)
- Returns
(bool)
- Raises
AnnDataTypeError
anndata.ann.annlabel.tagtypes module¶
- filename
sppas.src.anndata.annlabel.tagtypes.py
- author
Brigitte Bigi
- contact
- summary
Represent custom types of tags (point/rect)
- class anndata.ann.annlabel.tagtypes.sppasFuzzyPoint(coord, radius=None)[source]¶
Bases:
object
Data structure to represent a point (x,y) with a radius (r).
Mainly used to represent a point in an image with a vagueness around the midpoint. The fuzzy point is then representing a rectangle area. The radius is half of the vagueness.
Two fuzzy points are equals if their area overlaps.
- __init__(coord, radius=None)[source]¶
Create a sppasFuzzyPoint instance.
The given coordinates of the midpoint can be a tuple of int values or a string representing it.
- Parameters
coord – (int,int) x,y coords of the midpoint value.
radius – (int) the radius around the midpoint.
- contains(coord)[source]¶
Check if the given midpoint is inside the vagueness of self.
- Parameters
coord – (tuple) An (x, y) coordinates
- static parse(str_point)[source]¶
Return a tuple (x,y) or (x,y,r).
- Parameters
str_point – (str) A string representing a fuzzy point.
- set(other)[source]¶
Set self members from another sppasFuzzyPoint instance.
- Parameters
other – (sppasFuzzyPoint)
- class anndata.ann.annlabel.tagtypes.sppasFuzzyRect(coord, radius=None)[source]¶
Bases:
object
Data structure to represent an area (x,y,w,h) with a radius (r).
Mainly used to represent a rectangle in an image with a vagueness around the midpoint, which is a rectangle. The radius is half of the vagueness.
- __init__(coord, radius=None)[source]¶
Create a sppasFuzzyRect instance.
The given coordinates of the midpoint can be a tuple of int values or a string representing it.
- Parameters
coord – (int,int,int,int) x,y,w,h coords of the midpoint value.
radius – (int) the radius around the midpoint.
- contains(coord)[source]¶
Check if the given point is inside the vagueness of self.
- Parameters
coord – (tuple) An (x, y) coordinates
- static parse(str_rect)[source]¶
Return a tuple (x,y,w,h) or (x,y,w,h,r).
- Parameters
str_rect – (str) A string representing a fuzzy rect.
- set(other)[source]¶
Set self members from another sppasFuzzyRect instance.
- Parameters
other – (sppasFuzzyRect)
Module contents¶
- filename
sppas.src.anndata.annlabel.__init__.py
- author
Brigitte Bigi
- contact
- summary
one of the labels of an annotation.
- class anndata.ann.annlabel.sppasFuzzyPoint(coord, radius=None)[source]¶
Bases:
object
Data structure to represent a point (x,y) with a radius (r).
Mainly used to represent a point in an image with a vagueness around the midpoint. The fuzzy point is then representing a rectangle area. The radius is half of the vagueness.
Two fuzzy points are equals if their area overlaps.
- __init__(coord, radius=None)[source]¶
Create a sppasFuzzyPoint instance.
The given coordinates of the midpoint can be a tuple of int values or a string representing it.
- Parameters
coord – (int,int) x,y coords of the midpoint value.
radius – (int) the radius around the midpoint.
- contains(coord)[source]¶
Check if the given midpoint is inside the vagueness of self.
- Parameters
coord – (tuple) An (x, y) coordinates
- static parse(str_point)[source]¶
Return a tuple (x,y) or (x,y,r).
- Parameters
str_point – (str) A string representing a fuzzy point.
- set(other)[source]¶
Set self members from another sppasFuzzyPoint instance.
- Parameters
other – (sppasFuzzyPoint)
- class anndata.ann.annlabel.sppasFuzzyRect(coord, radius=None)[source]¶
Bases:
object
Data structure to represent an area (x,y,w,h) with a radius (r).
Mainly used to represent a rectangle in an image with a vagueness around the midpoint, which is a rectangle. The radius is half of the vagueness.
- __init__(coord, radius=None)[source]¶
Create a sppasFuzzyRect instance.
The given coordinates of the midpoint can be a tuple of int values or a string representing it.
- Parameters
coord – (int,int,int,int) x,y,w,h coords of the midpoint value.
radius – (int) the radius around the midpoint.
- contains(coord)[source]¶
Check if the given point is inside the vagueness of self.
- Parameters
coord – (tuple) An (x, y) coordinates
- static parse(str_rect)[source]¶
Return a tuple (x,y,w,h) or (x,y,w,h,r).
- Parameters
str_rect – (str) A string representing a fuzzy rect.
- set(other)[source]¶
Set self members from another sppasFuzzyRect instance.
- Parameters
other – (sppasFuzzyRect)
- class anndata.ann.annlabel.sppasLabel(tag, score=None)[source]¶
Bases:
object
Represent the content of an annotation.
sppasLabel allows to store a set of sppasTags with their scores. This class is using a list of lists, i.e. a list of pairs (tag, score). This is the best compromise between memory usage, speed and readability.
A label is a list of possible sppasTag(), represented as a UNICODE string. A data type can be associated, as sppasTag() can be ‘int’, ‘float’ or ‘bool’.
- __init__(tag, score=None)[source]¶
Create a new sppasLabel instance.
- Parameters
tag – (sppasTag or list of sppasTag or None)
score – (float or list of float or None)
- append(tag, score=None)[source]¶
Add a sppasTag into the list.
Do not add the tag if this alternative is already inside the list, but add the scores.
- Parameters
tag – (sppasTag)
score – (float)
- append_content(content, data_type='str', score=None)[source]¶
Add a text into the list.
- Parameters
content – (str)
data_type – (str): The type of this text content.
One of: (str, int, float, bool) :param score: (float)
- get_best()[source]¶
Return the best sppasTag, i.e. the one with the better score.
- Returns
(sppasTag or None)
- get_score(tag)[source]¶
Return the score of a tag or None if tag is not in the label.
- Parameters
tag – (sppasTag)
- Returns
score: (float)
- match(tag_functions, logic_bool='and')[source]¶
Return True if a tag matches all or any of the functions.
- Parameters
tag_functions – list of (function, value, logical_not)
logic_bool – (str) Apply a logical “and” or a logical “or” between the functions.
- Returns
(bool)
function: a function in python with 2 arguments: tag/value
value: the expected value for the tag
logical_not: boolean
- Example
Search if a tag is exactly matching “R”:
>>> l.match([(exact, "R", False)])
- Example
Search if a tag is starting with “p” or starting with “t”:
>>> l.match([(startswith, "p", False), >>> (startswith, "t", False), ], logic_bool="or")
- remove(tag)[source]¶
Remove a tag of the list.
- Parameters
tag – (sppasTag) the tag to be removed of the list.
- class anndata.ann.annlabel.sppasTag(tag_content, tag_type=None)[source]¶
Bases:
object
Represent one of the possible tags of a label.
A sppasTag is a data content of any type. By default, the type of the data is “str” and the content is empty, but internally the sppasTag stores ‘None’ values because None is 16 bits and an empty string is 37.
A sppasTag() content can be one of the following types:
string/unicode - (str)
integer - (int)
float - (float)
boolean - (bool)
point - (sppasFuzzyPoint)
rect - (sppasFuzzyRect)
Get access to the content with the get_content() method and to the typed content with get_typed_content().
>>> t1 = sppasTag("2") # "2" (str) >>> t2 = sppasTag(2) # "2" (str) >>> t3 = sppasTag(2, tag_type="int") # 2 (int) >>> t4 = sppasTag("2", tag_type="int") # 2 (int) >>> t5 = sppasTag("2", tag_type="float") # 2. (float) >>> t6 = sppasTag("true", tag_type="bool") # True (bool) >>> t7 = sppasTag(0, tag_type="bool") # False (bool) >>> t8 = sppasTag((27, 32), tag_type="point") # x=27, y=32 (point) >>> t9 = sppasTag((27, 32, 320, 200), tag_type="rect")
- TAG_TYPES = ('str', 'float', 'int', 'bool', 'point', 'rect')¶
- __init__(tag_content, tag_type=None)[source]¶
Initialize a new sppasTag instance.
- Parameters
tag_content – (any) Data content
tag_type – (str): The type of this content. One of: (‘str’, ‘int’, ‘float’, ‘bool’, ‘point’, ‘rect’).
‘str’ is the default tag_type.
- get_content()[source]¶
Return an unicode string corresponding to the content.
Also returns a unicode string in case of a list (elements are separated by a whitespace).
- Returns
(unicode)
- class anndata.ann.annlabel.sppasTagCompare[source]¶
Bases:
sppas.src.structs.basecompare.sppasBaseCompare
Comparison methods for sppasTag.
Label’tags can be of 3 types in anndata (str, num, bool) so that this class allows to create different comparison methods depending on the type of the tags.
- Example
Three different ways to compare a tag content to a given string
>>> tc = sppasTagCompare() >>> tc.exact(sppasTag("abc"), u("abc")) >>> tc.methods['exact'](sppasTag("abc"), u("abc")) >>> tc.get('exact')(sppasTag("abc"), u("abc"))
- static bool(tag, x)[source]¶
Return True if boolean value of the tag is equal to boolean x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (bool)
- Returns
(bool)
- Raises
AnnDataTypeError
- static contains(tag, text)[source]¶
Test if the first text contains the second text.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static endswith(tag, text)[source]¶
Test if first text ends with the characters of the second text.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static equal(tag, x)[source]¶
Return True if numerical value of the tag is equal to x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (int, float)
- Returns
(bool)
- Raises
AnnDataTypeError
- static exact(tag, text)[source]¶
Test if two texts strictly contain the same characters.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static greater(tag, x)[source]¶
Return True if numerical value of the tag is greater than x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (int, float)
- Returns
(bool)
- Raises
AnnDataTypeError
- static icontains(tag, text)[source]¶
Case-insensitive contains.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static iendswith(tag, text)[source]¶
Case-insensitive endswith.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static iexact(tag, text)[source]¶
Case-insensitive exact.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static istartswith(tag, text)[source]¶
Case-insensitive startswith.
- Parameters
tag – (sppasTag) Tag to compare.
text – (unicode) Unicode string to be compared with.
- Returns
(bool)
- Raises
AnnDataTypeError
- static lower(tag, x)[source]¶
Return True if numerical value of the tag is lower than x.
- Parameters
tag – (sppasTag) Tag to compare.
x – (int, float)
- Returns
(bool)
- Raises
AnnDataTypeError