←Select platform

ActionElement Class

Summary

Defines an action to be run after the document analyzer has finished inspecting the document.

Syntax
C#
C++/CLI
Python
public abstract class ActionElement 
public: 
   ref class ActionElement abstract 
class ActionElement: 
Remarks

To implement a custom action, derive from this class and implement the Run() function.

Any number of public properties for the custom type can be implemented.

This action receives the document and the analysis results and can perform tasks to edit the document accordingly.

ActionElement also can be saved and restored from DocumentAnalyzerRepository.

Example

This example shows how to define a custom action.

C#
Java
using Leadtools; 
using Leadtools.Document.Analytics; 
using Leadtools.Document; 
using Leadtools.Document.Unstructured; 
 
 
 
public class RedactAction : ActionElement 
{ 
   public RedactAction() 
   { 
      Id = "REDACT_DOCUMENT"; 
   } 
 
   public override void Run(LEADDocument document, IList<ElementSetResult> results) 
   { 
      //process(document, results.Items); 
      //save(document); 
   }          
} 
 
public void Sample() 
{ 
   var leadDoc = DocumentFactory.LoadFromFile(@"c:\test.docx", new LoadDocumentOptions()); 
   var analyzer = new DocumentAnalyzer(); 
   var elem = new UnstructuredElementSet() { Name = "Test", Element = CreateElement() }; 
   var actions = new ActionElementSet(); 
   actions.ActionElements.Add(new RedactAction()); 
 
   var runOptions = new DocumentAnalyzerRunOptions() 
   {             
      Actions = actions, 
   }; 
   runOptions.Elements.Add(elem); 
   analyzer.Run(leadDoc, runOptions); 
} 
 
private static GroupElement CreateElement() 
{ 
   GroupElement mainGroup = new GroupElement(); 
   mainGroup.Id = "ALL"; 
   mainGroup.Settings.SetValue(SettingsManager.Name, "all"); 
   mainGroup.Settings.SetValue(SettingsManager.ReportInElementResult, "true"); 
   mainGroup.Settings.SetValue(SettingsManager.Description, "Rules"); 
   mainGroup.Settings.SetValue(SettingsManager.Language, "en"); 
                   
   return mainGroup; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.IOException; 
import java.util.List; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.document.*; 
import leadtools.document.analytics.*; 
import leadtools.document.unstructured.*; 
 
 
public class RedactAction extends ActionElement { 
   private String Id; 
 
   public RedactAction() { 
      Id = "REDACT_DOCUMENT"; 
   } 
 
   @Override 
   public void run(LEADDocument document, List<ElementSetResult> results) { 
      System.out.println("Process hit"); 
      assertTrue(document != null); 
      // process(document, results.Items); 
      // save(document); 
   } 
} 
 
public void sample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   LEADDocument leadDoc = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "LEADTOOLSEditor.docx"), 
         new LoadDocumentOptions()); 
   DocumentAnalyzer analyzer = new DocumentAnalyzer(); 
   UnstructuredElementSet elem = new UnstructuredElementSet(); 
   elem.setName("Test"); 
   elem.setElement(createElement()); 
   ActionElementSet actions = new ActionElementSet(); 
   actions.getActionElements().add(new RedactAction()); 
 
   DocumentAnalyzerRunOptions runOptions = new DocumentAnalyzerRunOptions(); 
 
   runOptions.setActions(actions); 
 
   runOptions.getElements().add(elem); 
   analyzer.run(leadDoc, runOptions); 
} 
 
private static GroupElement createElement() { 
   GroupElement mainGroup = new GroupElement(); 
   mainGroup.setId("ALL"); 
   mainGroup.getSettings().setValue(SettingsManager.NAME, "all"); 
   mainGroup.getSettings().setValue(SettingsManager.REPORT_IN_ELEMENT_RESULT, "true"); 
   mainGroup.getSettings().setValue(SettingsManager.DESCRIPTION, "Rules"); 
   mainGroup.getSettings().setValue(SettingsManager.LANGUAGE, "en"); 
 
   return mainGroup; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Analytics Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.