UNPKG

@wowool/portal

Version:

A library for natural language processing tasks including tokenization, entity recognition, anonymization, semantic chunking, and much more.

169 lines (158 loc) 5.36 kB
interface PingResponse { status: string; apiVersion: string; message: string; clientAgent: string; clientMinimumVersion?: string; clientCurrentVersion?: string; } type PipelineSteps = string | string[]; type InputMimeType = "text/plain" | "text/html" | "text/markdown" | "application/pdf" | "application/rtf" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.wowool.document-analysis+json"; type AnalysisMimeType = "application/vnd.wowool.document-analysis+json"; type Metadata = Record<string, string>; interface DocumentInterface<MimeType> { id: string; mimeType: MimeType; encoding: string; data: unknown; metadata: Metadata; } interface InputDocumentInterface extends DocumentInterface<InputMimeType> { } interface AnalysisDocumentInterface extends DocumentInterface<AnalysisMimeType> { } interface Diagnostic { message: string; type: number; id?: string; line?: number; offset?: number; } interface AppResults { results?: any; diagnostics?: Diagnostic[]; } interface TextAnalysis$1 extends AppResults { results?: { language: string; sentences: any[]; metadata?: Record<string, string>; }; diagnostics?: Diagnostic[]; } type DocumentAnalysis = Record<string, AppResults>; type AnnotationType = "Sentence" | "Entity" | "Token"; declare class Annotation { readonly raw: any[]; readonly rawChildren: any[]; constructor(raw: any[], rawChildren: any[]); get type(): AnnotationType; get beginOffset(): number; get endOffset(): number; toJSON(): { type: AnnotationType; beginOffset: number; endOffset: number; }; log(): void; } interface Morpheme { lemma: string; partOfSpeech: string; } declare class Token extends Annotation { literal: string; properties: string[]; morphemes: Morpheme[]; constructor(rawToken: any[]); toJSON(): { literal: string; properties: string[]; morphemes: Morpheme[]; type: AnnotationType; beginOffset: number; endOffset: number; }; } interface Attribute { key: string; values: string[]; } declare class Entity extends Annotation { uri: string; attributes: Attribute[]; tokens: Token[]; constructor(rawEntity: any, rawAnnotations: any[]); get text(): string; toJSON(): { uri: string; attributes: Attribute[]; type: AnnotationType; beginOffset: number; endOffset: number; }; } declare class Sentence extends Annotation { annotations: Annotation[]; constructor(rawSentence: any[]); get entities(): Entity[]; get tokens(): Token[]; get text(): string; forEachEntity(callback: (entity: Entity, index: number) => void): void; forEachToken(callback: (token: Token, index: number) => void): void; toJSON(): { annotations: { type: AnnotationType; beginOffset: number; endOffset: number; }[]; type: AnnotationType; beginOffset: number; endOffset: number; }; } declare class TextAnalysis { private readonly rawTextAnalysis; readonly sentences: Sentence[]; private _tokens?; private _entities?; constructor(rawTextAnalysis: TextAnalysis$1); get tokens(): Token[]; get entities(): Entity[]; forEachSentence(callback: (sentence: Sentence, index: number) => void): void; forEachToken(callback: (token: Token, index: number) => void): void; forEachEntity(callback: (entity: Entity, index: number) => void): void; } declare class AnalysisDocument implements AnalysisDocumentInterface { private readonly _rawAnalysisDocument; private readonly _analysis?; constructor(_rawAnalysisDocument: AnalysisDocumentInterface); get id(): string; get mimeType(): "application/vnd.wowool.document-analysis+json"; get encoding(): string; get data(): unknown; get metadata(): Metadata; get analysis(): TextAnalysis; } declare function isSentence(annotation: Annotation): boolean; declare function isEntity(annotation: Annotation): boolean; declare function isToken(annotation: Annotation): boolean; declare class Pipeline { private readonly steps; private readonly portal; constructor(steps: PipelineSteps, portal: Portal); constructor(steps: PipelineSteps, apiKey?: string); process(document: InputDocumentInterface | string): Promise<AnalysisDocument>; processBatch(documents: (InputDocumentInterface | string)[]): Promise<AnalysisDocument[]>; } declare class Portal { private readonly apiKey; readonly baseUrl: string; constructor(apiKey?: string, hostUrl?: string); ping(): Promise<PingResponse>; createPipeline(steps: PipelineSteps): Pipeline; get headers(): Record<string, string>; validateResponse(response: Response): Promise<void>; private throwApiError; } export { AnalysisDocument, type AnalysisDocumentInterface, type AnalysisMimeType, Annotation, type AppResults, type Diagnostic, type DocumentAnalysis, type DocumentInterface, Entity, type InputDocumentInterface, type InputMimeType, type Metadata, Pipeline, Portal, Sentence, type TextAnalysis$1 as TextAnalysis, Token, isEntity, isSentence, isToken };