Files
AI-Studio/app/MindWork AI Studio/Tools/DocumentSegments/IDocumentSegmentFormat.cs
T

63 lines
3.3 KiB
C#
Raw Normal View History

using AIStudio.Tools.Rust;
namespace AIStudio.Tools.DocumentSegments;
/// <summary>
/// A kind of document whose text a model works on segment by segment, while everything else of the
/// document stays as it is, e.g., Word documents or Markdown files.
/// </summary>
public interface IDocumentSegmentFormat
{
/// <summary>
/// The kind of file this format reads and writes, which the save dialog offers.
/// </summary>
public FileTypeFilter FileType { get; }
/// <summary>
/// What of a document of this kind stays as it is, for the user, e.g., "Code and formulas stay as they are."
/// </summary>
public string LimitsNotice { get; }
/// <summary>
/// The size of the largest text of a document this format reads on this computer, in bytes, see TextSizeOf.
/// </summary>
/// <remarks>
/// A format holds the text of a document in memory, as bytes, as text, and as the tree of its parser or the DOM of
/// the Open XML SDK, and takes many times its size while reading and writing it. Its limit keeps that within the
/// memory of this computer, see DocumentMemoryBudget, and a document with a larger text is refused with a
/// DocumentTooLargeException.
/// </remarks>
public long MaxTextSize { get; }
/// <summary>
/// Measures the text of a document, which the format holds in memory: the whole file of a document which is text
/// itself, and the XML of an Office document without its pictures and videos.
/// </summary>
/// <param name="path">The document.</param>
/// <returns>The size in bytes.</returns>
public long TextSizeOf(string path);
/// <summary>
/// Reads the segments of a document, in the order of the document.
/// </summary>
/// <param name="path">The document.</param>
/// <param name="logger">Where the format reports what goes wrong on the way, e.g., a temporary file which cannot be removed.</param>
/// <param name="token">Cancels the reading.</param>
/// <returns>The segments, including those without letters.</returns>
public Task<IReadOnlyList<DocumentSegment>> ReadAsync(string path, ILogger logger, CancellationToken token);
/// <summary>
/// Writes a copy of a document with the new texts of its segments.
/// </summary>
/// <remarks>
/// The format reads the source again and writes nothing when the results do not cover one of its
/// segments, or when the source changes while the format writes. It writes only into the target, which the user chose, and leaves the source as it is.
/// </remarks>
/// <param name="sourcePath">The document the segments were read from.</param>
/// <param name="targetPath">The new document, which the user chose.</param>
/// <param name="results">What became of the segments.</param>
/// <param name="languageTag">The IETF tag of the language of the new texts, e.g., "de-DE", which the format notes where the document records languages; empty when the language is unknown or unchanged.</param>
/// <param name="logger">Where the format reports what goes wrong on the way, e.g., a temporary file which cannot be removed.</param>
/// <param name="token">Cancels the writing.</param>
public Task<SegmentWriteResult> WriteAsync(string sourcePath, string targetPath, SegmentResults results, string languageTag, ILogger logger, CancellationToken token);
}