C# Class SIL.FieldWorks.FDO.DomainImpl.AnalysisAdjuster

The general scenario is that an StText is being edited and we wish to preserve as much as possible of the analysis: that is its segments, their translations and notes, and the analyses that have been assigned to the words of the paragraph. For example if the user makes a small change to one word we do not want to lose all the analysis that the user has already done on the rest of the paragraph. 1) Any segment whose text is unaffected by edits should be unmodified in every other way, except that its begin offset should be adjusted if text has been inserted or deleted before it. 2) If two segments are combined (eg. period removed): we want to concatenate their free translations, and keep all their notes as separate notes. 3) If a segment is split into two segments: We will keep the free translations, literal translations and notes on the first new segment. Enhance JohnT: Would it be better to put them on both segments or on the longer one? 4) If the text of a particular wordform has not changed then it should still have the same analysis. 5) It is particularly important that if the paragraph has a valid analysis beforehand, then it still should after edits. More specific notes on how translations and notes are handled: a. translations and notes are discarded for any original segment that is completely destroyed, that is, it is entirely within the range of characters deleted. b. translations and notes are preserved somewhere for any segment (there can be at most two) which overlaps the range deleted, that is, any segment which at least partly survives. c. material from the first of the partly preserved segments goes to the first of the resulting new segments, and from the second (last) partly preserved segment goes to the last of the resulting new segments. e.g. if we delete the material between the slashes in the following five segments, and insert two complete sentences A and B, we get the following segments and free translations ----0---- ---1a---/---1b--- ----2---- --3a--/--3b-- ---4---- TN0 TN1 TN2 TN3 TN4 ----0---- ---1a---/---A--- ----B---- --3b-- ---4---- TN0 TN1 TN3 TN4 d. If there is only one new segment and more than one partly surviving segment, we concatenate translations, and concatenate lists of notes (not the contents of the notes). e. If all the characters in the paragraph 'changed' but actually remained identical then the users would prefer that the analysis stick around (LT-12403) so we'll pretend it didn't change for adjustment purposes.
Exibir arquivo Open project: sillsdev/FieldWorks Class Usage Examples

Public Methods

Method Description
AdjustAnalysis ( IStTxtPara para, ITsString oldContents ) : void

This is the main entry point called by the setter on the StTxtPara.Contents

AdjustAnalysis ( IStTxtPara para, ITsString oldContents, TsStringDiffInfo diffInfo ) : void

This is the main entry point called by the setter on the StTxtPara.Contents used when the GetDiffsInTsStrings is also needed by another method that is called.

HandleMoveDest ( IStTxtPara destPara, ITsString oldContents, int ichInsert, int cchInsert, IStTxtPara sourcePara, int ichSource, bool fDestParaIsNew ) : void

This is a primary entry point for IStTxtPara.SetContentsForMoveDest. It is similar to the top-level AdjustAnalysis, except that we know exactly what was inserted where, AND, we know it came from another paragraph. If the source paragraph is analysed, we can transfer any relevant analysis. Enhance JohnT: Currently this only supports moving from the end of one paragraph to the end of another. This is sufficient for all current usages of the MoveString method which this supports.

Private Methods

Method Description
AdjustAnalysisInternal ( ) : void

This is the main workhorse for adjusting analyses.

AdjustReferenceEndPoint ( ISegment seg, IAnalysisReference iar, int newIndex, bool fbeg ) : void
AdjustSegments ( ) : void

Add any necessary new segments, or delete any unwanted ones. (Todo: salvage free translations etc from deleted ones). Assign analyses to segments if paragraph has them.

AnalysisAdjuster ( ) : System

for tests

AnalysisAdjuster ( IStTxtPara para, ITsString oldContents, TsStringDiffInfo diffInfo ) : System

Make one for adjusting the specified paragraph to its current contents from the specified old contents

AnalyzeNewText ( ) : void

This loop reparses m_baseline, determining m_iFirstAnalysisToFix, initializing m_trailingTokens and setting up m_newAnalysisGroups (which gives new Segment boundaries). It also initializes m_newAnalyses with the contents of m_oldAnalyses

ChangeCanAffectSegments ( ) : bool

Determine whether the changes to process could change segments or their analyses.

ChangedToLabelAtBeginSegment ( ) : bool

Checks changed text to determine if text at the beginning of a segment was changed to a label - will happen if a run of text is changed to verse number or chapter number style.

CheckForDeleteableIAR ( IAnalysisReference iar, int ifirstAnalysisInSegToFix, int cRemovedAnalyses, int cAddedAnalyses ) : bool

Delete any IAnalysisReference objects whose begin and end references fall within the range of indices removed and not added back in. Example: Old text: the big red pickup truck New text: the VW Index in Segment: 0 1 2 3 4 This method will delete any objects whose begin AND end references fall within the range 2 to 4 (inclusive). In this example, ifirstAnalysisInSegToFix would be 1.

CleanupSpuriousWordforms ( ) : void

If the adjustment resulted in wordforms that are not worth keeping, get rid of them. A wordform is not worth keeping if it - has no analyses - has no incoming references - has a spelling status of unknown

