mirror of https://github.com/doccano/doccano.git
pythonannotation-tooldatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learning
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.5 KiB
69 lines
1.5 KiB
import { Fields, ParametersForUI } from '@/models/config/config-item-list'
|
|
|
|
export interface Schema {
|
|
title: string,
|
|
type: string,
|
|
properties: object
|
|
}
|
|
|
|
export interface ConfigResponse {
|
|
name: string,
|
|
schema: Schema,
|
|
template: string
|
|
}
|
|
|
|
export class ConfigTemplateItem {
|
|
constructor(
|
|
private schema: Schema,
|
|
public template: string
|
|
) {}
|
|
|
|
static valueOf(
|
|
{ schema, template }:
|
|
{ schema: Schema, template: string }
|
|
): ConfigTemplateItem {
|
|
return new ConfigTemplateItem(schema, template)
|
|
}
|
|
|
|
get modelName(): string {
|
|
return this.schema.title
|
|
}
|
|
|
|
get fields(): ParametersForUI[] {
|
|
const response: ParametersForUI[] = []
|
|
for (const [key, value] of Object.entries(this.schema.properties)) {
|
|
if ('type' in value && value.type === 'string') {
|
|
response.push({name: key, type: 'textField', value: ''})
|
|
} else if ('anyOf' in value) {
|
|
response.push(
|
|
{
|
|
name: key,
|
|
type: 'selectField',
|
|
value: '',
|
|
items: value.anyOf.map(
|
|
(item: {'const': string, 'type': string}) => item.const
|
|
)
|
|
}
|
|
)
|
|
} else if ('type' in value && value.type === 'object') {
|
|
response.push(
|
|
{
|
|
name: key,
|
|
type: 'objectField',
|
|
value: []
|
|
}
|
|
)
|
|
}
|
|
}
|
|
return response
|
|
}
|
|
|
|
toObject(): Fields {
|
|
return {
|
|
modelName: this.modelName,
|
|
template: this.template,
|
|
modelAttrs: this.fields,
|
|
labelMapping: []
|
|
}
|
|
}
|
|
}
|