icat.anchorlist.AnchorList#

class icat.anchorlist.AnchorList(model=None, table_width=700, table_height=150, anchor_types=None, **params)#

Bases: Viewer

A model’s list tracking and managing a collection of anchors.

This is what handles creating features for a dataset. This class is also a visual component for interacting with and modifying those anchors in a table format and is used as part of the greater model interactive view.

Parameters:
  • model – The parent model.

  • table_width (int) – Static width of the visual component table.

  • table_height (int) – Static height of the visual component table. (Currently unused)

  • anchor_types (list[type | dict[str, any]]) – The anchor types to start the interface with. This list can contain a combination of types and dictionaries with keys ref (containing the type), name (display name) and color (the color to render anchors of this type with.) If left None (the default), will add DictionaryAnchor and TFIDFAnchor.

Methods

__init__([model, table_width, table_height, ...])

add_anchor(anchor)

Add the passed anchor to this anchor list.

add_anchor_type(anchor_type[, name, color])

Register the passed anchor type (must be a subclass of Anchor) in the UI.

add_anchor_types(anchor_types)

Add multiple anchor types to the UI.

build_tfidf_features()

debug(**kwargs)

Inspect .param.debug method for the full docstring

defaults(**kwargs)

Inspect .param.defaults method for the full docstring

featurize(data[, normalize, reference_data])

Apply the featurization from each anchor to the passed data.

fire_on_anchor_added(anchor)

Trigger the event to notify that a new anchor was added.

fire_on_anchor_changed(name, key, value)

Trigger the event to notify that a property on an anchor changed.

fire_on_anchor_removed(anchor)

Trigger the event to notify that an anchor was removed.

fire_on_anchor_types_changed()

Trigger the event to notify that the anchor types have been changed.

fire_on_default_example_anchor_type_changed()

Trigger the event to notify that the default anchor type used for 'example' instances is changed.

force_new_dynamic_value(**kwargs)

Inspect .param.force_new_dynamic_value method for the full docstring

get_anchor_by_panel_id(panel_id)

Get the anchor instance with the associated panel name/id.

get_anchor_type_config(anchor_type)

Get the dictionary of UI properties for the specified registered anchor type.

get_param_values(**kwargs)

Inspect .param.get_param_values method for the full docstring

get_unique_anchor_name()

Returns a name for a new anchor that won't conflict with any existing.

get_value_generator(**kwargs)

Inspect .param.get_value_generator method for the full docstring

highlight_regex()

Construct a regex for all keywords in dictionary anchors, for use in highlighting keywords in a text.

inspect_value(**kwargs)

Inspect .param.inspect_value method for the full docstring

load(path)

Reload parameters for and re-add all anchors from specified location, as well as unpickle any previously saved cache.

message(**kwargs)

Inspect .param.message method for the full docstring

modify_anchor_type(anchor_type, key, val)

Change an associated property of the specified anchor type.

on_anchor_added(callback)

Register a callback function for the "anchor added" event.

on_anchor_changed(callback)

Register a callback function for the "anchor changed" event.

on_anchor_removed(callback)

Register a callback function for the "anchor removal" event.

on_anchor_types_changed(callback)

Register a callback functino for the "anchor types changed" event.

on_default_example_anchor_type_changed(callback)

Register a callback function for the "default example anchor changed event.

params(**kwargs)

Inspect .param.params method for the full docstring

pprint(*args, **kwargs)

print_param_defaults(*args, **kwargs)

Inspect .param.print_param_defaults method for the full docstring

print_param_values(**kwargs)

Inspect .param.print_param_values method for the full docstring

refresh_anchor_types()

Re-populate lists of anchor types in the interface.

refresh_anchors_table()

Re-populate the list of anchors and coverage stats.

remove_anchor(anchor)

Remove the specified anchor from this anchor list.

remove_anchor_type(anchor_type)

Removes this anchor type from the current possible anchor types list, and removes any corresponding anchors.

save(path)

Save the configuration for each individual anchor, and pickle the cache, at the specified location.

script_repr([imports, prefix])

Deprecated variant of __repr__ designed for generating a runnable script.

servable([title, location, area, target])

Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.

set_coverage(coverage_info)

Set the anchor coverage data, to be updated and displayed in the table.

set_default(*args, **kwargs)

Inspect .param.set_default method for the full docstring

