SPARQL endpoint for transit data using Apache Jena Fuseki and GTFS ontologies.
This project provides a SPARQL endpoint for querying transit data based on the General Transit Feed Specification (GTFS). It uses Apache Jena Fuseki as the triplestore and includes a comprehensive set of GTFS ontologies.
- Apache Jena Fuseki Server: High-performance RDF triplestore with SPARQL endpoint
- GTFS Ontologies: Comprehensive ontologies covering all GTFS data elements:
gtfs.ttl
- Core GTFS ontology with base classes and propertiesstops.ttl
- Ontology for stop locations, stations, and facilitiestrips.ttl
- Ontology for trip scheduling and operationsroutes.ttl
- Ontology for transit routescalendar.ttl
- Ontology for service schedules and calendarsagency.ttl
- Ontology for transit agenciesshapes.ttl
- Ontology for route shapes and geographic pathsfares.ttl
- Ontology for fare information and pricing rules
- TDB2 Storage: Efficient persistent storage using Apache Jena TDB2
- Auto-loading: Automatically loads ontologies from the
ontology/
directory on startup
infobus-sparql/
├── ontology/ # GTFS ontology files (.ttl)
│ ├── gtfs.ttl
│ ├── stops.ttl
│ ├── trips.ttl
│ ├── routes.ttl
│ ├── calendar.ttl
│ ├── agency.ttl
│ ├── shapes.ttl
│ └── fares.ttl
├── data/
│ └── tdb2/ # TDB2 triplestore data (auto-created)
├── config/
│ └── fuseki-config.ttl # Fuseki server configuration
├── src/
│ └── main/java/
│ └── com/simovilab/infobus/
│ └── FusekiServer.java
└── pom.xml # Maven project configuration
- Java 11 or higher
- Maven 3.6 or higher
mvn clean package
This will compile the code and create an executable JAR file in the target/
directory.
java -jar target/infobus-sparql-1.0.0-SNAPSHOT.jar
Or run directly with Maven:
mvn exec:java -Dexec.mainClass="com.simovilab.infobus.FusekiServer"
Once the server is running, the following endpoints are available:
- SPARQL Query:
http://localhost:3030/infobus/sparql
- SPARQL Update:
http://localhost:3030/infobus/update
- Graph Store:
http://localhost:3030/infobus/data
- Fuseki UI:
http://localhost:3030/
(if using full Fuseki server)
Query all GTFS classes defined in the ontologies:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX gtfs: <http://vocab.gtfs.org/terms#>
SELECT ?class ?label ?comment
WHERE {
?class rdf:type owl:Class .
?class rdfs:label ?label .
OPTIONAL { ?class rdfs:comment ?comment }
FILTER(STRSTARTS(STR(?class), "http://vocab.gtfs.org/terms#"))
}
ORDER BY ?label
You can insert transit data using SPARQL UPDATE:
PREFIX gtfs: <http://vocab.gtfs.org/terms#>
PREFIX ex: <http://example.org/transit/>
INSERT DATA {
ex:agency1 a gtfs:Agency ;
gtfs:agencyId "METRO" ;
gtfs:agencyName "Metro Transit" ;
gtfs:agencyUrl <http://metro.example.org> ;
gtfs:agencyTimezone "America/New_York" .
}
Defines the base classes and properties for GTFS data:
- Classes: Agency, Stop, Route, Trip, StopTime, Calendar, etc.
- Properties: Identifiers, names, relationships
- Route types: Bus, Subway, Rail, Ferry, etc.
Extended ontology for stop locations:
- Stop location types (platform, station, entrance, etc.)
- Geographical properties
- Accessibility features
- Amenities (shelters, benches, ticket machines, etc.)
Extended ontology for trip operations:
- Trip properties (headsign, direction, block ID)
- Stop time properties (pickup/dropoff types)
- Trip status (scheduled, delayed, canceled)
- Accessibility information
Extended ontology for transit routes:
- Route properties (colors, URLs, descriptions)
- Route classifications (local, express, rapid transit)
- Route patterns
Extended ontology for service schedules:
- Service availability by day of week
- Date ranges for service
- Calendar exceptions (holidays, special events)
- Frequency-based service
Extended ontology for transit agencies:
- Agency contact information
- Service areas
- Agency relationships (parent/subsidiary)
Extended ontology for route shapes:
- Shape points and sequences
- Geographic coordinates
- Distance calculations
- GeoJSON and WKT representations
Extended ontology for fare information:
- Fare attributes and pricing
- Payment methods
- Fare rules and zones
- Discount types and fare products
- Create a new
.ttl
file in theontology/
directory - Define your RDF classes and properties using Turtle syntax
- Restart the server - ontologies are auto-loaded
Edit config/fuseki-config.ttl
to customize:
- Dataset location
- Service endpoints
- Security settings
- Query timeouts
Apache License 2.0 - See LICENSE file for details
Contributions are welcome! Please submit pull requests or open issues for bugs and feature requests.