Installation
Lindera .NET is the package Lindera, which has the library of Lindera C for each platform: adding the package is all a program does.
Prerequisites
- .NET 10 or later: the package targets
net10.0 - A supported platform (below)
Adding the package
From the release after 7.3.0, the package has a version for each release of Lindera:
dotnet add package Lindera
The version of the package is the version of Lindera, and the package has the library of that version.
Platforms
The package has the library of the C archive of the release for each of these platforms, in runtimes/<rid>/native/, and .NET finds the one of the machine with nothing to set: when the program runs with dotnet run, when it is published for a runtime identifier (-r linux-x64), self-contained, as a single file, and with Native AOT.
| Platform | Runtime identifier | Library |
|---|---|---|
| Linux on x86_64 (glibc 2.34 or later) | linux-x64 | liblindera.so |
| Linux on arm64 (glibc 2.34 or later) | linux-arm64 | liblindera.so |
| macOS on x86_64 | osx-x64 | liblindera.dylib |
| macOS on arm64 | osx-arm64 | liblindera.dylib |
| Windows on x86_64 | win-x64 | lindera.dll |
| Windows on arm64 | win-arm64 | lindera.dll |
The library for Windows on arm64 is in the package, and is not run by the tests of Lindera.
The library for Linux needs glibc 2.34 or later: Ubuntu 22.04, Debian 12 and RHEL 9 or later. The package has no library for musl (Alpine Linux): there .NET picks the library for glibc, which fails to load. A program on Alpine uses a library built for musl, through LINDERA_LIBRARY_FILE (below).
A library of one's own
When the environment variable LINDERA_LIBRARY_FILE names a file, the package loads the library from that file instead of the one it has:
export LINDERA_LIBRARY_FILE=/path/to/liblindera.so
It is for a platform the package has no library for, and for a library built from the sources, with an embedded dictionary for example (Lindera C). A file that cannot be loaded is an error that names it, and the package does not fall back to its own library. The library must have the interface of the package and be of its version or later (see Versions).
A Native AOT program that links the library statically does not read the variable.
Obtaining Dictionaries
The library of the package embeds no dictionary. A program loads one from a directory.
Pre-built dictionaries are available on the GitHub Releases page. Download and extract the dictionary archive; the archive holds one directory, lindera-ipadic for IPADIC:
# Example: download and extract the IPADIC dictionary
curl -LO https://github.com/lindera/lindera/releases/download/<version>/lindera-ipadic-<version>.zip
unzip lindera-ipadic-<version>.zip -d /path/to
The dictionary is then /path/to/lindera-ipadic, which is what a program passes to SetDictionary or to Dictionary.Load.
A library built from the sources with an embed-* feature holds the dictionary, and a program names it as embedded://<name>, for example embedded://ipadic (see Feature Flags).
Development
The Makefile has the targets of the binding:
make format-lindera-dotnet # dotnet format
make lint-lindera-dotnet # fail when dotnet format would change a file
make test-lindera-dotnet # the build, the tests and the package, against the library cargo-c installs
make test-lindera-dotnet builds the library of Lindera C with the features of its tests and installs it under target/capi/stage-dotnet, then builds the solution lindera-dotnet/Lindera.slnx with the warnings as errors, runs the tests with that library next to them, and makes the package with it, which a project of its own adds to run the example of the Quick Start (scripts/test_lindera_dotnet.sh). It needs the .NET SDK 10 and cargo-c (make setup-lindera-c-tools). The builds write to target/dotnet.
A test compares the functions and the constants of the C API (lindera-c/abi/symbols.txt, lindera.h) with what the package declares: one the C API gains is declared by the package, or listed in lindera-dotnet/tests/Lindera.Tests/CApiTests.cs with the reason it is not.