Magic Property | AllegroGraph 9.0.1
Author: Franz Incorporated

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

# SPARQL Magic Property

- 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.

## http://franz.com/ns/allegrograph/4.11/sna/communityLeiden

Magic property `sna:communityLeiden` implements Leiden Community Detection algorithm, it takes a list of keyword arguments:

Name | Type | Default | Optional | Description
`generator` | Resource | `nil` | yes | A defined SNA generator
`actor` | Resource | `nil` | yes | A start node (actor) for traversing the RDF graph by the generator
`depth` | Numeric or nil | `nil` | yes | The depth for making an ego group. Must not be `nil` if generator is non-`nil`. See note 1 following the table.
`selector` | Resource | `nil` | yes | A defined SNA selector
`resolution` | Numeric | `1.0` | yes | A parameter that is used when computing the modularity
`beta` | Numeric | `0.01` | yes | A parameter that controls the randomness while breaking a community into smaller ones
`iterations` | Numeric | `-1` | yes | A parameter that controls the total iterations. -1 means iterate until modularity cannot be improved further.
`seed` | Numeric or nil | `nil` | yes | A parameter that sets the random generator’s seed to have re-producible communities

Note 1 The depth argument can only be `nil` when the generator argument is not specified or `nil`. Otherwise, depth must be a non-negative integer and will be used along with the `generator` and `actor` for constructing an SNA ego group.

Note that, users must supply either a `generator` or a `selector`. When the computation is done, it returns detected communities as ego groups (fully compatible with other operations e.g. `sna:groupDegreeCentrality`, and each group will be assigned with an integer community ID. For example, the query below not only runs a leiden cummunity detection, but also inserts new triples by utilizing the returned ego groups as well as IDs:

    PREFIX sna: <http://franz.com/ns/allegrograph/4.11/sna/>
    PREFIX : <http://franz.com/ns/keyword#>

    PREFIX ex: <ex://#>

    INSERT {
      ?communityId rdf:type sna:Community .
      ?actor sna:communityMember ?communityId .
    }
    WHERE {
      (?group ?groupId) sna:communityLeiden (:selector ex:someSelector :seed 1000) .
      BIND (IRI(concat("ex://#Community-", str(?groupId) )) AS ?communityId) .
      ?actor sna:members ?group .
    }

### Notes

The following namespace abbreviations are used:

- fti - <http://franz.com/ns/allegrograph/2.2/textindex/>
- geo - <http://franz.com/ns/allegrograph/3.0/geospatial/>
- geofn - <http://franz.com/ns/allegrograph/3.0/geospatial/fn/>
- nd - <http://franz.com/ns/allegrograph/5.0/geo/nd#>
- ndfn - <http://franz.com/ns/allegrograph/5.0/geo/nd/fn#>
- sna - <http://franz.com/ns/allegrograph/4.11/sna/>

The SPARQL magic properties reference has additional information on using AllegroGraph magic properties and functions.