Alter chunks with a script component
After you have generated document chunks, you can add the ability to create, edit, and delete chunks through a custom script component in your pipeline. This component is useful when you want to add additional metadata properties to a chunk, add a custom chunk to the generated chunks, or remove a specific chunk from a document (for example, a privacy notice that you may have appended to all documents). To add this component to your pipeline, do the following:
-
In your pipeline, add a script component.
-
Enter a name for your script component and click Add.
-
Click on the new component.
-
In the Configuration section, enter the custom script you want to apply to your chunks. Refer to the following example which uses a C# script to add, edit, and remove chunks:
Copyvar childItems = item.ChildItems;
//
var newChildItem = new BAInsight.ContentProcessing.V1.ProcessedChildItem(){
ItemProperties = new List<AbstractProperty>(){
new Property<string>(){Name="ChunkBody", Value="This is Chunk Body property Value"}
}
};
// Add Child
item.AddChild(newChildItem);
// Add Child item inheriting all the parent properties
item.AddChild(childItem, true);
// Add Child item inheriting all the parent properties but skipping few properties from parent
item.AddChild(childItem, true, new List<string>(){"Property1" "Property2"});
// Add Properties to ChildItem
foreach(var childItem in childItems){
var updatedChildItem = childItem;
updatedChildItem.AddProperty<string>("PropertyName", "PropertyValue");
}
// Get child Item property
var property = childItem.GetProperty<string>("PropertyName");
// Remove child Item property
childItem.RemoveProperty<string>("PropertyName");
//RemoveChild
item.RemoveChild(childItems[0].UniqueId); -
Click the sprocket icon ().
-
In the Namespaces textbox, add
BAInsight.ContentProcessing.V1
. When complete, the Namespaces textbox will look like the following:CopySystem.Text.RegularExpressions
System.Text
System.Linq
System.Collections.Generic
BAInsight.ContentProcessing.V1If you implement extra code in your script that calls third-party APIs, you will also need to add the namespaces for the necessary libraries in this textbox. For more information, see the "How to Define Assemblies and Namespaces to Import" section in how to use custom logic script.
-
Click OK
-
Click Compile to verify that the script successfully compiles.
-
Click Save.
-
When complete, you must position your script component after your document chunker component and before the chunk processor component.