Class AlignedSegments
- java.lang.Object
-
- net.sf.okapi.common.resource.AlignedSegments
-
- All Implemented Interfaces:
Iterable<Segment>,IAlignedSegments
public class AlignedSegments extends Object implements IAlignedSegments
Provides a standard implementation of the IAlignedSegments interface that works with variant sources.Currently tightly coupled to ITextUnit.
-
-
Constructor Summary
Constructors Constructor Description AlignedSegments(ITextUnit parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidalign(List<AlignedPair> alignedSegmentPairs, LocaleId trgLoc)Aligns all the segments listed in the aligned pairs for given locale.voidalign(LocaleId trgLoc)Force one to one alignment.voidalignCollapseAll(LocaleId trgLoc)Aligns all the segments for the specified sources and targets by collapsing all segments into one.voidappend(Segment srcSeg, Segment trgSeg, LocaleId trgLoc)Adds given source and target segments to the end of the content.AlignmentStatusgetAlignmentStatus()Gets the status of the alignment for this entire text unit.AlignmentStatusgetAlignmentStatus(LocaleId trgLoc)Gets the status of the alignment the given target locale in this text unit.SegmentgetCorrespondingSource(Segment trgSeg, LocaleId trgLoc)Gets the source segment corresponding to a given target segmentSegmentgetCorrespondingTarget(Segment srcSeg, LocaleId trgLoc)Gets the target segment corresponding to a given source segmentITextUnitgetParent()SegmentgetSource(int index, LocaleId trgLoc)Gets the source segment for the given target locale at a given position.voidinsert(int index, Segment srcSeg, Segment trgSeg, LocaleId trgLoc)Inserts given source and target segments at the specified position in the list of segments.Iterator<Segment>iterator()Gets an iterator for the default source segments of this text unit.Iterator<Segment>iterator(LocaleId trgLoc)Gets an iterator for the source of the specified target locale.voidjoinAll(LocaleId trgLoc)Joins all segments for the specified sources and targets.voidjoinWithNext(Segment seg, LocaleId trgLoc)Joins the segment for a given segment's id to the next segment, including all the parts between the two segments.booleanremove(Segment seg, LocaleId trgLoc)Removes the given segment and any segments with the same id from the specified sources and targets.voidsegmentSource(ISegmenter segmenter, LocaleId targetLocale)Segments the source content used for the given target locale based on the rules provided by a givenISegmenter.voidsegmentTarget(ISegmenter segmenter, LocaleId targetLocale)Segments the specified target content based on the rules provided by a givenISegmenter.voidsetSegment(int index, Segment seg, LocaleId trgLoc)Replaces a segment at a given position with a clone of the given segment.SegmentsplitSource(LocaleId trgLoc, Segment srcSeg, int splitPos)Splits a given source segment into two.SegmentsplitTarget(LocaleId trgLoc, Segment trgSeg, int splitPos)Splits a given target segment into two.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
AlignedSegments
public AlignedSegments(ITextUnit parent)
-
-
Method Detail
-
append
public void append(Segment srcSeg, Segment trgSeg, LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsAdds given source and target segments to the end of the content.If srcSeg is non-null, the content of srcSeg will be used for any new segments that are not empty, otherwise the content of trgSeg will be used. srcSeg and trgSeg cannot both be null.
- Specified by:
appendin interfaceIAlignedSegments- Parameters:
srcSeg- the source segment to add.trgSeg- the target segment to add. Null to use a clone of srcSeg instead.trgLoc- the target locale for which to append segments
-
insert
public void insert(int index, Segment srcSeg, Segment trgSeg, LocaleId trgLoc)Description copied from interface:IAlignedSegmentsInserts given source and target segments at the specified position in the list of segments.The validated id (after insertion) of srcSeg will be applied to all other inserted segments, including trgSeg.
- Specified by:
insertin interfaceIAlignedSegments- Parameters:
index- the segment index position.srcSeg- the source segment to insert.trgSeg- the target segment to insert. Null to use srcSeg instead.trgLoc- the target locale for which to insert the segment
-
setSegment
public void setSegment(int index, Segment seg, LocaleId trgLoc)Description copied from interface:IAlignedSegmentsReplaces a segment at a given position with a clone of the given segment.The segment id is determined by the segment at the position of index in the source for trgLoc, the segment id is then used to locate the segments in other sources and targets to replace.
- Specified by:
setSegmentin interfaceIAlignedSegments- Parameters:
index- the segment index positionseg- the new segment to place at the positiontrgLoc- the target locale
-
remove
public boolean remove(Segment seg, LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsRemoves the given segment and any segments with the same id from the specified sources and targets.- Specified by:
removein interfaceIAlignedSegments- Parameters:
seg- the segment to remove.trgLoc- the locale used in specifying which sources and targets to use.- Returns:
- true if remove success
-
getSource
public Segment getSource(int index, LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsGets the source segment for the given target locale at a given position.The first segment has the index 0, the second has the index 1, etc.
- Specified by:
getSourcein interfaceIAlignedSegments- Parameters:
index- the segment index of the segment to retrieve.trgLoc- the target locale for the source from which to retrieve the indicated segment.- Returns:
- the segment at the given position.
-
getCorrespondingTarget
public Segment getCorrespondingTarget(Segment srcSeg, LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsGets the target segment corresponding to a given source segment- Specified by:
getCorrespondingTargetin interfaceIAlignedSegments- Parameters:
srcSeg- the source (or other target) segment for which a corresponding target segment is requested.trgLoc- the target to look up.- Returns:
- the corresponding target
Segment(may be empty).
-
getCorrespondingSource
public Segment getCorrespondingSource(Segment trgSeg, LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsGets the source segment corresponding to a given target segment- Specified by:
getCorrespondingSourcein interfaceIAlignedSegments- Parameters:
trgSeg- the target segment for which the corresponding source segment is requested.trgLoc- the target locale of the source to look up.- Returns:
- the source segment.
-
align
public void align(List<AlignedPair> alignedSegmentPairs, LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsAligns all the segments listed in the aligned pairs for given locale.This will replace any content in the target and variant source for the given target locale (if either are not present they will be created).
The target for the given locale will be considered aligned with its source when this operation is complete.
- Specified by:
alignin interfaceIAlignedSegments- Parameters:
alignedSegmentPairs- the list of pairs to aligntrgLoc- the target locale to work with.
-
align
public void align(LocaleId trgLoc)
Force one to one alignment. Assume that both source and target have the same number of segments.- Specified by:
alignin interfaceIAlignedSegments- Parameters:
trgLoc- target locale used to align with the source
-
alignCollapseAll
public void alignCollapseAll(LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsAligns all the segments for the specified sources and targets by collapsing all segments into one.- Specified by:
alignCollapseAllin interfaceIAlignedSegments- Parameters:
trgLoc- the target locale of the target (and its corresponding source) to collapse.
-
splitSource
public Segment splitSource(LocaleId trgLoc, Segment srcSeg, int splitPos)
Description copied from interface:IAlignedSegmentsSplits a given source segment into two.Alignment statuses are updated for the locales that have been modified. May cause a misalignment.
- Specified by:
splitSourcein interfaceIAlignedSegments- Parameters:
trgLoc- the target locale that uses the source in which the segment is to be splitsrcSeg- the source segment to split.splitPos- the position where to split.- Returns:
- the new source segment created, or null if none was created.
-
splitTarget
public Segment splitTarget(LocaleId trgLoc, Segment trgSeg, int splitPos)
Description copied from interface:IAlignedSegmentsSplits a given target segment into two.Alignment statuses are updated for the locales that have been modified. May cause a misalignment.
- Specified by:
splitTargetin interfaceIAlignedSegments- Parameters:
trgLoc- the target locale to work on.trgSeg- the targets segment.splitPos- the position where to split.- Returns:
- the new target segment created, or null if none was created.
-
joinWithNext
public void joinWithNext(Segment seg, LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsJoins the segment for a given segment's id to the next segment, including all the parts between the two segments.- Specified by:
joinWithNextin interfaceIAlignedSegments- Parameters:
seg- a segment holding the id to use for the join.trgLoc- the target locale
-
joinAll
public void joinAll(LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsJoins all segments for the specified sources and targets. The content becomes a single segment.- Specified by:
joinAllin interfaceIAlignedSegments- Parameters:
trgLoc- the target locale
-
getAlignmentStatus
public AlignmentStatus getAlignmentStatus()
Description copied from interface:IAlignedSegmentsGets the status of the alignment for this entire text unit. The status will be NOT_ALIGNED if any of the targets in the parent TextUnit have a status of NOT_ALIGNED- Specified by:
getAlignmentStatusin interfaceIAlignedSegments- Returns:
- the status of the alignment for this text unit.
-
getAlignmentStatus
public AlignmentStatus getAlignmentStatus(LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsGets the status of the alignment the given target locale in this text unit.- Specified by:
getAlignmentStatusin interfaceIAlignedSegments- Parameters:
trgLoc- the target locale for which to get the alignment status.- Returns:
- the status of the alignment for this text unit.
-
segmentSource
public void segmentSource(ISegmenter segmenter, LocaleId targetLocale)
Description copied from interface:IAlignedSegmentsSegments the source content used for the given target locale based on the rules provided by a givenISegmenter.No associated targets are modified.
- Specified by:
segmentSourcein interfaceIAlignedSegments- Parameters:
segmenter- the segmenter to use to create the segments.targetLocale- the target locale that uses the source to segment.
-
segmentTarget
public void segmentTarget(ISegmenter segmenter, LocaleId targetLocale)
Description copied from interface:IAlignedSegmentsSegments the specified target content based on the rules provided by a givenISegmenter.If the given target does not exist one is created.
- Specified by:
segmentTargetin interfaceIAlignedSegments- Parameters:
segmenter- the segmenter to use to create the segments.targetLocale-LocaleIdof the target we want to segment.
-
iterator
public Iterator<Segment> iterator()
Description copied from interface:IAlignedSegmentsGets an iterator for the default source segments of this text unit. This iterator does not iterate through non-segment parts of the content.- Specified by:
iteratorin interfaceIAlignedSegments- Specified by:
iteratorin interfaceIterable<Segment>- Returns:
- an iterator for the source segments of this text unit.
-
iterator
public Iterator<Segment> iterator(LocaleId trgLoc)
Description copied from interface:IAlignedSegmentsGets an iterator for the source of the specified target locale. This iterator does not iterate through non-segment parts of the content.- Specified by:
iteratorin interfaceIAlignedSegments- Parameters:
trgLoc- the target locale for the source to iterate over.- Returns:
- an iterator for the source segments used for trgLoc.
-
getParent
public final ITextUnit getParent()
-
-