Skip to content

Commit

Permalink
feat: LangChain Matching (#2)
Browse files Browse the repository at this point in the history
* LangChain based matching
* Basic boolean output parser
* CLI for experimenting
* Hard coded prompt
  • Loading branch information
cbolles authored Jun 17, 2024
1 parent 208d4a7 commit 331c296
Show file tree
Hide file tree
Showing 17 changed files with 1,768 additions and 7 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/frp-cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: FRP-cli

on:
workflow_dispatch:
push:
paths:
- 'packages/frp-cli/**'
branches:
- main
tags:
- "v*.*.*"
pull_request:
paths:
- 'packages/frp-cli/**'
branches:
- main


jobs:
lint:
runs-on: ubuntu-latest
name: Check for Linting Errors
defaults:
run:
working-directory: packages/frp-cli

steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.9"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with dev
- name: Lint
run: poetry run flake8

build:
runs-on: ubuntu-latest
name: Build
defaults:
run:
working-directory: packages/frp-cli

steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.9"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
cd ../frp
poetry install
cd ../frp-cli
poetry install --with dev
- name: Build
run: poetry build

type-checking:
runs-on: ubuntu-latest
name: Run Type Checking
defaults:
run:
working-directory: packages/frp-cli

steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.9"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
cd ../frp
poetry config virtualenvs.create false
poetry install
cd ../frp-cli
poetry install --with dev
- name: Type Checking
run: poetry run mypy frp_cli/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
venv/
__pycache__/
3 changes: 3 additions & 0 deletions packages/frp-cli/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 160
per-file-ignores = __init__.py:F401
3 changes: 3 additions & 0 deletions packages/frp-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
*.pyc
data/
Empty file added packages/frp-cli/README.md
Empty file.
1 change: 1 addition & 0 deletions packages/frp-cli/frp_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from frp_cli.main import main
68 changes: 68 additions & 0 deletions packages/frp-cli/frp_cli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from argparse import ArgumentParser, BooleanOptionalAction
from pathlib import Path
from frp import FRPScholarlyAnalysis, Matcher


def scholarly_analysis(input_csv: Path, frp_title: str, frp_year: int, save_results: bool, save_output: Path) -> None:
if not input_csv.exists():
print('File {} does not exist'.format(input_csv))
exit(1)

# Make the matcher
matcher = Matcher()

# Run the analysis
analyzer = FRPScholarlyAnalysis(matcher)

# Collect the results
results = analyzer.run_frp_analysis(input_csv, frp_title, frp_year)

# If the user wants the data saved, save it to the output location
if save_results:
results.to_csv(save_output)

print(results['Part of FRP'])


def main():
parser = ArgumentParser()

# Sub parser for the different commands
sub_parser = parser.add_subparsers(dest='command', required=True)

# Command: scholarly
scholarly_parser = sub_parser.add_parser('scholarly')
scholarly_parser.add_argument('--input',
required=True,
help='Input CSV')
scholarly_parser.add_argument('--frp-title',
required=False,
default='Leveraging AI to Examine Disparities and Bias in Health Care',
help='Name of the FRP to run matching against')
scholarly_parser.add_argument('--frp-year',
required=False,
default=2022,
type=int,
help='Year to start (inclusive) considering articles')
scholarly_parser.add_argument('--save-output',
required=False,
default=False,
action=BooleanOptionalAction,
help='Flag if the results of the matching should be stored')
scholarly_parser.add_argument('--output-csv',
required=False,
default='data/scholarly_matching_results.csv',
help='Where to store the results of the matching')

args = parser.parse_args()

# Determine the correct command to run
if args.command == 'scholarly':
scholarly_analysis(Path(args.input), args.frp_title, args.frp_year, args.save_output, Path(args.output_csv))
return
else:
print('Command {} not recognized'.format(args.command))


if __name__ == '__main__':
main()
Loading

0 comments on commit 331c296

Please sign in to comment.