---
title: "Find contact field spans in text with a local model in C#"
url: https://recursiveai.org/onecontact/cookbook/detect-contact-spans-with-tier1-model/
description: "Use OneContact’s Tier 1 model to find names, addresses and other contact fields in plain text, with character offsets, confidence and block starts."
version: "1.1.0"
---

# Find contact spans in C# with a local model

**OneContact** is a free, open-source contact data library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies, no network access.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneContact.Models.Tier1) · [GitHub](https://github.com/recursive-ai-oss/onecontact-csharp) · [Docs](https://recursiveai.org/onecontact/docs/) · [Download example (.zip)](https://recursiveai.org/onecontact/cookbook/detect-contact-spans-with-tier1-model/detect-contact-spans-with-tier1-model.zip)

`Tier1Model.Instance.Find` marks where contact fields appear in plain text. It doesn’t build records.

OneContact uses built-in rules first to classify names; `RecursiveAI.OneContact.Models.Tier1` bundles a small offline model for the United States and Canada, and `RecursiveAI.OneContact.Models` also covers Mexico, Australia, the United Kingdom, the Crown dependencies, and the Latin-script countries of Europe.

```shell
dotnet add package RecursiveAI.OneContact.Models.Tier1
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneContact.Models.Tier1;

var text = "Avery Example\n"
    + "Northwind Traders LLC\n"
    + "avery@example.com";
var result = Tier1Model.Instance.Find(text);
foreach (var span in result.Spans)
    Console.WriteLine($"{span.Label}: "
        + text[span.Start..span.End]);
```

[The example](https://recursiveai.org/onecontact/cookbook/detect-contact-spans-with-tier1-model/detect-contact-spans-with-tier1-model.zip) 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`.

Prints:

```text
person: Avery Example
company: Northwind Traders LLC
email: avery@example.com
```

## The full program

The same input gives each field’s character range and confidence, plus the block starts: where the model thinks a new contact record starts.

```csharp
using RecursiveAI.OneContact.Models.Tier1;

var text = "Avery Example\n"
    + "Northwind Traders LLC\n"
    + "avery@example.com";
var result = Tier1Model.Instance.Find(text);
foreach (var span in result.Spans)
{
    var value = text[span.Start..span.End];
    Console.WriteLine(FormattableString.Invariant(
        $"{span.Label} [{span.Start}, {span.End}): {value} ({span.Confidence:F2})"));
}
Console.WriteLine("Block starts: " + string.Join(", ", result.BlockStarts));
```

```text
person [0, 13): Avery Example (0.76)
company [14, 35): Northwind Traders LLC (0.53)
email [36, 53): avery@example.com (0.91)
Block starts: 0, 14
```

A score like `0.53` is the model’s confidence in the label, averaged across the span’s words; this example keeps every span, with no cutoff.

A prediction can miss a field, cut it short or start a block you wouldn’t make; the two block starts here are model output, not two confirmed contacts.

## Variations

### Keep just email candidates

Filter by label before passing candidates to a separate email parser.

```csharp
using RecursiveAI.OneContact.Models.Tier1;

var text = "Avery Example\n"
    + "Northwind Traders LLC\n"
    + "avery@example.com";
var result = Tier1Model.Instance.Find(text);
foreach (var span in result.Spans)
    if (span.Label == "email")
        Console.WriteLine(text[span.Start..span.End]);
```

```text
avery@example.com
```

## Related recipes

- [Extract contact records from plain text](https://recursiveai.org/onecontact/cookbook/extract-contact-records-from-plain-text/)
- [Extract email addresses from text](https://recursiveai.org/onecontact/cookbook/extract-emails-from-text/)

## The short answer

Call `Tier1Model.Instance.Find(text)` on the original plain text, including its line breaks. Read `Spans` for the field labels and their offsets, and `BlockStarts` for the offsets where the model thinks new contact records start. The package includes the model weights; it doesn’t fetch them when the program runs.

## How do I find and highlight contact fields in plain text?

This is a contact-specific form of named entity recognition: the model labels pieces of a larger string rather than giving the whole string a single class. The six labels are `person`, `company`, `address`, `phone`, `email` and `website`. The `Start` and `End` offsets let you display a highlight in the original text, or pull out the substring as the example does. `Start` is inclusive and `End` is exclusive. Use the exact string you passed to `Find`: trimming it or changing its line endings afterward can move the offsets.

According to the [model notes](https://recursiveai.org/onecontact/docs/models/), a span’s confidence is the mean probability of its words’ tags. It doesn’t tell you that a phone number is complete or an email address is valid. If you need normalized or checked values, use the spans as candidates and parse them separately.

## Does the local model extract complete contact records?

No. The model marks a first field when it predicts that a new block begins. Its offset goes into `BlockStarts` without changing the field’s ordinary label. Use these offsets as hints if you’re building your own grouping for notes or pasted signatures; don’t assume every group has a name or that neighboring spans belong to the same person.

The [OneContact extraction API](https://recursiveai.org/onecontact/docs/extraction/#the-span-model) uses rules and, for HTML, markup to find and group contact fields. It never uses the span head to discover fields, even with Tier 1 installed. Installing a model can still change how an already-found name or address is normalized. Call `Find` directly when you need the model’s raw positions, and use record extraction when you want grouped contact information instead.
