On this page | |
Since | 20.0 |
The node lets you choose a (regex) delimiter between sets of attributes listed in a file; for files with work item data separated line-by-line, this delimiter would be \n
. The text for each attribute set is futher parsed into a new work item by using a simple pattern replacement language, or full-on regular expressions. The simple patterns are easier to write and make sense to use for structured strings with separators.
Simple pattern language ¶
This node supports a fairly simple pattern language (similar to the Attribute from String node), alternating named “capture” groups and literal characters. The strings captured by the groups are assigned to attributes. This can be useful for parsing information formatted in a regular structure with separator characters.
For example, given a line in a file describing a set of attributes in the form:
"cat","cat0.png",1
You can parse the different parts into attributes using a pattern such as:
"{name}","{filename}.{}",{size:int}
(Empty braces capture a string but aren’t assigned to an attribute.)
-
In the pattern, curly braces (
{name}
) match up to the next literal character in the pattern.-
If the braces are empty, the matching string is thrown away.
-
The braces contain a name, the matching string is assigned to an attribute with that name. For exmaple, the part of the source string “captured” by
{name}
is assigned to theshot
attribute. -
If Infer attribute type is on, the node guesses the attribute type based on the matched string (if it looks like a whole number, it’s an integer; if it looks like a number with a decimal point, it’s a float; otherwise it’s a string). You can explicitly specify the type using
{name:type}
. For example,{shot:string}
,{frame:int}
,{time:float}
. -
Braces with no type or a string type only match text containing alphanumeric characters and underscores. Formally, they match text using the regex
\w+
.
-
-
If you have capture braces at the end of the pattern, they match to the end of the source string.
-
Outside braces, characters in the pattern must match characters in the source string exactly.
-
Braces are not “greedy”… they only match up to the next literal character, even if going further would give a better match.
For example, in
day.01.csv
, with the pattern{name}.csv
you might expect{name}
to captureday.01
, but in fact it will only captureday
(since it captures up to the next literal character, a period). The pattern will then fail because it expects the characters after the period to becsv
, not01
. -
The whole pattern must match the source string (not just a prefix).
-
If the whole pattern doesn’t match, none of the attributes in the pattern will be set.
Regular expression ¶
For maximum power/flexibility, you can use a regular expression instead. This node uses Python’s regular expression syntax.
-
Using a regular expression implies Infer attribute type.
パラメータ ¶
Generate When
このノードがワークアイテムを生成するタイミングを決めます。 このノードがどの生成モードを必須にしているのか、もしくは、ワークアイテムを動的に生成させる必要があるのかどうか分からないのであれば、通常では、これを“Automatic”のままに設定してください。
All Upstream Items are Generated
このノードは、すべての入力ノードが自身のワークアイテムを生成した時にワークアイテムを生成します。
All Upstream Items are Cooked
このノードは、すべての入力ノードが自身のワークアイテムをクックした時にワークアイテムを生成します。
Each Upstream Item is Cooked
このノードは、入力ノード内のワークアイテムがクックされる度にワークアイテムを生成します。
Automatic
入力ノードの生成モードに基づいて生成モードが選択されます。 入力ノードのどれかがその入力のクック時にワークアイテムが生成されている場合、このノードには Each Upstream Item is Cooked が設定されます。 そうでない場合、 All Upstream Items are Generated が設定されます。
File Path
Path of the file to parse.
Work Item Delimiter (regex)
Separator regular expression between text containing attribute values for a work item.
Pattern Type
Determines if the Pattern field is using the simple brace syntax or a regular expression. When using a regular expression, captured groups are assigned to attributes by number, for example, group0
, group1
, and so on. If the capture groups are named, e.g. using the syntax (?P<name>)
, then the attribute name is set to the capture group name.
Pattern
The pattern to use to extract attributes from each string in a delimiter-separated file. The language is controlled by the Use custom regex checkbox. When the checkbox is off, this parameter uses a simple pattern substitution language (see above). When the checkbox is on, this parameter is a regular expression.
Infer Attribute Type
When this is on, if you don’t explicitly state the type of a capture pattern (for example, {shotnum:int}
), the node will try to guess the type based on the matched string content (if it looks like a whole number, it’s an integer; if it looks like a number with a decimal point, it’s a float; otherwise it’s a string).
Create Items With No Matches
By default, the node only creates new work items from a string where the pattern matched. When this is on, work items are created even if they didn’t match.
Parsing Issues
How to report parsing issues such as a failed match.
See also |