:py:mod:`maha.parsers.rules` ============================ .. py:module:: maha.parsers.rules Subpackages ----------- .. toctree:: :titlesonly: :maxdepth: 3 duration/index.rst numeral/index.rst ordinal/index.rst time/index.rst Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 common/index.rst names/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: maha.parsers.rules.Expression Functions ~~~~~~~~~ .. autosummary:: get_fractions_of_unit_pattern get_fractions_of_pattern wrap_pattern spaced_patterns parse_duration parse_numeral parse_ordinal parse_time compile_rules compile_numeral_rules compile_ordinal_rules compile_time_rules compile_duration_rules Attributes ~~~~~~~~~~ .. autoapisummary:: maha.parsers.rules.THIRD maha.parsers.rules.QUARTER maha.parsers.rules.HALF maha.parsers.rules.THREE_QUARTERS maha.parsers.rules.WAW_CONNECTOR maha.parsers.rules.WORD_SEPARATOR maha.parsers.rules.ALL_ALEF maha.parsers.rules.TWO_SUFFIX maha.parsers.rules.SUM_SUFFIX maha.parsers.rules.EXPRESSION_START maha.parsers.rules.EXPRESSION_END maha.parsers.rules.RULE_DURATION_SECONDS maha.parsers.rules.RULE_DURATION_MINUTES maha.parsers.rules.RULE_DURATION_HOURS maha.parsers.rules.RULE_DURATION_DAYS maha.parsers.rules.RULE_DURATION_WEEKS maha.parsers.rules.RULE_DURATION_MONTHS maha.parsers.rules.RULE_DURATION_YEARS maha.parsers.rules.RULE_DURATION maha.parsers.rules.RULE_NAME maha.parsers.rules.RULE_NUMERAL_ONES maha.parsers.rules.RULE_NUMERAL_TENS maha.parsers.rules.RULE_NUMERAL_HUNDREDS maha.parsers.rules.RULE_NUMERAL_THOUSANDS maha.parsers.rules.RULE_NUMERAL_MILLIONS maha.parsers.rules.RULE_NUMERAL_BILLIONS maha.parsers.rules.RULE_NUMERAL_TRILLIONS maha.parsers.rules.RULE_NUMERAL_INTEGERS maha.parsers.rules.RULE_NUMERAL_DECIMALS maha.parsers.rules.RULE_NUMERAL maha.parsers.rules.RULE_ORDINAL_ONES maha.parsers.rules.RULE_ORDINAL_TENS maha.parsers.rules.RULE_ORDINAL_HUNDREDS maha.parsers.rules.RULE_ORDINAL_THOUSANDS maha.parsers.rules.RULE_ORDINAL_MILLIONS maha.parsers.rules.RULE_ORDINAL_BILLIONS maha.parsers.rules.RULE_ORDINAL_TRILLIONS maha.parsers.rules.RULE_ORDINAL maha.parsers.rules.RULE_TIME_YEARS maha.parsers.rules.RULE_TIME_MONTHS maha.parsers.rules.RULE_TIME_WEEKS maha.parsers.rules.RULE_TIME_DAYS maha.parsers.rules.RULE_TIME_HOURS maha.parsers.rules.RULE_TIME_MINUTES maha.parsers.rules.RULE_TIME_AM_PM maha.parsers.rules.RULE_TIME_NOW maha.parsers.rules.RULE_TIME .. py:function:: get_fractions_of_unit_pattern(unit) Returns the fractions of a unit pattern. :param unit: The unit pattern. :type unit: str :returns: Pattern for the fractions of the unit. :rtype: str .. py:function:: get_fractions_of_pattern(pattern) Returns the fractions of a pattern. :param pattern: The pattern. :type pattern: str :returns: Pattern for the fractions of the input pattern. :rtype: str .. py:function:: wrap_pattern(pattern) Adds start and end expression to the pattern. .. py:function:: spaced_patterns(*patterns) Returns a regex pattern that matches any of the given patterns, separated by spaces. :param patterns: The patterns to match. .. py:data:: THIRD Pattern that matches the pronunciation of third in Arabic .. py:data:: QUARTER Pattern that matches the pronunciation of quarter in Arabic .. py:data:: HALF Pattern that matches the pronunciation of half in Arabic .. py:data:: THREE_QUARTERS Pattern that matches the pronunciation of three quarters in Arabic .. py:data:: WAW_CONNECTOR Pattern that matches WAW as a connector between two words .. py:data:: WORD_SEPARATOR Pattern that matches the word separator between numerals in Arabic .. py:data:: ALL_ALEF Pattern that matches all possible forms of the ALEF in Arabic .. py:data:: TWO_SUFFIX Pattern that matches the two-suffix of words in Arabic .. py:data:: SUM_SUFFIX Pattern that matches the sum-suffix of words in Arabic .. py:data:: EXPRESSION_START Pattern that matches the start of a rule expression in Arabic .. py:data:: EXPRESSION_END Pattern that matches the end of a rule expression in Arabic .. py:data:: RULE_DURATION_SECONDS .. py:data:: RULE_DURATION_MINUTES .. py:data:: RULE_DURATION_HOURS .. py:data:: RULE_DURATION_DAYS .. py:data:: RULE_DURATION_WEEKS .. py:data:: RULE_DURATION_MONTHS .. py:data:: RULE_DURATION_YEARS .. py:data:: RULE_DURATION .. py:function:: parse_duration(match) Parse duration. .. py:class:: Expression(pattern, pickle = False) Regex pattern holder. :param pattern: Regular expression pattern. :type pattern: str :param pickle: If ``True``, the compiled pattern will be pickled. This is useful to save compilation time for large patterns. :type pickle: bool .. py:attribute:: pattern :annotation: :str Regular expersion(s) to match .. py:method:: compile(self) Compile the regular expersion. .. py:method:: from_cache(cls, cache) :classmethod: Load an expression from cache. :param cache: Name of the cache file. :type cache: str :returns: Expression. :rtype: :class:`~.Expression` .. py:method:: search(self, text) Search for the pattern in the input ``text``. :param text: Text to search in. :type text: str :returns: Matched object. :rtype: :class:`regex.Match` .. py:method:: match(self, text) Match the pattern in the input ``text``. :param text: Text to match in. :type text: str :returns: Matched object. :rtype: :class:`regex.Match` .. py:method:: fullmatch(self, text) Match the pattern in the input ``text``. :param text: Text to match in. :type text: str :returns: Matched object. :rtype: :class:`regex.Match` .. py:method:: sub(self, repl, text) Replace all occurrences of the pattern in the input ``text``. :param repl: Replacement string. :type repl: str :param text: Text to replace. :type text: str :returns: Text with replaced occurrences. :rtype: str .. py:method:: parse(self, text) Extract values from the input ``text``. :param text: Text to extract the value from. :type text: str :Yields: :class:`~.ExpressionResult` -- Extracted value. .. py:data:: RULE_NAME .. py:data:: RULE_NUMERAL_ONES .. py:data:: RULE_NUMERAL_TENS .. py:data:: RULE_NUMERAL_HUNDREDS .. py:data:: RULE_NUMERAL_THOUSANDS .. py:data:: RULE_NUMERAL_MILLIONS .. py:data:: RULE_NUMERAL_BILLIONS .. py:data:: RULE_NUMERAL_TRILLIONS .. py:data:: RULE_NUMERAL_INTEGERS .. py:data:: RULE_NUMERAL_DECIMALS .. py:data:: RULE_NUMERAL .. py:function:: parse_numeral(match) .. py:data:: RULE_ORDINAL_ONES .. py:data:: RULE_ORDINAL_TENS .. py:data:: RULE_ORDINAL_HUNDREDS .. py:data:: RULE_ORDINAL_THOUSANDS .. py:data:: RULE_ORDINAL_MILLIONS .. py:data:: RULE_ORDINAL_BILLIONS .. py:data:: RULE_ORDINAL_TRILLIONS .. py:data:: RULE_ORDINAL .. py:function:: parse_ordinal(match) .. py:data:: RULE_TIME_YEARS .. py:data:: RULE_TIME_MONTHS .. py:data:: RULE_TIME_WEEKS .. py:data:: RULE_TIME_DAYS .. py:data:: RULE_TIME_HOURS .. py:data:: RULE_TIME_MINUTES .. py:data:: RULE_TIME_AM_PM .. py:data:: RULE_TIME_NOW .. py:data:: RULE_TIME .. py:function:: parse_time(match) .. py:function:: compile_rules() .. py:function:: compile_numeral_rules() .. py:function:: compile_ordinal_rules() .. py:function:: compile_time_rules() .. py:function:: compile_duration_rules()