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
16 changes: 11 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v3
- name: Publish to pypi
uses: JRubics/poetry-publish@v1.16
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
- name: Check out repository
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Build
run: uv build

- name: Publish to pypi
run: uv publish --token ${{ secrets.PYPI_TOKEN }}
34 changes: 8 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,22 @@ jobs:

strategy:
matrix:
python-version: ["3.10"]
python-version: ["3.12"]

steps:
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
python-version: ${{ matrix.python-version }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Install project
run: poetry install --no-interaction
run: uv sync

- name: Lint
run: make pysen-lint
run: make lint

- name: Test
run: make pytest
run: make test
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
FROM ubuntu:22.04

RUN apt update -y \
&& apt install -y python3 python3-dev python3-pip \
&& rm -rf /var/lib/apt/lists
FROM ghcr.io/astral-sh/uv:python3.12-bookworm

WORKDIR /work
COPY pyproject.toml poetry.lock ./
COPY pyproject.toml uv.lock ./

RUN pip3 install -U pip \
&& pip3 install poetry \
&& poetry install
RUN uv sync --frozen --no-install-project

CMD ["/bin/bash"]
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ remove-image:
remove-container:
docker rm -f $(CONTAINER_NAME)

pytest:
env PYTHONPATH=. poetry run pytest -vv
test:
uv run pytest -vv

pysen-lint:
poetry run pysen run lint
lint:
uv run ruff check .
uv run ruff format --check .
uv run mypy

pysen-format:
poetry run pysen run format
format:
uv run ruff check --fix .
uv run ruff format .
3 changes: 2 additions & 1 deletion ncnc/c_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from typing import List

import pandas as pd
from ncnc.logging import logger
from tqdm import tqdm

from ncnc.logging import logger


def calc_c_value(df: pd.DataFrame) -> pd.DataFrame:
ngrams = df.index.values
Expand Down
8 changes: 5 additions & 3 deletions ncnc/nc_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from typing import Dict

import pandas as pd
from ncnc.logging import logger
from tqdm import tqdm

from ncnc.logging import logger


def calc_nc_value(df: pd.DataFrame, n: int = 100) -> pd.DataFrame:
logger.info('started setting df["nc-value"]')
Expand All @@ -20,7 +21,8 @@ def _extract_context(df: pd.DataFrame, n: int = 100) -> Dict[str, float]:

n = min(n, len(df))

# use the top candidate terms from the C-value list as pseudo real terms (see 3.4 in the paper)
# use the top candidate terms from the C-value list as pseudo real terms
# (see 3.4 in the paper)
df = df.sort_values(by="c-value", ascending=False)[:n]

# ngram => "basal cell carcinoma"
Expand Down Expand Up @@ -67,7 +69,7 @@ def _extract_context(df: pd.DataFrame, n: int = 100) -> Dict[str, float]:
return context_to_weight


def replaced_string(match: re.Match) -> str:
def replaced_string(match: re.Match[str]) -> str:
if not match.group(0).startswith(" "):
return "[term] "
elif not match.group(0).endswith(" "):
Expand Down
Loading
Loading