sergey-tihon / Stanford.NLP.NET

Stanford NLP for .NET
http://sergey-tihon.github.io/Stanford.NLP.NET/
MIT License
598 stars 123 forks source link
dotnet fsharp recompiled-packages stanford-nlp

Stanford.NLP for .NET

2024-03-21: All Stanford.NLP NuGet packages are marked as deprecated (legacy and no longer maintained). Please use the official Stanford CoreNLP Maven package instead, along with the IKVM.Maven.Sdk.

Getting started with IKVM.Maven.Sdk

Copy the following lines into your project file:

<ItemGroup>
    <PackageReference Include="IKVM" Version="8.7.5" />
    <PackageReference Include="IKVM.Maven.Sdk" Version="1.6.8" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
    <MavenReference Include="edu.stanford.nlp:stanford-corenlp" Version="4.5.6"/>
    <MavenReference Include="edu.stanford.nlp:stanford-corenlp" Version="4.5.6" Classifier="models" />
</ItemGroup>

First two PackageReferencees add IKVM and IKVM.Maven.Sdk to your project. The MavenReferencees are used to download and compile Stanford CoreNLP .jar files and models.

The next step is to manually load the assembly with models into you process:

var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
var modelsAssemblyPath = Path.Combine(baseDirectory, "edu.stanford.nlp.corenlp_english_models.dll");
Assembly.LoadFile(modelsAssemblyPath);

Previously you have to manually find *.jar file with models, unpack it and temporary change the current directory to the unpacked folder. This is no longer needed with IKVM.Maven.Sdk. The *.jar with models is automatically downloaded and compiled to *.dll with the same name. The only thing that you have to do is it to load this assembly into your process.

You are now ready to use Stanford CoreNLP in your .NET project.

var text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";

// Annotation pipeline configuration
var props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
props.setProperty("ner.useSUTime", "false");

var pipeline = new StanfordCoreNLP(props);

// Annotation
var annotation = new Annotation(text);
pipeline.annotate(annotation);

P.S. More samples are available in the Stanford.NLP.NET repository.

Licensing of the code/content of this repo

The source code of this repo(build scripts, integration tests, docs and samples) under the MIT license.

Licensing of NuGet packages

All these software distributions are open source, licensed under the GNU General Public License (v2 or later). Note that this is the full GPL, which allows many free uses, but does not allow its incorporation into any type of distributed proprietary software, even in part or in translation. Commercial licensing is also available; please contact The Stanford Natural Language Processing Group if you are interested.