SPARQL Magic Properties | AllegroGraph 9.0.1
Author: Franz Incorporated

Copyright (c) 2005 - 2026 Franz, Incorporated
Last updated 27 May 2026 at 10:34

# SPARQL Magic Properties

- Documentation Index
  - Release Notes
  - Quick Start
  - SSL/TLS Quick Start
  - Introduction
  - Setup and Configuration
    - Download
    - Server Installation
    - Server Configuration and Control
    - WebView
    - Database Upgrading
    - Managing Users
  - Server Management
    - Performance Tuning
    - Deleting Duplicate Triples
    - Purging Deleted Triples
    - Auditing
    - Managing Users
    - Replication
    - Point-in-Time Recovery
    - Transaction Log Archiving
    - Security Overview
    - Security Implementation
  - Tools
    - agtool
    - Data Loading
    - Data Export
    - Backup and Restore
    - Querying
    - RDFS++
    - Materializer
    - Event Scheduler
    - SHACL
  - Details
    - Triple Indices
    - Freetext Indices
    - Encoded IDs
    - Connection Pooling
    - N-dimensional Geospatial Overview
    - 2-D Geospatial
    - Temporal
    - Social Network
    - JavaScript
    - Datatypes
    - Data Conversion (Rapper)
    - Stored Procedures
    - Triple Attributes
    - Lineparse Format
  - Querying
    - SPARQL documentation summary
    - SPARQL Reference
    - SPIN
    - SPARQL Magic Properties
    - Prolog
  - 3rd-party tools
    - Solr text Indices
    - MongoDB integration
    - TopBraid Composer Plugin
    - Cloudera
  - Client APIs
    - Gruff
    - GraphTalker
    - REST/HTTP interface
    - HTTP reference
    - Javadocs (Sesame and Jena)
    - Python API
    - Lisp Reference
    - JavaScript
  - Tutorials
    - N-dimensional Geospatial
    - SPARQL Tutorial
    - Java Sesame
    - Java Jena
    - Python Sesame
    - Lisp
    - Prolog
    - More...
  - Other
    - Conferences and Seminars
    - Source Code on Github
    - Amazon EC2
    - Copyrights
  - Franz, Inc.

- Introduction
- Freetext
- n-Dimensional (nD) Geospatial
- 2D Geospatial
- SNA
- Temporal
  - relations between points
  - relation between intervals
  - relations between points and intervals
  - relations between points and datetimes
  - relations between intervals and datetimes
- Large Language Models (LLMagic)
- Magic properties list

Documentation Index

## Introduction

See the Defining Magic Properties Tutorial for more information on how to define your own magic properites using Lisp.

A Magic Property (also called a Computed Property by W3C) is a predicate in a SPARQL query that produces bindings using something other than simple subgraph matching. These extensions provide a much richer query environment at the cost of non-portability. AllegroGraph has long supported a Magic Property to enable freetext queries and to interface to Solr and MongoDB. For example, when a query contains a pattern like

    ?subject fti:match 'baseball' .

AllegroGraph does not look at the triples in the triple-store to find matching patterns; rather, it uses the freetext index to find the triples that have objects with `baseball` in their text.

AllegroGraph includes both enhanced Magic Properties for freetext queries and new properties to enable SPARQL queries to access Geospatial, Temporal and Social Network Analysis.

Note that Magic Properties can use patterns with multiple inputs and outputs. SPARQL's list notation provides a syntactic sugar to make this quite readable. Here is an example that looks for text matching willows in the freetext index named titles and then binds ?book to the matches it finds:

    select * {
      ?book fti:match ('willows' 'titles' ) .
    }

This parenthetical notation uses SPARQL's (and Turtle's) syntactic sugar for the longer (and harder to read!) but equivalent query:

    SELECT * {
      ?book fti:match _:b0 .
      _:b0 rdf:first "willows" .
      _:b0 rdf:rest _:b1 .
      _:b1 rdf:first "titles" .
      _:b1 rdf:rest rdf:nil
    }

## Freetext

AllegroGraph supports freetext queries with enhancements that allow the selection of the index to use and the easy retrieval of the object of any matching triples. Both `fti:match` and `fti:matchExpression` provide the same four pattern forms:

