Skip to content

Commit

Permalink
docs: add pre annoation schema
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-Shen committed Feb 26, 2024
1 parent 754de83 commit 54a7ff9
Show file tree
Hide file tree
Showing 42 changed files with 3,327 additions and 96 deletions.
61 changes: 58 additions & 3 deletions src/components/schema-table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, type FC } from 'react';
import { Link } from 'react-router-dom';
import { BiChevronRight } from '@react-icons/all-files/bi/BiChevronRight';
import { BiChevronDown } from '@react-icons/all-files/bi/BiChevronDown';
import clsx from 'clsx';
Expand All @@ -7,10 +8,11 @@ import { useTranslation } from 'react-i18next';
interface SchemaProp {
[key: string]: {
required?: string[];
$ref?: string;
type: string | string[];
description?: string;
default?: string | number | boolean;
items?: { properties: SchemaProp };
items?: { properties: SchemaProp, $ref?: string, anyOf?: SchemaProp[]};
properties?: SchemaProp;
additionalProperties?: {
anyOf?: SchemaProp[];
Expand All @@ -23,18 +25,48 @@ const typeBadgeMap = {
boolean: 'badge-error',
array: 'badge-primary',
object: 'badge-neutral',
null: 'badge-neutral',
} as Record<string, string>;

interface Schema {
type: 'object';
properties: SchemaProp;
required: string[];
definitions: SchemaProp;
}

interface JsonSchemaTableProps {
schema: Schema;
}

// #/definitions/TextAttribute -> text-attribute
function getReferenceName(ref: string) {
return ref.split('/').pop()!.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}

function makeReferenceUrl(ref: string) {
return `/schema/reference/${getReferenceName(ref)}`;
}

const resolveRef = (ref: string, definitions: SchemaProp | undefined) => {
if (!definitions || !ref.startsWith('#/definitions/')) {
return null;
}

const path = ref.slice('#/definitions/'.length).split('/');
let schema: SchemaProp | undefined = definitions;

for (const segment of path) {
schema = schema[segment] as unknown as SchemaProp;

if (!schema) {
break;
}
}

return schema;
};

const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
const { t } = useTranslation();
const headers = [t('field'), t('type'), t('required'), t('default'), t('description')];
Expand Down Expand Up @@ -68,6 +100,8 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
<div className="flex items-center gap-2">
{key}
{((value.type === 'array' && value.items?.properties) ||
(value.type === 'array' && value.items?.$ref) ||
value.$ref ||
(value.type === 'object' && (value.properties || value.additionalProperties))) && (
<button className="btn btn-square btn-xs text-lg" onClick={() => handleClick(fullKey)}>
{expandedFields.includes(fullKey) ? <BiChevronDown /> : <BiChevronRight />}
Expand All @@ -78,11 +112,11 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
<td>
<div className="flex gap-2">
{Array.isArray(value.type) ? (
value.type.map((typeItem) => (
value.type.map((typeItem) => typeBadgeMap[typeItem] ? (
<div key={typeItem} className={clsx('badge badge-outline', typeBadgeMap[typeItem])}>
{typeItem}
</div>
))
) : <Link key={typeItem} to={makeReferenceUrl(typeItem)}>{typeItem.split('/')[2]}</Link>)
) : (
<div className={clsx('badge badge-outline', typeBadgeMap[value.type])}>{value.type}</div>
)}
Expand All @@ -94,6 +128,27 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
</tr>,
];

if (value.type === 'array' && value?.items?.anyOf) {
rows.push(
...generateRows(
{ '': { type: value.items.anyOf.map((item) => (item.type || item.$ref) as unknown as string) } },
value.required ?? [],
`${fullKey}.`,
true,
depth + 1,
),
);
}

if (
((value.type === 'array' && value.items?.$ref) || (value.type === 'object' && value.$ref))
&& expandedFields.includes(fullKey)
) {
const refs = resolveRef(value.$ref || value.items!.$ref!, schema.definitions);

rows.push(...generateRows(refs.properties!, refs.required ?? [], `${fullKey}.`, true, depth + 1));
}

if (
((value.type === 'array' && value.items?.properties) || (value.type === 'object' && value.properties)) &&
expandedFields.includes(fullKey)
Expand Down
8 changes: 7 additions & 1 deletion src/locale/resources/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@
"audio": "Audio",
"audio.segment": "Segment",
"audio.frame": "Timestamp",
"general": "Text and tag",
"general.text": "Text",
"general.tag": "Tag",
"field": "Field",
"type": "Type",
"description": "Description",
"default": "Default",
"required": "Required",
"yes": "Yes",
"no": "No"
"no": "No",
"reference": "Reference",
"guide.reference.attribute": "Attribute",
"pre-annotation": "Pre-annotation"
}
7 changes: 6 additions & 1 deletion src/locale/resources/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@
"audio": "音频",
"audio.segment": "片断截取",
"audio.frame": "时间戳",
"general.text": "文本描述",
"general.tag": "标签分类",
"field": "字段",
"type": "类型",
"description": "描述",
"default": "默认值",
"required": "必填",
"yes": "",
"no": ""
"no": "",
"reference": "类型引用",
"guide.reference.attribute": "Attribute",
"pre-annotation": "预标注"
}
3 changes: 2 additions & 1 deletion src/pages/guide.introduction/markdown_en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
### Product Overview

LabelU is an open-source data annotation tool that can help users quickly, accurately, and efficiently annotate data, thereby improving the performance and quality of machine learning models. LabelU supports various types of annotations, including label classification, text description, bounding boxes, polygons, points, lines, cuboids, timestamps, segmentations, etc., meeting the annotation tasks of different scenarios and needs.
You can experience the product in two ways:
You can experience the product in ways below:

- Try LabelU tool kit: [https://opendatalab.github.io/labelU-Kit/](https://opendatalab.github.io/labelU-Kit/)
- Try LabelU online: [https://labelu.shlab.tech/](https://labelu.shlab.tech/)
- LabelU for local deployment: [https://opendatalab.github.io/labelU/#/guide/install](https://opendatalab.github.io/labelU/#/guide/install)
Expand Down
1 change: 1 addition & 0 deletions src/pages/guide.introduction/markdown_zh-CN.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

LabelU是一个开源的数据标注工具,它可以帮助用户快速、准确、高效地对数据进行标注,从而提高机器学习模型的性能和质量。LabelU支持多种标注类型,包括标签分类、文本描述、拉框、多边形、点、线、立体框、时间戳、片段分割等,满足不同场景和需求的标注任务。
体验产品可通过以下方式:

- 标注工具:[https://opendatalab.github.io/labelU-Kit/](https://opendatalab.github.io/labelU-Kit/)
- LabelU 在线体验:[https://labelu.shlab.tech/](https://labelu.shlab.tech/)
- LabelU 本地部署:[https://opendatalab.github.io/labelU/#/guide/install](https://opendatalab.github.io/labelU/#/guide/install)
Expand Down
9 changes: 0 additions & 9 deletions src/pages/schema.audio.frame/example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ import CodePreview from '../../components/code-preview';
"attributes": {
"contains": "Hello"
}
},
{
"id": "c8il22ceipi",
"time": 7.917824773413897,
"label": "label-1",
"order": 4,
"attributes": {
"contains": "Human"
}
}
]
}} />
3 changes: 1 addition & 2 deletions src/pages/schema.audio.frame/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
"description": "标注类别"
},
"attributes": {
"type": "object",
Expand Down
12 changes: 1 addition & 11 deletions src/pages/schema.audio.segment/example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ import CodePreview from '../../components/code-preview';
"order": 1,
"label": "label-1",
"attributes": {
"car": ["bmw"]
}
},
{
"id": "dtgvrzgfgcp",
"start": 5.713595166163143,
"end": 9.89003,
"order": 2,
"label": "label-1",
"attributes": {
"car": ["bmw"]
"car": ["smart"]
}
}
]
Expand Down
3 changes: 1 addition & 2 deletions src/pages/schema.audio.segment/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
"description": "标注类别"
},
"attributes": {
"type": "object",
Expand Down
9 changes: 7 additions & 2 deletions src/pages/schema.image.cuboid/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
Expand All @@ -186,8 +192,7 @@
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
"description": "标注类别"
}
},
"required": ["direction", "front", "back", "x", "y", "width", "height", "id", "order", "label"]
Expand Down
24 changes: 0 additions & 24 deletions src/pages/schema.image.line/example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,6 @@ import CodePreview from '../../components/code-preview';
"attributes": {},
"order": 1,
"label": "noneAttribute"
},
{
"points": [
{
"x": 684.9192073170732,
"y": 127.18064024390246,
"id": "yjRg1N7e"
},
{
"x": 787.5685975609756,
"y": 173.19588414634148,
"id": "ZNhLz1HW"
},
{
"x": 732.704268292683,
"y": 240.4489329268293,
"id": "4SKym9kd"
}
],
"id": "TZZj1VdS",
"visible": true,
"attributes": {},
"order": 2,
"label": "noneAttribute"
}
]
}} />
Expand Down
6 changes: 6 additions & 0 deletions src/pages/schema.image.line/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions src/pages/schema.image.point/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
Expand All @@ -37,8 +43,7 @@
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
"description": "标注类别"
}
},
"required": ["x", "y", "width", "height", "id", "order", "label"]
Expand Down
9 changes: 7 additions & 2 deletions src/pages/schema.image.polygon/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
Expand All @@ -70,8 +76,7 @@
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
"description": "标注类别"
}
},
"required": ["lineType", "points", "x", "y", "width", "height", "id", "order", "label"]
Expand Down
10 changes: 0 additions & 10 deletions src/pages/schema.image.rect/example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ import CodePreview from '../../components/code-preview';
"id": "0kjFS5rI",
"order": 4,
"label": "label-1"
},
{
"x": 515.016768292683,
"y": 603.2614329268292,
"width": 194.67987804878047,
"height": 69.02286585365853,
"visible": true,
"id": "AcO6GXyc",
"order": 5,
"label": "label-1"
}
]
}} />
9 changes: 7 additions & 2 deletions src/pages/schema.image.rect/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
Expand All @@ -45,8 +51,7 @@
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
"description": "标注类别"
}
},
"required": ["x", "y", "width", "height", "id", "order", "label"]
Expand Down
Loading

0 comments on commit 54a7ff9

Please sign in to comment.