FSW Query Module
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
- sutton_signwriting_core.fswquery.fswquery_parse(fsw_query_string)
Parse an FSW query string to a structured dictionary.
- Parameters:
fsw_query_string (str) – an FSW query string
- Returns:
Dictionary representing the query structure
- Return type:
Example
>>> 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}
- sutton_signwriting_core.fswquery.fswquery_compose(fsw_query_object)
Function to compose FSW query string from object.
- Parameters:
fsw_query_object (QueryObject) – Dictionary of type QueryObject
- Returns:
FSW query string
- Return type:
str | None
Example
>>> 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-'
- sutton_signwriting_core.fswquery.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:
fsw_sign (str) – FSW sign
flags (str) – flags for query string creation
- Returns:
FSW query string
- Return type:
str | None
Example
>>> fsw_to_query('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475', 'ASL') 'QAS10011S10019S2e704S2e748TS2e748483x510S10011501x466S2e704510x500S10019476x475'
- sutton_signwriting_core.fswquery.fswquery_range(min_, max_, hex_=False)
Function to transform a range to a regular expression.
- Parameters:
min – either a decimal number or hexidecimal string
max – either a decimal number or hexidecimal string
hex – if True, the regular expression will match a hexidecimal range
min_ (int | str)
max_ (int | str)
hex_ (bool)
- Returns:
a regular expression that matches a range
- Return type:
str
Example
>>> fswquery_range(500, 750) '(([56][0-9][0-9])|(7[0-4][0-9])|(750))' >>> fswquery_range('100', '10e', True) '10[0-9a-e]'
- sutton_signwriting_core.fswquery.fswquery_regex(query)
Function to transform an FSW query string to one or more regular expressions.
- Parameters:
query (str) – an FSW query string
- Returns:
a list of one or more regular expression strings
- Return type:
List[str]
Example
>>> 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})*']
- sutton_signwriting_core.fswquery.fswquery_results(query, text)
Function that uses a query string to match signs from a string of text.
- Parameters:
query (str) – an FSW query string
text (str) – a string of text containing multiple signs
- Returns:
an array of FSW signs
- Return type:
List[str]
Example
>>> fswquery_results('QAS10011T','AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 AS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 AS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476') ['AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475']
- sutton_signwriting_core.fswquery.fswquery_lines(query, text)
Function that uses an FSW query string to match signs from multiple lines of text.
- Parameters:
query (str) – an FSW query string
text (str) – multiple lines of text, each starting with an FSW sign
- Returns:
an array of lines of text, each starting with an FSW sign
- Return type:
List[str]
Example
>>> fswquery_lines('QAS10011T',`AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one ... AS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 line two ... AS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476 line three`) ['AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one']