Skip to content

Commit

Permalink
GH-185: implement rust for CRFFeaturizer (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
rain1024 authored Nov 15, 2021
1 parent cceeda0 commit dbc9153
Show file tree
Hide file tree
Showing 15 changed files with 893 additions and 21 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/release-pypi-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
on:
push:
branches: [ GH-185 ]

jobs:
build:
name: Build rust
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v1
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Install dependencies
run: |
python -m pip install --upgrade pip
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
- name: Add poetry to path
run: echo "${HOME}/.poetry/bin" >> $GITHUB_PATH
- name: Install package deps
working-directory: ./extensions/underthesea_core
run: |
poetry install
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Build Python package
working-directory: ./extensions/underthesea_core
run: poetry run maturin develop --release
pypi-publish:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Install dependencies
working-directory: ./extensions/underthesea_core
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Build Python package
working-directory: ./extensions/underthesea_core
run: poetry run maturin build --release --no-sdist --strip --interpreter python${{ matrix.python-version }}
- name: List wheels
working-directory: ./extensions/underthesea_core
run: find ./target/wheels/
- name: Install wheels
working-directory: ./extensions/underthesea_core
run: pip install target/wheels/underthesea_core*.whl
- name: PyPi publish
working-directory: ./extensions/underthesea_core
env:
MATURIN_PASSWORD: ${{ secrets.PYPI_UNDERTHESEA_CORE_API_TOKEN }}
run: poetry run maturin publish --username __token__
42 changes: 21 additions & 21 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ jobs:
name: Build and package Pypi
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v1
with:
python-version: 3.6
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Checkout master
uses: actions/checkout@v1
with:
python-version: 3.6
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
1 change: 1 addition & 0 deletions extensions/underthesea_core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cargo.lock
24 changes: 24 additions & 0 deletions extensions/underthesea_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "underthesea_core"
version = "0.0.4-alpha.6"
authors = ["Vu Anh <[email protected]>"]
description = "Underthesea Core (fast & fun)"
license = "GPL-3.0"
edition = "2021"
readme = "README.md"
repository = "https://github.com/undertheseanlp/underthesea/"
homepage = "https://github.com/undertheseanlp/underthesea/"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = [ "derive" ] }
regex = "1"

[dependencies.pyo3]
version = "0.15.0"
features = ["extension-module"]

[lib]
name = "underthesea_core"
crate-type = ["cdylib"]
1 change: 1 addition & 0 deletions extensions/underthesea_core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Underthesea Core (fast & fun)
22 changes: 22 additions & 0 deletions extensions/underthesea_core/lab_underthesea_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from underthesea_core import CRFFeaturizer
print("-------------------")
print("Test underthesea_core")


sentences = [
[["Chàng", "X"], ["trai", "X"], ["9X", "X"]],
[["Khởi", "X"], ["nghiệp", "X"], ["từ", "X"]],
[["trường", "X"], ["học", "X"], ["từ", "X"]]
]
feature_configs = [
"T[0]", "T[1]", "T[2]",
"T[0,1].is_in_dict"
]
dictionary = set(["Chàng", "trai", "trường học"])

# print("Call featurizer function")
# print(featurizer(sentences, feature_configs, dictionary))

print("Call CRFFeaturizer function")
crf_featurizer = CRFFeaturizer(feature_configs, dictionary)
print(crf_featurizer.process(sentences))
38 changes: 38 additions & 0 deletions extensions/underthesea_core/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions extensions/underthesea_core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "underthesea_core"
version = "0.0.4-alpha.6"
authors = ["Vu Anh <[email protected]>"]
description = "Underthesea Core (fast & fun)"
license = "GPL-3.0"
readme = "README.md"
repository = "https://github.com/undertheseanlp/underthesea/"
homepage = "https://github.com/undertheseanlp/underthesea/"

[tool.poetry.dependencies]
python = "^3.5"

[tool.poetry.dev-dependencies]
maturin = "==0.9.4"

[build-system]
requires = ["==0.9.4"]
build-backend = "maturin"
Loading

0 comments on commit dbc9153

Please sign in to comment.