Expressions Cookbook (Concept): Difference between revisions

From Grooper Wiki
No edit summary
No edit summary
Line 1: Line 1:
<blockquote>{{#lst:Glossary|Expressions Cookbook}}</blockquote>
<blockquote>This article is a running list of code expressions used in Grooper, such as '''''Default Value Expressions''''', '''Calculated Value Expressions''''', '''''Should Submit Expressions''''' and more.</blockquote>


Expressions are snippets of .NET code, allowing Grooper to do various things outside its "normal" parameters.  This includes calculating or validating extracted '''Data Field''' values in a '''Data Model''', applying conditional execution of a '''Batch Process''' or '''IP Profile''', and more!  This article collects examples of common (and maybe not so common) uses of expressions in Grooper.
Expressions are snippets of .NET code, allowing Grooper to do various things outside its "normal" parameters.  This includes calculating or validating extracted '''Data Field''' values in a '''Data Model''', applying conditional execution of a '''Batch Process''' or '''IP Profile''', and more!  This article collects examples of common (and maybe not so common) uses of expressions in Grooper.


<!--- Hiding Glossary for time being
== Glossary ==
== Glossary ==
<u><big>'''Batch Folder'''</big></u>: {{#lst:Glossary|Batch Folder}}
<u><big>'''Batch Folder'''</big></u>: {{#lst:Glossary|Batch Folder}}
Line 45: Line 46:


<u><big>'''Service'''</big></u>: {{#lst:Glossary|Service}}
<u><big>'''Service'''</big></u>: {{#lst:Glossary|Service}}
 
Hiding Glossary for time being --->
{|class="important-box"
{|class="important-box"
|
|
Line 56: Line 57:


=== Default Value Expressions ===
=== Default Value Expressions ===
Current date
* <code>Now</code>


==== Global/System Variables ====
<pre>"Literal value"</pre>
Literal string values.  Insert a literal string value into the field using quotes.
<pre>25.00</pre>
Literal numeric values.  Insert a literal numeric values entering the number only.
<pre>Now</pre>
Current date and time
<pre>Now.ToString("d")</pre>
Current date only
<pre>Now.ToString("t")</pre>
Current time only
<pre>DateAdd("d", 30, Now)</pre>
Date and time 30 days from now.
<pre>Guid.NewGuid</pre>
New Guid (Globally Unique IDentifier)
New Guid (Globally Unique IDentifier)
* <code>Guid.NewGuid</code>


Inspecting portions of link path for original file (path, filename, metadata) attached to a '''Batch Folder'''
* These examples extract information (full path & filename, filename, path, extension) from a '''Batch Folder's''' content link
** <code>Link.FullPath</code>
*** Returns the attached file's path, including the file's name.
** <code>Link.Path</code>
*** Returns the attached file's path, not including the file's name.
** <code>Link.ObjectName</code>
*** Returns the attached file's name.
** <code>Link.LinkName</code>
*** Returns the name of the link (e.g. "Import" or "Export")
** <code>IO.Path.GetFileNameWithoutExtension(Link.ObjectName)</code>
*** Returns the attached file's name without the extension.
** <code>IO.Path.GetExtension(Link.ObjectName)</code>
* These examples extract specific path segments (drive letter, first folder name) from a batch folder's content link
** <code>Link.PathSegments(0)</code>
*** Returns the first segment of the file path (e.g. "C:" in "C:\Documents\Howdy.pdf").
** <code>Link.PathSegments(1)</code>
*** Returns the second segment of the file path (e.g. "Documents" in "C:\Documents\Howdy.pdf").


''Note: If you have removed the document link with the '''Execute > Remove Link''' command, you can still access the attached file's name using the expression'' <code>Folder.AttachmentFileName</code>
<pre>My.User.Name</pre>
Name of the current user
 
 
<pre>My.Computer.Name</pre>
Name of the local machine
 
==== Files and Links ====
 
<pre>Link.FullPath</pre>
Returns the attached file's path, including the file's name from a '''Batch Folder's''' content link.
 
 
<pre>Link.Path</pre>
Returns the attached file's path, not including the file's name from a '''Batch Folder's''' content link.
 
 
<pre>Link.PathSegments(0)</pre>
Returns the first segment in a file path from a '''Batch Folder's''' content link.  For example, "servername" in "servername\folder\subfolder\file.pdf"
 


Populating fields with specific values (i.e. strings, numbers, dates)
<pre>Folder.AttachmentFileName</pre>
* <code>"Hello world!"</code>
Returns the attached file's name.
* <code>123.45</code>
* <code>DateAdd("d", 30, Now)</code>
* <code>Now.ToString("yyyyMMddhhmmss")</code>


Populating fields with the name of the document's classified '''Document Type'''
* <code>ContentTypeName</code>
* Note:  This is a shortcut for the expression <code>Folder.ContentType.DisplayName</code>


Populating fields with the name of the document's classified '''Document Type's''' '''Content Category'''.
<pre>Folder.AttachmentFileExtension</pre>
* <code>Folder.ContentType.ParentNode.DisplayName</code>
Returns the attached file's extension.
* Note:  When using '''Content Categories''', '''Document Types''' are added as child nodes to the '''Content Category''' object in the node tree.  So, this expression first uses <code>Folder</code> to select the document folder in the '''Batch'''. Then, <code>ContentType</code> inspects the document's classified '''Document Type'''.  The '''Document Type''' is a child of the '''Content Category''' in this example.  Since the '''Content Category''' is the '''Document Type's''' parent object, the <code>ParentNode</code> jumps up the node tree hierarchy to inspect the parent '''Content Category'''.  Last, <code>DisplayName</code> returns the '''Content Category's''' name.


=== Calculate Expressions ===
 
<pre>IO.Path.GetFileNameWithoutExtension(Link.ObjectName)</pre>
Returns the attached file's name only (without the extension) from a '''Batch Folder's''' content link.
 
 
<pre>Link.LinkName</pre>
Returns the name of the link (e.g. "Import" or "Export") from a '''Batch Folder's''' content link.
 
 
<pre>DirectCast(Link,FileSystemLink).CreatedTime</pre>
Inserts the complete DateTime representing when the original file was created.
 
 
<pre>DirectCast(Link,FileSystemLink).LastModifiedTime</pre>
Inserts the complete DateTime representing when the original file was last modified.
 
 
<pre>DirectCast(Link,MailLink).Subject</pre>
Inserts the Subject of an Imported Email
 
 
<pre>DirectCast(Link,MailLink).From</pre>
Inserts the From field of an Imported Email
 
 
<pre>DirectCast(Link,MailLink).To</pre>
Inserts the To field of an Imported Email
 
 
<pre>DirectCast(Link,MailLink).Date</pre>
Inserts the Date field of an Imported Email
 
==== Content Types ====
 
<pre>ContentTypeName</pre>
Populates the field with the name of the document's '''Content Type''' (its classified '''Document Type''')
 
Note:  This is a shortcut for the expression <code>Folder.ContentType.DisplayName</code>
 
 
<pre>Folder.ContentType.ParentNode.DisplayName</pre>
Useful to populate fields with the name of the document's '''Document Type's''' parent '''Content Category'''.
<!--- This is probably overkill
Note:  When using '''Content Categories''', '''Document Types''' are added as child nodes to the '''Content Category''' object in the node tree.  So, this expression first uses <code>Folder</code> to select the document folder in the '''Batch'''. Then, <code>ContentType</code> inspects the document's classified '''Document Type'''.  The '''Document Type''' is a child of the '''Content Category''' in this example.  Since the '''Content Category''' is the '''Document Type's''' parent object, the <code>ParentNode</code> jumps up the node tree hierarchy to inspect the parent '''Content Category'''.  Last, <code>DisplayName</code> returns the '''Content Category's''' name.
Removing overkill --->
 
==== Misc Default Value Expressions ====
 
<pre>Guid.NewGuid</pre>
Creates a new Globally Unique Identifier (GUID) and inserts the value.
 
 
<pre>Folder.Id</pre>
Inserts the GUID of the current '''Batch Folder'''.
 
 
<pre>Folder.Batch.Id</pre>
Inserts the GUID of the current '''Batch Folder's''' '''Batch''', regardless of the current folder's level
 
=== Calculated Value Expressions ===
Addition of multiple fields
Addition of multiple fields
* <code>IntegerField1 + IntegerField2</code>
* <code>IntegerField1 + IntegerField2</code>
* <code>DecimalField1 + DecimalField2 + DecimalField3</code>
* <code>DecimalField1 + DecimalField2 + DecimalField3</code>


Concatenation of multiple fields
Concatenation of multiple fields
Line 108: Line 186:
* <code>String.Concat(StringField1, StringField2, StringField3)</code>
* <code>String.Concat(StringField1, StringField2, StringField3)</code>
* <code>String.Concat(StringField1, StringField2, StringField3, StringField4)</code>
* <code>String.Concat(StringField1, StringField2, StringField3, StringField4)</code>


Rounding
Rounding
* This example rounds a decimal value to a precision of 4 digits (e.g. 2.34567891 to 2.3457)
* This example rounds a decimal value to a precision of 4 digits (e.g. 2.34567891 to 2.3457)
** <code>Math.Round(DecimalField1, 4)</code>
** <code>Math.Round(DecimalField1, 4)</code>


Non-integer addition (e.g. of date values)
Non-integer addition (e.g. of date values)
Line 118: Line 198:
** <code>DateAdd("yyyy", 1, DateField1)</code>
** <code>DateAdd("yyyy", 1, DateField1)</code>
** <code>DateAdd("m", -3, DateField1)</code>
** <code>DateAdd("m", -3, DateField1)</code>


Reformatting / Normalization of values
Reformatting / Normalization of values
Line 124: Line 205:
* This example removes any backslashes
* This example removes any backslashes
** <code>StringField1.Replace("\", "")</code>
** <code>StringField1.Replace("\", "")</code>


Substring calculation
Substring calculation
Line 131: Line 213:
** XXXX (4 characters within the string): <code>StringField1.Substring(9, 4)</code>
** XXXX (4 characters within the string): <code>StringField1.Substring(9, 4)</code>
** YYY (last 3 characters): <code>StringField1.Substring(StringField1.Length - 3)</code>
** YYY (last 3 characters): <code>StringField1.Substring(StringField1.Length - 3)</code>


Getting the location coordinates of a field on the document
Getting the location coordinates of a field on the document
Line 144: Line 227:
* This example ensures the date value is at least 30 days in the future
* This example ensures the date value is at least 30 days in the future
** <code>DateField1 >= DateAdd("d", 30, Now)</code>
** <code>DateField1 >= DateAdd("d", 30, Now)</code>


Equality / inequality of two fields (multiple options)
Equality / inequality of two fields (multiple options)
Line 150: Line 234:
* <code>IntegerField1 <> DecimalField1</code>
* <code>IntegerField1 <> DecimalField1</code>
* <code>Not DecimalField1.Equals(DecimalField2)</code>
* <code>Not DecimalField1.Equals(DecimalField2)</code>


Summing fields and comparing to another field
Summing fields and comparing to another field
Line 155: Line 240:
* <code>DecimalField1 + DecimalField2 = DecimalField3</code>
* <code>DecimalField1 + DecimalField2 = DecimalField3</code>
* <code>DecimalField1 = SumFieldInstance("Table1\AmountColumn")</code>
* <code>DecimalField1 = SumFieldInstance("Table1\AmountColumn")</code>


Running regular expression against field
Running regular expression against field
* <code>Text.RegularExpressions.Regex.IsMatch(StringField1, "[0-9]{6}")</code>
* <code>Text.RegularExpressions.Regex.IsMatch(StringField1, "[0-9]{6}")</code>


Inspecting field-level confidence scores
Inspecting field-level confidence scores
Line 172: Line 259:
* This example would submit the task when the object (folder) contains one or more flagged pages
* This example would submit the task when the object (folder) contains one or more flagged pages
** <code>DirectCast(Item, BatchFolder).FlaggedPages.Any()</code>
** <code>DirectCast(Item, BatchFolder).FlaggedPages.Any()</code>


Inspecting flagged message
Inspecting flagged message
* <code>Item.FlagReason = "Needs classification"</code>
* <code>Item.FlagReason = "Needs classification"</code>
* <code>Item.FlagReason <> "Bypass review"</code>
* <code>Item.FlagReason <> "Bypass review"</code>


Inspecting presence of local copy in Grooper
Inspecting presence of local copy in Grooper
* <code>DirectCast(Item, BatchFolder).HasLocalCopy</code>
* <code>DirectCast(Item, BatchFolder).HasLocalCopy</code>


Inspecting existence of native version
Inspecting existence of native version
* <code>DirectCast(Item, BatchFolder).HasAttachment</code>
* <code>DirectCast(Item, BatchFolder).HasAttachment</code>


Inspecting MIME type
Inspecting MIME type
Line 187: Line 278:
** <code>DirectCast(Item, BatchFolder).IsNativePDF</code>
** <code>DirectCast(Item, BatchFolder).IsNativePDF</code>
** <code>DirectCast(Item, BatchFolder).AttachmentMimeType = "application/pdf"</code>
** <code>DirectCast(Item, BatchFolder).AttachmentMimeType = "application/pdf"</code>


Inspecting content type / parent content category
Inspecting content type / parent content category
* <code>DirectCast(Item, BatchFolder).ContentTypeName = "MyContentType"</code>
* <code>DirectCast(Item, BatchFolder).ContentTypeName = "MyContentType"</code>
* <code>DirectCast(DirectCast(Item, BatchFolder).ContentType.ParentNode, ContentCategory).Name = "MyContentCategory"</code>
* <code>DirectCast(DirectCast(Item, BatchFolder).ContentType.ParentNode, ContentCategory).Name = "MyContentCategory"</code>


Inspecting if a field is blank / populated
Inspecting if a field is blank / populated
* <code>DirectCast(Item, BatchFolder).IndexData.Fields("StringField1").Value <> ""</code>
* <code>DirectCast(Item, BatchFolder).IndexData.Fields("StringField1").Value <> ""</code>
* <code>Not String.IsNullOrEmpty(DirectCast(Item, BatchFolder).IndexData.Fields("StringField1").Value)</code>
* <code>Not String.IsNullOrEmpty(DirectCast(Item, BatchFolder).IndexData.Fields("StringField1").Value)</code>


Inspecting image properties (resolution, color mode, aspect ratio, size (in bytes), pixel count, etc.)
Inspecting image properties (resolution, color mode, aspect ratio, size (in bytes), pixel count, etc.)
Line 204: Line 298:
* <code>DirectCast(Item, BatchPage).PrimaryImage.Size > 40960</code>
* <code>DirectCast(Item, BatchPage).PrimaryImage.Size > 40960</code>
* <code>DirectCast(Item, BatchPage).PrimaryImage.PixelCount > 3500000</code>
* <code>DirectCast(Item, BatchPage).PrimaryImage.PixelCount > 3500000</code>


Inspecting presence of layout data (of a certain type: lines, OMR boxes, etc.)
Inspecting presence of layout data (of a certain type: lines, OMR boxes, etc.)
* <code>DirectCast(Item, BatchFolder).HasLayoutData</code>
* <code>DirectCast(Item, BatchFolder).HasLayoutData</code>


Does page / document have OCR text?
Does page / document have OCR text?
* <code>DirectCast(Item, BatchFolder).HasRuntimeOCR</code>
* <code>DirectCast(Item, BatchFolder).HasRuntimeOCR</code>
* <code>DirectCast(Item, BatchPage).HasRuntimeOCR</code>
* <code>DirectCast(Item, BatchPage).HasRuntimeOCR</code>


Inspecting classification candidates and classification scores, incl. alternate candidate scores
Inspecting classification candidates and classification scores, incl. alternate candidate scores
Line 244: Line 341:
* <code>If(Batch.CreatedBy.ToLower() = "domain\jusername", TrueStepName, FalseStepName)</code>
* <code>If(Batch.CreatedBy.ToLower() = "domain\jusername", TrueStepName, FalseStepName)</code>
* <code>If(Batch.CreatedByDisplayName = "Joe Username", TrueStepName, FalseStepName)</code>
* <code>If(Batch.CreatedByDisplayName = "Joe Username", TrueStepName, FalseStepName)</code>


Inspecting creation time (range, day of week)
Inspecting creation time (range, day of week)
Line 259: Line 357:
* <code>Image.Size > 40960</code>
* <code>Image.Size > 40960</code>
* <code>Image.PixelCount > 3500000</code>
* <code>Image.PixelCount > 3500000</code>


Inspecting presence of layout data (of a certain type: lines, OMR boxes, etc.)
Inspecting presence of layout data (of a certain type: lines, OMR boxes, etc.)
Line 265: Line 364:
* <code>Results.Box_Detection.Boxes.Any()</code>
* <code>Results.Box_Detection.Boxes.Any()</code>
* <code>Results.Patch_Code_Detection.PatchCodes.Any()</code>
* <code>Results.Patch_Code_Detection.PatchCodes.Any()</code>


Decisioning based on image classification (Results.ClassifyImage.whatever)
Decisioning based on image classification (Results.ClassifyImage.whatever)
* <code>Results.Classify_Image.ClassName = "Sample 1"</code>
* <code>Results.Classify_Image.ClassName = "Sample 1"</code>


Accessing and inspecting results log of prior IP commands
Accessing and inspecting results log of prior IP commands
* <code>Results.Measure_Entropy.Entropy > 0.85</code>
* <code>Results.Measure_Entropy.Entropy > 0.85</code>


Inspecting whether prior commands modified image(s)
Inspecting whether prior commands modified image(s)
Line 280: Line 382:
* <code>String.Concat(field1, field2)</code>
* <code>String.Concat(field1, field2)</code>
* <code>String.Concat(field1, " ", field2)</code>
* <code>String.Concat(field1, " ", field2)</code>


Value padding (adding or removing)
Value padding (adding or removing)
Line 286: Line 389:
** <code>field2.PadRight(40)</code>
** <code>field2.PadRight(40)</code>
** <code>field3.Trim()</code>
** <code>field3.Trim()</code>


Adding environment variables (date, user, etc.)
Adding environment variables (date, user, etc.)
Line 299: Line 403:
* <code>IntegerField1 + IntegerField2</code>
* <code>IntegerField1 + IntegerField2</code>
* <code>DecimalField1 + DecimalField2 + DecimalField3</code>
* <code>DecimalField1 + DecimalField2 + DecimalField3</code>


Concatenation of multiple fields
Concatenation of multiple fields
* <code>String.Concat(StringField1, StringField2)</code>
* <code>String.Concat(StringField1, StringField2)</code>
* <code>String.Concat(StringField2, ", ", StringField1, ": ", StringField3)</code>
* <code>String.Concat(StringField2, ", ", StringField1, ": ", StringField3)</code>


How to access Grooper attributes (content type name, GUID, index data, etc.)
How to access Grooper attributes (content type name, GUID, index data, etc.)
Line 310: Line 416:
* <code>CurrentDocument.IndexData.Sections("Section1").Sections("SectionA").Fields("Field1A").Value</code>
* <code>CurrentDocument.IndexData.Sections("Section1").Sections("SectionA").Fields("Field1A").Value</code>
* <code>CurrentDocument.IndexData.Tables("Table1").Rows.First().Cells("Column1").Value</code>
* <code>CurrentDocument.IndexData.Tables("Table1").Rows.First().Cells("Column1").Value</code>


Naming based on original file name
Naming based on original file name
* <code>IO.Path.GetFileNameWithoutExtension(CurrentDocument.ContentLink.Name)</code>
* <code>IO.Path.GetFileNameWithoutExtension(CurrentDocument.ContentLink.Name)</code>


Converting a date field to a string in a "year-month-day" format
Converting a date field to a string in a "year-month-day" format

Revision as of 16:10, 19 June 2024

This article is a running list of code expressions used in Grooper, such as Default Value Expressions, Calculated Value Expressions, Should Submit Expressions and more.

Expressions are snippets of .NET code, allowing Grooper to do various things outside its "normal" parameters. This includes calculating or validating extracted Data Field values in a Data Model, applying conditional execution of a Batch Process or IP Profile, and more! This article collects examples of common (and maybe not so common) uses of expressions in Grooper.

😎

Special thanks to BIS team member Brian Godwin (and others on the Professional Services team) for contributing this article!

Data Model Expressions

Default Value Expressions

Global/System Variables

"Literal value"

Literal string values. Insert a literal string value into the field using quotes.


25.00

Literal numeric values. Insert a literal numeric values entering the number only.


Now

Current date and time


Now.ToString("d")

Current date only


Now.ToString("t")

Current time only


DateAdd("d", 30, Now)

Date and time 30 days from now.


Guid.NewGuid

New Guid (Globally Unique IDentifier)


My.User.Name

Name of the current user


My.Computer.Name

Name of the local machine

Files and Links

Link.FullPath

Returns the attached file's path, including the file's name from a Batch Folder's content link.


Link.Path

Returns the attached file's path, not including the file's name from a Batch Folder's content link.


Link.PathSegments(0)

Returns the first segment in a file path from a Batch Folder's content link. For example, "servername" in "servername\folder\subfolder\file.pdf"


Folder.AttachmentFileName

Returns the attached file's name.


Folder.AttachmentFileExtension

Returns the attached file's extension.


IO.Path.GetFileNameWithoutExtension(Link.ObjectName)

Returns the attached file's name only (without the extension) from a Batch Folder's content link.


Link.LinkName

Returns the name of the link (e.g. "Import" or "Export") from a Batch Folder's content link.


DirectCast(Link,FileSystemLink).CreatedTime

Inserts the complete DateTime representing when the original file was created.


DirectCast(Link,FileSystemLink).LastModifiedTime

Inserts the complete DateTime representing when the original file was last modified.


DirectCast(Link,MailLink).Subject

Inserts the Subject of an Imported Email


DirectCast(Link,MailLink).From

Inserts the From field of an Imported Email


DirectCast(Link,MailLink).To

Inserts the To field of an Imported Email


DirectCast(Link,MailLink).Date

Inserts the Date field of an Imported Email

Content Types

ContentTypeName

Populates the field with the name of the document's Content Type (its classified Document Type)

Note: This is a shortcut for the expression Folder.ContentType.DisplayName


Folder.ContentType.ParentNode.DisplayName

Useful to populate fields with the name of the document's Document Type's parent Content Category.

Misc Default Value Expressions

Guid.NewGuid

Creates a new Globally Unique Identifier (GUID) and inserts the value.


Folder.Id

Inserts the GUID of the current Batch Folder.


Folder.Batch.Id

Inserts the GUID of the current Batch Folder's Batch, regardless of the current folder's level

Calculated Value Expressions

Addition of multiple fields

  • IntegerField1 + IntegerField2
  • DecimalField1 + DecimalField2 + DecimalField3


Concatenation of multiple fields

  • String.Concat(StringField1, StringField2)
  • String.Concat(StringField1, StringField2, StringField3)
  • String.Concat(StringField1, StringField2, StringField3, StringField4)


Rounding

  • This example rounds a decimal value to a precision of 4 digits (e.g. 2.34567891 to 2.3457)
    • Math.Round(DecimalField1, 4)


Non-integer addition (e.g. of date values)

  • These examples increment a date by 30 days ("d"), 1 year ("yyyy"), and the last decrements the date by 3 months ("m")
    • DateAdd("d", 30, DateField1)
    • DateAdd("yyyy", 1, DateField1)
    • DateAdd("m", -3, DateField1)


Reformatting / Normalization of values

  • This example replaces any backslashes with underscores
    • StringField1.Replace("\", "_")
  • This example removes any backslashes
    • StringField1.Replace("\", "")


Substring calculation

  • These examples extract information contained within a string "ABC123456XXXX654321YYY" by designating the 0-based starting index and desired number of characters
    • ABC (first 3 characters): StringField1.Substring(0, 3)
    • 123456 (6 characters within the string): StringField1.Substring(3, 6)
    • XXXX (4 characters within the string): StringField1.Substring(9, 4)
    • YYY (last 3 characters): StringField1.Substring(StringField1.Length - 3)


Getting the location coordinates of a field on the document

  • This could be used to determine the coordinates and size of an extracted value on a document.
    • GetFieldInstance("Field Name").Location.ToString
    • Note, this returns logical location in inches, not pixels. So additional work would need to be performed to convert this to pixels if needed.

Validate Expressions

Date in past / future

  • This example ensures the date value is a past date
    • DateField1 < Now
  • This example ensures the date value is at least 30 days in the future
    • DateField1 >= DateAdd("d", 30, Now)


Equality / inequality of two fields (multiple options)

  • StringField1 = StringField2
  • IntegerField1.Equals(IntegerField2)
  • IntegerField1 <> DecimalField1
  • Not DecimalField1.Equals(DecimalField2)


Summing fields and comparing to another field

  • IntegerField1 + IntegerField2 = IntegerField3
  • DecimalField1 + DecimalField2 = DecimalField3
  • DecimalField1 = SumFieldInstance("Table1\AmountColumn")


Running regular expression against field

  • Text.RegularExpressions.Regex.IsMatch(StringField1, "[0-9]{6}")


Inspecting field-level confidence scores

  • Instance.Confidence > 0.8

Batch Processing Expressions

Should Submit Expression

Inspecting flagged status

  • These examples would submit the task when the object (i.e. folder, page) is flagged or not flagged (2nd example)
    • Item.Flagged
    • Not Item.Flagged
  • This example would submit the task when the object (folder) contains one or more flagged pages
    • DirectCast(Item, BatchFolder).FlaggedPages.Any()


Inspecting flagged message

  • Item.FlagReason = "Needs classification"
  • Item.FlagReason <> "Bypass review"


Inspecting presence of local copy in Grooper

  • DirectCast(Item, BatchFolder).HasLocalCopy


Inspecting existence of native version

  • DirectCast(Item, BatchFolder).HasAttachment


Inspecting MIME type

  • This example would submit the task when the object's (folder) represents a native PDF or the second if its mime type is PDF
    • DirectCast(Item, BatchFolder).IsNativePDF
    • DirectCast(Item, BatchFolder).AttachmentMimeType = "application/pdf"


Inspecting content type / parent content category

  • DirectCast(Item, BatchFolder).ContentTypeName = "MyContentType"
  • DirectCast(DirectCast(Item, BatchFolder).ContentType.ParentNode, ContentCategory).Name = "MyContentCategory"


Inspecting if a field is blank / populated

  • DirectCast(Item, BatchFolder).IndexData.Fields("StringField1").Value <> ""
  • Not String.IsNullOrEmpty(DirectCast(Item, BatchFolder).IndexData.Fields("StringField1").Value)


Inspecting image properties (resolution, color mode, aspect ratio, size (in bytes), pixel count, etc.)

  • DirectCast(Item, BatchPage).PrimaryImage.ResolutionX < 240
  • DirectCast(Item, BatchPage).PrimaryImage.IsBinary
  • DirectCast(Item, BatchPage).PrimaryImage.IsColor
  • DirectCast(Item, BatchPage).PrimaryImage.IsLandscape
  • DirectCast(Item, BatchPage).PrimaryImage.AspectRatio > 1.25
  • DirectCast(Item, BatchPage).PrimaryImage.Size > 40960
  • DirectCast(Item, BatchPage).PrimaryImage.PixelCount > 3500000


Inspecting presence of layout data (of a certain type: lines, OMR boxes, etc.)

  • DirectCast(Item, BatchFolder).HasLayoutData


Does page / document have OCR text?

  • DirectCast(Item, BatchFolder).HasRuntimeOCR
  • DirectCast(Item, BatchPage).HasRuntimeOCR


Inspecting classification candidates and classification scores, incl. alternate candidate scores

  • DirectCast(Item, BatchFolder).ContentTypeName = "Document Type Name"

Functions and Should Submits

Grooper can now use lambda functions in expressions (and not just Should Submits, all expressions!). This gives you some really advanced capabilities if you have more advanced .NET programing skills.

This example determines if a page scoped task, like Recognize or Execute > Rasterize should be submitted depending on how many text segments are present on a PDF page. If the PDF page has less than 15 text segments, the tasks submits, otherwise the PDF page is not processed.

  • This is useful when dealing with poorly formed PDFs that must be forced to be treated like an image when Grooper otherwise thinks they are a native text document.
Function() As Boolean
  If DirectCast(Item, BatchPage).IsPDF
    Dim doc As Grooper.PDF.PdfDoc = New Grooper.PDF.PdfDoc(DirectCast(Item, BatchPage).GetImageVersion, True)
    Dim info As Grooper.PDF.PdfPageInfo = doc.Sharp.GetPageInfo(0)
    Return (info.DrawTextOps.Count < 15)
  End If
  
End Function

You could change what property values determine if the task is submitted by changing the Return statement in the function. Here are some examples:

  • Return info.PageType = PDF.PdfPageInfo.PageTypes.Mixed - Tasks would submit if the PDF's page type is "Mixed"
  • Return info.RenderResolution = "Color @ 300 DPI" - Tasks would submit if the PDF's render format is Color @ 300 DPI.
  • Return info.PageSize = "8.50"" x 11.00""" - Tasks would submit if the PDF's page size is 8.5 x 11.
  • Return info.Images.Count = 4 - Tasks would submit if PDF has exactly 4 images embedded in it.
  • Return info.PathSegments.Count > 257 - Tasks would submit if the PDF has more than 257 vector drawing paths.

Next Step Expressions

Inspecting batch creator

  • If(Batch.CreatedBy.ToLower() = "domain\jusername", TrueStepName, FalseStepName)
  • If(Batch.CreatedByDisplayName = "Joe Username", TrueStepName, FalseStepName)


Inspecting creation time (range, day of week)

  • If(DatePart(DateInterval.Month, Batch.Created) = 6, TrueStepName, FalseStepName)
  • If(DatePart(DateInterval.Day, Batch.Created) > 15, TrueStepName, FalseStepName)

IP Profile Expressions

IP Command Should Execute Expressions

Inspecting image properties (resolution, color mode, aspect ratio, size, pixel count, etc.)

  • Image.ResolutionX < 240
  • Image.IsBinary
  • Image.IsColor
  • Image.IsLandscape
  • Image.AspectRatio > 1.25
  • Image.Size > 40960
  • Image.PixelCount > 3500000


Inspecting presence of layout data (of a certain type: lines, OMR boxes, etc.)

  • Results.Line_Detection.HorizontalLines.Any()
  • Results.Line_Detection.VerticalLines.Any()
  • Results.Box_Detection.Boxes.Any()
  • Results.Patch_Code_Detection.PatchCodes.Any()


Decisioning based on image classification (Results.ClassifyImage.whatever)

  • Results.Classify_Image.ClassName = "Sample 1"


Accessing and inspecting results log of prior IP commands

  • Results.Measure_Entropy.Entropy > 0.85


Inspecting whether prior commands modified image(s)

  • ResultList.IsImageSourceImage

Mapping Expressions

Import Mapping Expressions

Value concatenation

  • String.Concat(field1, field2)
  • String.Concat(field1, " ", field2)


Value padding (adding or removing)

  • These examples show how to left-pad a value with zeroes for 20 characters, right-pad a value with spaces for 40 characters, and finally trim a padded value of spaces.
    • field1.PadLeft(20, "0"c)
    • field2.PadRight(40)
    • field3.Trim()


Adding environment variables (date, user, etc.)

  • Now
  • Environment.MachineName
  • Environment.UserName
  • Environment.UserDomainName
  • Environment.OSVersion
  • Environment.ProcessorCount

Export Mapping Expressions

Addition of multiple fields

  • IntegerField1 + IntegerField2
  • DecimalField1 + DecimalField2 + DecimalField3


Concatenation of multiple fields

  • String.Concat(StringField1, StringField2)
  • String.Concat(StringField2, ", ", StringField1, ": ", StringField3)


How to access Grooper attributes (content type name, GUID, index data, etc.)

  • CurrentDocument.ContentTypeName
  • CurrentDocument.Id
  • CurrentDocument.IndexData.Sections("Section1").Fields("Field1").Value
  • CurrentDocument.IndexData.Sections("Section1").Sections("SectionA").Fields("Field1A").Value
  • CurrentDocument.IndexData.Tables("Table1").Rows.First().Cells("Column1").Value


Naming based on original file name

  • IO.Path.GetFileNameWithoutExtension(CurrentDocument.ContentLink.Name)


Converting a date field to a string in a "year-month-day" format

  • DateField.ToString("yyyy-MM-dd")

Misc Expression Snippets

These expressions may or may not be useful by themselves. It's most likely they are used as part of a larger expression. They are documented here to keep track of previously requested solutions.

Count the number of children at a certain level. This would count the number of Batch Folders that are direct children of a Batch Folder being processed.

  • ChildrenAtLevel(1).Count

Count the number of children at a certain level of a parent folder. This would count the number of Batch Folders that are direct children of the parent Batch Folder relative to the Batch Folder being processed.

  • ParentFolder.ChildrenAtLevel(1).Count

General

WIP

This section is a work-in-progress. It needs to be expanded for completeness.

Understanding how to traverse hierarchy of, e.g. batch or content model

Understanding how to parse tables by row & column

Identifying Sections by instance number

How to inspect properties of node

Dynamic referencing vs. GUID referencing

Conditional expressions with IIF / IF

Using LINQ in Expressions

Direct Casting: when to (Cast)