About the Semantic Graph Index Data Model

Semantic Graph Index has an object-oriented data model. Unlike an SQL Database, which uses tables, Semantic Graph Index uses classes like object-oriented programming languages.

There are 2 main differences:

  • The support of inheritance between classes.
  • The native support of references between objects.

This page discusses:

See Also
Configuring Index Units
Main Workflows

Classes and Attributes

Being object-oriented the Semantic Graph Index data model uses classes. A class can inherit from one or more classes. Use a single inheritance when possible. A class is composed of attributes.

Example:

class Person {
    firstName : String
    lastName : String
    size : Integer
}

As you can see in this example, attributes are typed. The supported types are:

Default Class

The default class is Item. This type is the equivalent of Object in Java. When you declare a class without parent, it inherits from the Item class.

class Item {
    @RootClass
    uri: ItemUri
    class: ItemClass
    self: Binary
    text: FullTextSearch
    source: String
    stamp: String
}

The most important element in this class is the uri attribute. Fill this attribute (with a string) when pushing the item. It identifies the Item uniquely within an Index Unit.

Reference Type

The Reference type allows you to connect objects together.

Example:

class Company {
    name : String
    description : Text
}

class Employee : Person {
    employeeId : Integer
    company : Reference<Company>
}

In this example, the Reference type has a parameter, which is the Item type that the Reference targets. When pushing the items, you must use the uri of the targeted item.

Important: Reference attributes are indexed, which means that the query engine can reverse and traverse references efficiently.

In our example, it means that from a Company, you can efficiently retrieve all the employees of the company, even if the Reference is in the Employee class.

Standard traversal is faster than reverse traversal, but with this ability to traverse the Reference both ways, you can put the Reference attribute in the type that fits the best.

In our example, the Reference is in the Employee class to simplify the update. There is no need to repush the Company class every time an employee is added or deleted.

Structure Attributes (Collection, List, and Map Types)

The Data Model supports several "structure" attribute types: Collection, List, and Map.

Collection is a List in which the order may not be conserved for optimization reasons. You parameterize both types according to the type of the elements contained.

class Factory {
    name : String
    location : Geo
}

class Company {
    name : String
    description : Text
    factories : Collection<Factory>
}

The Map type is similar to a Map in Java or Javascript. It is a key / value structure. The key being necessarily a String, the Map type is parameterized according to the value only.

Use the Map type when it is impossible to create an attribute per key. This might occur because the set of keys is unknown when defining the Data Model, or if the set of keys is open. For example, photo captured by digital devices (scanner, camera) often contains EXIF or IPTC metadata. These formats are open and require a Map.

class Photo {
    filename : String
    content : Binary
    exif : Map<String>
}
Important: You cannot mix the use of primitive types (for example, Integers and Strings) in Map values.

However, you can specify advanced attribute types, like:

class Person {
    firstName : String
    lastName : String
    size : Integer
    relationships : Map<List<Reference<Person>>>
}

Packages

A class is part of a package. Packages are similar to Java packages, they are used as namespaces. A class is identified by the pair (package name, class name), which means that it is possible to have 2 classes with the same name in 2 different packages. When referencing a class outside of the current package, you must use its full name.

class Company {
    name : String
    description : Text
    factories : Collection<manufacturing.Factory>
}