Ignore:
Timestamp:
Jul 13, 2018, 5:16:39 PM (6 years ago)
Author:
chronos
Message:
  • Added: Support for document plural acronyms check.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormCheck.pas

    r186 r190  
    5555    function IsUppercaseAlpha(Text: string): Boolean;
    5656    function IsAlpha(Text: string): Boolean;
     57    function IsAcronym(Text: string): Boolean;
    5758    procedure ReportDifferencies;
    5859    function WordContainsLetters(Text, Letters: string): Boolean;
     
    7778  SAcronymCountContent = 'Content acronym count:';
    7879  SAcronymCountSummary = 'Summary acronym count:';
    79   SDuplicateAcronymContent = 'Duplicate acronym %s with "%s" in document content.';
    80   SDuplicateAcronymSummary = 'Duplicate acronym %s with "%s" in acronym summary.';
    81   SMissingAcronymContent = 'Content acronym %s with meaning "%s" missing from summary acronyms.';
    82   SMissingAcronymSummary = 'Summary acronym %s with meaning "%s" missing from content acronyms.';
    83 
     80  SDuplicateAcronymContent = 'Warning: Duplicate acronym %s with "%s" in document body.';
     81  SDuplicateAcronymSummary = 'Warning: Duplicate acronym %s with "%s" in acronym summary.';
     82  SMissingAcronymContent = 'Warning: Document body acronym %s with meaning "%s" missing from acronym summary.';
     83  SMissingAcronymSummary = 'Warning: Summary acronym %s with meaning "%s" missing from document body.';
     84  SPluralAcronym = 'Note: Acronym %s is defined as plural in document body.';
    8485
    8586{ TFormCheck }
     
    218219  HasMeaning1: Boolean;
    219220  HasMeaning2: Boolean;
     221  Plural: Boolean;
    220222begin
    221223  AcronymDbContent.Acronyms.Clear;
     
    232234      if EndIndex <> 0 then begin
    233235        Acronym := Trim(Copy(Text, StartIndex + 1, EndIndex - StartIndex - 1));
    234         if (Length(Acronym) > 1) and IsUppercaseAlpha(Acronym) then begin
     236        // Allow plural acronyms with ending 's' character
     237        if (Length(Acronym) >= 1) and (Acronym[Length(Acronym)] = 's') then begin
     238          Acronym := Copy(Acronym, 1, Length(Acronym) - 1);
     239          Plural := True;
     240        end else Plural := False;
     241        if IsAcronym(Acronym) then begin
    235242          HasMeaning1 := ParseMeaning(Acronym, Text, StartIndex - 1, Meaning1);
    236243          if HasMeaning1 then Meaning := Meaning1;
     
    242249          end;
    243250          if HasMeaning1 or HasMeaning2 then begin
     251            // If plural acronym then try to remove ending 's' character from the meaning
     252            if Plural then MemoReport.Lines.Add(Format(SPluralAcronym, [Acronym]));
     253            if Plural and (Length(Meaning) >= 1) and (Meaning[Length(Meaning)] = 's') then begin
     254              Meaning := Copy(Meaning, 1, Length(Meaning) - 1);
     255            end;
    244256            if Assigned(AcronymDbContent.SearchAcronym(Acronym, Meaning)) then
    245257              MemoReport.Lines.Add(Format(SDuplicateAcronymContent, [Acronym, Meaning]))
     
    360372end;
    361373
     374function TFormCheck.IsAcronym(Text: string): Boolean;
     375const
     376  MinAcronymLength = 2;
     377begin
     378  Result := (Length(Text) >= MinAcronymLength) and IsUppercaseAlpha(Text);
     379end;
     380
    362381procedure TFormCheck.ReportDifferencies;
    363382var
Note: See TracChangeset for help on using the changeset viewer.