ComputeRangeOfModifiedSegments ( ) : void
ComputeRequiredBeginOffsets ( ) : void
ConcatenateTranslationsAndNotes ( ISegment destination, ISegment source ) : void
DeleteChartRefs ( IEnumerable cellList ) : void
DeleteReferences ( IEnumerable iarList ) : void
DeleteTextTags ( IEnumerable tagList ) : void
DetermineWhatToMove ( int ichSource, int cchInsert, IStTxtPara source ) : void

Initialize m_segsToMove and m_analysesToMove from the given source information. Don't modify the source paragraph until this is done.

DiscardDeletedRefs ( ISegment seg ) : void

Get rid of IAnalysisReferences that only reference a segment that is being deleted (i.e. reference end points are wholly contained within deleted text)

DiscardDeletedSegments ( ) : void
DoTheAdjustment ( ) : void

Common to various ways of initializing the algorithm, this actually figures out what the new state of the paragraph analysis should be.

EndOfNewSeg ( int iseg ) : int

Get the end of the specified segment from m_newBeginOffsets or the length of the paragraph if it is the last

FixHangingReferences ( int iFirstSegmentSurviving, int cOldAnalyses ) : void

Fix a reference where one (or both of the end points' Segments just got deleted

FixSingleHangingReference ( int firstSurvivor ) : void
GetBaselineTexts ( ) : void

Initialize m_baseline to the contents of the segments we have determined need to be processed.

GetFirstVernacularWs ( ITsString token ) : int
GetLastAnalysisToFix ( int &iTokenIndex ) : int

Scan the trailing tokens to see which ones occur in the input analysis list. Determine the last one that does not. Also determine the corresponding position in m_trailingTokens.

GetNewAnalysisGroups ( ) : void

Initialize m_newAnalyses and m_newAnalysisGroups, the Analyses that should go on each new segment. Also initializes m_cRemovedAnalyses and m_cAddedAnalyses.

GetNewWordformAnalyses ( int iTokenIndex ) : List

For each trailing token up to iTokenIndex, find or create a corresponding WfiWordform or PunctuationForm.

HandleMoveDest ( int cchInsert, IStTxtPara source, int ichSource, bool fParaIsNew ) : void

This is a primary entry point for IStTxtPara.SetContentsForMoveDest. It is similar to the top-level AdjustAnalysis, except that we know exactly what was inserted where, AND, we know it came from another paragraph. If the source paragraph is analysed, we can transfer any relevant analysis. Enhance JohnT: Currently this only supports moving from the end of one paragraph to the end of another. This is sufficient for all current usages of the MoveString method which this supports.

InitializeAdjustmentForMove ( ) : void
IsAWordBreak ( int limOldWordform ) : bool

Answer true if a word must end at the given character index: either the end of the text or a non-wordforming character.

MoveAnalysisAndReferencesFromOldPara ( int cchInsert, IStTxtPara source, bool fParaIsNew ) : List
MoveReferencesFromOldPara ( ISegment newSeg, int canalysesLeftBehind ) : List
PrintAnalysesInfo ( List analyses ) : void
PrintDebugInfo ( ) : void

This method is available to help display information about how the adjustments are being calculated, it uses several other helper methods to fill out the debug display

PrintOffsetLines ( string text, int begin, int end ) : void
PrintOneOffsetLine ( string text, int offsetArray, string beginOffsets ) : void
PrintTrailingTokens ( ) : void
SaveAnalysesOfModifiedSegments ( ) : void

Remember the original analyses of segments we may modify.

SegmentIsOutsideOfRange ( IAnalysisReference refObj ) : bool
TrimModifiedAnnotationSet ( Set annObjectsToCheck ) : Set

Trim down set of AnalysisReference objects to only those referencing segments that are modified. (We aren't deleting them, just narrowing down the ones to possibly update.) NB.: Use this BEFORE modifying the old Segments on the paragraph!

UpdateAffectedReferences ( ) : void

Update all IAnalysisReference objects pointing to the segments just modified .

Method Details

AdjustAnalysis() public static method

This is the main entry point called by the setter on the StTxtPara.Contents
public static AdjustAnalysis ( IStTxtPara para, ITsString oldContents ) : void
para IStTxtPara
oldContents ITsString
return void

AdjustAnalysis() public static method

This is the main entry point called by the setter on the StTxtPara.Contents used when the GetDiffsInTsStrings is also needed by another method that is called.
public static AdjustAnalysis ( IStTxtPara para, ITsString oldContents, TsStringDiffInfo diffInfo ) : void
para IStTxtPara
oldContents ITsString
diffInfo SIL.CoreImpl.TsStringDiffInfo
return void

HandleMoveDest() public static method

This is a primary entry point for IStTxtPara.SetContentsForMoveDest. It is similar to the top-level AdjustAnalysis, except that we know exactly what was inserted where, AND, we know it came from another paragraph. If the source paragraph is analysed, we can transfer any relevant analysis. Enhance JohnT: Currently this only supports moving from the end of one paragraph to the end of another. This is sufficient for all current usages of the MoveString method which this supports.
public static HandleMoveDest ( IStTxtPara destPara, ITsString oldContents, int ichInsert, int cchInsert, IStTxtPara sourcePara, int ichSource, bool fDestParaIsNew ) : void
destPara IStTxtPara
oldContents ITsString
ichInsert int
cchInsert int
sourcePara IStTxtPara
ichSource int
fDestParaIsNew bool
return void