Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
create python directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuhey committed Dec 31, 2019
1 parent 34996f5 commit ce8774c
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ unicode-normalization = "0.1.8"
[dev-dependencies]
itertools = "0.8.2"
quickcheck = "0.8"
quickcheck_macros = "0.8"
quickcheck_macros = "0.8"
128 changes: 128 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
### https://raw.github.com/github/gitignore/499ae899e7b54e701e878759f73d9092302fd07a/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/


19 changes: 19 additions & 0 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "python"
version = "0.1.0"
authors = ["Yohei Tamura <[email protected]>"]
edition = "2018"

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

[dependencies]
tokenizations = { path = ".." }


[lib]
name = "tokenizations"
crate-type = ["cdylib"]

[dependencies.pyo3]
version = "0.8.4"
features = ["extension-module"]
3 changes: 3 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["maturin"]
build-backend = "maturin"
3 changes: 3 additions & 0 deletions python/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
hypothesis
black
17 changes: 17 additions & 0 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use tokenizations::{get_alignments, Alignment};

#[pymodule]
fn tokenizations(py: Python, m: &PyModule) -> PyResult<()> {
#[pyfn(m, "get_alignments")]
pub fn get_alignments_py(
_py: Python,
a: Vec<&str>,
b: Vec<&str>,
) -> PyResult<(Alignment, Alignment)> {
Ok(get_alignments(&a, &b))
}

Ok(())
}
Empty file added python/tests/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ extern crate unicode_normalization;
use std::collections::HashMap;
use unicode_normalization::UnicodeNormalization;

pub type Alignment = Vec<Vec<usize>>;

fn normalize(text: &str) -> String {
text.nfkd().collect()
}
Expand Down Expand Up @@ -204,8 +206,6 @@ fn get_alignment(
at2bt
}

type Alignment = Vec<Vec<usize>>;

pub fn get_alignments(a: &[&str], b: &[&str]) -> (Alignment, Alignment) {
let a: Vec<String> = a.iter().map(|x| normalize(*x)).collect();
let b: Vec<String> = b.iter().map(|x| normalize(*x)).collect();
Expand Down

0 comments on commit ce8774c

Please sign in to comment.