Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
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
import { types } from "mobx-state-tree";
 
import Registry from "../../core/Registry";
import Types from "../../core/Types";
import { guidGenerator } from "../../core/Helpers";
 
/**
 * The `Relations` tag is used to create label relations between regions. Use to provide many values to apply to the relationship between two labeled regions.
 *
 * Use with the following data types: audio, image, HTML, paragraphs, text, time series, video.
 * @example
 * <!--Basic labeling configuration to apply the label "similar" or "dissimilar" to a relation identified between two labeled regions of text -->
 * <View>
 *   <Relations>
 *     <Relation value="similar" />
 *     <Relation value="dissimilar" />
 *   </Relations>
 *
 *   <Text name="txt-1" value="$text" />
 *   <Labels name="lbl-1" toName="txt-1">
 *     <Label value="Relevant" />
 *     <Label value="Not Relevant" />
 *   </Labels>
 * </View>
 * @name Relations
 * @meta_title Relations Tag for Multiple Relations
 * @meta_description Customize Label Studio by adding labels to relationships between labeled regions for machine learning and data science projects.
 * @param {single|multiple=} [choice=single] Configure whether you can select one or multiple labels
 */
const TagAttrs = types.model({
  choice: types.optional(types.enumeration(["single", "multiple"]), "multiple"),
});
 
/**
 * @param {boolean} showinline
 * @param {identifier} id
 * @param {string} pid
 */
const ModelAttrs = types
  .model({
    id: types.optional(types.identifier, guidGenerator),
    pid: types.optional(types.string, guidGenerator),
    type: "relations",
    children: Types.unionArray(["relation"]),
  })
  .views((self) => ({
    get values() {
      return self.children.map((c) => c.value);
    },
    findRelation(value) {
      return self.children.find((c) => c.value === value);
    },
  }))
  .actions(() => ({}));
 
const RelationsModel = types.compose("RelationsModel", ModelAttrs, TagAttrs);
 
const HtxRelations = () => {
  return null;
};
 
Registry.addTag("relations", RelationsModel, HtxRelations);
 
export { HtxRelations, RelationsModel };