]> gerrit.simantics Code Review - simantics/platform.git/blob - docs/Developer/Ontology/TransferableGraph.md
c40e25be0c796c60796eda1798bb9ced14e026aa
[simantics/platform.git] / docs / Developer / Ontology / TransferableGraph.md
1 Transferable Graph (.tg) is a statement container file. Transferable Graphs can be exported from and imported into graph databases.\r
2 \r
3 The format uses [Binary Container Format](BinaryContainerFormat.md) where content is encoded with the following datatype according to the [Databoard Specification](../Data/Databoard.md):\r
4 \r
5 ## Format (graph:1)\r
6 \r
7 ~~~\r
8  type TransferableGraph1 = {\r
9      resourceCount : Integer,\r
10      extensions : Map(String, Variant),\r
11      identities : Identity[],    \r
12      statements : Integer[],\r
13      values : Value[]\r
14  }\r
15 \r
16  type Identity {\r
17      resource : Integer,\r
18      definition : IdentityDefinition\r
19  }\r
20 \r
21  type IdentityDefinition =\r
22      | Root { name : String, type : String }\r
23      | External { parent : Resource, name : String }     \r
24      | Optional { parent : Resource, name : String }\r
25      | Internal { parent : Resource, name : String }\r
26 \r
27  type Value = {\r
28      resource : Integer,\r
29      value : Variant\r
30  }\r
31 ~~~\r
32 \r
33 Each resource in a transferable graph is referred with a 32-bit integer beginning with zero.\r
34 \r
35 | Field | Description |\r
36 |-------|-------------|\r
37 |resourceCount|Tells how many resources are used in the file. Some resources may already exist in the database, some will be new.|\r
38 |extensions|Any additional data represented as variants and identified by string keys. Allows transferable graph contents extensibility without format changes. Extensions will most probably contain data that is somehow related to statement and value data that comes after it. Therefore it is better for streaming input to have it available earlier than the data itself.|\r
39 |identities|Tells how to find the resources that should already exist in the database. Also the new resources with URI are given an identity so that it easier to refer to them when the graphs are compiled separately. The identities have to be ordered so that if the identity refers to another resource, its identity is already given.|\r
40 |statements|Contains all new statements that the transferable graph defines. The length of the array is 4*resourceCount. The array has for every statement its subject, predicate, inverse of the predicate and object in this order. If the statement does not have an inverse (that is different from itself), the inverse is -1.|\r
41 |values|Assigns values to all literals in the transferable graph. Literals are represented as variants.|\r
42 \r
43 An identity can be of one of the following types:\r
44 * `Root` defines a resource as a root. If `name` is "", the resource is the root library of the database. Other roots are interpreted in application specific ways.\r
45 * `External` tells that a resource is a child of some other resource and should already exist in the database.\r
46 * `Optional` tells that a resource is a child of some other resource. It may exist or not exist already in the database. In the latter case, it is created.\r
47 * `Internal` tells that a resource is a child of some other resource. It may not yet exist in the database for the import to be successful.\r
48 \r
49 ## Conversions\r
50 \r
51 Conversion from version 0 to version graph:1. [[File:tg0_tg1.jar]] Usage:\r
52 \r
53     java -jar tg0_tg1.jar graph input.tg output.tg\r
54 \r
55 The second argument is the name of the target file format.\r