Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions .github/workflows/build-python-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- id: check_build_trigger
name: Check build trigger
run: bash build_tools/github/check_build_trigger.sh
Expand All @@ -56,13 +56,11 @@ jobs:
needs: check_build_trigger
if: needs.check_build_trigger.outputs.build
strategy:
# Ensure that a wheel builder finishes even if another fails
fail-fast: false
fail-fast: false # If false, all jobs continue even if one fails
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ["3.14"] # Check with PyO3's maximum supported version
env:
CIBW_BUILD: "" # blank, let cibuildwheel build all supported platforms
# cibuildwheel will manage multiple Python versions internally

steps:
- name: Checkout source code
Expand Down Expand Up @@ -92,17 +90,19 @@ jobs:
package-dir: nlpo3-python
output-dir: wheelhouse
env:
CIBW_BUILD_VERBOSITY: 1
# See CIBW_BUILD, CIBW_SKIP, CIBW_ARCHS and other build selectors at:
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
CIBW_SKIP: "*-musllinux_i686"
CIBW_ENABLE: "graalpy pypy" # Enable GraalPy and PyPy builds
CIBW_BUILD: "cp* gp* pp*" # Build for CPython, GraalPy and PyPy
CIBW_BUILD_VERBOSITY: 1
CIBW_SKIP: "*-musllinux_i686 gp*-win_*"
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_ENVIRONMENT_MACOS: |
MACOSX_DEPLOYMENT_TARGET=10.12
PATH="$HOME/.cargo/bin:$PATH"
CC=/usr/bin/clang
CXX=/usr/bin/clang++
CIBW_ARCHS_LINUX: "auto"
CIBW_ARCHS_LINUX: "x86_64 i686"
CIBW_ENVIRONMENT_LINUX: PATH="$HOME/.cargo/bin:$PATH"
CIBW_BEFORE_BUILD_LINUX: |
pip install --upgrade setuptools-rust
Expand All @@ -112,13 +112,20 @@ jobs:
# and the container does not have Rust.
CIBW_ARCHS_WINDOWS: "AMD64 x86"

