Use ontology class and property labels in INSERT, MATCH, and REMOVE operations to leverage semantic capabilities.
Use the @prefix:ClassName syntax to assign ontology class labels to nodes:
Syntax: :@prefix:ClassName in INSERT or MATCH patterns.
| Syntax | Description |
|---|---|
:@prefix:ClassName | Assign an ontology class to a node |
:@prefix:Class1&@prefix:Class2 | Assign multiple ontology classes using & |
Insert node with ontology class label:
GQLINSERT (:@foaf:Person {name: 'Alice', age: 30})
Insert node with multiple ontology labels:
GQLINSERT (:@foaf:Person&@foaf:Agent {name: 'Bob'})
Create a path with ontology labels:
GQLINSERT (:@ex:Person {name: 'Alice'})-[:@ex:knows]->(:@ex:Person {name: 'Bob'})
Edges can also have ontology labels using the @prefix:propertyName syntax. This enables domain/range validation and property characteristics like SYMMETRIC and TRANSITIVE.
Syntax: [:@prefix:propertyName] in edge patterns.
| Syntax | Description |
|---|---|
[:@prefix:propertyName] | Assign an ontology object property to an edge |
[@<http://full-iri>] | Use full IRI for edge type |
Insert edge with ontology label:
GQLMATCH (a@ex:Person), (b@ex:Person) WHERE a.name = 'Alice' AND b.name = 'Bob' INSERT (a)-[:@ex:knows]->(b)
Match edges by ontology property:
GQLMATCH (a)-[r:@ex:knows]->(b) RETURN a.name, b.name
Edge with full IRI syntax:
GQLMATCH (a)-[@<http://example.org/knows>]->(b) RETURN a.name, b.name
Use @prefix:name (without colon before @) to match nodes by their ontology class label:
Important: This matches the actual label assigned to the node.
| Syntax | Description |
|---|---|
MATCH (n@prefix:ClassName) | Match nodes by ontology class label |
MATCH (n) WHERE n@prefix:ClassName | Filter by ontology label in WHERE clause |
Match nodes by ontology class:
GQLMATCH (n@foaf:Person) RETURN n.name
Subclass inference - Employee extends Person:
GQL// Querying Person also returns Employee nodes MATCH (n@ex:Person) RETURN n.name, n.role
Match with both label and properties:
GQLMATCH (n@ex:Person) WHERE n.age > 25 RETURN n.name, n.age
The @= syntax matches nodes by their _iri property value, NOT by their label. This is useful for finding specific individuals in semantic web data.
Key Distinction:
@prefix:name - matches by label (ontology class)@=prefix:name - matches by _iri property value| Syntax | Description |
|---|---|
@=prefix:localName | Match node where _iri equals the expanded IRI |
@=<http://full-iri> | Match node where _iri equals the full IRI |
Insert nodes with _iri property:
GQLINSERT (:Person {name: 'Alice', _iri: 'http://example.org/alice'}) INSERT (:Person {name: 'Bob', _iri: 'http://example.org/bob'})
Match by IRI using prefix:
GQLMATCH (n@=ex:alice) RETURN n.name
| n.name |
|---|
| Alice |
Match by full IRI:
GQLMATCH (n@=<http://example.org/bob>) RETURN n.name
| n.name |
|---|
| Bob |
Label match vs IRI match:
GQL// Given: (:@ex:Person {name: 'Alice', _iri: 'http://example.org/alice'}) // This matches by LABEL (ontology class) MATCH (n@ex:Person) RETURN n.name // Returns Alice // This matches by _iri PROPERTY MATCH (n@=ex:alice) RETURN n.name // Returns Alice // These are DIFFERENT - one checks label, one checks _iri property
Use the REMOVE clause to remove ontology labels from nodes. The node itself remains; only the label is removed.
Syntax: REMOVE variable@prefix:ClassName
Remove ontology label from a node:
GQLMATCH (n@foaf:Person) WHERE n.name = 'Alice' REMOVE n@foaf:Person
Verify label was removed:
GQL// This now returns empty - Alice no longer has the label MATCH (n@foaf:Person) WHERE n.name = 'Alice' RETURN n
Node still exists with its properties:
GQLMATCH (n) WHERE n.name = 'Alice' RETURN n.name, n.age
You can combine regular labels, ontology labels, and IRI matching using & (conjunction) and | (disjunction).
| Syntax | Description |
|---|---|
:Label&@prefix:Class | Match nodes with both labels (AND) |
:Label|@prefix:Class | Match nodes with either label (OR) |
Combine regular label with IRI match:
GQLMATCH (n:Person&@=ex:alice) RETURN n.name
Multiple ontology labels:
GQLMATCH (n@foaf:Person&@foaf:Agent) RETURN n.name
Insert with regular and ontology labels:
GQLINSERT (:Employee&@ex:Person {name: 'Carol', role: 'Developer'})