Recursive AI

Migrate from Catalyst NLP to OneNlp in C#

Two runnable examples show where the English pipelines disagree on contraction boundaries, part-of-speech tags, and lemmas.

Replace Catalyst’s Pipeline.ForAsync, new Document, and ProcessSingle with Nlp.Analyze(text). Drop the + 1 when slicing with OneNlp’s exclusive EndIdx.

OneNlp is a free, open-source C# NLP library (tokens, sentences, POS tags, lemmas) from Recursive AI, licensed MIT OR Apache-2.0. NuGet: RecursiveAI.OneNlp · GitHub: OneNlp.

OneNlp with English modelsNuGet
dotnet add package RecursiveAI.OneNlp --version 1.0.0
dotnet add package RecursiveAI.OneNlp.Models.English --version 1.0.0

Run the same text through both pipelines

Use separate .NET 10 console projects. Both examples print sentence boundaries and token details. Every range shown is half-open: its left edge is included, its right edge is not.

After: OneNlp

Reference the English model package. Nlp.Analyze uses the packaged model; this call needs neither a registration method nor a model download.

Program.cs.NET 10
using RecursiveAI.OneNlp;
 
Doc doc = Nlp.Analyze("We've met Ada. She runs.");
foreach (var sentence in doc.Sentences)
{
    Console.WriteLine("Sentence:");
    foreach (Token token in sentence)
    {
        Console.WriteLine($"[{token.Idx},{token.EndIdx}) {token.Text} | {token.Pos} | {token.Lemma}");
    }
}

Output columns: source range, source text, coarse POS tag, lemma.

OneNlp 1.0.0Output
Sentence:
[0,2) We | PRON | we
[2,5) 've | AUX | have
[6,9) met | VERB | meet
[10,13) Ada | PROPN | ada
[13,14) . | PUNCT | .
Sentence:
[15,18) She | PRON | she
[19,23) runs | VERB | run
[23,24) . | PUNCT | .

Before: Catalyst

This follows Catalyst’s setup example using Catalyst 26.10.6514 and Catalyst.Models.English 26.9.5316. Add one to the inclusive End before slicing the original string.

Catalyst with English modelsNuGet
dotnet add package Catalyst --version 26.10.6514
dotnet add package Catalyst.Models.English --version 26.9.5316
Program.cs.NET 10
using Catalyst;
using Mosaik.Core;
 
const string text = "We've met Ada. She runs.";
Catalyst.Models.English.Register();
Storage.Current = new DiskStorage("catalyst-models");
var nlp = await Pipeline.ForAsync(Language.English);
var doc = new Document(text, Language.English);
nlp.ProcessSingle(doc);
 
foreach (var sentence in doc.Spans)
{
    Console.WriteLine("Sentence:");
    foreach (var token in sentence.Tokens)
    {
        int end = token.End + 1;
        Console.WriteLine($"[{token.Begin},{end}) {text[token.Begin..end]} | {token.Value} | {token.POS} | {token.Lemma}");
    }
}

Output columns: source range, source text, Value, POS tag, lemma. Value is not always the source slice.

Catalyst 26.10.6514Output
Sentence:
[0,1) W | We | PRON | We
[1,5) e've | have | VERB | have
[6,9) met | met | VERB | meet
[10,13) Ada | Ada | PROPN | Ada
[13,14) . | . | PUNCT | .
Sentence:
[15,18) She | She | PRON | She
[19,23) runs | runs | VERB | run
[23,24) . | . | PUNCT | .

Map the pipeline and its output

The rows map the calls used above and in Catalyst’s document reference. The OneNlp migration guide also covers explicit pipelines and batch processing.

CatalystOneNlp 1.0.0What to change
Register the English models; set Storage.Current.Reference RecursiveAI.OneNlp.Models.English.Remove the registration and storage setup for this packaged model.
Pipeline.ForAsync(Language.English), new Document, then ProcessSingleDoc doc = Nlp.Analyze(text)Use the returned document rather than an object you create and pass in for annotation.
doc.Spans, then sentence.Tokensdoc.Sentences, then iterate the spanUse the document’s sentence ranges, not positions inferred from the previous tokenizer.
Begin, inclusive EndIdx, exclusive EndIdxDon’t carry over the + 1 when slicing OneNlp results. Its offsets are UTF-16 code units into the original string.
Value (can differ from source text)Text for source text; Norm for a supplied normalized formKeep display text separate from normalization. Norm is empty when no component sets it.
POS and LemmaPos and LemmaPos is a coarse Universal Dependencies tag string. OneNlp’s separate Tag is the fine-grained tag.

Recheck spans, models, and tags before switching

  • Offsets: Converting the endpoint convention doesn’t align token boundaries. In the sample, the contraction’s second range starts at 1 in Catalyst and 2 in OneNlp. Recompute highlights against the original input. Test contractions and non-ASCII text, including characters that take two UTF-16 code units.
  • Tags and lemmas: The example’s second token changes from VERB to AUX, and Ada becomes the lemma ada rather than Ada. Audit tag filters and lemma lookup keys on your own text instead of translating property names alone.
  • Models and labels: OneNlp doesn’t load models trained for Catalyst. For your own trained components, plan to retrain. If you consume entity annotations, review the entity label scheme and test the labels and span boundaries that your application expects.