set_dynamic_time_fn(**kwargs)

Inspect .param.set_dynamic_time_fn method for the full docstring

set_param(**kwargs)

Inspect .param.set_param method for the full docstring

show([title, port, address, ...])

Starts a Bokeh server and displays the Viewable in a new tab.

state_pop()

Restore the most recently saved state.

state_push()

Save this instance's state.

verbose(**kwargs)

Inspect .param.verbose method for the full docstring

warning(**kwargs)

Inspect .param.warning method for the full docstring

Attributes

anchors

The param list of anchors.

default_example_anchor_type_dict

The dictionary of the anchor type information for the current default example anchor type.

name

param

possible_anchor_types

The list of registered anchor types within the interface, each entry is a dictionary containing ref, name, and color.

coverage_info

Dictionary associating panel id of anchor with dictionary of 'coverage', 'pct_positive', and 'pct_negative' stats.

anchors_layout

The full component layout for panel to display.

cache

This cache gets pickled on save, useful for anchors to store results of processing-intensive tasks to reduce featurizing time.

model

The parent model these anchors apply to.

add_anchor(anchor)#

Add the passed anchor to this anchor list.

Parameters:

anchor (Anchor) – The anchor to add to the list.

Important

This function should be used rather than directly mutating the internal anchors list with anchors.append. Panel/param won’t detect this change, and certain functionality will probably not work on the frontend.

Note

This triggers the “anchor added” event. You can watch for it by specifying a callback function to on_anchor_added()

add_anchor_type(anchor_type, name=None, color='#777777')#

Register the passed anchor type (must be a subclass of Anchor) in the UI. This adds a corresponding “add new” button for this type.

Parameters:
  • anchor_type (type) – The class type (of subclass Anchor) to register.

  • name (str) – The name to associate with the type in the UI.

  • color (str) – The hex color to use in the CSS for rows in the anchorlist and anchors in anchorviz for this anchor type.

add_anchor_types(anchor_types)#

Add multiple anchor types to the UI.

Parameters:

anchor_types (list[type|dict[str, any]]) – the list of anchor types to add, this can consist of a combination of straight class types and dictionaries containing ref (the class type), name, and color.

Example

al = AnchorList(anchor_types=[])
al.add_anchor_types([
    icat.anchors.DictionaryAnchor,
    {"ref": icat.anchors.TFIDFAnchor, "color": "#778899"}
])
anchors = []#

The param list of anchors.

Important

Care must be taken when directly setting this variable. Lists are mutable, and panel/param do not detect inner changes to mutable objects. This includes things like anchors.append(my_anchor) and anchors[1] = some_anchor. Use the various functions on this class such as add_anchor and so on. Notably, entire list replacements, e.g. anchors = [my_anchor, some_anchor], work as expected.

anchors_layout#

The full component layout for panel to display.

build_tfidf_features()#
cache: dict[str, any]#

This cache gets pickled on save, useful for anchors to store results of processing-intensive tasks to reduce featurizing time.

coverage_info#

Dictionary associating panel id of anchor with dictionary of ‘coverage’, ‘pct_positive’, and ‘pct_negative’ stats.

default_example_anchor_type_dict = {}#

The dictionary of the anchor type information for the current default example anchor type. This should contain keys ref (type), name, and color.

featurize(data, normalize=True, reference_data=None)#

Apply the featurization from each anchor to the passed data.

Parameters:
  • data (pd.DataFrame) – The data to compute the features on.

  • normalize (bool) – Whether to apply L1 norm (column-wise) to the features.

  • reference_data (Optional[pd.DataFrame]) – If normalizing, use this data to determine feature sums.

Returns:

The featured dataframe.

Return type:

DataFrame

fire_on_anchor_added(anchor)#

Trigger the event to notify that a new anchor was added.

Parameters:

anchor (icat.Anchor) – the anchor that was added.

fire_on_anchor_changed(name, key, value)#

Trigger the event to notify that a property on an anchor changed.

Note that this is usually used for simply passing along the change directly from the anchor’s individual on_anchor_changed events

Parameters:
  • name (str) – the internal name that panel is using, which we’re using as the anchor id.

  • key (str) – the name of the property being changed.

  • value (any) – The value the property was changed to.

fire_on_anchor_removed(anchor)#

Trigger the event to notify that an anchor was removed.

Parameters:

