Enhance edge type handling and categorization
- Added optional description and category fields to edge type entries, improving metadata for edge types. - Updated the `getAllEdgeTypes` and `groupEdgeTypesByCategory` functions to utilize new fields for better organization and display. - Enhanced UI components to show descriptions as tooltips and categorize edge types in the EdgeTypeChooserModal and InlineEdgeTypeModal. - Improved parsing logic in `parseEdgeVocabulary` to extract descriptions and categories from the vocabulary table, ensuring richer edge type data. - Adjusted the LinkPromptModal to clarify edge type actions and maintain alias information during selection.
This commit is contained in:
1 parent
7ea36fbed4
commit
2fcf333e56
7 files changed
+353
-68
No files matched your search
@@ -19,12 +19,20 @@ const BACKTICK_RE = /`([^`]+)`/g;
|
||||
*/
|
||||
export function parseEdgeVocabulary(md: string): EdgeVocabulary {
|
||||
const lines = md.split(/\r?\n/);
|
||||
const byCanonical = new Map<string, { canonical: string; inverse?: string; aliases: string[] }>();
|
||||
const byCanonical = new Map<string, { canonical: string; inverse?: string; aliases: string[]; description?: string; category?: string }>();
|
||||
const aliasToCanonical = new Map<string, string>();
|
||||
|
||||
let skippedRows = 0;
|
||||
let currentCategory: string | null = null; // Track current H3 category
|
||||
|
||||
for (const line of lines) {
|
||||
// Detect H3 headings (###) as category separators
|
||||
const h3Match = line.match(/^###\s+(.+)$/);
|
||||
if (h3Match && h3Match[1]) {
|
||||
currentCategory = h3Match[1].trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip header separator rows (e.g., "| :--- | :--- |")
|
||||
if (/^\s*\|[\s:|-]+\|\s*$/.test(line)) {
|
||||
continue;
|
||||
@@ -35,6 +43,12 @@ export function parseEdgeVocabulary(md: string): EdgeVocabulary {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip header rows (contains "Canonical", "System-Typ", "Beschreibung", "Kategorie", etc.)
|
||||
// Check for common header keywords
|
||||
if (/canonical|system-typ|beschreibung|kategorie|category|description|inverser|aliasse/i.test(line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract all backticked tokens
|
||||
const tokens: string[] = [];
|
||||
let match: RegExpExecArray | null;
|
||||
@@ -54,6 +68,49 @@ export function parseEdgeVocabulary(md: string): EdgeVocabulary {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse table cells (split by |, skip first and last empty cells)
|
||||
const cells = line.split("|").map(c => c.trim()).filter(c => c);
|
||||
|
||||
// Extract description and category from cells
|
||||
// Expected order: Canonical | Inverse | Aliases | Description | Category (optional)
|
||||
let description: string | undefined = undefined;
|
||||
let category: string | undefined = undefined;
|
||||
|
||||
// Try to extract from cells after aliases (index 3+)
|
||||
// Description is usually the first text cell after aliases
|
||||
// Category might be in brackets, short, or in a separate column
|
||||
for (let i = 3; i < cells.length; i++) {
|
||||
const cell = cells[i];
|
||||
if (!cell || !cell.trim()) continue;
|
||||
|
||||
const trimmed = cell.trim();
|
||||
|
||||
// Check if this looks like a category:
|
||||
// - Short text (< 40 chars)
|
||||
// - Might be in brackets [Category]
|
||||
// - Might be all caps
|
||||
// - Might match category pattern
|
||||
const looksLikeCategory =
|
||||
trimmed.length < 40 && (
|
||||
/^\[.+\]$/.test(trimmed) || // [Category]
|
||||
trimmed === trimmed.toUpperCase() || // ALL CAPS
|
||||
/^[A-ZÄÖÜ][a-zäöüß]+(\s+[A-ZÄÖÜ][a-zäöüß]+)*$/.test(trimmed) // Title Case
|
||||
);
|
||||
|
||||
if (looksLikeCategory && !category) {
|
||||
// Remove brackets if present
|
||||
category = trimmed.replace(/^\[|\]$/g, "");
|
||||
} else if (!description && trimmed.length > 0) {
|
||||
// First substantial cell is likely description
|
||||
// Remove markdown formatting but keep content
|
||||
description = trimmed
|
||||
.replace(/\*\*/g, "") // Remove bold
|
||||
.replace(/\*/g, "") // Remove italic
|
||||
.replace(/`/g, "") // Remove code
|
||||
.trim();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if aliases cell contains "(Kein Alias)"
|
||||
const hasNoAliases = /\(Kein Alias\)/i.test(line);
|
||||
|
||||
@@ -76,11 +133,16 @@ export function parseEdgeVocabulary(md: string): EdgeVocabulary {
|
||||
}
|
||||
}
|
||||
|
||||
// Store canonical entry
|
||||
// Store canonical entry with description and category
|
||||
// Use currentCategory from H3 heading if available, otherwise use extracted category
|
||||
const finalCategory = currentCategory || category;
|
||||
|
||||
byCanonical.set(canonical, {
|
||||
canonical,
|
||||
inverse,
|
||||
aliases,
|
||||
description,
|
||||
category: finalCategory,
|
||||
});
|
||||
|
||||
// Build alias-to-canonical mapping (case-insensitive keys)
|
||||
@@ -95,7 +157,9 @@ export function parseEdgeVocabulary(md: string): EdgeVocabulary {
|
||||
}
|
||||
|
||||
if (skippedRows > 0) {
|
||||
console.warn(`parseEdgeVocabulary: Skipped ${skippedRows} rows with insufficient tokens`);
|
||||
// Only warn if there are actually problematic rows (not just header/separator rows)
|
||||
// Header and separator rows are expected and should not trigger warnings
|
||||
console.debug(`parseEdgeVocabulary: Skipped ${skippedRows} data rows with insufficient tokens (this is normal if the file contains empty or malformed table rows)`);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -4,6 +4,8 @@ export interface EdgeTypeEntry {
|
||||
canonical: CanonicalEdgeType;
|
||||
inverse?: CanonicalEdgeType;
|
||||
aliases: string[];
|
||||
description?: string; // Description from vocabulary table
|
||||
category?: string; // Category/group from vocabulary table
|
||||
}
|
||||
|
||||
export interface EdgeVocabulary {
|
||||
|
||||
Reference in new issue
Block a user