FSW
Formal SignWriting (FSW) parsing, composition, and helpers.
Functions
Sgnw\Core\Fsw\fsw_structure_kind
function fsw_structure_kind()
The fsw module contains functions for handling Formal SignWriting in ASCII (FSW) characters.
FSW characters definition:
https://datatracker.ietf.org/doc/id/draft-slevinski-formal-signwriting-10.html#name-formal-signwriting-in-ascii
Sgnw\Core\Fsw\fsw_structure_category
function fsw_structure_category()
Sgnw\Core\Fsw\fsw_structure_group
function fsw_structure_group()
Sgnw\Core\Fsw\fsw_structure_ranges
function fsw_structure_ranges()
Sgnw\Core\Fsw\fsw_is_type
function fsw_is_type($sym_key, $type_name)
Test whether an FSW symbol key is of the given type/range.
Parameters
| Parameter | Type |
|---|---|
sym_key | string |
type_name | string |
Returns
bool
Examples
\Sgnw\Core\Fsw\fsw_is_type('S10000', 'hand'); // trueSgnw\Core\Fsw\fsw_colors
function fsw_colors()
Sgnw\Core\Fsw\fsw_colorize
function fsw_colorize($key)
Function that returns the standardized color for a symbol.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
string
Examples
\Sgnw\Core\Fsw\fsw_colorize('S10000'); // '#0000CC'Sgnw\Core\Fsw\fsw_parse_symbol
function fsw_parse_symbol($fsw_sym)
Parse an FSW symbol with optional coordinate and style string.
Parameters
| Parameter | Type |
|---|---|
fsw_sym | string |
Returns
array
Examples
\Sgnw\Core\Fsw\fsw_parse_symbol('S10000500x500-C');
// ['symbol' => 'S10000', 'coord' => [500, 500], 'style' => '-C']Sgnw\Core\Fsw\fsw_parse_sign
function fsw_parse_sign($fsw_sign)
Parse an FSW sign with optional style string.
Parameters
| Parameter | Type |
|---|---|
fsw_sign | string |
Returns
array
Examples
\Sgnw\Core\Fsw\fsw_parse_sign('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475-C');Sgnw\Core\Fsw\fsw_parse_text
function fsw_parse_text($fsw_text)
Parse an FSW text into signs and punctuations.
Parameters
| Parameter | Type |
|---|---|
fsw_text | string |
Returns
array
Examples
\Sgnw\Core\Fsw\fsw_parse_text('AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496');Sgnw\Core\Fsw\fsw_compose_symbol
function fsw_compose_symbol($fsw_sym_object)
Function to compose an fsw symbol with optional coordinate and style string.
Parameters
| Parameter | Type |
|---|---|
fsw_sym_object | array |
Returns
string|null
Examples
\Sgnw\Core\Fsw\fsw_compose_symbol(['symbol' => 'S10000', 'coord' => [480, 480], 'style' => '-C']);
// 'S10000480x480-C'Sgnw\Core\Fsw\fsw_compose_sign
function fsw_compose_sign($fsw_sign_object)
Function to compose an fsw sign with style string.
Parameters
| Parameter | Type |
|---|---|
fsw_sign_object | array |
Returns
string|null
Examples
\Sgnw\Core\Fsw\fsw_compose_sign([
'sequence' => ['S10011', 'S10019', 'S2e704', 'S2e748'],
'box' => 'M',
'max' => [525, 535],
'spatials' => [
['symbol' => 'S2e748', 'coord' => [483, 510]],
['symbol' => 'S10011', 'coord' => [501, 466]],
['symbol' => 'S2e704', 'coord' => [510, 500]],
['symbol' => 'S10019', 'coord' => [476, 475]]
],
'style' => '-C'
]);Sgnw\Core\Fsw\fsw_info
function fsw_info($fsw)
Function to gather sizing information about an fsw sign or symbol.
Parameters
| Parameter | Type |
|---|---|
fsw | string |
Returns
array
Examples
\Sgnw\Core\Fsw\fsw_info('AS14c20S27106L518x529S14c20481x471S27106503x489-P10Z2');Sgnw\Core\Fsw\fsw_column_defaults
function fsw_column_defaults()
Sgnw\Core\Fsw\fsw_column_defaults_merge
function fsw_column_defaults_merge($options = null)
Function to merge an object of column options with default values.
Parameters
| Parameter | Type |
|---|---|
options | array|null |
Returns
array
Examples
\Sgnw\Core\Fsw\fsw_column_defaults_merge(['height' => 500, 'width' => 150]);Sgnw\Core\Fsw\fsw_columns
function fsw_columns($fsw_text, $options = null)
Function to transform an FSW text to an array of columns.
Parameters
| Parameter | Type |
|---|---|
fsw_text | string |
options | array|null |
Returns
array
Examples
\Sgnw\Core\Fsw\fsw_columns('AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496', ['height' => 500, 'width' => 150]);Sgnw\Core\Fsw\_default_special_tokens
function _default_special_tokens()
Sgnw\Core\Fsw\_generate_tokens
function _generate_tokens()
Sgnw\Core\Fsw\_create_special_token_mappings
function _create_special_token_mappings($special_tokens)
Sgnw\Core\Fsw\_create_token_mappings
function _create_token_mappings($tokens, $special_token_mappings, $starting_index)
Sgnw\Core\Fsw\fsw_tokenize
function fsw_tokenize($fsw, $sequence = true, $signbox = true, $sep = '[SEP]')
Tokenizes an FSW string into an array of tokens.
Parameters
| Parameter | Type |
|---|---|
fsw | string |
sequence | bool |
signbox | bool |
sep | string|null |
Returns
array
Examples
\Sgnw\Core\Fsw\fsw_tokenize("AS10e00M507x515S10e00492x485", false, true, null);Sgnw\Core\Fsw\substr
function substr($symbol, 0, 4)
Sgnw\Core\Fsw\fsw_parse_text
function fsw_parse_text($fsw)
Sgnw\Core\Fsw\fsw_detokenize
function fsw_detokenize($tokens, $special_tokens = null)
Converts an array of tokens back into an FSW string.
Parameters
| Parameter | Type |
|---|---|
tokens | array |
special_tokens | array|null |
Returns
string
Examples
\Sgnw\Core\Fsw\fsw_detokenize(['M', 'p507', 'p515', 'S10e', 'c0', 'r0', 'p492', 'p485']);Sgnw\Core\Fsw\in_array
function in_array($t, $special_values, true)
Sgnw\Core\Fsw\fsw_chunk_tokens
function fsw_chunk_tokens($tokens, $chunk_size, $cls = '[CLS]', $sep = '[SEP]', $pad = '[PAD]')
Splits tokens into chunks of specified size while preserving sign boundaries.
Parameters
| Parameter | Type |
|---|---|
tokens | array |
chunk_size | int |
cls | string |
sep | string |
pad | string |
Returns
array
Classes
Sgnw\Core\Fsw\SpecialTokenMappings
Methods
SpecialTokenMappings::__construct
function __construct($by_index, $by_name, $by_value)
SpecialTokenMappings::get_by_index
function get_by_index($index)
SpecialTokenMappings::get_by_name
function get_by_name($name)
SpecialTokenMappings::get_by_value
function get_by_value($value)
SpecialTokenMappings::get_all_values
function get_all_values()
SpecialTokenMappings::get_all_indices
function get_all_indices()
Sgnw\Core\Fsw\FSWTokenizer
Methods
FSWTokenizer::__construct
function __construct($special_tokens = null, $starting_index = null)
FSWTokenizer::vocab
function vocab()
FSWTokenizer::encode_tokens
function encode_tokens($tokens)
FSWTokenizer::decode_tokens
function decode_tokens($indices)
FSWTokenizer::encode
function encode($text, $sequence = true, $signbox = true)
FSWTokenizer::decode
function decode($tokens)
FSWTokenizer::chunk
function chunk($tokens, $chunk_size)