Inheritence |
|
This is a pattern matching object that can be constructed from an attribute pattern. It can be used with the pdg.WorkItem.attribMatch function to find the list of matching work item attribute names.
The pattern uses the rules specified in the attribute pattern syntax section.
Methods
Static methods
isValidName(attrib_name)
→ bool
Returns True
if the specified name is a valid attribute name, else returns
False
.
makeValidName(attrib_name)
→ bool
Converts the specified string into a valid attribute name.
splitByAttribute(work_items, attrib_names, partial_matches=False)
→ tuple
Splits the work items in the input list by the specified attribute name(s). Returns a map of attribute values to the list of work items that have that value, as well as the list of work items that are missing the attribute and the list of unique values. The unique value list is sorted in ascending order of value.
The values for attrib_name
on the work items do not all have to be the same type. All attribute values are converted to strings. Multiple attribute names can be passed in as a space-separate string. When multiple names are passed into the function, the attribute values are treated as a tuple instead of as a single value.
When multiple attribute names are specified, the partial_matches
flag indicates that work items with only some of the attributes should be still be added to partially matching map entries.
For example:
attribute = "wedgeindex" (value_map, missing, unique) = pdg.AttributePattern.splitByAttribute(node.work_items, attribute) print("Attribute {} has {} unique values".format(attribute, len(unique))) for work_item in missing: print("Work Item {} is missing attrib {}".format(attribute)) for entry in value_map: print("{} work items have value {}".format(len(value_map[entry]), entry))
splitByFloat(work_items, attrib_name)
→ tuple
Splits the input work items by the specified float attribute name.
This function is the same as splitByAttribute
, but it will not convert attribute values to strings. Work items that have an attribute with the specified name, but a different type, will be considered as missing the attribute.
splitByInt(work_items, attrib_name)
→ tuple
Splits the input work items by the specified integer attribute name.
This function is the same as splitByAttribute
, but it will not convert attribute values to strings. Work items that have an attribute with the specified name, but a different type, will be considered as missing the attribute.
splitByString(work_items, attrib_name)
→ tuple
Splits the input work items by the specified integer attribute name.
This function is the same as splitByAttribute
, but it will not convert attribute values to strings. Work items that have an attribute with the specified name, but a different type, will be considered as missing the attribute.
Instance Methods
__init__(pattern, default_match_type=pdg.attribMatchType.Plain, strict=True)
Constructs a new pattern object from the specified string. If strict is set
to False
, the attribute names in the pattern can use any characters except
for *
, ^
and white space. If strict is True, only _
or characters that
are alphanumeric can appear in an attribute name. When strict mode is off,
it is not possible to specify an attribute type using the :
separator.
The default_match_type
determines what type of pattern is used when a term in the input string has no explicit *
tokens. For example, if default_match_type
is set to pdg.attribMatchType.Both the pattern will automatically add a *
token on both ends of every term in the pattern, if the term has no existing *
tokens. The pattern example other*
would effectively be the same as *example* other*
in that case. By default, no extra *
tokens are added because the argument is set to pdg.attribMatchType.Plain.
contains(name, type=pdg.attribType.Undefined)
→ bool
Returns True if the specified attribute name and type match the pattern,
else False. If type
is set to pdg.attribType.Undefined the type is
ignored when matching the attribute.
multiMatch(input_names=[], keep_plain=False)
→ list
of str
Returns an array of string names from the input list that match the pattern. If keep_plain
is set to True
, any pattern components that don’t have a *
token in them will always be included in the output list, even if they do not appear in the input_names
. Consequently, if input_names
is empty and keep_plain
is True
, this function returns the list of pattern components that are expressed as simple string names.
Methods from pdg.BasePattern
errors
: str
Property
If the pattern is invalid, this string contains the parse errors.
isValid
: bool
Property
Set to True if the pattern is valid, else False.
pattern
: str
Property
The source string used to construct this pattern object.