- name: List wheel files
run: |
echo "Files to upload (binary wheels):"
find ./wheelhouse -maxdepth 1 -type f -name '*.whl' -print | sort || true
echo "Count: $(find ./wheelhouse -maxdepth 1 -type f -name '*.whl' -print | wc -l || true)"
shell: bash
- name: Store artifacts
uses: actions/upload-artifact@v6
with:
path: ./wheelhouse/*.whl
name: wheelhouse-${{ matrix.os }}-${{ matrix.python-version }}
name: ${{ github.job }}-wheelhouse-${{ matrix.os }}-${{ github.run_id }}
if-no-files-found: warn
overwrite: true
retention-days: 1

Comment thread
bact marked this conversation as resolved.
build_sdist:
name: Build source distribution
Expand All @@ -131,16 +138,25 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.14" # Check with PyO3's maximum supported version
python-version: "3.14" # Ideally matches with the python-version in build_wheels
cache: "pip"
- name: Build source distribution
run: |
cd nlpo3-python
bash ../build_tools/github/build_source.sh
- name: List sdist files
run: |
echo "Files to upload (sdist):"
find nlpo3-python/dist -maxdepth 1 -type f -name '*.tar.gz' -print | sort || true
echo "Count: $(find nlpo3-python/dist -maxdepth 1 -type f -name '*.tar.gz' -print | wc -l || true)"
shell: bash
- name: Store artifacts
uses: actions/upload-artifact@v6
with:
path: nlpo3-python/dist/*.tar.gz
name: sdist
overwrite: true
retention-days: 1

Comment thread
bact marked this conversation as resolved.
publish_pypi:
name: Publish to PyPI
Expand All @@ -151,11 +167,11 @@ jobs:
# Alternatively, upload to PyPI on every tag starting with 'v':
#if: github.event_name == 'push' && startsWith(github.event.ref, 'v')
steps:
- name: Retrieve artifacts
- name: Retrieve all artifacts
uses: actions/download-artifact@v6
with:
name: artifact
path: dist
merge-multiple: true
- name: Publish package
uses: pypa/gh-action-pypi-publish@v1.13.0
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v6

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -58,7 +58,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -72,4 +72,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
27 changes: 9 additions & 18 deletions .github/workflows/test-nlpo3-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,19 @@ jobs:
uses: actions/checkout@v6

- name: Setup Rust toolchain - non-win32
uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
toolchain: stable
if: ${{ !startsWith(matrix.os, 'windows') || matrix.bitness != '32' }}
uses: actions-rust-lang/setup-rust-toolchain@v1
if: "!startsWith(matrix.os, 'windows') || matrix.bitness != '32'"

- name: Setup Rust toolchain - win32
uses: actions-rs/toolchain@v1
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
override: true
profile: minimal
toolchain: stable
target: i686-pc-windows-msvc
if: startsWith(matrix.os, 'windows') && matrix.bitness == '32'

- name: Setup Rust dependencies
uses: actions-rs/cargo@v1
with:
command: check
- name: Test - non-win32
run: cargo test
if: "!startsWith(matrix.os, 'windows') || matrix.bitness != '32'"

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
- name: Test - win32
run: cargo test --target i686-pc-windows-msvc
if: startsWith(matrix.os, 'windows') && matrix.bitness == '32'
2 changes: 1 addition & 1 deletion .github/workflows/test-nlpo3-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defaults:
jobs:
test:
strategy:
fail-fast: false
fail-fast: true
matrix:
Comment thread
bact marked this conversation as resolved.
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ["3.14", "3.13", "3.12", "3.11", "3.10", "3.9"]
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ SPDX-License-Identifier: Apache-2.0
[![Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg "Apache-2.0")](https://opensource.org/license/apache-2-0)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14082448.svg)](https://doi.org/10.5281/zenodo.14082448)

A Thai natural language processing library written in Rust,
with optional Python and Node.js bindings. Formerly known as `oxidized-thainlp`.
A Thai natural language processing library written in Rust with optional
Python and Node.js bindings. Formerly known as `oxidized-thainlp`.

To use as a library in a Rust project:
Using in a Rust project

```shell
cargo add nlpo3
```

To use as a library in a Python project:
Using in a Python project

```shell
pip install nlpo3
Expand Down Expand Up @@ -75,26 +75,25 @@ See more at [nlpo3-python](./nlpo3-python/).

[![crates.io](https://img.shields.io/crates/v/nlpo3.svg "crates.io")](https://crates.io/crates/nlpo3/)

#### Add to dependency
#### Add as a dependency

To use as a library in a Rust project:
To add `nlpo3` to your project's dependencies:

```shell
cargo add nlpo3
```

It will add "nlpo3" to `Cargo.toml`:
This updates `Cargo.toml` with:

```toml
[dependencies]
# ...
nlpo3 = "1.4.0"
```

#### Example

Create a tokenizer using a dictionary from file,
then use it to tokenize a string (safe mode = true, and parallel mode = false):
Create a tokenizer from a dictionary file and use it to tokenize a string
(safe mode = true, parallel mode = false):

```rust
use nlpo3::tokenizer::newmm::NewmmTokenizer;
Expand All @@ -104,7 +103,7 @@ let tokenizer = NewmmTokenizer::new("path/to/dict.file");
let tokens = tokenizer.segment("ห้องสมุดประชาชน", true, false).unwrap();
```

Create a tokenizer using a dictionary from a vector of Strings:
Create a tokenizer from a vector of strings:

```rust
let words = vec!["ปาลิเมนต์".to_string(), "คอนสติติวชั่น".to_string()];
Expand Down
3 changes: 2 additions & 1 deletion nlpo3-nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ For now, copy the whole `nlpo3/` directory after build to your project.

### npm (experitmental)

npm is still experimental and may not work on all platforms. Please report issues at <https://github.com/PyThaiNLP/nlpo3/issues>
npm is still experimental and may not work on all platforms.
Please report issues at <https://github.com/PyThaiNLP/nlpo3/issues>

```shell
npm i nlpo3
Expand Down
10 changes: 9 additions & 1 deletion nlpo3-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ authors = [
]
description = "Python binding for nlpO3 Thai language processing library"
categories = ["text-processing"]
keywords = ["thai", "tokenizer", "nlp", "word-segmentation", "python"]
keywords = [
"thai",
"tokenizer",
"tokenization",
"text-processing",
"nlp",
"word-segmentation",
"pythainlp",
]
homepage = "https://github.com/PyThaiNLP/nlpo3/tree/main/nlpo3-python"
repository = "https://github.com/PyThaiNLP/nlpo3/"
documentation = "https://github.com/PyThaiNLP/nlpo3/blob/main/nlpo3-python/README.md"
Expand Down
11 changes: 11 additions & 0 deletions nlpo3-python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
include LICENSE README.md pyproject.toml Cargo.toml
recursive-include src *

# Ensure the Python package files are included in the sdist
graft nlpo3

# Include PEP 561 marker and type stubs for compiled extension
include nlpo3/py.typed
recursive-include nlpo3 *.pyi

# Exclude test notebooks and tests from the sdist to keep it small
prune tests
prune notebooks
Loading
Loading