Documentation / Aligned Chunk, Alignment

Aligned Chunk

(com.betterdiff.api.alignment.AlignedChunk)

AlignedChunk is a PairedChunk that has been assigned a position in the aligned matrix after the Alignment phase.

Aligned matrix is a 2-dimensional array that contains PairedChunks that were aligned based on their similarity via their identification number.

The position of an AlignedChunk in the aligned matrix is defined by following attributes:

  • Ordinal number - Because the ordinal number never changes, the actual value is stored in the Chunk. The reference to the Chunk can be retrieved through PairedChunk#getOriginalChunk(), and the PairedChunk through AlignedChunk#getPairedChunk(). For more information about the ordinal number, see Evidence.
  • Y Axis - Denotes a sequence position within the same ordinal number. Y Axis number must be unique within the same ordinal number, gaps are permitted.

Alignment

(com.betterdiff.api.alignment.Alignment)

Alignment is one of the core phases. During this phase, the PairedChunks from the Pairing phase are aligned based on their identification number and weight.

Example 1:

PairedChunks from the Pairing phase:

  • PairedChunk 1: (Chunk)/ordinalNumber = 1, (Chunk)/yAxis = 1, id = 5, weight = 0
  • PairedChunk 2: (Chunk)/ordinalNumber = 1, (Chunk)/yAxis = 2, id = 1, weight = 0
  • PairedChunk 3: (Chunk)/ordinalNumber = 2, (Chunk)/yAxis = 1, id = 5, weight = 0
  • PairedChunk 4: (Chunk)/ordinalNumber = 2, (Chunk)/yAxis = 2, id = 9, weight = 0
  • PairedChunk 5: (Chunk)/ordinalNumber = 3, (Chunk)/yAxis = 1, id = 1, weight = 0
  • PairedChunk 6: (Chunk)/ordinalNumber = 3, (Chunk)/yAxis = 2, id = 9, weight = 0

Result after the Alignment:

  • AlignedChunk 1: (Chunk)/ordinalNumber = 1, yAxis = 1
  • AlignedChunk 2: (Chunk)/ordinalNumber = 1, yAxis = 2
  • AlignedChunk 3: (Chunk)/ordinalNumber = 2, yAxis = 1
  • AlignedChunk 4: (Chunk)/ordinalNumber = 2, yAxis = 3
  • AlignedChunk 5: (Chunk)/ordinalNumber = 3, yAxis = 2
  • AlignedChunk 6: (Chunk)/ordinalNumber = 3, yAxis = 3

Visual transformation:

Each position (pair of brackets) represents one PairedChunk. Number in the brackets is the identification numbers of the corresponding PairedChunk. And the position of each PairedChunk is based on the Chunk's ordinalNumber and yAxis.

[5]   [5]   [1]        [5]   [5]
[1]   [9]   [9]   ->   [1]         [1]
                       [9]   [9]

Example 2:

PairedChunks from the Pairing phase:

  • PairedChunk 1: (Chunk)/ordinalNumber = 1, (Chunk)/yAxis = 1, id = 5, weight = 5
  • PairedChunk 2: (Chunk)/ordinalNumber = 1, (Chunk)/yAxis = 2, id = 1, weight = 2
  • PairedChunk 3: (Chunk)/ordinalNumber = 2, (Chunk)/yAxis = 1, id = 5, weight = 0
  • PairedChunk 4: (Chunk)/ordinalNumber = 2, (Chunk)/yAxis = 2, id = 9, weight = 10
  • PairedChunk 5: (Chunk)/ordinalNumber = 3, (Chunk)/yAxis = 1, id = 1, weight = 2
  • PairedChunk 6: (Chunk)/ordinalNumber = 3, (Chunk)/yAxis = 2, id = 9, weight = 11

Result after the Alignment:

  • AlignedChunk 1: (Chunk)/ordinalNumber = 1, yAxis = 1
  • AlignedChunk 2: (Chunk)/ordinalNumber = 1, yAxis = 4
  • AlignedChunk 3: (Chunk)/ordinalNumber = 2, yAxis = 1
  • AlignedChunk 4: (Chunk)/ordinalNumber = 2, yAxis = 3
  • AlignedChunk 5: (Chunk)/ordinalNumber = 3, yAxis = 2
  • AlignedChunk 6: (Chunk)/ordinalNumber = 3, yAxis = 3

Visual transformation:

Each position (pair of brackets) represents one PairedChunk. Number in the brackets is the identification numbers of the corresponding PairedChunk. And the position of each PairedChunk is based on the Chunk's ordinalNumber and yAxis.

[5]   [5]   [1]        [5]   [5]
[1]   [9]   [9]   ->               [1]
                             [9]   [9]
                       [1]

Note. In some cases (like this one), an additional alignment can and might be done, but the example shows the difference when weighting is used, and the way how it's defined by the Falling algorithm (c).

AlignedChunks created during this phase should not be modified after the phase has been finished.