Extract grouped contacts and ungrouped fields from a text signature.
dotnet add package RecursiveAI.OneContact.ExtractionRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneContact .Extraction; var result = new ContactExtractor() .ExtractText( "Name: Ada Example\nada@example.com"); foreach (var contact in result.Records) Console.WriteLine(contact.Name?.Text);
Unzip the example, then dotnet run.
Prints:
Ada ExampleThe full program
The full program supplies a US region for the national address. All names, businesses and contact details below are fictional. It reports the grouped fields, the complete flat-field count, the ungrouped email and extraction issues.
Its entire input is:
Name: Ada Example Company: Example Works LLC Phone: +1 202-555-0123 Email: ada@example.com Address: 123 Main St, Springfield, IL 62704 support@example.com
using RecursiveAI.OneContact; using RecursiveAI.OneContact.Extraction; string text = """ Name: Ada Example Company: Example Works LLC Phone: +1 202-555-0123 Email: ada@example.com Address: 123 Main St, Springfield, IL 62704 support@example.com """; var extractor = new ContactExtractor { DefaultRegion = Region.US }; var result = extractor.ExtractText(text); foreach (var record in result.Records) { Console.WriteLine($"Record: {record.Kind} {record.Name?.Text}"); foreach (var field in record.Fields) Console.WriteLine($" {field.Kind}: {field.Text}"); } Console.WriteLine($"Flat fields: {result.Fields.Count}"); foreach (var field in result.Ungrouped) Console.WriteLine($"Ungrouped {field.Kind}: {field.Text}"); Console.WriteLine($"Issues: {result.Issues.Count}");
dotnet run prints:
Record: Person Ada Example Name: Ada Example Organization: Example Works LLC Phone: +1 202-555-0123 Email: ada@example.com Address: 123 Main St, Springfield, IL 62704 Flat fields: 6 Ungrouped Email: support@example.com Issues: 0
Inputs beyond the configured extraction input limits throw ContactExtractionException; ungrouped or unnormalized fields remain visible in the result rather than being invented.
Variations
Keep flat fields without assuming a person
Run this on its own to collect details even when no name establishes a record:
using RecursiveAI.OneContact .Extraction; var result = new ContactExtractor() .ExtractText( "support@example.com"); foreach (var field in result.Fields) Console.WriteLine($"{field.Kind}: {field.Text}"); Console.WriteLine($"Ungrouped: {result.Ungrouped.Count}");
Email: support@example.com Ungrouped: 1
Related recipes
The short answer
Use an instance of ContactExtractor from RecursiveAI.OneContact.Extraction and call ExtractText, not the static HTML helper. The result contains grouped person or organization records, all fields in input order, ungrouped details and issues. Set DefaultRegion when your source uses national phone numbers or addresses that need country context.
OneContact 1.0.0 runs extraction with rules, not a trained contact-span model. It reads the text you pass in; it does not visit a website or search for more information about the people it finds. That makes the result a reading of your input, not an independently verified contact list.
How do I extract contact records from plain text in C#?
Keep the source as text and call ExtractText explicitly. A string is not inspected to guess whether it contains HTML. The API shapes documentation separates the format-specific instance methods so the caller decides which reader to use.
The full program shows a signature with a name, employer, phone, email and postal address. A Name: label provides evidence that the words following it name a person. The company is retained as that person’s organization field. The separate support email remains ungrouped: an email address alone does not establish who owns it.
Do not discard Fields just because Records is empty. The flat list is useful for importing contact details for review; Ungrouped identifies details that the grouping rules did not attach to a record. Keep Issues alongside the values when an import needs a review trail rather than silently accepting every field.
How do I extract contact records from plain text as JSON?
Choose what your application needs to persist before serializing. A grouped contact and a flat email field are different kinds of result. An export that contains only Records can leave out the support address in this example. An export intended for review should retain both grouped and ungrouped details.
The extraction result model gives each field a kind, raw source slice, text, span, source and optional normalized value. Preserve these distinctions in your JSON schema. Text is readable extracted content; Normalized is the core parser’s interpretation when one is available. A field without a normalized value is not evidence that the original source had no contact information.
Offsets from ExtractText are UTF-16 offsets into the exact input string, including line endings. If you replace line endings or trim the input before showing the stored offsets, they no longer point into that changed string. Retain the original input when you need to highlight a source span later.
Can I extract contact details from HTML the same way?
Use ExtractHtml for HTML, rather than stripping tags yourself and assuming the offsets still match the original page. The HTML path reads supported structured markup and visible text. The plain-text path treats lines as its unit and blank lines or separator lines as paragraph boundaries.
The distinction affects evidence as well as offsets. Plain-text notes can use cues such as greetings and header labels that would be ambiguous in web navigation or bylines. Capitalized words alone do not prove that a contact name is present. The documented text rules explain which nearby cues establish a name.
Country context is separate from these cues. The region is not guessed. Without one, an address can remain unnormalized with address.country-required, and an unlabelled national phone can be dropped. Use the region of the source only when you actually know it; a default is context supplied by your application, not a country detected by the extractor.