SWU Query Module
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
- sutton_signwriting_core.swuquery.swuquery_parse(swu_query_string)
Parse an SWU query string to a structured dictionary.
- Parameters:
swu_query_string (str) – an SWU query string
- Returns:
Dictionary representing the query structure
- Return type:
Example
>>> swuquery_parse('QARTR𝤆𝤆V5-') {'query': True, 'prefix': {'required': True, 'parts': ['', ['', ''], '']}, 'signbox': [{'symbol': ''}, {'range': ['', ''], 'coord': [500, 500]}], 'variance': 5, 'style': True}
- sutton_signwriting_core.swuquery.swuquery_compose(swu_query_object)
Function to compose SWU query string from object.
- Parameters:
swu_query_object (QueryObject) – Dictionary of type QueryObject
- Returns:
SWU query string
- Return type:
str | None
Example
>>> swuquery_compose({ ... 'query': True, ... 'prefix': { ... 'required': True, ... 'parts': [ ... '', ... ['', ''], ... '' ... ] ... }, ... 'signbox': [ ... {'symbol': ''}, ... {'range': ['', ''], 'coord': [500, 500]} ... ], ... 'variance': 5, ... 'style': True ... }) 'QARTR𝤆𝤆V5-'
- sutton_signwriting_core.swuquery.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:
swu_sign (str) – SWU sign
flags (str) – flags for query string creation
- Returns:
SWU query string
- Return type:
str | None
Example
>>> swu_to_query('𝠀𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭', 'ASL') 'QAT𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭'
- sutton_signwriting_core.swuquery.swuquery_range(min_char, max_char)
Function to transform a range of SWU characters to a regular expression.
- Parameters:
min_char (str) – an SWU character
max_char (str) – an SWU character
- Returns:
a regular expression that matches a range of SWU characters
- Return type:
str
Example
>>> swuquery_range('', '') '[\U00040001-\U000401E1]'
>>> swuquery_range('𝣔', '𝤸') '[\U0001D8D4-\U0001D938]'
- sutton_signwriting_core.swuquery.swuquery_regex(query)
Function to transform an SWU query string to one or more regular expressions.
- Parameters:
query (str) – an SWU query string
- Returns:
a list of one or more regular expression strings
- Return type:
List[str]
Example
>>> swuquery_regex('QAT') ['(?:\U0001d800\U00040012(?:\U00040000|(?:[\U00040001-\U0004f480]))*)\U0001d80[1-4](?:\U0001d8[0c-f][0-9a-f]|\U0001d9[0-9a-f][0-9a-f]){2}(?:(?:[\U00040001-\U0004f480])(?:\U0001d8[0c-f][0-9a-f]|\U0001d9[0-9a-f][0-9a-f]){2})*']
- sutton_signwriting_core.swuquery.swuquery_results(query, text)
Function that uses a query string to match signs from a string of text.
- Parameters:
query (str) – an SWU query string
text (str) – a string of text containing multiple signs
- Returns:
an array of SWU signs
- Return type:
List[str]
Example
>>> swuquery_results('QAT','𝠀𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭 𝠀𝠃𝤛𝤬𝤀𝣺𝤄𝣻𝤄𝤗𝤃𝣟𝣱𝣸 𝠀𝠃𝤙𝤞𝣷𝤀𝣼𝤀𝣳𝣮') ['𝠀𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭']
- sutton_signwriting_core.swuquery.swuquery_lines(query, text)
Function that uses an SWU query string to match signs from multiple lines of text.
- Parameters:
query (str) – an SWU query string
text (str) – multiple lines of text, each starting with an SWU sign
- Returns:
an array of lines of text, each starting with an SWU sign
- Return type:
List[str]
Example
>>> swuquery_lines('QAT', '''𝠀𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭 line one ... 𝠀𝠃𝤛𝤬𝤀𝣺𝤄𝣻𝤄𝤗𝤃𝣟𝣱𝣸 line two ... 𝠀𝠃𝤙𝤞𝣷𝤀𝣼𝤀𝣳𝣮 line three''') ['𝠀𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭 line one']