SWU Query

SWU query parsing, composition, and result helpers.

Source

Functions

Sgnw\Core\SwuQuery\_swuquery_parse_prefix

function _swuquery_parse_prefix($text)

The swuquery module contains functions for handling the SWU query language.

Query Language definition:
https://datatracker.ietf.org/doc/id/draft-slevinski-formal-signwriting-10.html#name-query-language

Sgnw\Core\SwuQuery\_swuquery_parse_signbox

function _swuquery_parse_signbox($text)

Parse a signbox query string into a list of query elements.

Parameters

ParameterTypeDescription
textstringA string representing the signbox query.

Returns

array — A list of symbols, ranges, or OR groups.

Examples

\Sgnw\Core\SwuQuery\_swuquery_parse_signbox('񀀁𝤆𝤆');
// [['symbol' => '񀀁', 'coord' => [500, 500]]]

Sgnw\Core\SwuQuery\swuquery_parse

function swuquery_parse($swu_query_string)

Parse an SWU query string to a structured dictionary.

Parameters

ParameterTypeDescription
swu_query_stringstringan SWU query string

Returns

array — Dictionary representing the query structure

Examples

\Sgnw\Core\SwuQuery\swuquery_parse('QA񀀁R񀀁񆆑񆇡T񆀁R񀀁񀇱𝤆𝤆V5-');
// ['query' => true, 'prefix' => ['required' => true, 'parts' => ['񀀁', ['񀀁', '񆆑'], '񆇡']], 'signbox' => [['symbol' => '񆀁'], ['range' => ['񀀁', '񀇱'], 'coord' => [500, 500]]], 'variance' => 5, 'style' => true]

Sgnw\Core\SwuQuery\swuquery_compose

function swuquery_compose($swu_query_object)

Function to compose SWU query string from object.

Parameters

ParameterTypeDescription
swu_query_objectarrayDictionary of query elements

Returns

string|null — SWU query string

Examples

\Sgnw\Core\SwuQuery\swuquery_compose([
    'query' => true,
    'prefix' => ['required' => true, 'parts' => ['񀀁', ['񀀁', '񆆑'], '񆇡']],
    'signbox' => [
        ['symbol' => '񆀁'],
        ['range' => ['񀀁', '񀇱'], 'coord' => [500, 500]]
    ],
    'variance' => 5,
    'style' => true
]);
// 'QA񀀁R񀀁񆆑񆇡T񆀁R񀀁񀇱𝤆𝤆V5-'

Sgnw\Core\SwuQuery\swu_to_query

function swu_to_query($swu_sign, $flags)

Function to convert an SWU 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

ParameterTypeDescription
swu_signstringSWU sign
flagsstringflags for query string creation

Returns

string|null — SWU query string

Examples

\Sgnw\Core\SwuQuery\swu_to_query('𝠀񀀒񀀚񋚥񋛩𝠃𝤟𝤩񋛩𝣵𝤐񀀒𝤇𝣤񋚥𝤐𝤆񀀚𝣮𝣭', 'ASL');
// 'QA񀀒񀀚񋚥񋛩T񋛩𝣵𝤐񀀒𝤇𝣤񋚥𝤐𝤆񀀚𝣮𝣭'

Sgnw\Core\SwuQuery\swuquery_range

function swuquery_range($min_char, $max_char)

Function to transform a range of SWU characters to a regular expression.

Parameters

ParameterTypeDescription
min_charstringan SWU character
max_charstringan SWU character

Returns

string — a regular expression that matches a range of SWU characters

Examples

\Sgnw\Core\SwuQuery\swuquery_range('񀀁', '񀇡');
// '[\\x{40001}-\\x{401E1}]'

Sgnw\Core\SwuQuery\_regex_range

function _regex_range($sym_range)

Sgnw\Core\SwuQuery\_regex_symbol

function _regex_symbol($sym)

Sgnw\Core\SwuQuery\swuquery_regex

function swuquery_regex($query)

Function to transform an SWU query string to one or more regular expressions.

Parameters

ParameterTypeDescription
querystringan SWU query string

Returns

array — a list of one or more regular expression strings

Examples

\Sgnw\Core\SwuQuery\swuquery_regex('QA񀀒T');

Sgnw\Core\SwuQuery\swuquery_results

function swuquery_results($query, $text)

Function that uses a query string to match signs from a string of text.

Parameters

ParameterTypeDescription
querystringan SWU query string
textstringa string of text containing multiple signs

Returns

array — an array of SWU signs

Examples

Sgnw\Core\SwuQuery\swuquery_lines

function swuquery_lines($query, $text)

Function that uses an SWU query string to match signs from multiple lines of text.

Parameters

ParameterTypeDescription
querystringan SWU query string
textstringmultiple lines of text, each starting with an SWU sign

Returns

array — an array of lines of text, each starting with an SWU sign

Examples