FSW Query
FSW query parsing, composition, and result helpers.
Functions
Sgnw\Core\FswQuery\_fswquery_parse_prefix
function _fswquery_parse_prefix($text)
The fswquery module contains functions for handling the FSW query language.
Query Language definition:
https://datatracker.ietf.org/doc/id/draft-slevinski-formal-signwriting-10.html#name-query-language
Sgnw\Core\FswQuery\_fswquery_parse_signbox
function _fswquery_parse_signbox($text)
Parse a signbox query string into a list of query elements.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | A string representing the signbox query. |
Returns
array — A list of symbols, ranges, or OR groups.
Examples
\Sgnw\Core\FswQuery\_fswquery_parse_signbox('S100uu500x500');
// [['symbol' => 'S100uu', 'coord' => [500, 500]]]Sgnw\Core\FswQuery\fswquery_parse
function fswquery_parse($fsw_query_string)
Parse an FSW query string to a structured dictionary.
Parameters
| Parameter | Type | Description |
|---|---|---|
fsw_query_string | string | an FSW query string |
Returns
array — Dictionary representing the query structure
Examples
\Sgnw\Core\FswQuery\fswquery_parse('QAS10000S10500oS20500oR2fft304TS100uuR205t206oS207uu510x510V5-');
// ['query' => true, 'prefix' => ['required' => true, 'parts' => ['S10000', ['or_list', 'S10500', 'S20500', ['2ff', '304']]]], 'signbox' => [['symbol' => 'S100uu'], ['or_list' => [['205', '206'], 'S207uu'], 'coord' => [510, 510]]], 'variance' => 5, 'style' => true]Sgnw\Core\FswQuery\fswquery_compose
function fswquery_compose($fsw_query_object)
Function to compose FSW query string from object.
Parameters
| Parameter | Type | Description |
|---|---|---|
fsw_query_object | array | Dictionary of query elements |
Returns
string|null — FSW query string
Examples
\Sgnw\Core\FswQuery\fswquery_compose([
'query' => true,
'prefix' => ['required' => true, 'parts' => ['S10000', ['100', '204'], 'S20500']],
'signbox' => [
['symbol' => 'S20000'],
['range' => ['100', '105'], 'coord' => [500, 500]]
],
'variance' => 5,
'style' => true
]);
// 'QAS10000R100t204S20500TS20000R100t105500x500V5-'Sgnw\Core\FswQuery\fsw_to_query
function fsw_to_query($fsw_sign, $flags)
Function to convert an FSW sign to a query string.
For the flags parameter, use one or more of the following:
- A: exact symbol in temporal prefix
- a: general symbol in temporal prefix
- S: exact symbol in spatial signbox
- s: general symbol in spatial signbox
- L: spatial signbox symbol at location
Parameters
| Parameter | Type | Description |
|---|---|---|
fsw_sign | string | FSW sign |
flags | string | flags for query string creation |
Returns
string|null — FSW query string
Examples
\Sgnw\Core\FswQuery\fsw_to_query('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475', 'ASL');
// 'QAS10011S10019S2e704S2e748TS2e748483x510S10011501x466S2e704510x500S10019476x475'Sgnw\Core\FswQuery\_range_pattern
function _range_pattern($low, $high, $is_hex)
Sgnw\Core\FswQuery\_regex_geq
function _regex_geq($p, $q, $is_hex)
Sgnw\Core\FswQuery\_regex_leq
function _regex_leq($r, $s, $is_hex)
Sgnw\Core\FswQuery\_regex_between_two_digits
function _regex_between_two_digits($s, $t, $is_hex)
Sgnw\Core\FswQuery\fswquery_range
function fswquery_range($min_, $max_, $hex_ = false)
Function to transform a range to a regular expression.
Parameters
| Parameter | Type | Description |
|---|---|---|
min_ | int|string | either a decimal number or hexidecimal string |
max_ | int|string | either a decimal number or hexidecimal string |
hex_ | bool | if True, the regular expression will match a hexidecimal range |
Returns
string — a regular expression that matches a range
Examples
\Sgnw\Core\FswQuery\fswquery_range('100', '10e', true);
// '10[0-9a-e]'\Sgnw\Core\FswQuery\fswquery_range('100', '10e', true);
// '10[0-9a-e]'Sgnw\Core\FswQuery\_regex_symbol
function _regex_symbol($sym)
Sgnw\Core\FswQuery\_regex_range
function _regex_range($sym_range)
Sgnw\Core\FswQuery\fswquery_regex
function fswquery_regex($query)
Function to transform an FSW query string to one or more regular expressions.
Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | an FSW query string |
Returns
array — a list of one or more regular expression strings
Examples
\Sgnw\Core\FswQuery\fswquery_regex('QS100uuS20500480x520');
// ['(?:A(?:S[123][0-9a-f]{2}[0-5][0-9a-f])+)?[BLMR][0-9]{3}x[0-9]{3}(?:S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*S100[0-5][0-9a-f][0-9]{3}x[0-9]{3}(?:S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*', '(?:A(?:S[123][0-9a-f]{2}[0-5][0-9a-f])+)?[BLMR][0-9]{3}x[0-9]{3}(?:S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*S20500(?:4[6-9][0-9]|500)x(?:5[0-3][0-9]|540)(?:S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*']Sgnw\Core\FswQuery\fswquery_results
function fswquery_results($query, $text)
Function that uses a query string to match signs from a string of text.
Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | an FSW query string |
text | string | a string of text containing multiple signs |
Returns
array — an array of FSW signs
Examples
\Sgnw\Core\FswQuery\fswquery_results('QAS10011T','AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 AS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 AS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476');
// ['AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475']Sgnw\Core\FswQuery\fswquery_lines
function fswquery_lines($query, $text)
Function that uses an FSW query string to match signs from multiple lines of text.
Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | an FSW query string |
text | string | multiple lines of text, each starting with an FSW sign |
Returns
array — an array of lines of text, each starting with an FSW sign
Examples
\Sgnw\Core\FswQuery\fswquery_lines('QAS10011T',"AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one\nAS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 line two\nAS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476 line three");
// ['AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one']