Skip to content

Commit

Permalink
pull-up offset fixing code to cover all parts
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm committed Aug 8, 2023
1 parent a91c0b9 commit 1bd3912
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
34 changes: 24 additions & 10 deletions IsIdentifiable/Reporting/Reports/FailureStoreReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static IEnumerable<Failure> Deserialize(IFileInfo oldFile, Action<int> lo
token.ThrowIfCancellationRequested();
lineNumber++;
var problemField = r["ProblemField"];
var problemValue = r["ProblemValue"];
var problemValue = r["ProblemValue"] ?? throw new Exception("ProblemValue was null");
var words = r["PartWords"].Split(Separator);
var classes = r["PartClassifications"].Split(Separator);
var offsets = r["PartOffsets"].Split(Separator);
Expand All @@ -166,22 +166,36 @@ public static IEnumerable<Failure> Deserialize(IFileInfo oldFile, Action<int> lo
)
);

// Fixes any offsets that have been mangled by file endings etc.
foreach (var part in parts)
{
if (problemValue.Substring(part.Offset, part.Word.Length) == part.Word)
continue;

// Try looking ahead first, then back
var origOffset = part.Offset;
try
{
while (problemValue.Substring(part.Offset, part.Word.Length) != part.Word)
part.Offset++;
}
catch (ArgumentOutOfRangeException)
{
part.Offset = origOffset;
while (problemValue.Substring(part.Offset, part.Word.Length) != part.Word)
part.Offset--;
}
}

/* TEMP - Filter out any FailureParts covered by an PartRegexRule_Temp */
var toRemove = new List<FailurePart>();
foreach (var partRule in partRules)
{
if (!string.IsNullOrWhiteSpace(partRule.IfColumn) && !string.Equals(partRule.IfColumn, problemField, StringComparison.InvariantCultureIgnoreCase))
continue;

foreach (var part in parts)
{
var origOffset = part.Offset;
if (partRule.Covers(part, problemValue))
{
part.Offset = origOffset;
toRemove.Add(part);
}
}
foreach (var part in parts.Select(x => partRule.Covers(x, problemValue))

Check failure on line 197 in IsIdentifiable/Reporting/Reports/FailureStoreReport.cs

View workflow job for this annotation

GitHub Actions / build

) expected

Check failure on line 197 in IsIdentifiable/Reporting/Reports/FailureStoreReport.cs

View workflow job for this annotation

GitHub Actions / build

) expected
toRemove.Add(part);
}
parts = parts.Except(toRemove);
/* TEMP */
Expand Down
23 changes: 0 additions & 23 deletions IsIdentifiable/Rules/RegexRule_PartTemp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,11 @@ private void RebuildPartRegex()
IfPartPatternRegex = new Regex(_ifPartPatternString, (CaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase) | RegexOptions.Compiled);
}

private static void FixupOffset(FailurePart failurePart, string problemValue)
{
if (problemValue.Substring(failurePart.Offset, failurePart.Word.Length) == failurePart.Word)
return;

// Try looking ahead first, then back
var origOffset = failurePart.Offset;
try
{
while (problemValue.Substring(failurePart.Offset, failurePart.Word.Length) != failurePart.Word)
failurePart.Offset++;
}
catch (ArgumentOutOfRangeException)
{
failurePart.Offset = origOffset;
while (problemValue.Substring(failurePart.Offset, failurePart.Word.Length) != failurePart.Word)
failurePart.Offset--;
}
}

public bool Covers(FailurePart failurePart, string problemValue)
{
if (As != failurePart.Classification)
return false;

// Fixes any offsets that have been mangled by file endings etc.
FixupOffset(failurePart, problemValue);

bool matchesBefore = false;
if (!string.IsNullOrWhiteSpace(WordBefore))
{
Expand Down

0 comments on commit 1bd3912

Please sign in to comment.