UltipaDocs
Try Playground
  • Overview
  • Class Definitions
  • Property Definitions
  • Using Ontology Labels
  • Validation & Enforcement
  1. Docs
  2. /
  3. Ontology

Property Definitions

Overview

Define ontology properties to describe relationships between classes (object properties) and attributes of nodes (data properties).

Object Properties

Object properties define edge types with domain (source) and range (target) constraints:

GQL
// Person knows Person
CREATE OBJECT PROPERTY @foaf:knows DOMAIN @foaf:Person RANGE @foaf:Person
GQL
// Person works for Organization
CREATE OBJECT PROPERTY @ex:worksFor DOMAIN @ex:Person RANGE @ex:Organization
GQL
// Organization employs Person
CREATE OBJECT PROPERTY @ex:employs DOMAIN @ex:Organization RANGE @ex:Person

Property Characteristics

Properties can have special characteristics that affect behavior:

CharacteristicDescription
SYMMETRICIf A->B exists, B->A is inferred
TRANSITIVEIf A->B and B->C exist, A->C is inferred
REFLEXIVEEvery node is related to itself
IRREFLEXIVENo node can be related to itself
FUNCTIONALEach node can have at most one outgoing edge
INVERSE FUNCTIONALEach node can have at most one incoming edge

Create property with characteristics:

GQL
// knows is symmetric - if Alice knows Bob, Bob knows Alice
CREATE OBJECT PROPERTY @foaf:knows DOMAIN @foaf:Person RANGE @foaf:Person SYMMETRIC
GQL
// ancestorOf is transitive - if A ancestor of B, B ancestor of C, then A ancestor of C
CREATE OBJECT PROPERTY @ex:ancestorOf DOMAIN @ex:Person RANGE @ex:Person TRANSITIVE
GQL
// hasBirthPlace is functional - a person has only one birthplace
CREATE OBJECT PROPERTY @ex:hasBirthPlace DOMAIN @ex:Person RANGE @ex:Location FUNCTIONAL

Inverse Properties

Define inverse relationships:

GQL
// worksFor and employs are inverses
CREATE OBJECT PROPERTY @ex:worksFor DOMAIN @ex:Person RANGE @ex:Organization
CREATE OBJECT PROPERTY @ex:employs DOMAIN @ex:Organization RANGE @ex:Person INVERSE OF @ex:worksFor

When you create one edge, the inverse is automatically inferred:

GQL
// Insert worksFor edge
INSERT (:@ex:Person {name: 'Alice'})-[:@ex:worksFor]->(:@ex:Organization {name: 'Acme'})

// Query employs (inverse) - returns the same relationship
MATCH (org@ex:Organization)-[:@ex:employs]->(person@ex:Person)
RETURN org.name, person.name
org.nameperson.name
AcmeAlice

Cardinality Constraints

Limit the number of relationships:

GQL
// A person can have at most one spouse
CREATE OBJECT PROPERTY @ex:hasSpouse FUNCTIONAL
GQL
// A country has exactly one capital
CREATE OBJECT PROPERTY @ex:hasCapital
  DOMAIN @ex:Country
  RANGE @ex:City
  FUNCTIONAL

Data Properties

Data properties define attributes with XSD types:

GQL
// String property
CREATE DATA PROPERTY @foaf:name DOMAIN @foaf:Agent TYPE xsd:string
GQL
// Numeric properties
CREATE DATA PROPERTY @foaf:age DOMAIN @foaf:Person TYPE xsd:integer
CREATE DATA PROPERTY @ex:salary DOMAIN @ex:Employee TYPE xsd:decimal
GQL
// Date/time properties
CREATE DATA PROPERTY @ex:birthDate DOMAIN @ex:Person TYPE xsd:date
CREATE DATA PROPERTY @ex:createdAt DOMAIN @ex:Document TYPE xsd:dateTime
GQL
// Boolean property
CREATE DATA PROPERTY @ex:isActive DOMAIN @ex:Account TYPE xsd:boolean

Supported XSD types:

TypeDescriptionExample
xsd:stringText"Alice"
xsd:integerWhole number42
xsd:decimalDecimal number3.14
xsd:floatFloating point1.5e10
xsd:doubleDouble precision1.5e100
xsd:booleanTrue/falsetrue
xsd:dateDate2024-03-15
xsd:dateTimeDate and time2024-03-15T10:30:00
xsd:timeTime10:30:00

Viewing Properties

List all defined properties:

GQL
SHOW PROPERTIES
propertytypedomainrangecharacteristics
@foaf:knowsOBJECT@foaf:Person@foaf:PersonSYMMETRIC
@ex:worksForOBJECT@ex:Person@ex:Organization
@ex:employsOBJECT@ex:Organization@ex:PersonINVERSE OF @ex:worksFor
@foaf:nameDATA@foaf:Agentxsd:string
@foaf:ageDATA@foaf:Personxsd:integer

Deleting Properties

Remove a property definition:

GQL
DROP PROPERTY @ex:tempProperty

Remove if exists:

GQL
DROP PROPERTY IF EXISTS @ex:tempProperty