public class InMemoryOptimizedAlignment extends java.lang.Object implements Alignment
Alignment
interface in that all
the methods take at most a logarithmic time, but with a considerable overhead
to achieve it. This makes InMemoryAlignment
both faster and more
memory efficient for relatively simple alignments, making it more suitable
for most of the cases.
The provided implementation is immutable and, therefore, instances can be freely shared.
Modifier and Type | Class and Description |
---|---|
static class |
InMemoryOptimizedAlignment.Builder
A builder to create
InMemoryOptimizedAlignment instances. |
Modifier and Type | Method and Description |
---|---|
boolean |
areAligned(int src,
int trg)
Checks if the specified indexes are aligned.
|
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
boolean |
isAlignedSrc(int src)
Checks if the specified index in the source sentence is aligned.
|
boolean |
isAlignedTrg(int trg)
Checks if the specified index in the target sentence is aligned.
|
int |
maxAlignmentSrc(int src)
Returns the maximum index in the target sentence that is aligned with the specified index in the source sentence.
|
int |
maxAlignmentTrg(int trg)
Returns the maximum index in the source sentence that is aligned with the specified index in the target sentence.
|
int |
minAlignmentSrc(int src)
Returns the minimum index in the target sentence that is aligned with the specified index in the source sentence.
|
int |
minAlignmentTrg(int trg)
Returns the minimum index in the source sentence that is aligned with the specified index in the target sentence.
|
static InMemoryOptimizedAlignment |
parseAlignment(java.lang.String alignment)
Creates an
OptmizedAlignment by parsing a String . |
java.lang.String |
toString()
Returns a string representation of this alignment following the format
specified at
parseAlignment(java.lang.String) . |
public static InMemoryOptimizedAlignment parseAlignment(java.lang.String alignment)
OptmizedAlignment
by parsing a String
.alignment
- a String
that represents the alignment between two sentences. It should be something like A-B C-D E-F..., which would mean that the token with the A index in the source sentence is aligned with the token with the B index in the target sentence, the token with the C index in the source sentence is aligned with the token with the D index in the target sentence and so on. Indexes start at 0
and must be integer values.InMemoryOptimizedAlignment
represented by the given argument.java.lang.IllegalArgumentException
- if the given argument doesn't represent a valid alignment (it doesn't follow the specified format).public boolean areAligned(int src, int trg)
Alignment
areAligned
in interface Alignment
src
- the index in the source sentence.trg
- the index in the target sentence.true
if the specified indexes are aligned, false
otherwise.public boolean isAlignedSrc(int src)
Alignment
isAlignedSrc
in interface Alignment
src
- the index in the source sentence.true
if the specified index in the source sentence is aligned with some index in the target sentence; false
otherwise.public boolean isAlignedTrg(int trg)
Alignment
isAlignedTrg
in interface Alignment
trg
- the index in the target sentence.true
if the specified index in the target sentence is aligned with some index in the source sentence; false
otherwise.public int minAlignmentSrc(int src)
Alignment
minAlignmentSrc
in interface Alignment
src
- the index in the source sentence.-1
if it is not aligned.public int maxAlignmentSrc(int src)
Alignment
maxAlignmentSrc
in interface Alignment
src
- the index in the source sentence.-1
if it is not aligned.public int minAlignmentTrg(int trg)
Alignment
minAlignmentTrg
in interface Alignment
trg
- the index in the target sentence.-1
if it is not aligned.public int maxAlignmentTrg(int trg)
Alignment
maxAlignmentTrg
in interface Alignment
trg
- the index in the target sentence.-1
if it is not aligned.public java.lang.String toString()
parseAlignment(java.lang.String)
.toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object