Class Unit

    • Constructor Detail

      • Unit

        public Unit​(Unit original)
        Copy constructor.

        Important: Most of the time you MUST change the id of the resulting unit as a unit id must be unique within its parent file element.

        Parameters:
        original - the original unit to duplicate.
      • Unit

        public Unit​(String id)
        Creates a new Unit object.
        Parameters:
        id - the id of the unit.
      • Unit

        public Unit​(String id,
                    StartFileData startFileData)
        Creates a new Unit object with a given id and file context.
        Parameters:
        id - the id of the unit.
        startFileData - the file context (can be null).
    • Method Detail

      • iterator

        public Iterator<Part> iterator()
        Creates a new iterator to loop through the segments and ignorables of this unit.
        Specified by:
        iterator in interface Iterable<Part>
        Returns:
        a new iterator to loop through the segments and ignorables of this unit.
      • getPartCount

        public int getPartCount()
        Gets the number of parts in this unit.
        Returns:
        the number of parts in this unit.
      • getSegmentCount

        public int getSegmentCount()
        Gets the number of segments in this unit.
        Returns:
        the number of segments in this unit.
      • appendSegment

        public Segment appendSegment()
        Appends a new empty segment to this unit.
        Returns:
        the new segment created.
      • appendIgnorable

        public Part appendIgnorable()
        Appends an empty ignorable part to this unit.
        Returns:
        the new ignorable part created.
      • getPart

        public Part getPart​(int partIndex)
        Gets the part at a given index.
        Parameters:
        partIndex - the index of the part to retrieve (between 0 and getPartCount()-1).
        Returns:
        the Part object at the given index position, the part may or may not be a Segment.
        Throws:
        IndexOutOfBoundsException - if the index is invalid.
      • getSegment

        public Segment getSegment​(int segIndex)
        Gets the segment at a given index. Note that the retrieval of the object is not direct, but rely on looping through the parts.
        Parameters:
        segIndex - the index of the segment to retrieve (between 0 and getSegmentCount()-1).
        Returns:
        the Segment object at the given index position.
        Throws:
        IndexOutOfBoundsException - if the index is invalid.
      • getStore

        public Store getStore()
        Gets the store for this unit.
        Specified by:
        getStore in interface IWithStore
        Returns:
        the Store object for this unit.
      • isIdUsed

        public boolean isIdUsed​(String id)
        Description copied from interface: IWithStore
        Indicates if a given id value is already in use in the object (for a Part or for a Tag).
        Specified by:
        isIdUsed in interface IWithStore
        Parameters:
        id - the id value to lookup.
        Returns:
        true if the value is already used, false otherwise.
      • getObjectFromId

        public Object getObjectFromId​(String id)
        Gets the object associated with a given span-class id in this unit.

        The objects checked are: the parts (including segments) and all the tags except the PCont objects.

        Parameters:
        id - the id to look for.
        Returns:
        the object found, or null if not found.
      • split

        public void split​(int partIndex,
                          int srcStart,
                          int srcEnd,
                          int trgStart,
                          int trgEnd,
                          boolean changeState)
        Splits a segment.
        Parameters:
        partIndex - the part index of the segment to split.
        srcStart - the start position of the middle new segment for the source (inclusive, in coded text).
        srcEnd - the end position of the middle new segment for the source (exclusive, in coded text), use -1 for the end of the current segment.
        trgStart - the start position of the middle new segment for the target (inclusive, in coded text).
        trgEnd - the end position of the middle new segment for the target (exclusive, in coded text), use -1 for the end of the current segment.
        changeState - true to change the state and possibly the subState attributes for the modified or added segments if the initial segment as a target and its state is other than "initial" and "translated". Use false to keep the same state and subState.
      • hasTargetOrder

        public boolean hasTargetOrder()
        Indicates if this unit has at least one target part not in the same order as the source.
        Returns:
        true if there is a target-specific order for this unit, false otherwise
      • join

        public void join​(int startPartIndex,
                         int endPartIndex,
                         boolean restrictedJoin,
                         boolean adjustTargetIgnorable)
        Joins two or more parts together into the first one.
        Parameters:
        startPartIndex - the index of the first part to join (in the target order)
        endPartIndex - the index of the last part to join (in the target order)
        restrictedJoin - true to throw an exception if one of the segment cannot be merged, false to allow to merge regardless of the canResegment values (merger mode)
        adjustTargetIgnorable - TODO
      • joinAll

        public void joinAll​(boolean adjustTargetIgnorable)
      • getTargetOrderedParts

        public List<Part> getTargetOrderedParts()
        Gets the list of the parts for this unit in the order specified for the target content.
        Returns:
        a list of all the parts, in the target order.
      • getPlainText

        public String getPlainText​(boolean target,
                                   boolean useSourceForMissingTargetIgnorables)
        Gets the plain text version of the full content of this unit, for either the source or the target.
        Parameters:
        target - true to generate the text for the target, false for the source.
        useSourceForMissingTargetIgnorables - true to use the source content when generating the target text and a target ignorable is missing. this parameter is ignored when generating the source text.
        Returns:
        the plain text full content requested.
      • hideProtectedContent

        public void hideProtectedContent()
        Hides all protected spans of this unit into PCont objects. No target parts are created.
        See Also:
        showProtectedContent()
      • getTranslateStateEndings

        public List<Boolean> getTranslateStateEndings​(boolean doSource)
        Creates a list of booleans corresponding to the translate state at the end of each part in this unit.
        Parameters:
        doSource - true to generates the list from the source viewpoint, false to do it for the target.
        Returns:
        a list of booleans where true means the state of translate at the end of the corresponding part is 'yes', and false means it is 'no'.
      • showProtectedContent

        public void showProtectedContent()
        Show all PCont references in this unit into content.
        See Also:
        hideProtectedContent()
      • verifyOpeningsBeforeClosings

        public void verifyOpeningsBeforeClosings​(boolean target)
        Verifies that all opening tags in the source or targt content of this unit are located before their closing counterparts.
        Parameters:
        target - true to verify the target, false to verify the source.
      • verifyReadOnlyTags

        public void verifyReadOnlyTags()
        Verifies if the non-removable tags in the source content of this unit are present in the target. Note that only the source tags that are in parts with an existing target are verified (as the absence of target is allowed).
      • getSourceOrTargetReference

        public Object getSourceOrTargetReference​(String ref)
        Gets the span-like object associated with a given id in this unit.
        Parameters:
        ref - the reference of the object.
        Returns:
        the object or null if not found.
      • getOrderedCTags

        public List<CTag> getOrderedCTags​(boolean target)
        Creates the list of CTag in the source or target content, in their respective order. This method does not check content inside protected text.
        Parameters:
        target - true to create the target list (in target order).
        Returns:
        the list of codes.
      • doNonEmptySourcesHaveNonEmptyTargets

        public boolean doNonEmptySourcesHaveNonEmptyTargets()
        Indicates if all parts (segments and ignorables) of this unit that have a non-empty source have also a non-empty target.
        Returns:
        true if all source parts that are not empty have a non-empty target too, false otherwise.
      • removeMarkers

        public void removeMarkers()
        Removes all the annotation markers from the source and target (if a target is available) in this unit.
      • hasITSGroup

        public boolean hasITSGroup()
        Description copied from interface: IWithITSGroups
        Indicates if the object has at least one ITS group.
        Specified by:
        hasITSGroup in interface IWithITSGroups
        Returns:
        true if the object has at least one ITS group.
      • getITSGroups

        public List<DataCategoryGroup<?>> getITSGroups()
        Description copied from interface: IWithITSGroups
        Gets the ITS groups associated with this object.
        Specified by:
        getITSGroups in interface IWithITSGroups
        Returns:
        the ITS groups associated with this object (can be empty, but never null).
      • hasITSItem

        public boolean hasITSItem()
        Description copied from interface: IWithITSAttributes
        Indicates if the object has at least one ITS item.
        Specified by:
        hasITSItem in interface IWithITSAttributes
        Returns:
        true if the object has at least one ITS item.
      • getITSItems

        public ITSItems getITSItems()
        Description copied from interface: IWithITSAttributes
        Gets the ITS items associated with this object.
        Specified by:
        getITSItems in interface IWithITSAttributes
        Returns:
        the ITS items associated with this object (can be empty, but never null).
      • setITSItems

        public void setITSItems​(ITSItems itsItems)
        Description copied from interface: IWithITSAttributes
        Sets the list of the ITS items associated with this object.
        Specified by:
        setITSItems in interface IWithITSAttributes
        Parameters:
        itsItems - the new items to set.
      • hasMatch

        public boolean hasMatch()
        Indicates if this unit has at least one match.
        Returns:
        true if this unit has at least one match, false if not.
      • getMatches

        public Matches getMatches()
        Gets the Matches object for this unit, creates an empty of if there is none.
        Returns:
        the Matches object for this unit (can be empty, but never null).
      • setMatches

        public void setMatches​(Matches matches)
        sets the Matches object for this unit.
        Parameters:
        matches - the new Matches object for this unit.
      • hasGlossEntry

        public boolean hasGlossEntry()
        Indicates if this unit has at least one glossary entry.
        Returns:
        true if this unit has at least one glossary entry, false if not.
      • getGlossary

        public Glossary getGlossary()
        Gets the Glossary object for this unit, creates an empty of if there is none.
        Returns:
        the Glossary object for this unit (can be empty, but never null).
      • setGlossary

        public void setGlossary​(Glossary glossary)
        sets the Glossary object for this unit.
        Parameters:
        glossary - the new Glossary object for this unit.
      • getAnnotatedSpans

        public List<AnnotatedSpan> getAnnotatedSpans​(boolean target)
        Creates a list of the annotated spans in this unit.

        The Part and MTag objects in the list are live references, but any static data (e.g. the start and end position of the span) are a snapshot of the information at the moment of the call, any change to the content may make that information out-of-date and invalid.

        The spans are listed in the order their opening markers appears in the coded text.

        The call is expected to be made on a unit with no hidden protected content.

        Parameters:
        target - true to lookup the target, false to lookup the source.
        Returns:
        a list of AnnotatedSpan objects for this unit.
      • getAllExactMatches

        public List<Match> getAllExactMatches()
        Retrieves all exact matches from this unit, i.e. similarity >= 100.0.
        Returns:
        An array list with the relevant matches
      • getMatchesByMinimumSimilarity

        public List<Match> getMatchesByMinimumSimilarity​(double minSim)
        Retrieves all matches from this unit with the given minimum similarity.
        Parameters:
        minSim - The minimum similarity as a percentage, e.g. 75.0 for all matches with 75% or higher
        Returns:
        An array list with the relevant matches
      • getMatchesBySimilarityRange

        public List<Match> getMatchesBySimilarityRange​(double minSim,
                                                       double maxSim)
        Retrieves all matches from this unit in the given similarity range.
        Parameters:
        minSim - The minimum similarity as a percentage, e.g. 75.0 for all matches with 75% or higher
        maxSim - The maximum similarity
        Returns:
        An array list with the relevant matches
      • getMatchesForSegment

        public List<Match> getMatchesForSegment​(int segIdx)
        Retrieves all matches from this unit for the given segment (zero-based index)
        Parameters:
        segIdx - The index of the segment (zero-based)
        Returns:
        An array list with the relevant matches
      • getMatchesByRef

        public List<Match> getMatchesByRef​(String ref)
        Retrieves all matches from this unit for the given ref attribute value.
        Parameters:
        ref - The value of the ref attribute, with or without the "#" prefix
        Returns:
        An array list with the relevant matches
      • getPreserveWS

        public boolean getPreserveWS()
        Indicates if the whitespace of this part's content must be preserved.
        Returns:
        true if the whitespace must be preserved, false if the whitespace can be modified.
      • setPreserveWS

        public void setPreserveWS​(boolean preserveWS)
        Sets the flag indicating if the whitespace of this part's content must be preserved.
        Parameters:
        preserveWS - true to preserve the whitespace, false otherwise.
      • addNote

        public void addNote​(Note note)
        Description copied from interface: IWithNotes
        Adds a note to the list of notes.
        Specified by:
        addNote in interface IWithNotes
        Parameters:
        note - the note to add.
      • getNotes

        public Notes getNotes()
        Description copied from interface: IWithNotes
        Gets the Notes object for this object.
        Specified by:
        getNotes in interface IWithNotes
        Returns:
        the notes for this object. Never returns null.
      • getNoteCount

        public int getNoteCount()
        Description copied from interface: IWithNotes
        Gets the number of notes for this object.
        Specified by:
        getNoteCount in interface IWithNotes
        Returns:
        the number of notes available.
      • getName

        public String getName()
        Gets the name for this group.
        Returns:
        the name for this group (can be null).
      • setName

        public void setName​(String name)
        Sets the name for this group.
        Parameters:
        name - the new name to set (can be null).
      • getType

        public String getType()
        Gets the type for this group.
        Returns:
        the type for this group (can be null).
      • setType

        public void setType​(String type)
        Sets the type for this group. The value must have a prefix (for both unit and group elements)
        Parameters:
        type - the new type to set (can be null).
      • hasMetadata

        public boolean hasMetadata()
        Description copied from interface: IWithMetadata
        Indicates if the object has metadata.
        Specified by:
        hasMetadata in interface IWithMetadata
        Returns:
        true if the object has metadata, false otherwise.
      • getMetadata

        public Metadata getMetadata()
        Description copied from interface: IWithMetadata
        Gets the Metadata object for the parent, creates an empty of if there is none.
        Specified by:
        getMetadata in interface IWithMetadata
        Returns:
        the Metadata object for the parent (can be empty, but never null).
      • hasValidation

        public boolean hasValidation()
        Description copied from interface: IWithValidation
        Indicates if the object has validation data.
        Specified by:
        hasValidation in interface IWithValidation
        Returns:
        true if the object has validataion data, false otherwise.
      • hasChangeTrack

        public boolean hasChangeTrack()
        Description copied from interface: IWithChangeTrack
        Check if there is at least a revision for this element.
        Specified by:
        hasChangeTrack in interface IWithChangeTrack
        Returns:
        true if there is at least a revision for this element; false otherwise.
      • setId

        public void setId​(String id)
        Sets the id for this object.
        Parameters:
        id - the id for this object.
      • getId

        public String getId()
        Gets the id for this object.
        Returns:
        the id for this object.
      • hasExtAttribute

        public boolean hasExtAttribute()
        Description copied from interface: IWithExtAttributes
        Indicates if at least one extension attribute is present.
        Specified by:
        hasExtAttribute in interface IWithExtAttributes
        Returns:
        true if at least one extension attribute is present; false otherwise.
      • getExtAttributeValue

        public String getExtAttributeValue​(String namespaceURI,
                                           String localName)
        Description copied from interface: IWithExtAttributes
        Gets the value for a given extension attribute.
        Specified by:
        getExtAttributeValue in interface IWithExtAttributes
        Parameters:
        namespaceURI - the URI of the namespace for the attribute.
        localName - the name of the attribute.
        Returns:
        the value of the extension attribute, or null if it does not exist.