Have got text transformations working
This commit is contained in:
parent
9f2fa96b92
commit
41daf7cfc9
14 changed files with 178 additions and 17 deletions
53
frontend/wailsjs/go/models.ts
Executable file
53
frontend/wailsjs/go/models.ts
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
export namespace main {
|
||||
|
||||
export class TextSpan {
|
||||
text: string;
|
||||
pos: number;
|
||||
len: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new TextSpan(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.text = source["text"];
|
||||
this.pos = source["pos"];
|
||||
this.len = source["len"];
|
||||
}
|
||||
}
|
||||
export class ProcessTextRequest {
|
||||
action: string;
|
||||
input: TextSpan[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ProcessTextRequest(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.action = source["action"];
|
||||
this.input = this.convertValues(source["input"], TextSpan);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue