Skip to content

Main content

Token Offset Domain Gap Tool

Extract a half-open token span with an explicit code-point versus UTF-16 offset domain.

Loading tool…

Description

Slice a supplied string under a code-point or UTF-16 coordinate convention.

Language-processing records depend on tokenization, indexing, null sentinels and text representation. A UTF-8 byte offset, UTF-16 index, dependency link or literal feature label can be handled precisely without inferring linguistic correctness or semantic equivalence.

Slice a supplied string under a code-point or UTF-16 coordinate convention.

When to use this tool

Use Token Offset Domain Gap when checking a supplied linguistic annotation, span, alignment or text-offset convention.

How to use the tool and how it works

  1. Enter sourceText, start, end, codePointOffsets. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read slice, length, utf16Start, utf16End. Use the output convention below.

Slice a supplied string under a code-point or UTF-16 coordinate convention. Require 0 <= start <= end <= chosen unit count; return the half-open slice, selected-unit length and equivalent UTF-16 start/end offsets.1

UTF-8 bytes, UTF-16 code units and Unicode code points are distinct; grapheme boundaries need separate treatment.2

Input fieldMeaning and unitsAccepted input
sourceTextSource TextRequired. Text; maximum UTF-16 length 8192.
startStartRequired. Safe integer; minimum 0.
endEndRequired. Safe integer.
codePointOffsetsCode Point OffsetsRequired. Boolean.
Output fieldInterpretationReturned shape
sliceSliceRequired. Text; maximum UTF-16 length 8192.
lengthLengthRequired. Safe integer.
utf16StartZero-based UTF-16 code-unit start of the chosen-unit slice.Required. Safe integer.
utf16EndExclusive UTF-16 code-unit end; may split a surrogate under code-unit mode.Required. Safe integer.
json
{
  "input": {
    "sourceText": "A😀B",
    "start": 1,
    "end": 2,
    "codePointOffsets": true
  },
  "output": {
    "slice": "😀",
    "length": 1,
    "utf16Start": 1,
    "utf16End": 3
  }
}

Limitations and assumptions

  • Code-point indexes are not grapheme indexes; UTF-16 slicing can split surrogate pairs and no normalization is applied.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
  • Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.

Alternative or Complementary methods

Use the appropriate tokenizer, Unicode and annotation-format conventions and validate the complete text or tree for full linguistic processing.

References

  1. Calculation and input contract: computational-linguistics/token-offset-domain-gap — tool.io

  2. Unicode 17.0: conformance and encoding forms — Unicode Consortium

Similar or alternative tools