idaes_flowsheet_processor.util

Utility functions.

Module Contents

Classes

ShortPrefix

Map unique prefixes to words.

class idaes_flowsheet_processor.util.ShortPrefix(words, lowercase: bool = True)

Map unique prefixes to words.

Usage: >>> sp = ShortPrefix([“apple”, “banana”, “apricot”, “berry”]) >>> sp.match(“app”) # Returns “apple” >>> sp.match(“ap”) # Returns [] (ambiguous) >>> sp.match(“ban”) # Returns “banana” >>> sp.match(“b”) # Returns None (ambiguous) >>> sp.could_be(“ap”) # Returns [“apple”, “apricot”] >>> sp.could_be(“b”) # Returns [“banana”, “berry”] >>> sp.could_be(“c”) # Returns [] (no matches)

property words: list[str]

Get the list of words that were used to construct the prefix map.

match(s: str) str | None

Find the unique word for a given prefix string.

Returns:

The unique word that matches the prefix, or None if no unique word, or any word, matches.

Return type:

str or None

could_be(s: str) list[str]

Find all words that _could_ match a given prefix string.

Note that this will not return words that are unambiguous matches. Put another way, if match() returns a word for this input, then this method will return an empty list.

Returns:

A list of words that could match the prefix.

Return type:

list of str