1. ?subject fti:match 'text to query' .
2. (?subject ?object) fti:match 'text to query' .
3. ?subject fti:match ('text to query' 'index name') .
4. (?subject ?object) fti:match ('text to query' 'index name') .

The second and fourth forms bind the second variable on the subject side to the object of any matching triples.

Note that both the query text and the index name must be constants. You can, however, specify a particular subject or object to have the Magic Property act as a filter. For example,

    <ex:wind_in_the_williows> fti:match ('toad' 'characters') .

would succeed if and only if the freetext index named characters indexed a triple with subject <ex:wind_in_the_williows> whose object contained toad.

## n-Dimensional (nD) Geospatial

The nD geospatial facility is described generally in nD Geospatial Overview. A tutorial is in the nD Geospatial Usage Guide. The magic properties for making nD geospatial queries are listed below in the Magic properties list.

The Lisp interface to nD geospatial is described here in the Lisp Reference.

The nD definitions that follow use these prefix definitions:

    PREFIX geofn: <http://franz.com/ns/allegrograph/3.0/geospatial/fn/>
    PREFIX geo:   <http://franz.com/ns/allegrograph/3.0/geospatial/>
    PREFIX nd:    <http://franz.com/ns/allegrograph/5.0/geo/nd#>
    PREFIX ndfn:  <http://franz.com/ns/allegrograph/5.0/geo/nd/fn#>
    PREFIX :      <http://franz.com/ns/keyword#>

The several SPARQL Magic Predicates in both systems (nD and 2D) find triples in the store based on their encoded data. To use a geospatial Magic Property in either system you must ensure that the query engine can determine the geospatial subtype based on the triple predicate. This can be done by creating a predicate type mapping between the predicate and the subtype. The mechanics of this vary with the client. For example, in the Python client we could create a predicate mapping between `<http://example.com/pointLatLong>` and the spherical geospatial subtype with a strip width of 1 kilometer using code like:

    geoSubtype = conn.createURI("http://franz.com/ns/allegrograph/3.0/geospatial/spherical/km/-180.0/180.0/-90.0/90.0/1")
    latlon = conn.createURI("http://example.com/pointLatLong")
    conn.registerDatatypeMapping(datatype=geoSubtype, predicate=latlon, nativeType="int")

These links document establishing a predicate mapping in HTTP, Lisp, Java, and Python.

## 2D Geospatial

2D SPARQL Magic Properties are no longer supported.

## SNA

AllegroGraph now provides Magic Properties that work with its Social Networking Analysis (SNA) Library. They are described in the SNA Magic Properties document.

## Temporal

There is a tutorial using an older interface here. The older interface is also described here.

AllegroGraph supports efficient storage and retrieval of temporal data including:

- dateTimes in ISO 8601 format: "2008-02-01T00:00:00-08:00"
- time points: ex:point1, ex:h-hour, ex:when-the-meeting-began, etc
- time intervals: ex:delay-interval (e.g., from point ex:point1 to ex:h-hour)

In the following, the namespace prefix t is short for http://franz.com/ns/allegrograph/3.0/temporal/. AllegroGraph also requires that time points are defined using the t:time predicate and that intervals are defined using either t:starttime and t:endtime or t:startpoint and t:endpoint. Starting in version 4.11 of AllegroGraph, the t:time, t:starttime, and t:endtime predicates are automatically mapped to xsd:dateTimes (see predicate type mapping for more details).

Once data has been encoded, you can query for:

- relations between two points
- relations between two intervals
- relations between points and dateTimes
- relations between intervals and dateTimes
- relations between points and intervals

The temporal reasoning tutorial describes all of these capabilities in detail and also functions as a general reference guide. Below, we will quickly outline the various SPARQL Magic Properties. To illustrate them, we'll use a triple-store with intervals defined for days and months of 2013 like:

    :day1Start t:time "2013-01-01T00:00:00"^^xsd:dateTime .
    :day1End t:time "2013-01-01T12:59:59"^^xsd:dateTime .
    :day1 t:startpoint :day1Start ;
       t:endpoint :day1End ;
       rdfs:label "January 1st" .
    :day2Start t:time "2013-01-02T00:00:00"^^xsd:dateTime .
    :day2End t:time "2013-01-02T12:59:59"^^xsd:dateTime .
    :day2 t:startpoint :day2Start ;
       t:endpoint :day2End ;
       rdfs:label "January 2nd" .
    ...
    :month1 t:startpoint :day1Start ;
      t:endpoint :day31End ;
      rdfs:label "January" .
    ...

