import type { AsyncRes, Result } from "sortug"; const ENDPOINT = "http://localhost:8102"; export async function segmenter(text: string, lang: string) { try { const body = JSON.stringify({ lang, string: text }); const opts = { headers: { "Content-type": "application/json" }, method: "POST", body, }; const res = await fetch(ENDPOINT + "/segment", opts); console.log("stanza", res); const j = await res.json(); return { ok: j }; } catch (e) { return { error: `${e}` }; } } export async function idLang(text: string) { try { const body = JSON.stringify({ string: text }); const opts = { headers: { "Content-type": "application/json" }, method: "POST", body, }; const res = await fetch(ENDPOINT + "/detect-lang", opts); const j = await res.json(); return { ok: j }; } catch (e) { return { error: `${e}` }; } } export type Sentence = { text: string; sentiment: number; constituency: string; dependencies: Dependency[]; entities: Entity[]; tokens: Token[]; words: Word[]; }; export type Dependency = Array<[Word, string, Word]>; export type Word = { id: number; text: string; lemma: string; upos: string; xpos: string; feats: string; head: number; deprel: string; start_char: number; end_char: number; }; export type Token = { id: [number, number]; text: string; misc: string; words: Word[]; start_char: number; end_char: number; ner: string; }; export type Entity = { text: string; misc: string; start_char: number; end_char: number; type: string; }; // "amod", // { // "id": 1, // "text": "Stony", // "lemma": "Stony", // "upos": "ADJ", // "xpos": "NNP", // "feats": "Degree=Pos", // "head": 3, // "deprel": "amod", // "start_char": 0, // "end_char": 5 // }