Skip to content

AbstractDiffer

Bases: ABC

Source code in src/library_analyzer/processing/migration/model/_differ.py
@dataclass
class AbstractDiffer(ABC):
    previous_base_differ: AbstractDiffer | None
    previous_mappings: list[Mapping]
    apiv1: API
    apiv2: API

    @abstractmethod
    def compute_attribute_similarity(
        self,
        attributev1: Attribute,
        attributev2: Attribute,
    ) -> float:
        """
        Compute the similarity between attributes from apiv1 and apiv2.

        Parameters
        ----------
        attributev1 : Attribute
            attribute from apiv1
        attributev2 : Attribute
            attribute from apiv2

        Returns
        -------
        similarity : float
            value between 0 and 1, where 1 means that the elements are equal.
        """

    @abstractmethod
    def compute_class_similarity(self, classv1: Class, classv2: Class) -> float:
        """
        Compute the similarity between classes from apiv1 and apiv2.

        Parameters
        ----------
        classv1 : Class
            class from apiv1
        classv2 : Class
            class from apiv2

        Returns
        -------
        similarity : float
            value between 0 and 1, where 1 means that the elements are equal.
        """

    @abstractmethod
    def compute_function_similarity(self, functionv1: Function, functionv2: Function) -> float:
        """
        Compute the similarity between functions from apiv1 and apiv2.

        Parameters
        ----------
        functionv1 : Function
            function from apiv1
        functionv2 : Function
            function from apiv2

        Returns
        -------
        similarity : float
            value between 0 and 1, where 1 means that the elements are equal.
        """

    @abstractmethod
    def compute_parameter_similarity(self, parameterv1: Parameter, parameterv2: Parameter) -> float:
        """
        Compute similarity between parameters from apiv1 and apiv2.

        Parameters
        ----------
        parameterv1 : Parameter
            parameter from apiv1
        parameterv2 : Parameter
            parameter from apiv2

        Returns
        -------
        similarity : float
            value between 0 and 1, where 1 means that the elements are equal.
        """

    @abstractmethod
    def compute_result_similarity(self, resultv1: Result, resultv2: Result) -> float:
        """
        Compute similarity between results from apiv1 and apiv2.

        Parameters
        ----------
        resultv1 : Result
            result from apiv1
        resultv2 : Result
            result from apiv2

        Returns
        -------
        similarity : float
            value between 0 and 1, where 1 means that the elements are equal.
        """

    @abstractmethod
    def get_related_mappings(
        self,
    ) -> list[Mapping] | None:
        """
        Whether all api elements should be compared to each other or just the ones that are mapped to each other.

        Returns
        -------
        mappings : list[Mapping] | None
            a list of Mappings if only previously mapped api elements should be mapped to each other or else None.
        """

    @abstractmethod
    def notify_new_mapping(self, mappings: list[Mapping]) -> None:
        """
        If previous mappings return None, the differ will be notified about a new mapping.

        Thereby the differ can calculate the similarity with more information.

        Parameters
        ----------
        mappings : list[Mapping]
            a list of mappings new appended mappings.
        """

    @abstractmethod
    def get_additional_mappings(self) -> list[Mapping]:
        """
        Allow the differ to add further mappings from previous differs.

        Returns
        -------
        mappings : list[Mapping]
            additional mappings that should be included in the result of the differentiation.
        """

    def is_base_differ(self) -> bool:
        return False

apiv1: API instance-attribute

apiv2: API instance-attribute

previous_base_differ: AbstractDiffer | None instance-attribute

previous_mappings: list[Mapping] instance-attribute

__init__(previous_base_differ, previous_mappings, apiv1, apiv2)

compute_attribute_similarity(attributev1, attributev2) abstractmethod

Compute the similarity between attributes from apiv1 and apiv2.

Parameters:

Name Type Description Default
attributev1 Attribute

attribute from apiv1

required
attributev2 Attribute

attribute from apiv2

required

Returns:

Name Type Description
similarity float

value between 0 and 1, where 1 means that the elements are equal.

Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def compute_attribute_similarity(
    self,
    attributev1: Attribute,
    attributev2: Attribute,
) -> float:
    """
    Compute the similarity between attributes from apiv1 and apiv2.

    Parameters
    ----------
    attributev1 : Attribute
        attribute from apiv1
    attributev2 : Attribute
        attribute from apiv2

    Returns
    -------
    similarity : float
        value between 0 and 1, where 1 means that the elements are equal.
    """

compute_class_similarity(classv1, classv2) abstractmethod

Compute the similarity between classes from apiv1 and apiv2.

