Skip to content

(V) SL2TL Projection

Margo Ulasik edited this page Sep 10, 2025 · 1 revision

Theoretical Framework

As a result a projection from Sentence Layer on Transformation Layer, the TPSFs and the TSs are enriched with sentence-related data:

  • the TPSFs are segmented into text units
  • the sentence-level scope of the TSs is defined
  • the TS are split into segments corresponding to text units

The main concepts developed to reflect this projection are:

  • text units building the TPSF
  • sentences, sentence candidates, sentence interspaces, and paragraph interspaces (subcategories of text units)
  • sentence-level scope of the TS
  • segments building the TS

See Key Terms and Their Definitions for detailed definitions of the terms text unit, sentence and sentence candidate, sentence interspace and paragraph interspace, sentence-level scope, transforming sequence segment.

Classes

class SL2TLProjector

The class SenTransProjector projects a sentence layer onto a transformation layer. It orchestrates the process of mapping sentence-level structures to transformation-level representations.

The projection process involves:

  1. Extracting current, previous, and deleted text units.
  2. Classifying the scope of the TS with respect to sentences.
  3. Identifying the segments of the TS.

Fields:

  • tpsf_id: ID of the current TPSF
  • tpsf_text: Text content of the current TPSF.
  • tsb: Transformation sentence builder.
  • prev_tpsf: Previous TPSF, if any.
  • tubs_current: List of text units extracted from the current TPSF.
  • deleted_tubs: List of deleted text units.
  • sscope: Sentence scope classification result.
  • ts_segments: Segments building the TS, each segment is associated with one text unit.
  • replaced_segments: List of replaced segments of the TS (only relevant for REPL transformations).

class Textunit (immutable)

Represents an immutable text unit.

Fields:

  • type: Type of the text unit.
  • text: Text content.
  • state: State of the text unit in the pipeline.
  • startpos: Start position in the text.
  • endpos: End position in the text.
  • tpsf_id: ID of the TPSF.

Public Methods:

__str__() → str

Returns a human-readable representation of the Textunit.

to_dict() → TextUnitDict

Converts the Textunit to a dictionary representation.

to_json() → str

Serializes the Textunit to JSON.

copy_to_builder() → TextUnitBuilder

Creates a mutable TextUnitBuilder copy.

TypedDict TextunitDict

A dictionary representation of a Textunit instance.

class TextUnitDict(TypedDict):
    type: str
    text: str
    state: str
    startpos: int
    endpos: int
    tpsf_id: int

TypedDict TextunitsDict

A dictionary representation of a pair of text unit collections before and after transformation.

class TextUnitsDict(TypedDict):
    previous_textunits: list[TextUnitDict]
    current_textunits: list[TextUnitDict]

class TextunitBuilder (Mutable)

Represents a mutable builder for creating or modifying Textunit instances.

Fields:

  • type: Type of the text unit.
  • text: Text content.
  • state: Processing state.
  • startpos: Start position.
  • endpos: End position.
  • tpsf_id: TPSF ID.

Public Methods:

set_state(state: str)

Sets the state of the text unit.

set_tpsf_id(tpsf_id: int)

Assigns TPSF id to the text unit.

set_startpos(startpos: int)

Sets the start position.

set_endpos(endpos: int)

Sets the end position.

copy_with_text(new_text: str) → Self

Returns a copy with new text.

copy_with_appended_text(to_add: str) → Self

Returns a copy with appended text.

to_text_unit() → Textunit

Converts the builder to an immutable Textunit. Raises RuntimeError if required fields are missing.

__str__() → str

Returns a human-readable representation of the TextunitBuilder.

class TextunitFactory

TextunitFactory is a factory class for generating and managing TextUnitBuilder instances.

Public Methods:

run(
    revision_id, 
    tpsf_text, 
    tsb, 
    prev_tpsf, 
    replaced_text, 
    settings
) -> tuple[list[TextUnitBuilder], list[TextUnitBuilder], list[TextUnitBuilder]]

Generates a list of current, previous, and deleted text units.

Description:

  • Splits input text into sentences using the NLP model.
  • Transforms the sentences extracted by the NLP model into text units of a corresponding type. All text unit types are listed in the class TUTypes in the module names.py.
  • Assigns states to text units. All states are listed in the class TUStates in the module names.py.
  • Assigns TPSF IDs to text unit.
  • Detects merges and splits of text units.
  • Ensures proper segmentation consistency.

class SScopeClassifier

SScopeClassifier is a utility class responsible for classifying the sentence-level scope (sscope) of a transforming sequence based on its relationship with impacted text units. It helps determine how a transformation affects surrounding sentences or sentence candidates.

Public Methods:

run(
   ts_text: str,
   ts_label: str,
   textunits: list[TextUnitBuilder],
   deleted_tus: list[TextUnitBuilder],
) -> str

Determines the sentence scope classification of a transformation sequence.

class TSSegment (immutable)

TSSegment represents a subsequence extracted from a transformation sequence corresponding to one text unit.

Fields:

  • text: Text content of the segment.
  • type: Type/category of the segment (e.g., sentence, word, clause).
  • startpos: Absolute starting position in the source text.
  • endpos: Absolute ending position in the source text.
  • relative_startpos: Position relative to the transformation sequence start.
  • relative_endpos: Position relative to the transformation sequence end.

Public Methods:

to_dict()

Converts the segment into a serializable dictionary format.

__str__()

Returns a detailed string representation of the segment.

TypedDict TSSegmentDict

class TSSegmentDict(TypedDict):
    text: str
    type: str
    startpos: int | None
    endpos: int | None
    relative_startpos: int | None
    relative_endpos: int | None

class TSSegmenter

The TSSegmenter and its specialized subclasses (DelTSSegmenter and ReplTSSegmenter) are responsible for extracting text units within transforming sequences.

Warnings are raised when the number of extracted TUs within TS does not match impacted TUs of the TPSF.

Fields:

  • tpsf_id — Identifier of the TPSF to which this segmentation belongs.
  • tpsf_text — Current text of the TPSF.
  • ts — Transforming sequence defining the text change.
  • sscope — Sentence scope of the transformation.
  • textunits — Current text units in the TPSF.
  • impacted_tus_prev — Impacted text units from the previous TPSF.
  • prev_tpsf_text — Previous TPSF text (if applicable).
  • impacted_tus — List of text units from textunits whose state is one of:
    • TUState.MOD
    • TUState.NEW
    • TUState.MER
    • TUState.SPLIT
  • spsfs — List of text units from textunits where type is:
    • TUTypes.SEN
    • TUTypes.SEC
  • impacted_spsfs_prev — List of previous impacted text units (impacted_tus_prev) where type is:
    • TUTypes.SEN
    • TUTypes.SEC
  • modified_spsfs — Subset of spsfs whose state is one of:
    • TUState.MOD
    • TUState.MER
    • TUState.SPLIT
  • new_spsfs — Subset of spsfs whose state is:
    • TUState.NEW
  • impacted_spsfs — Combination of:
    • self.modified_spsfs
    • self.new_spsfs

Public Methods:

run() -> list[Segment]

Generates a list of segments corresponding to the impacted text units.

class DelTSSegmenter

Specialized segmenter for deletion operations (DEL, MID). It inherits from SegmentFactory but uses previous TPSF state to extract segments that are being removed.

Public Methods:

run() -> list[Segment]

Generates segments for deleted text based on the previous TPSF state.

class ReplTSSegmenter

Specialized segmenter for replacement operations. Handles both the newly inserted text and the text being replaced.

run() -> list[Segment]

Generates segments for the replacement result (produced text).

Clone this wiki locally