Skip to content

Commit

Permalink
Merge pull request #1 from nestauk/add-structure
Browse files Browse the repository at this point in the history
Begin project
  • Loading branch information
lizgzil authored Jul 26, 2024
2 parents 8e72832 + e50c769 commit d7d695e
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy docs to gh-pages

on:
workflow_dispatch:
push:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest
name: Deploy docs to gh-pages
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Deploy
uses: mhausenblas/mkdocs-deploy-gh-pages@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CONFIG_FILE: docs/mkdocs.yml
REQUIREMENTS: docs/site_assets/requirements.txt
57 changes: 57 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Unit Tests

on: [push]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
python-version: ["3.9", "3.10"]
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- 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') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install additional dependencies
run: |
poetry install --no-interaction
#----------------------------------------------
# add matrix specifics and run test suite
#----------------------------------------------
- name: Run tests
run: poetry run pytest tests/ --verbose
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Mac OS-specific storage files
.DS_Store

__pycache__/
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
require_serial: true

- repo: https://github.com/prettier/pre-commit
rev: v2.1.2
hooks:
- id: prettier
10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

The MIT License (MIT)
=====================
Copyright (c) 2024, Nesta

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# nlp-link

A python package to semantically link two lists of texts.

## Set-up

In setting up this project we ran:

```
conda create --name nlp-link pip python=3.9
conda activate nlp-link
pip install poetry
pip install pre-commit black
pre-commit install
```

```
poetry init
```

```
poetry install
```

## Tests

To run tests:

```
poetry run pytest tests/
```

## Documentation

Docs for this repo are automatically published to gh-pages branch via. Github actions after a PR is merged into dev. We use Material for MkDocs for these. Nothing needs to be done to update these.

However, if you are editing the docs you can test them out locally by running

```
cd guidelines
pip install -r docs/requirements.txt
mkdocs serve
```
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# nlp-link

Documentation for NLP Link

- [Page1](./page1.md)
44 changes: 44 additions & 0 deletions docs/mkdocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
site_name: NLP Link
site_description: A python package to semantically link two lists of texts..
site_url: https://nestauk.github.io/nlp-link
repo_name: nestauk/nlp-link
repo_url: https://github.com/nestauk/nlp-link
extra:
homepage: https://nestauk.github.io/nlp-link
docs_dir: .
extra_css:
- site_assets/style.css
theme:
name: material
# disable_nav_previous_next: true
# disable_footer: false
logo: site_assets/nesta_logo.png
favicon: site_assets/nesta_logo.png
features:
- navigation.instant
- navigation.tracking
# - navigation.tabs
- navigation.sections
- navigation.top
font:
text: Century Gothic
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
primary: custom
accent: custom
toggle:
icon: material/weather-night
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: amber
accent: pink
toggle:
icon: material/weather-sunny
name: Switch to light mode
nav:
- Home: README.md
- Page 1: page1.md
plugins:
- same-dir
1 change: 1 addition & 0 deletions docs/page1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Title
Binary file added docs/site_assets/nesta_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/site_assets/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mkdocs
mkdocs-material
mkdocs-same-dir
10 changes: 10 additions & 0 deletions docs/site_assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import url("https://fonts.cdnfonts.com/css/century-gothic");
html,
body,
[class*="css"] {
font-family: "Century Gothic";
}
:root {
--md-primary-fg-color: #18a48c;
--md-accent-fg-color: #eb003b;
}
Empty file added nlp_link/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions nlp_link/linker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pandas as pd
import random


def link_lists(list_1, list_2):
"""
Mock linker
"""
list_1_index = list(range(len(list_1)))
list_2_index = list(range(len(list_2)))

return [(i, random.choice(list_1_index)) for i in list_2_index]
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "nlp-link"
version = "0.1.0"
description = "A python package to semantically link two lists of texts."
authors = ["Nesta <[email protected]>"]
readme = "README.md"
packages = [{include = "nlp_link"}]

[tool.poetry.dependencies]
python = "^3.9"
scikit-learn = "^1.4.2"
pandas = "^2.2.2"
sentence-transformers = "^2.1.0"
torch = "^1.10.0"
pytest = "^8.2.0"
tqdm = "^4.64.1"
numpy = "^1.24.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/test_linker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from nlp_link.linker import link_lists


def test_link_lists():

list_1 = ["dog", "cat"]
list_2 = ["kitten", "puppy"]
linked = link_lists(list_1, list_2)

assert len(linked) == len(list_1)

0 comments on commit d7d695e

Please sign in to comment.