Skip to content

Commit 6ebdcf0

Browse files
committed
refactor: arguments
1 parent f70ec63 commit 6ebdcf0

6 files changed

Lines changed: 11 additions & 14 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@
3333

3434
# Python cache
3535
__pycache__/
36+
37+
# Generated turtle files
38+
*.ttl

justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ test *args:
5757

5858
# Run an executable.
5959
run *args:
60-
uv run --env-file=.env cli "$@"
60+
# uv run --env-file=.env cli "$@"
61+
uv run --env-file=.env cli2 "$@"
6162

6263
# Run the Jupyter notebook.
6364
notebook *args:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dev = [
2323

2424
[project.scripts]
2525
cli = 'strings2things.cli:main'
26+
cli2 = 'strings2things.cli2:main'
2627

2728
[build-system]
2829
requires = ["hatchling"]

src/strings2things/cli2.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import glob
33
import argparse
44
import rdflib
5-
from config import args
5+
from strings2things.config import args
66
from strings2things.sparql import (
77
strings_to_things_query,
88
things_to_strings_query
@@ -36,7 +36,7 @@ def initialize_graphs(ontology_path, kg_path, ontology_uri, kg_uri):
3636
return dataset
3737

3838

39-
def strings_to_things(dataset, output_file="subgraph.ttl"):
39+
def strings_to_things(dataset, output_file=args.output):
4040
"""
4141
Replace human-readable strings in the KG with ontology IRIs based on matches.
4242
"""
@@ -50,7 +50,7 @@ def strings_to_things(dataset, output_file="subgraph.ttl"):
5050
print(f"Strings replaced with IRIs and written to {output_file} ({len(new_graph)} triples).")
5151

5252

53-
def things_to_strings(dataset, output_file="output.ttl"):
53+
def things_to_strings(dataset, output_file=args.output):
5454
"""
5555
Replace IRIs in the KG with human-readable labels using the ontology.
5656
"""
@@ -65,14 +65,6 @@ def things_to_strings(dataset, output_file="output.ttl"):
6565

6666

6767
def main():
68-
parser = argparse.ArgumentParser(description="Convert between strings and ontology terms.")
69-
parser.add_argument("direction", choices=["string2thing", "thing2string"], help="Conversion direction")
70-
parser.add_argument("--ontology", required=True, help="Path to ontology files directory")
71-
parser.add_argument("--kg", required=True, help="Path to knowledge graph files directory")
72-
parser.add_argument("--ontology-uri", default="https://imaging-plaza.epfl.ch/ontology#", help="Named graph URI for ontology")
73-
parser.add_argument("--kg-uri", default="https://imaging-plaza.epfl.ch/finalGraph", help="Named graph URI for knowledge graph")
74-
args = parser.parse_args()
75-
7668
dataset = initialize_graphs(args.ontology, args.kg, args.ontology_uri, args.kg_uri)
7769

7870
if args.direction == "string2thing":

src/strings2things/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
parser.add_argument("--kg", required=True, help="Path to knowledge graph files directory")
77
parser.add_argument("--ontology-uri", default="https://imaging-plaza.epfl.ch/ontology#", help="Named graph URI for ontology")
88
parser.add_argument("--kg-uri", default="https://imaging-plaza.epfl.ch/finalGraph", help="Named graph URI for knowledge graph")
9+
parser.add_argument("-o", "--output", default="output.ttl", help="Output file for the converted graph")
910
args = parser.parse_args()

src/strings2things/sparql.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import os
21
from dotenv import load_dotenv
3-
from config import args
2+
from strings2things.config import args
43

54
# Load environment variables from the .env file
65
load_dotenv()

0 commit comments

Comments
 (0)