|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * External Parser Allowlist Configuration. |
| 5 | + * |
| 6 | + * SECURITY: This file defines which external programs can be executed for text parsing. |
| 7 | + * Only server administrators should modify this file. Never allow user input to determine |
| 8 | + * parser paths or arguments. |
| 9 | + * |
| 10 | + * PHP version 8.1 |
| 11 | + * |
| 12 | + * @category Configuration |
| 13 | + * @package Lwt\Config |
| 14 | + * @author HugoFara <[email protected]> |
| 15 | + * @license Unlicense <http://unlicense.org/> |
| 16 | + * @link https://hugofara.github.io/lwt/docs/php/ |
| 17 | + * @since 3.0.0 |
| 18 | + */ |
| 19 | + |
| 20 | +declare(strict_types=1); |
| 21 | + |
| 22 | +/** |
| 23 | + * External parser configurations. |
| 24 | + * |
| 25 | + * Each parser entry is keyed by a unique type identifier and contains: |
| 26 | + * |
| 27 | + * - 'name' (string, required): Human-readable name displayed in the UI |
| 28 | + * - 'binary' (string, required): Path to executable. Can be: |
| 29 | + * - Absolute path: '/usr/bin/python3' |
| 30 | + * - Command name: 'python3' (uses system PATH) |
| 31 | + * - 'args' (array, optional): Command-line arguments passed to the binary |
| 32 | + * - 'input_mode' (string, optional): How text is passed to the parser: |
| 33 | + * - 'stdin' (default): Text is piped to stdin |
| 34 | + * - 'file': Text is written to a temp file, path appended as last argument |
| 35 | + * - 'output_format' (string, optional): How parser output is interpreted: |
| 36 | + * - 'line' (default): One token per line |
| 37 | + * - 'wakati': Space-separated tokens (like MeCab wakati mode) |
| 38 | + * |
| 39 | + * Built-in parsers (regex, character, mecab) are always available and do not |
| 40 | + * need to be configured here. This file is for adding additional external parsers. |
| 41 | + * |
| 42 | + * Example configurations: |
| 43 | + * |
| 44 | + * return [ |
| 45 | + * 'jieba' => [ |
| 46 | + * 'name' => 'Jieba (Chinese)', |
| 47 | + * 'binary' => '/usr/bin/python3', |
| 48 | + * 'args' => ['/opt/lwt/parsers/jieba_tokenize.py'], |
| 49 | + * 'input_mode' => 'stdin', |
| 50 | + * 'output_format' => 'line', |
| 51 | + * ], |
| 52 | + * |
| 53 | + * 'sudachi' => [ |
| 54 | + * 'name' => 'Sudachi (Japanese)', |
| 55 | + * 'binary' => 'sudachipy', |
| 56 | + * 'args' => ['-m', 'C', '-a'], |
| 57 | + * 'input_mode' => 'stdin', |
| 58 | + * 'output_format' => 'wakati', |
| 59 | + * ], |
| 60 | + * |
| 61 | + * 'custom_tokenizer' => [ |
| 62 | + * 'name' => 'Custom Tokenizer', |
| 63 | + * 'binary' => '/opt/lwt/bin/tokenize', |
| 64 | + * 'args' => ['--format=simple'], |
| 65 | + * 'input_mode' => 'file', |
| 66 | + * 'output_format' => 'line', |
| 67 | + * ], |
| 68 | + * ]; |
| 69 | + */ |
| 70 | +return [ |
| 71 | + // Jieba - Chinese word segmentation |
| 72 | + // Requires: Python 3, jieba package |
| 73 | + // Docker: Included by default |
| 74 | + // Manual: pip install jieba |
| 75 | + 'jieba' => [ |
| 76 | + 'name' => 'Jieba (Chinese)', |
| 77 | + 'binary' => '/opt/lwt-parsers/bin/python3', |
| 78 | + 'args' => ['/opt/lwt/parsers/jieba_tokenize.py'], |
| 79 | + 'input_mode' => 'stdin', |
| 80 | + 'output_format' => 'line', |
| 81 | + ], |
| 82 | + |
| 83 | + // MeCab Python - Japanese morphological analyzer |
| 84 | + // Requires: Python 3, mecab-python3 package, system MeCab with dictionary |
| 85 | + // Docker: Included by default |
| 86 | + // Manual: apt-get install mecab mecab-ipadic-utf8 && pip install mecab-python3 |
| 87 | + 'mecab-python' => [ |
| 88 | + 'name' => 'MeCab Python (Japanese)', |
| 89 | + 'binary' => '/opt/lwt-parsers/bin/python3', |
| 90 | + 'args' => ['/opt/lwt/parsers/mecab_tokenize.py'], |
| 91 | + 'input_mode' => 'stdin', |
| 92 | + 'output_format' => 'line', |
| 93 | + ], |
| 94 | +]; |
0 commit comments