Skip to content

Complexity Analyzer

Bases: Enum

The heuristic according to which the complexity of a sentence is to be quantified. GLOBAL uses an algorithm that evaluates a sentence as a monolith; AGGREGATED_LOCAL uses an algorithm that calculates phrasal complexity for each phrase in a given sentence, and then aggregates these values.

Source code in src/limes/models.py
class ComplexityAlgorithm(Enum):
    """
    The heuristic according to which the complexity of a sentence is to be
    quantified. `GLOBAL` uses an algorithm that evaluates a sentence as a
    monolith; `AGGREGATED_LOCAL` uses an algorithm that calculates phrasal
    complexity for each phrase in a given sentence, and then aggregates these
    values.
    """

    GLOBAL = "global"
    AGGREGATED_LOCAL = "aggregated_local"

Bases: ABC

Class for calculating language complexity.

Source code in src/limes/analyzers/interfaces.py
class ComplexityAnalyzer(ABC):
    """
    Class for calculating language complexity.
    """

    @abstractmethod
    def get_global_complexity(
        self,
        sentence: DocumentProtocol,
        heuristic: ComplexityAlgorithm,
    ) -> float:
        """
        Calculate the complexity of the entire sentence.

        Parameters
        ----------
        sentence : DocumentProtocol
            The sentence for which the complexity is to be calculated. Please
            note that this function is designed to perform only on single
            sentences but won't complain if you pass a DocumentProtocol instance
            that constitutes a complete text. In that case, the values returned
            may be nonsensical.
        heuristic : ComplexityAlgorithm
            Determines which heuristic to use to calculate the complexity.
        """
        ...

    @abstractmethod
    def get_local_complexities(
        self,
        sentence: DocumentProtocol,
    ) -> list[tuple[SpanProtocol, float]]:
        """
        Get a list of syntactically coherent phrases that constitute the given
        text, as well as their respective calculated syntactic complexities.
        You can sum the local complexities to get a sound heuristic for the
        complexity of the complete sentence.
        """
        ...

get_global_complexity(sentence, heuristic) abstractmethod

Calculate the complexity of the entire sentence.

Parameters:

Name Type Description Default
sentence DocumentProtocol

The sentence for which the complexity is to be calculated. Please note that this function is designed to perform only on single sentences but won't complain if you pass a DocumentProtocol instance that constitutes a complete text. In that case, the values returned may be nonsensical.

required
heuristic ComplexityAlgorithm

Determines which heuristic to use to calculate the complexity.

required
Source code in src/limes/analyzers/interfaces.py
@abstractmethod
def get_global_complexity(
    self,
    sentence: DocumentProtocol,
    heuristic: ComplexityAlgorithm,
) -> float:
    """
    Calculate the complexity of the entire sentence.

    Parameters
    ----------
    sentence : DocumentProtocol
        The sentence for which the complexity is to be calculated. Please
        note that this function is designed to perform only on single
        sentences but won't complain if you pass a DocumentProtocol instance
        that constitutes a complete text. In that case, the values returned
        may be nonsensical.
    heuristic : ComplexityAlgorithm
        Determines which heuristic to use to calculate the complexity.
    """
    ...

get_local_complexities(sentence) abstractmethod

Get a list of syntactically coherent phrases that constitute the given text, as well as their respective calculated syntactic complexities. You can sum the local complexities to get a sound heuristic for the complexity of the complete sentence.

Source code in src/limes/analyzers/interfaces.py
@abstractmethod
def get_local_complexities(
    self,
    sentence: DocumentProtocol,
) -> list[tuple[SpanProtocol, float]]:
    """
    Get a list of syntactically coherent phrases that constitute the given
    text, as well as their respective calculated syntactic complexities.
    You can sum the local complexities to get a sound heuristic for the
    complexity of the complete sentence.
    """
    ...