-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement ChunkingRuleParser for file type and service mapping
- Loading branch information
Showing
3 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
type ChunkingService = 'unstructured' | 'doc2x' | 'default'; | ||
|
||
interface FileTypeRule { | ||
fileType: string; | ||
services: ChunkingService[]; | ||
} | ||
|
||
export class ChunkingRuleParser { | ||
static parse(rulesStr: string): Record<string, ChunkingService[]> { | ||
const rules: Record<string, ChunkingService[]> = {}; | ||
|
||
// Split by semicolon for different file types | ||
const fileTypeRules = rulesStr.split(';'); | ||
|
||
for (const rule of fileTypeRules) { | ||
const [fileType, services] = rule.split('='); | ||
if (!fileType || !services) continue; | ||
|
||
// Split services by comma and validate each service | ||
rules[fileType.toLowerCase()] = services | ||
.split(',') | ||
.map(s => s.trim().toLowerCase()) | ||
.filter((s): s is ChunkingService => | ||
['unstructured', 'doc2x', 'default'].includes(s)); | ||
} | ||
|
||
return rules; | ||
} | ||
} |