We will also include an interesting date in the store:

    :earthDay t:startpoint :day110Start .

### relations between points

- t:pointBefore
- t:pointAfter
- t:pointSimultaneous

We can ask for all the points before the month of January ends using

    select * {
       ?month rdfs:label 'January' .
       ?month t:endpoint ?monthEnds .
       ?point t:pointBefore ?monthEnds .
    }

This will return the start and end of each day in January (though it will not return the end of January 31st because that point is simultaneous with the end of the month and not before it).

### relation between intervals

- t:intervalBefore
- t:intervalAfter
- t:intervalMeets
- t:intervalMetBy
- t:intervalOverlaps
- t:intervalOverlappedBy
- t:intervalStarts
- t:intervalStartedBy
- t:intervalDuring
- t:intervalContains
- t:intervalFinishes
- t:intervalFinishedBy
- t:intervalCotemporal

For example, we can find the number of days 1 in January by querying:

    select (count(?day) as ?days) {
       ?month rdfs:label 'January' .
       ?day t:intervalDuring ?month .
    } group by ?month

### relations between points and intervals

- t:pointBeforeInterval
- t:pointStartsInterval
- t:pointDuringInterval
- t:pointEndsInterval
- t:pointAfterInterval

For example, we can ask for the month during which Earth Day falls using:

    select ?month ?label {
      :earthday t:startpoint ?start .
      ?start t:pointDuringInterval ?month .
      ?month rdfs:label ?label .
    }

### relations between points and datetimes

- t:pointBeforeDatetime
- t:pointAfterDatetime

### relations between intervals and datetimes

- t:intervalBeforeDatetime
- t:intervalAfterDatetime

## Large Language Models (LLMagic)

See Large Language Models (LLM) LLMagic and Vector Databases for information on Large Language Model support in AllegroGraph. LLM magic properties support support interfacing with GPT and creation and use of embedding vectors. There are examples in the LLM document and in the LLM embedding document. There are also some SPARQL magic functions, listed here.

## Magic properties list

### nD Geospatial

- <http://franz.com/ns/allegrograph/5.0/geo/nd#inBoundingBox>
- <http://franz.com/ns/allegrograph/5.0/geo/nd#inCircle>

### Attributes

- <http://franz.com/ns/allegrograph/6.2.0/attributes>
- <http://franz.com/ns/allegrograph/6.2.0/attributesNameValue>

### GeoSPARQL

- <http://franz.com/ns/allegrograph/3.0/geosparql/ext#buildGeohashIndex>
- <http://franz.com/ns/allegrograph/3.0/geosparql/ext#nearby>
- <http://franz.com/ns/allegrograph/3.0/geosparql/ext#rebuildGeohashIndex>
- <http://www.opengis.net/ont/geosparql#sfContains>
- <http://www.opengis.net/ont/geosparql#sfCrosses>
- <http://www.opengis.net/ont/geosparql#sfDisjoint>
- <http://www.opengis.net/ont/geosparql#sfEquals>
- <http://www.opengis.net/ont/geosparql#sfIntersects>
- <http://www.opengis.net/ont/geosparql#sfOverlaps>
- <http://www.opengis.net/ont/geosparql#sfTouches>
- <http://www.opengis.net/ont/geosparql#sfWithin>

### Large Language Model

- <http://franz.com/ns/allegrograph/8.0.0/llm/askForTable>
- <http://franz.com/ns/allegrograph/8.0.0/llm/askMyDocuments>
- <http://franz.com/ns/allegrograph/8.0.0/llm/chatState>
- <http://franz.com/ns/allegrograph/8.0.0/llm/nearestNeighbor>
- <http://franz.com/ns/allegrograph/8.0.0/llm/response>
- <http://franz.com/ns/allegrograph/8.0.0/llm/similarity>

### Reification

- <http://franz.com/ns/allegrograph/4.0/quotedTripleId>
- <http://franz.com/ns/allegrograph/4.0/tripleId>

### Social Network Analysis

