]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - docs/Developer/Ontology/GraphFileFormat.md
First test on Simantics documentation using gitbook
[simantics/platform.git] / docs / Developer / Ontology / GraphFileFormat.md
diff --git a/docs/Developer/Ontology/GraphFileFormat.md b/docs/Developer/Ontology/GraphFileFormat.md
new file mode 100644 (file)
index 0000000..6ea38fe
--- /dev/null
@@ -0,0 +1,219 @@
+Textual graph format is used to write ontologies in Simantics platform. [Graph Compiler](GraphCompiler.md) translates textual format to binary [Transferable graphs](TransferableGraph.md) that can be then imported to Simantics database.\r
+\r
+## Syntax\r
+\r
+### Indentation\r
+\r
+The graph format is indentation based. The amount of indentation can be freely chosen, but it has to be consistent with the previous lines. The lines can be indendented only with spaces. Tabulators are not allowed.\r
+\r
+Both C and C++ style comments are allowed. If a C style comment begins a line, there must not be anything else in the line after the comment, otherwise the amount of indentation would be then unclear. Text in parenthesis (), [] and {} can be freely indented.\r
+\r
+### Statements\r
+\r
+A graph file describes a collection of statements. One statement is written as:\r
+\r
+    Subject Predicate Object\r
+\r
+and represented graphically as\r
+\r
+![Subject Predicate Object](Images/SubPreObj.png)\r
+\r
+Statements with the same subject can be written in the same line\r
+\r
+    Subject Predicate1 Object1 Predicate2 Object2 Predicate3 Object3\r
+\r
+or with multiple indented lines\r
+\r
+~~~\r
+ Subject\r
+     Predicate1 Object1\r
+     Predicate2 Object2\r
+     Predicate3 Object3\r
+~~~\r
+\r
+These forms can also be combined\r
+\r
+~~~\r
+ Subject Predicate1 Object1 Predicate2 Object2\r
+     Predicate3 Object3\r
+     Predicate4 Object4\r
+~~~\r
+\r
+Statements with the same subject and predicate can be abbreviated as\r
+\r
+~~~\r
+ Subject\r
+     Predicate\r
+         Object1\r
+         Object2\r
+         Object3\r
+~~~\r
+\r
+In this case, there must be no objects in the same line with the predicate.\r
+\r
+Statements concerning the object of another statement can be written after the object if the object is not in the same line with the original subject. The following texts describe the same graph:\r
+\r
+![Subject Predicate Object Chain](Images/SubPreObj_chain_01.png)\r
+\r
+~~~\r
+Subject Predicate1 Object1\r
+Object1 Predicate2 Object2\r
+\r
+Subject\r
+    Predicate1 Object1 Predicate2 Object2\r
+\r
+Subject\r
+    Predicate1 Object1\r
+        Predicate2 Object2\r
+\r
+Subject\r
+    Predicate1\r
+        Object1 Predicate2 Object2         \r
+\r
+Subject\r
+    Predicate1\r
+        Object1\r
+            Predicate2 Object2\r
+\r
+Subject\r
+    Predicate1\r
+        Object1\r
+            Predicate2\r
+                Object2\r
+~~~\r
+\r
+### Resources\r
+\r
+Subject, predicate, and object of a statement are all resources. Predicates and other resources are handled little differently. A resource can be in one of the following forms:\r
+* Identifier\r
+* URI\r
+* Reference to a child of another resource\r
+* Literal value (not allowed as a predicate)\r
+* Data type (not allowed as a predicate)\r
+* A special relation: =, <T, <R, : (allowed only as a predicate)\r
+\r
+Identifier must begin with a letter or '_' and continue with letters, numbers and '_' characters. Single underscore _ is a special identifier that denotes a fresh resource: Every _ refers to a different resources.\r
+\r
+URI is enclosed in <>-characters and must begin with "http:". For example\r
+`<http://www.simantics.org/Layer0-1.0/InstanceOf>`.\r
+\r
+The syntax of literal values and data types is specified in [[Databoard Specification#Value Text Notation]]. Variants and tagged values (of some union type) must be enclosed in parenthesis. A data type must be prefixed with $ and union types and array types must be enclosed in parenthesis.\r
+\r
+References are used to refer URIs: If identifier A referes to <nowiki><http://somedomain/A></nowiki>, then A.Foo referes to <nowiki><http://somedomain/A/Foo></nowiki>. If URI contains non-alphanumerical characters, the name can be enclosed in double quotes. For example A."Cul-de-sac" refers to <nowiki><http://somedomain/A/Cul-de-sac></nowiki>.\r
+\r
+Special relations are abbreviations of some Layer0 relations:\r
+{|\r
+|-\r
+|width="40px" align="center"| =\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/Equals</nowiki>\r
+|-\r
+|width="40px" align="center"| <T\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/Inherits</nowiki>\r
+|-\r
+|width="40px" align="center"| <R\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/SubrelationOf</nowiki>\r
+|-\r
+|width="40px" align="center"| :\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/InstanceOf</nowiki>\r
+|-\r
+|width="40px" align="center"| >--\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/IsDomainOf</nowiki>\r
+|-\r
+|width="40px" align="center"| <--\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/HasDomain</nowiki>\r
+|-\r
+|width="40px" align="center"| -->\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/HasRange</nowiki>\r
+|-\r
+|width="40px" align="center"| ==>\r
+| <nowiki>http://www.simantics.org/Layer0-1.0/RequiresValueType</nowiki>\r
+|}\r
+\r
+### Templates\r
+\r
+A template is a parametrized graph that can be defined and instantiated.\r
+\r
+A template is defines as follows:\r
+\r
+~~~\r
+ <name of the template> : L0.Template\r
+     @template <parameters>\r
+         <template body>\r
+~~~\r
+\r
+for example\r
+\r
+~~~\r
+ L0.assert : L0.Template\r
+     @template %type %predicate %object\r
+         %type\r
+             L0.Asserts _ : L0.Assertion\r
+                 L0.HasPredicate %predicate\r
+                 L0.HasObject    %object\r
+~~~\r
+\r
+The template body is written in normal graph notation that can be refer to the parameters.\r
+\r
+A templates is applied as follows:\r
+\r
+    @<name of the template> <parameter1> ... <parameterN>\r
+        <parameterN+1> ...\r
+            ...\r
+        <parameterN+2> ...\r
+            ...\r
+        ...\r
+\r
+For example\r
+\r
+    My.Type <T L0.Entity\r
+        @L0.assert My.HasTransformation\r
+            4.0 : My.Transformation\r
+\r
+## Completion rules\r
+\r
+A textual graph is flattened to a set of raw statements in a straightforward way. After that some rules are applied that add statements to the graph.\r
+\r
+### Merging equal resources\r
+\r
+All resources that have the relation `<http://www.simantics.org/Layer0-1.0/Equals>` (=) between them are merged, i.e their statements are combined. This can be used to give shorthand references to resources:\r
+\r
+~~~\r
+L0 = <http://www.simantics.org/Layer0-1.0>\r
+Foo <T L0.Entity\r
+~~~\r
+\r
+### Typing literals\r
+\r
+The data type of a literal must be specified either with HasDataType statement or by instantiating a type that asserts this kind of statement:\r
+\r
+    1 : L0.Literal\r
+        L0.HasDataType @Integer\r
+\r
+    1 : L0.Integer\r
+\r
+In order to make writing graphs easier, the InstanceOf statement of a literal is derived from the value, if it is not explicitly specified. The following literal types defined in Layer0 are supported:\r
+* Boolean\r
+* Integer\r
+* Double\r
+* String\r
+* BooleanArray\r
+* IntegerArray\r
+* DoubleArray\r
+* StringArray\r
+\r
+### Inverse relations\r
+\r
+A default inverse relation is created for a relation whose superrelation has an inverse. Also superrelations are added to inverses automatically based on the superrelations of the relation.\r
+\r
+Relations will thus have inverses if:\r
+* an inverse is explicitly defined for a relation:\r
+\r
+      ONTOLOGY.SymmetricRelation <R L0.IsWeaklyRelatedTo\r
+         @L0.symmetric\r
+      ONTOLOGY.RelationWithExplicitInverse <R L0.IsRelatedTo\r
+         L0.InverseOf ONTOLOGY.RelationWithExplicitInverse.Inverse <R L0.IsRelatedTo\r
+\r
+* a relation is inherited from another relation that has an inverse, in which case an inverse relation is generated if one is not defined.\r
+\r
+      ONTOLOGY.RelationWithGeneratedInverse <R L0.IsComposedOf\r
+      // ONTOLOGY.RelationWithGeneratedInverse.Inverse will be generated\r