Nutrient Web SDK

ReferenceNutrientViewerComparisonOperation

Class ComparisonOperation

ComparisonOperation is a class that provides methods to describe a comparison operation. It encapsulates the type and optional settings for the comparison.

It is an Immutable.Record and thus can be updated using set(key, value), for example: scale.set("options", { numberOfContextWords: 4 })

Class

Example

Create a new text comparison operation.

const operation = new ComparisonOperation(NutrientViewer.ComparisonOperationType.TEXT, { numberOfContextWords: 2 });

Create a new AI comparison operation.

const aiOperation = new ComparisonOperation(
NutrientViewer.ComparisonOperationType.AI,
{ operationType: NutrientViewer.AIComparisonOperationType.ANALYZE, model: 'gpt4o' }
);

Default Value

{ type: NutrientViewer.ComparisonOperationType.TEXT, options: { numberOfContextWords: 0 } }

Hierarchy

RecordComparisonOperation

Constructors

  • Parameters

    type"text" | "ai"
    options
    {
    numberOfContextWords?: number;
    wordLevel?: boolean;
    [key: string]: any;
    }
    | { … }
    = {}

Properties

options

OptionalReadonly
IComparisonOperationOptions

type

Readonly
"text" | "ai"

Methods

  • Returns the AI operation type, if this is an AI comparison

    Returns

    "analyze" | "tag" | undefined
  • Returns true if this operation is an AI comparison

    Returns

    boolean
  • Returns true if this operation is a text comparison

    Returns

    boolean

Immutable Record API

31
string

The name provided to Record(values, name) can be accessed with displayName.

  • Returns

    IterableIterator<
    [
    keyof { options?: IComparisonOperationOptions; type: "text"
    | "ai" },
    "text" | "ai" | IComparisonOperationOptions | undefined
    ]
    >
  • Returns

    this

    See Also

    • Map#asImmutable

  • Returns

    this

    See Also

    • Map#asMutable

  • Returns a new instance of this Record type with all values set to their default values.

    Returns

    this
  • Returns a new instance of this Record type with the value for the specific key set to its default value.

    Type Parameters

    Kextends keyof { options?: IComparisonOperationOptions; type: "text" | "ai" }

    Parameters

    keyK

    Returns

    this
  • Parameters

    keyPathIterable<unknown>

    Returns

    this
  • Parameters

    otherunknown

    Returns

    boolean
  • Returns the value associated with the provided key, which may be the default value defined when creating the Record factory function.

    If the requested key is not defined by this Record type, then notSetValue will be returned if provided. Note that this scenario would produce an error when using Flow or TypeScript.

    Type Parameters

    Kextends keyof { options?: IComparisonOperationOptions; type: "text" | "ai" }

    Parameters

    keyK
    notSetValueunknown
    Optional

    Returns

    { options?: IComparisonOperationOptions; type: "text" | "ai" }[K]
  • Type Parameters

    T

    Parameters

    keystring
    notSetValueT

    Returns

  • Parameters

    keyPathIterable<unknown>

    Returns

    unknown
  • Parameters

    keystring

    Returns

    key is "type" | "options"
  • Returns

    number
  • Parameters

    keyPathIterable<unknown>

    Returns

    boolean
  • Parameters

    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ options?: IComparisonOperationOptions; type: "text" | "ai" }>
    )[]

    Returns

    this
  • Parameters

    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ options?: IComparisonOperationOptions; type: "text" | "ai" }>
    )[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collectionsunknown[]

    Returns

    this
  • Parameters

    merger(oldVal: unknown, newVal: unknown, key: unknown) => unknown
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ options?: IComparisonOperationOptions; type: "text" | "ai" }>
    )[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collectionsunknown[]

    Returns

    this
  • Parameters

    merger(
    oldVal: unknown,
    newVal: unknown,
    key: keyof { options?: IComparisonOperationOptions; type: "text" | "ai" }
    ) => unknown
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ options?: IComparisonOperationOptions; type: "text" | "ai" }>
    )[]

    Returns

    this
  • Type Parameters

    Kextends keyof { options?: IComparisonOperationOptions; type: "text" | "ai" }

    Parameters

    keyK

    Returns

    this
  • Parameters

    keyPathIterable<unknown>

    Returns

    this
  • Type Parameters

    Kextends keyof { options?: IComparisonOperationOptions; type: "text" | "ai" }

    Parameters

    keyK
    value{ options?: IComparisonOperationOptions; type: "text" | "ai" }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    valueunknown

    Returns

    this
  • Deeply converts this Record to equivalent native JavaScript Object.

    Note: This method may not be overridden. Objects with custom serialization to plain JS may override toJSON() instead.

    Returns

    { options?: unknown; type: "text" | "ai" }
  • Shallowly converts this Record to equivalent native JavaScript Object.

    Returns

    { options?: IComparisonOperationOptions; type: "text" | "ai" }
  • Shallowly converts this Record to equivalent JavaScript Object.

    Returns

    { options?: IComparisonOperationOptions; type: "text" | "ai" }
  • Returns

    Keyed<
    keyof { options?: IComparisonOperationOptions; type: "text"
    | "ai" },
    "text" | "ai" | IComparisonOperationOptions | undefined
    >
  • Type Parameters

    Kextends keyof { options?: IComparisonOperationOptions; type: "text" | "ai" }

    Parameters

    keyK
    updater(
    value: { options?: IComparisonOperationOptions; type: "text" | "ai" }[K]
    ) => { options?: IComparisonOperationOptions; type: "text" | "ai" }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    updater(value: unknown) => unknown

    Returns

    this
  • Returns

    boolean

    See Also

    • Map#wasAltered

  • Note: Not all methods can be used on a mutable collection or within withMutations! Only set may be used mutatively.

    Parameters

    mutator(mutable: this) => unknown

    Returns

    this

    See Also

    • Map#withMutations