Parameters:

Name Type Description Default
classv1 Class

class from apiv1

required
classv2 Class

class from apiv2

required

Returns:

Name Type Description
similarity float

value between 0 and 1, where 1 means that the elements are equal.

Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def compute_class_similarity(self, classv1: Class, classv2: Class) -> float:
    """
    Compute the similarity between classes from apiv1 and apiv2.

    Parameters
    ----------
    classv1 : Class
        class from apiv1
    classv2 : Class
        class from apiv2

    Returns
    -------
    similarity : float
        value between 0 and 1, where 1 means that the elements are equal.
    """

compute_function_similarity(functionv1, functionv2) abstractmethod

Compute the similarity between functions from apiv1 and apiv2.

Parameters:

Name Type Description Default
functionv1 Function

function from apiv1

required
functionv2 Function

function from apiv2

required

Returns:

Name Type Description
similarity float

value between 0 and 1, where 1 means that the elements are equal.

Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def compute_function_similarity(self, functionv1: Function, functionv2: Function) -> float:
    """
    Compute the similarity between functions from apiv1 and apiv2.

    Parameters
    ----------
    functionv1 : Function
        function from apiv1
    functionv2 : Function
        function from apiv2

    Returns
    -------
    similarity : float
        value between 0 and 1, where 1 means that the elements are equal.
    """

compute_parameter_similarity(parameterv1, parameterv2) abstractmethod

Compute similarity between parameters from apiv1 and apiv2.

Parameters:

Name Type Description Default
parameterv1 Parameter

parameter from apiv1

required
parameterv2 Parameter

parameter from apiv2

required

Returns:

Name Type Description
similarity float

value between 0 and 1, where 1 means that the elements are equal.

Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def compute_parameter_similarity(self, parameterv1: Parameter, parameterv2: Parameter) -> float:
    """
    Compute similarity between parameters from apiv1 and apiv2.

    Parameters
    ----------
    parameterv1 : Parameter
        parameter from apiv1
    parameterv2 : Parameter
        parameter from apiv2

    Returns
    -------
    similarity : float
        value between 0 and 1, where 1 means that the elements are equal.
    """

compute_result_similarity(resultv1, resultv2) abstractmethod

Compute similarity between results from apiv1 and apiv2.

Parameters:

Name Type Description Default
resultv1 Result

result from apiv1

required
resultv2 Result

result from apiv2

required

Returns:

Name Type Description
similarity float

value between 0 and 1, where 1 means that the elements are equal.

Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def compute_result_similarity(self, resultv1: Result, resultv2: Result) -> float:
    """
    Compute similarity between results from apiv1 and apiv2.

    Parameters
    ----------
    resultv1 : Result
        result from apiv1
    resultv2 : Result
        result from apiv2

    Returns
    -------
    similarity : float
        value between 0 and 1, where 1 means that the elements are equal.
    """

get_additional_mappings() abstractmethod

Allow the differ to add further mappings from previous differs.

Returns:

Name Type Description
mappings list[Mapping]

additional mappings that should be included in the result of the differentiation.

Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def get_additional_mappings(self) -> list[Mapping]:
    """
    Allow the differ to add further mappings from previous differs.

    Returns
    -------
    mappings : list[Mapping]
        additional mappings that should be included in the result of the differentiation.
    """

Whether all api elements should be compared to each other or just the ones that are mapped to each other.

Returns:

Name Type Description
mappings list[Mapping] | None

a list of Mappings if only previously mapped api elements should be mapped to each other or else None.

Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def get_related_mappings(
    self,
) -> list[Mapping] | None:
    """
    Whether all api elements should be compared to each other or just the ones that are mapped to each other.

    Returns
    -------
    mappings : list[Mapping] | None
        a list of Mappings if only previously mapped api elements should be mapped to each other or else None.
    """

is_base_differ()

Source code in src/library_analyzer/processing/migration/model/_differ.py
def is_base_differ(self) -> bool:
    return False

notify_new_mapping(mappings) abstractmethod

If previous mappings return None, the differ will be notified about a new mapping.

Thereby the differ can calculate the similarity with more information.

Parameters:

Name Type Description Default
mappings list[Mapping]

a list of mappings new appended mappings.

required
Source code in src/library_analyzer/processing/migration/model/_differ.py
@abstractmethod
def notify_new_mapping(self, mappings: list[Mapping]) -> None:
    """
    If previous mappings return None, the differ will be notified about a new mapping.

    Thereby the differ can calculate the similarity with more information.

    Parameters
    ----------
    mappings : list[Mapping]
        a list of mappings new appended mappings.
    """