GQLDB supports ontology features that bring semantic web capabilities to your graph database. This allows you to define classes, properties with domain/range constraints, and enable inference based on class hierarchies.
foaf: for FOAF vocabulary).| Feature | LPG (Labeled Property Graph) | Ontology Graph |
|---|---|---|
| Identity | Local identifier | Global IRI (foaf, ex), see Loading Prefixes |
| Node labels | Free-form labels | Ontology class labels (@prefix:Class), see Class Definitions |
| Edge labels | Free-form labels | Object properties, see Object Properties |
| Node attributes | Free-form key / value | Data properties with XSD-typed values, see Data Properties |
| Edge attributes | Free-form key / value | None |
| Schema | Optional (open graph) or defined (closed graph) | Class and property definitions |
| Inference | None | Subclass inference, property characteristics |
Create a graph with ontology support enabled:
GQLCREATE GRAPH myOntology WITH ONTOLOGY
A prefix is a short alias for a long IRI (Internationalized Resource Identifier). Ontology terms are identified by full IRIs, a prefix lets you write a short name instead.
For example, after loading foaf as an alias for http://xmlns.com/foaf/0.1/, the term <http://xmlns.com/foaf/0.1/Person> can be written as the ontology label @foaf:Person in GQL graph patterns.
Load common vocabularies:
GQLLOAD PREFIX foaf FROM 'http://xmlns.com/foaf/0.1/' LOAD PREFIX ex FROM 'http://example.org/' LOAD PREFIX rdfs FROM 'http://www.w3.org/2000/01/rdf-schema#' -- The FROM clause also accepts an IRI literal (angle-bracketed) instead of a quoted string LOAD PREFIX foaf FROM <http://xmlns.com/foaf/0.1/>
A few things follow from this:
LOAD PREFIX bigbird FROM 'http://xmlns.com/foaf/0.1/' works, and @bigbird:Person then means the same FOAF Person that @foaf:Person would. By convention, reuse the community-standard names (foaf, rdfs, schema, ex).Person (http://xmlns.com/foaf/0.1/Person) and Schema.org's Person (http://schema.org/Person) are distinct classes in the database even though both spell their local name "Person" — the prefix is what keeps them apart. A single node can be tagged as both without contradiction.Load all built-in standard prefixes (foaf, rdf, rdfs, owl, xsd, etc.):
GQLLOAD ALL PREFIX
To bulk-load every prefix declared in an RDF document at a URL or file path:
GQLLOAD PREFIX ALL FROM 'http://xmlns.com/foaf/spec/index.rdf' LOAD PREFIX ALL FROM <http://xmlns.com/foaf/spec/index.rdf> LOAD PREFIX ALL FROM 'file:///srv/onto/foaf.ttl'
View loaded prefixes:
GQLSHOW PREFIX
Drop a prefix:
GQLDROP PREFIX foaf
After dropping a prefix, ontology labels that referenced it (@foaf:Person, etc.) no longer resolve at parse time and queries using the short form fail. Any nodes / edges already stored under the prefix's full IRIs remain in the graph (the database stores IRIs, not the short name); re-LOAD PREFIX foaf FROM '…' to address them by short form again.
An external ontology is a vocabulary file authored outside of GQLDB, typically published by a standards body or community containing class hierarchies, property definitions, prefix declarations, and constraints in a serialization like OWL, Turtle, RDF/XML, or JSON-LD. Common examples include FOAF (people and social relations), Schema.org (web-structured-data terms used by Google), SKOS (concept schemes), Dublin Core (metadata terms), and PROV-O (provenance).
LOAD ONTOLOGY reads such a file and registers everything inside in one shot, saving you from defining classes and properties for each term by hand. The file path is resolved by the GQLDB server: the file must exist on the server's filesystem (and the GQLDB process must have read permission). Loading from a server-local file is the most reliable form as it avoids network and TLS variability.
Load from a file on the GQLDB server, format auto-detected from the .ttl extension:
GQLLOAD ONTOLOGY FROM 'file:///path/on/server/foaf.ttl'
The loader auto-detects from the file extension (.ttl → TURTLE, .owl/.rdf/.xml → RDFXML, .nt → NTriples). Pass FORMAT explicitly only when auto-detection would guess wrong (e.g. a .txt file containing Turtle, or a server that returns a generic content type):
GQLLOAD ONTOLOGY FROM 'file:///srv/onto/data.txt' FORMAT TURTLE
Supported FORMAT keywords: OWL, TURTLE, RDFXML, JSONLD.
VERBOSE surfaces parser warnings (unknown constructs, malformed triples) in the result message, useful when integrating a new ontology to surface silent compatibility issues:
GQLLOAD ONTOLOGY FROM 'file:///srv/onto/foaf.ttl' VERBOSE
FORMAT and VERBOSE can be combined, but FORMAT must come first:
GQLLOAD ONTOLOGY FROM 'file:///srv/onto/data.txt' FORMAT TURTLE VERBOSE
Loading from a URL is also supported. For https:// URLs the host's TLS certificate must be trusted by the system trust store; plain http:// skips TLS entirely. When FORMAT is omitted, the loader checks the response Content-Type header first, then the URL's file extension, and falls back to RDFXML if neither gives a hint.
GQLLOAD ONTOLOGY FROM 'https://schema.org/version/latest/schemaorg-current-https.rdf'
NOTEIf a URL fetch fails with a TLS error, download the file once onto the GQLDB server and load.
GQLSHOW ONTOLOGY
Example output:
| name | iri | classes | objectProperties | dataProperties |
|---|---|---|---|---|
| FOAF | http://xmlns.com/foaf/0.1/ | 14 | 25 | 19 |
| local | urn:local:myOntology | 3 | 1 | 2 |
It lists every ontology in the current graph with summary counts. It covers both imports and inline definitions:
LOAD ONTOLOGY import, named after the source IRI.local row is added if you've created any classes or properties inline (CREATE CLASS, CREATE OBJECT PROPERTY, CREATE DATA PROPERTY) instead of importing them. It groups all your inline definitions under one synthetic ontology.Related SHOW statements for finer views:
| Statement | Returns |
|---|---|
SHOW PREFIX | Loaded prefix → IRI mappings |
SHOW CLASSES | Every class, with localName, superClasses, label |
SHOW PROPERTIES | Every object/data property, with localName, type, domain, range, characteristics |