diff --git a/apps/web/components/atlas/pos-group.ts b/apps/web/components/atlas/pos-group.ts new file mode 100644 index 0000000..2fc2d3c --- /dev/null +++ b/apps/web/components/atlas/pos-group.ts @@ -0,0 +1,58 @@ +// Coarse POS bucket for the atlas's grouped layout. The atlas's POS +// strings come from kiri (Japanese tags like 動詞, 形容詞) and jmdict +// (English tags like "noun, common"), so this collapses both into a +// stable five-bucket alphabet that the hierarchical squarifier can +// pivot on. + +export type AtlasPosGroup = + | "verb" + | "adjective" + | "noun" + | "particle" + | "adverb" + | "other" + +const VERB_PATTERNS = [/動詞/, /\bv-/i, /\bv\b/i, /verb/i] +const ADJ_PATTERNS = [/形容詞/, /形状詞/, /adjective/i, /\badj\b/i] +const NOUN_PATTERNS = [/名詞/, /代名詞/, /\bnoun\b/i, /pronoun/i, /\bpron\b/i] +const PARTICLE_PATTERNS = [ + /助詞/, + /助動詞/, + /particle/i, + /copula/i, + /\bcop\b/i, + /auxiliary/i, + /\baux\b/i, +] +const ADVERB_PATTERNS = [/副詞/, /adverb/i, /\badv\b/i] + +export function posGroup(pos: string): AtlasPosGroup { + if (!pos) return "other" + if (VERB_PATTERNS.some((re) => re.test(pos))) return "verb" + if (ADJ_PATTERNS.some((re) => re.test(pos))) return "adjective" + if (NOUN_PATTERNS.some((re) => re.test(pos))) return "noun" + if (PARTICLE_PATTERNS.some((re) => re.test(pos))) return "particle" + if (ADVERB_PATTERNS.some((re) => re.test(pos))) return "adverb" + return "other" +} + +export const POS_GROUP_LABEL: Record = { + verb: "V", + adjective: "ADJ", + noun: "N", + particle: "PART", + adverb: "ADV", + other: "—", +} + +// Render order — puts the dense buckets first so they tend to land in +// the wider rows. squarify itself sorts by weight, so this is an +// aesthetic-stable secondary key only. +export const POS_GROUP_ORDER: AtlasPosGroup[] = [ + "noun", + "verb", + "adjective", + "adverb", + "particle", + "other", +] diff --git a/apps/web/components/atlas/types.ts b/apps/web/components/atlas/types.ts new file mode 100644 index 0000000..d81a958 --- /dev/null +++ b/apps/web/components/atlas/types.ts @@ -0,0 +1,5 @@ +import type { AtlasEntry } from "@yominoki/db/queries/treemap" +import type { Laid } from "@/lib/squarify" + +export type LaidAtlasEntry = Laid +export type { AtlasEntry } diff --git a/apps/web/lib/server/atlas.ts b/apps/web/lib/server/atlas.ts new file mode 100644 index 0000000..0471c67 --- /dev/null +++ b/apps/web/lib/server/atlas.ts @@ -0,0 +1,9 @@ +import { listAtlas, type AtlasEntry } from "@yominoki/db/queries/treemap" +import { getOps } from "@/lib/db" + +export async function getAtlas( + userId: string, + level: 1 | 2 | 3 | 4 | 5 +): Promise { + return listAtlas(getOps(), userId, level) +}