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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data/
/data/
artifacts/*
!artifacts/*.json
*.pkl
Expand Down
33 changes: 30 additions & 3 deletions api/artifacts.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import csv
import json
from typing import Any

from etl.paths import ARTIFACTS_DIR
from etl.paths import ARTIFACTS_DIR, TAXONOMY_DIR


class ArtifactsManager:
def __init__(self):
self.vocab: dict[str, Any] = {}
self.autocomplete: list[dict[str, Any]] = []
self.role_profiles: dict[str, Any] = {}
self.name_to_display: dict[str, str] = {}
self.artifacts_loaded = False

self.n_skills = 0
Expand All @@ -18,17 +20,42 @@ def __init__(self):
self.model_version: str | None = None
self.rules_version: str | None = None

def get_display_name(self, name: str) -> str:
s = name.lower().strip()
return self.name_to_display.get(s, name.title() if not name.isupper() else name)

def load(self):
vocab_path = ARTIFACTS_DIR / "skill_vocab.json"
if vocab_path.exists():
with open(vocab_path, "r") as f:
with open(vocab_path, "r", encoding="utf-8") as f:
self.vocab = json.load(f)
self.n_skills = len(self.vocab)

autocomplete_path = ARTIFACTS_DIR / "skills_autocomplete.json"
if autocomplete_path.exists():
with open(autocomplete_path, "r") as f:
with open(autocomplete_path, "r", encoding="utf-8") as f:
self.autocomplete = json.load(f)

self.name_to_display = {
item["name"].lower(): item.get("display", item["name"].title())
for item in self.autocomplete
}

overrides_path = TAXONOMY_DIR / "display_overrides.csv"
if overrides_path.exists():
with open(overrides_path, "r", encoding="utf-8") as f:
reader = csv.reader(f)
next(reader, None)
for row in reader:
if len(row) >= 2:
k, v = row[0].strip().lower(), row[1].strip()
if k and v:
self.name_to_display[k] = v

for item in self.autocomplete:
k = item["name"].lower()
if k in self.name_to_display:
item["display"] = self.name_to_display[k]

roles_path = ARTIFACTS_DIR / "role_profiles.json"
if roles_path.exists():
Expand Down
2 changes: 1 addition & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def lifespan(app: FastAPI):
cached_roles.append(schemas.RoleResponse(
role_family=role,
n_postings=details.get("n_postings", 0),
top_skills=details.get("top_skills", [])
top_skills=[artifacts.get_display_name(s) for s in details.get("top_skills", [])]
))

yield
Expand Down
Loading
Loading