ModelInterface
- class rosa_kb.typedb_model_interface.ModelInterface(address, database_name, schema_path=None, data_path=None, force_database=False, force_data=False, infer=False)
Class to interact with the ROSA knowledge model in typeDB.
Connect to a typeDB server and interacts with it.
Connects TypeDBInterface to typeDB server, creating a database, loading a schema and a data file.
- Parameters:
address (
str
) – TypeDB server address.database_name (
str
) – database name.schema_path (
Union
[list
[str
],str
,None
]) – list with paths to schema files (.tql).data_path (
Union
[list
[str
],str
,None
]) – list with paths to data files (.tql).force_database (
Optional
[bool
]) – if database should override an existing databaseforce_data (
Optional
[bool
]) – if the database data should be overriden.infer (
Optional
[bool
]) – if inference engine should be used.
Methods
__init__
(address, database_name[, ...])Connect to a typeDB server and interacts with it.
activate_component
(c_name, value)Activate a Component.
add_measurement
(name, value)Add new Quality Attribute or EnvironmentalAttribute measurement.
cancel_action
(action_name)Cancel Action.
create_reconfiguration_plan
(c_activate, ...)Create a reconfiguration plan.
delete_component_status
(component_name)Delete Component status.
Get all attributes owned by a Component, and the Component type.
Get the name of adaptable Components.
Get the name of adaptable Functions.
get_adaptable_things_raw
(thing)Get the name of adaptable individuals of a certain Thing.
get_component_all_attributes
(component)Get all attributes owned by a Component, and the Component type.
get_component_configuration_priority
(cc_name)Get component configuration priority value.
get_component_parameters
(c_config)Get ComponentParameters in a component configuration relationship.
get_components_in_function_design
(fd_name)Get components in relation with a function design.
get_function_design_priority
(fd_name)Get function design priority value.
get_instances_of_thing_with_status
(thing, status)Get name of instances of a certain Thing that have a certain status.
Get name of instances of a certain Thing that have always-improve true.
Get end-time of the most recent completed reconfiguration plan.
get_latest_measurement
(name)Get latest measurement value.
Get latest pending reconfiguration plan.
Get start-time of the most recent pending reconfiguration plan.
Get latest reconfiguration plan.
Get start-time of the most recent reconfiguration plan.
get_measurement
(name, time)Get measured value at a certain time.
Get selected component configurations that are not required anymore.
Get active components that are not required anymore.
Get selected fds that are not required anymore.
Get outdated reconfiguration plans.
get_reconfiguration_plan
(start_time)Get reconfiguration plan with start-time.
get_reconfiguration_plan_result
(start_time)Get result of recongiration plan with start_time.
get_relationship_with_attribute
(entity, ...)Get relationship name that has an attr and relates to a certain entity.
Get the name of selectable Actions.
get_selectable_c_configs
(component_name)Get the name of selectable component configurations for a Component.
get_selectable_fds
(function_name)Get the name of selectable funtion designs for a Function.
get_selectable_thing_raw
(thing)Get the name of selectable individuals of a specific Thing.
Get components with status solved.
Get functions with status solved.
Get unsolved Components.
Get unsolved Functions.
get_unsolved_thing_raw
(thing)Get unsolved individuals of a certain Thing type.
has_action
(action_name)Check whether model can an specific Action.
insert_action
(action_name)Add new Action.
insert_component
(component_name[, ...])Add new Component.
insert_component_process
(component_name, pid)Add new component-process.
insert_function
(function_name)Add new Function.
insert_function_design
(function_design_name, ...)Add new function-design.
insert_functional_requirement
(action_name, ...)Add new functional-requirement.
insert_ros_node_component
(component_name, ...)Add new ROSNode Component.
is_action_feasible
(action_name)Check if an Action only has status feasible.
is_action_required
(action_name)Check whether an Action is required.
is_action_selectable
(action_name)Check whether an Action can be selected, i.e., it can be performed.
is_component_active
(name)Check wheter a component is active or not.
request_action
(action_name[, preference])Request Action.
select_component_configuration
(c_name, cc_name)Select component-configuration 'cc_name' and unselect all other ccs.
Select component configuration and return them.
select_configuration
(functions_selected_fd, ...)Select configuration and create reconfiguration plan.
Select function design, and get components to activate and deactivate.
select_function_design
(f_name, fd_name)Select function-design 'fd_name' and unselect all other fds.
select_relationship
(entity, entity_name, ...)Select relationship individual, and unselect all other individuals.
set_component_process_end_time
(start_time)Set component process end time.
Unselect all obsolete function designs and component configurations.
update_action_status
(action_name, action_status)Update Action status.
update_component_status
(component_name, ...)Update Component status.
update_function_design_priority
(fd_name, value)Update function design priority.
Set outdated reconfiguration plans result to 'abandoned'.
Update reconfiguration plan result.
- __init__(address, database_name, schema_path=None, data_path=None, force_database=False, force_data=False, infer=False)
Connect to a typeDB server and interacts with it.
Connects TypeDBInterface to typeDB server, creating a database, loading a schema and a data file.
- Parameters:
address (
str
) – TypeDB server address.database_name (
str
) – database name.schema_path (
Union
[list
[str
],str
,None
]) – list with paths to schema files (.tql).data_path (
Union
[list
[str
],str
,None
]) – list with paths to data files (.tql).force_database (
Optional
[bool
]) – if database should override an existing databaseforce_data (
Optional
[bool
]) – if the database data should be overriden.infer (
Optional
[bool
]) – if inference engine should be used.
- activate_component(c_name, value)
Activate a Component.
Set ‘is-active’ attribute of a Component to true or false.
- add_measurement(name, value)
Add new Quality Attribute or EnvironmentalAttribute measurement.
Add new Quality Attribute or EnvironmentalAttribute measurement. The new measurement ‘latest’ attribute is set to true, and the old measurements ‘latest’ attribute are set to false.
- cancel_action(action_name)
Cancel Action.
- create_reconfiguration_plan(c_activate, c_deactivate, c_config)
Create a reconfiguration plan.
- delete_component_status(component_name)
Delete Component status.
- get_active_component_process()
Get all attributes owned by a Component, and the Component type.
- Parameters:
component – component name.
- Return type:
- Returns:
Dict with component type and all its attributes
- get_adaptable_components()
Get the name of adaptable Components.
Get the name of adaptable Components. A component is adaptable when its ‘always-improve’ attribute is true, or when it status is ‘unsolved’ or ‘configuration error’
- get_adaptable_functions()
Get the name of adaptable Functions.
Get the name of adaptable Functions. A function is adaptable when its ‘always-improve’ attribute is true, or when it status is ‘unsolved’ or ‘configuration error’
- get_adaptable_things_raw(thing)
Get the name of adaptable individuals of a certain Thing.
Get the name of adaptable individuals of a certain Thing. An individual is adaptable when it has an ‘always-improve’ attribute set to true, or when it has status ‘unsolved’ or ‘configuration error’
- Parameters:
thing (
str
) – Thing type- Return type:
- Returns:
name of adaptable individuals
- get_component_all_attributes(component)
Get all attributes owned by a Component, and the Component type.
- Parameters:
component (
str
) – component name.- Return type:
- Returns:
Dict with component type and all its attributes
- get_component_configuration_priority(cc_name)
Get component configuration priority value.
- get_component_parameters(c_config)
Get ComponentParameters in a component configuration relationship.
- Parameters:
c_config (
str
) – component configuration name.- Return type:
- Returns:
Dict with component-name, parameter-key, parameter-value
- get_components_in_function_design(fd_name)
Get components in relation with a function design.
- get_function_design_priority(fd_name)
Get function design priority value.
- get_instances_of_thing_with_status(thing, status)
Get name of instances of a certain Thing that have a certain status.
- get_instances_thing_always_improve(thing)
Get name of instances of a certain Thing that have always-improve true.
- get_latest_completed_reconfiguration_plan_time()
Get end-time of the most recent completed reconfiguration plan.
- get_latest_measurement(name)
Get latest measurement value.
- get_latest_pending_reconfiguration_plan()
Get latest pending reconfiguration plan.
- Return type:
- Returns:
dict representing the reconfiguration plan, its keys are: start_time, c_activate, c_deactivate, c_config
- get_latest_pending_reconfiguration_plan_time()
Get start-time of the most recent pending reconfiguration plan.
- get_latest_reconfiguration_plan()
Get latest reconfiguration plan.
- Return type:
- Returns:
dict representing the reconfiguration plan, its keys are: start_time, c_activate, c_deactivate, c_config
- get_latest_reconfiguration_plan_time()
Get start-time of the most recent reconfiguration plan.
- get_measurement(name, time)
Get measured value at a certain time.
- get_obsolete_component_configurations()
Get selected component configurations that are not required anymore.
- get_obsolete_components()
Get active components that are not required anymore.
- get_obsolete_fds()
Get selected fds that are not required anymore.
- get_outdated_reconfiguration_plans()
Get outdated reconfiguration plans.
A reconfiguration plan is considered outdated when it doesn’t have an end-time and its start-time is lower than the end-time of a reconfiguration plan with result ‘completed’.
- get_reconfiguration_plan(start_time)
Get reconfiguration plan with start-time.
- Parameters:
start_time (
datetime
) – start-time of the desired reconfiguration plan.- Return type:
- Returns:
dict representing the reconfiguration plan, its keys are: start_time, c_activate, c_deactivate, c_config
- get_reconfiguration_plan_result(start_time)
Get result of recongiration plan with start_time.
- get_relationship_with_attribute(entity, entity_name, relation, r_attribute, r_value)
Get relationship name that has an attr and relates to a certain entity.
Get relationship name that has an attr and relates to a certain entity. For example, a ‘function-design’ that has the ‘is-selected’ attribute set to true and is related to a ‘Function’ with ‘function-name’ ‘my_function’.
- get_selectable_actions()
Get the name of selectable Actions.
- get_selectable_c_configs(component_name)
Get the name of selectable component configurations for a Component.
- get_selectable_fds(function_name)
Get the name of selectable funtion designs for a Function.
- get_selectable_thing_raw(thing)
Get the name of selectable individuals of a specific Thing.
- Parameters:
thing (
str
) – Thing type- Return type:
- Returns:
name of selectable individuals
- get_unsolved_components()
Get unsolved Components.
Get unsolved Components. A component is unsolved when its ‘is-required’ attribute is True and its status is ‘unsolved’.
- get_unsolved_functions()
Get unsolved Functions.
Get unsolved Functions. A function is unsolved when its ‘is-required’ attribute is True and its status is ‘unsolved’.
- get_unsolved_thing_raw(thing)
Get unsolved individuals of a certain Thing type.
Get unsolved individuals of a certain Thing type. An individual is unsolved when its ‘is-required’ attribute is True and its status is ‘unsolved’.
- Return type:
- Returns:
name of unsolved individuals
- has_action(action_name)
Check whether model can an specific Action.
- insert_action(action_name)
Add new Action.
- insert_component(component_name, always_improve=False)
Add new Component.
- Parameters:
component configuration :rtype:
Optional
[Iterator
[ConceptMap
]] :return: insert query result
- insert_component_process(component_name, pid)
Add new component-process.
- insert_function(function_name)
Add new Function.
- insert_function_design(function_design_name, function_name, components_names, priority=None)
Add new function-design.
- insert_functional_requirement(action_name, functions_names)
Add new functional-requirement.
- insert_ros_node_component(component_name, package, executable, always_improve=False, lifecycle_node=False)
Add new ROSNode Component.
- Parameters:
component configuration :type lifecycle_node:
Optional
[bool
] :param lifecycle_node: if the ros node is a lifecycle node :rtype:Optional
[Iterator
[ConceptMap
]] :return: insert query result
- is_action_feasible(action_name)
Check if an Action only has status feasible.
- is_action_required(action_name)
Check whether an Action is required.
- is_action_selectable(action_name)
Check whether an Action can be selected, i.e., it can be performed.
- is_component_active(name)
Check wheter a component is active or not.
- request_action(action_name, preference='')
Request Action.
- select_component_configuration(c_name, cc_name)
Select component-configuration ‘cc_name’ and unselect all other ccs.
Set the ‘is-selected’ attribute of the ‘cc_name’ component configuration to true, and set ‘is-selected’ to false for all other component configurations related to ‘c_name’.
- select_components_selected_config(components_selected_config)
Select component configuration and return them.
Set the ‘is-selected’ attribute of the component configurations in components_selected_config to true, and returns a list with the name of the component configurations that need to be updated.
- Parameters:
components_selected_config (
list
[Tuple
[str
,str
]]) – a list of tuples with the form (COMPONENT_NAME, CC_NAME) representing the component configurations that were selected for which components- Return type:
- Returns:
list with the name of the component configurations that need to be updated
- select_configuration(functions_selected_fd, components_selected_config)
Select configuration and create reconfiguration plan.
- Parameters:
functions_selected_fd (
list
[Tuple
[str
,str
]]) – a list of tuples with the form (FUNCTION_NAME, FD_NAME) representing the function designs that were selected for which functioncomponents_selected_config (
list
[Tuple
[str
,str
]]) – a list of tuples with the form (COMPONENT_NAME, CC_NAME) representing the component configurations that were selected for which components
- Return type:
- Returns:
reconfig plan creation time.
- select_fd_and_get_components(functions_selected_fd)
Select function design, and get components to activate and deactivate.
Set the ‘is-selected’ attribute of the function desings in functions_selected_fd to true, and returns a tuple with a list with the components that need to be activated and a list with the components that need to be deactivated.
- Parameters:
functions_selected_fd (
list
[Tuple
[str
,str
]]) – a list of tuples with the form (FUNCTION_NAME, FD_NAME) representing the function designs that were selected for which function- Return type:
- Returns:
tuple with the form (c_activate, c_deactivate), indicating which components should be activated and deactivated
- select_function_design(f_name, fd_name)
Select function-design ‘fd_name’ and unselect all other fds.
Set the ‘is-selected’ attribute of the ‘fd_name’ function design to true, and set ‘is-selected’ to false for all other function designs related to ‘f_name’.
- select_relationship(entity, entity_name, relation, r_name)
Select relationship individual, and unselect all other individuals.
Set the ‘is-selected’ attribute of the ‘r_name’ individual to true, and set ‘is-selected’ to false for all other ‘relation’ individuals related to ‘entity_name’.
- set_component_process_end_time(start_time)
Set component process end time.
- unselect_obsolete_fds_cc()
Unselect all obsolete function designs and component configurations.
An obsolete function design or component configuration is the one that has ‘is-selected’ attribute set to true, but it is no required anymore
- Return type:
- update_action_status(action_name, action_status)
Update Action status.
- update_component_status(component_name, component_status)
Update Component status.
- update_function_design_priority(fd_name, value)
Update function design priority.
- update_outdated_reconfiguration_plans_result()
Set outdated reconfiguration plans result to ‘abandoned’.
- update_reconfiguration_plan_result(start_time, result_value)
Update reconfiguration plan result.