Recursive AI

Detect renamed defined terms in a contract diff in C#

OneDiff is a free, open-source diff library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Compare plain-text contract versions to review a definition and its renamed references together, without treating a changed deadline as part of the rename.

Terminal
dotnet add package RecursiveAI.OneDiff.Documents

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneDiff.Documents;
using OneDiff.Documents.Model;
 
var before = CompareDocument.FromText(
    "\"Software\" means the programs.\n\n" +
    "Deliver the Software within 30 days.");
var after = CompareDocument.FromText(
    "\"Platform\" means the programs.\n\n" +
    "Deliver the Platform within 60 days.");
var diff = Comparison.Of(
    before, after, CompareSettings.Legal);
foreach (var group in diff.Groups)
    if (group.Kind == GroupKind.Rename)
        Console.WriteLine($"{group.Title}: " +
            $"{group.ChangeIds.Length} edits");

The example is the full program below: unzip it and dotnet run. To run only the code above, paste it into Program.cs of a new dotnet new console project and dotnet run.

Text
"Software" → "Platform": 2 edits

CompareSettings.Legal groups a renamed definition with its renamed references.

The full program

C#
using OneDiff.Documents;
using OneDiff.Documents.Model;
 
var before = CompareDocument.FromText(
    "\"Software\" means the programs.\n\n" +
    "Deliver the Software within 30 days.");
var after = CompareDocument.FromText(
    "\"Platform\" means the programs.\n\n" +
    "Deliver the Platform within 60 days.");
var diff = Comparison.Of(
    before, after, CompareSettings.Legal);
var rename = diff.Groups.Single(g => g.Kind == GroupKind.Rename);
Console.WriteLine(rename.Title);
foreach (var change in diff.Changes)
{
    string group = rename.ChangeIds.Contains(change.Id) ? "rename" : "separate";
    Console.WriteLine($"{group}: {change.Type} " +
        $"{change.OldValue?.Canonical} -> {change.NewValue?.Canonical}");
}

dotnet run prints:

Text
"Software" → "Platform"
rename: DefinedTerm Software -> Platform
rename: DefinedTerm Software -> Platform
separate: Duration 30 d -> 60 d

The program checks each change ID against the rename group. The definition and its reference are members; the 30-to-60-day edit is not. If the comparison does not recognize a qualifying rename, there is no GroupKind.Rename to read; use the individual changes instead.

Variations

To inspect the same two versions without collapsing renames, append this to the full program:

C#
var strict = Comparison.Of(
    before, after, CompareSettings.Strict);
Console.WriteLine(strict.Groups.Count(
    g => g.Kind == GroupKind.Rename));
Text
0

The short answer

Compare the two text versions with CompareSettings.Legal, then look for GroupKind.Rename. The group contains IDs of the definition and reference edits. Join those IDs back to diff.Changes to show all the locations. Keep edits outside the group visible: in the sample, the delivery deadline changes even though the clause also uses the new name.

What is a defined term in a contract?

It’s a word or phrase the contract gives a specific meaning. In "Software" means the programs., the quoted word is the definition’s name. Later clauses can use Software instead of repeating the explanation. Changing the name to Platform can create several visible edits even when the text that explains what it means hasn’t changed.

OneDiff looks for quoted phrases in recognizable definition patterns, such as a quoted term followed by “means” or “shall mean.” A capitalized word alone isn’t enough. To group a rename, the old term must be defined only in the old version, the new term only in the new version, and the replacement must show up in at least two places. An edit that doesn’t match those conditions may still appear as an ordinary change. See the rename rules for recognized definition forms.

What is a redline in a contract?

A redline shows what was added, removed or replaced between two drafts. A rename group gives the reviewer one entry for a repeated change without removing the underlying marks. OneDiff’s HTML output can show grouped changes as well as the marks in the text. To build your own review list, use the group for the summary and follow its change IDs for the details.

Grouping isn’t a verdict that the edit has no legal effect. The full program deliberately changes both the term and the deadline in one sentence. It separates the term replacements from the duration in this case; it doesn’t decide what the new deadline means for either party. Review the surrounding clause, any changes to the definition itself and any old uses that were not replaced. OneDiff’s rules group recognized text edits; they don’t check that the drafting is consistent.

All onediff recipes