- <http://franz.com/ns/allegrograph/4.11/sna/actorBetweennessCentrality>
- <http://franz.com/ns/allegrograph/4.11/sna/actorClosenessCentrality>
- <http://franz.com/ns/allegrograph/4.11/sna/actorDegreeCentrality>
- <http://franz.com/ns/allegrograph/4.11/sna/bidirectionalSearch>
- <http://franz.com/ns/allegrograph/4.11/sna/bidirectionalSearchPaths>
- <http://franz.com/ns/allegrograph/4.11/sna/breadthFirstSearch>
- <http://franz.com/ns/allegrograph/4.11/sna/breadthFirstSearchPaths>
- <http://franz.com/ns/allegrograph/4.11/sna/cliquesOf>
- <http://franz.com/ns/allegrograph/4.11/sna/communityLeiden>
- <http://franz.com/ns/allegrograph/4.11/sna/depthFirstSearch>
- <http://franz.com/ns/allegrograph/4.11/sna/depthFirstSearchPaths>
- <http://franz.com/ns/allegrograph/4.11/sna/egoGroup>
- <http://franz.com/ns/allegrograph/4.11/sna/groupBetweennessCentrality>
- <http://franz.com/ns/allegrograph/4.11/sna/groupClosenessCentrality>
- <http://franz.com/ns/allegrograph/4.11/sna/groupDegreeCentrality>
- <http://franz.com/ns/allegrograph/4.11/sna/groupMember>
- <http://franz.com/ns/allegrograph/4.11/sna/isClique>
- <http://franz.com/ns/allegrograph/4.11/sna/members>
- <http://franz.com/ns/allegrograph/4.11/sna/neighborCache>
- <http://franz.com/ns/allegrograph/4.11/sna/nodalNeighbors>
- <http://franz.com/ns/allegrograph/4.11/sna/pageRankCentrality>
- <http://franz.com/ns/allegrograph/4.11/sna/size>

### Temporal

- <http://franz.com/ns/allegrograph/3.0/temporal/intervalAfter>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalAfterDatetime>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalBefore>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalBeforeDatetime>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalContains>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalContainsTime>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalCotemporal>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalDuring>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalFinishedBy>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalFinishes>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalMeets>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalMetBy>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalOverlappedBy>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalOverlaps>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalStartedBy>
- <http://franz.com/ns/allegrograph/3.0/temporal/intervalStarts>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointAfter>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointAfterDatetime>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointAfterInterval>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointBefore>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointBeforeDatetime>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointBeforeInterval>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointDuringInterval>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointEndsInterval>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointSimultaneous>
- <http://franz.com/ns/allegrograph/3.0/temporal/pointStartsInterval>

### Text Indexing

- <http://franz.com/ns/allegrograph/2.2/textindex/match>
- <http://franz.com/ns/allegrograph/2.2/textindex/matchExpression>
- <http://franz.com/ns/allegrograph/4.5/solr/match>
- <http://franz.com/ns/allegrograph/4.5/solr/matchId>
- <http://franz.com/ns/allegrograph/4.7/mongo/find>
- <http://franz.com/ns/allegrograph/4.7/mongo/slotValue>

### Validation

- <http://franz.com/ns/allegrograph/6.6.0/shaclFocusNodeValidationReport1>
- <http://franz.com/ns/allegrograph/6.6.0/shaclFocusNodeValidationReport2>
- <http://franz.com/ns/allegrograph/6.6.0/shaclShapeValidationReport1>
- <http://franz.com/ns/allegrograph/6.6.0/shaclShapeValidationReport2>
- <http://franz.com/ns/allegrograph/6.6.0/shaclValidationReport>

### 2D Geospatial

- <http://franz.com/ns/allegrograph/3.0/geospatial/inBoundingBox>
- <http://franz.com/ns/allegrograph/3.0/geospatial/inBoundingBoxXY>
- <http://franz.com/ns/allegrograph/3.0/geospatial/inCircle>
- <http://franz.com/ns/allegrograph/3.0/geospatial/inCircleKilometers>
- <http://franz.com/ns/allegrograph/3.0/geospatial/inCircleMiles>

## Footnotes

1. Actually this will be two less than the number of days in January because January 1st starts the month and January 31st finishes it. I.e. they are not during the month. ↩