1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
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
// }
|