anchor (icat.Anchor) – the anchor that was removed.

fire_on_anchor_types_changed()#

Trigger the event to notify that the anchor types have been changed.

fire_on_default_example_anchor_type_changed()#

Trigger the event to notify that the default anchor type used for ‘example’ instances is changed.

get_anchor_by_panel_id(panel_id)#

Get the anchor instance with the associated panel name/id.

Parameters:

panel_id (str) – The panel ID string of the anchor, the format should be DictinaryAnchor00XX or similar.

Return type:

Anchor

get_anchor_type_config(anchor_type)#

Get the dictionary of UI properties for the specified registered anchor type.

Returns:

A dictionary with ref, name, and color, or None if the specified type isn’t found.

Parameters:

anchor_type (type) –

get_unique_anchor_name()#

Returns a name for a new anchor that won’t conflict with any existing.

Return type:

str

highlight_regex()#

Construct a regex for all keywords in dictionary anchors, for use in highlighting keywords in a text.

Returns:

A regex string that is essentially just the “|” or’d regexes of the individual anchors.

Return type:

str

load(path)#

Reload parameters for and re-add all anchors from specified location, as well as unpickle any previously saved cache.

Parameters:

path (str) –

model#

The parent model these anchors apply to.

modify_anchor_type(anchor_type, key, val)#

Change an associated property of the specified anchor type.

This assumes the passed type has already been registered with add_anchor_type.

Parameters:
  • anchor_type (type) – The anchor type to modify the UI property of.

  • key (str) – The name of the property to update, use color or name.

  • val (str) – The new value to assign to the property.

name = 'AnchorList'#
on_anchor_added(callback)#

Register a callback function for the “anchor added” event.

Callbacks for this event should take a single parameter which is the anchor that was added.

Parameters:

callback (Callable) –

on_anchor_changed(callback)#

Register a callback function for the “anchor changed” event.

Callbacks for this event should take three parameters: * Name (string) (this is the internal panel name, which we use as the anchor id.) * Property name (string) that’s changing on the anchor. * Value that the property on the anchor was changed to.

Parameters:

callback (Callable) –

on_anchor_removed(callback)#

Register a callback function for the “anchor removal” event.

Callbacks for this event should take a single parameter which is the anchor that was removed.

Parameters:

callback (Callable) –

on_anchor_types_changed(callback)#

Register a callback functino for the “anchor types changed” event.

Callbacks for this event should take the list of dictionaries of type information, expect each dictionary to contain “name”, “ref”, and “color”.

Parameters:

callback (Callable) –

on_default_example_anchor_type_changed(callback)#

Register a callback function for the “default example anchor changed event.

Callbacks for this event should take the anchor type config dictionary, which contains “name”, “ref”, and “color”.

Parameters:

callback (Callable) –

possible_anchor_types = []#

The list of registered anchor types within the interface, each entry is a dictionary containing ref, name, and color. Note that this list should not be manually altered, as sub parameter changes won’t be picked up by the interface. Use add_anchor_type, modify_anchor_type, and remove_anchor_type.

refresh_anchor_types()#

Re-populate lists of anchor types in the interface.

refresh_anchors_table()#

Re-populate the list of anchors and coverage stats. This function is called automatically anytime the anchors property changes.

remove_anchor(anchor)#

Remove the specified anchor from this anchor list.

Parameters:

anchor (Anchor) – The anchor to remove from the list.

Important

This function should be used rather than directly mutating the internal anchors list with anchors.remove. Panel/param won’t detect this change, and certain functionality will probably not work on the frontend.

Note

This triggers the “anchor removed” event. You can watch for it by specifying a callback function to on_anchor_removed()

remove_anchor_type(anchor_type)#

Removes this anchor type from the current possible anchor types list, and removes any corresponding anchors.

Parameters:

anchor_type (type) – The class type of the anchor to exclude from the interface.

save(path)#

Save the configuration for each individual anchor, and pickle the cache, at the specified location.

Parameters:

path (str) –

set_coverage(coverage_info)#

Set the anchor coverage data, to be updated and displayed in the table.

Parameters:

coverage_info (dict[str, dict[str, Union[int, float]]]) – Dictionary (keys being the anchor panel ids) and the value being a dictionary with the “row” of data to display in the table. Keys expected: “total”, “pos”, “neg”, “total_pct”, “pos_pct”, “neg_pct”