Specifying -d FILENAME will load data from FILENAME into the default graph.
Alternatively, data can be loaded into a specific named graph (similarly, a
custom graph name can be used for the query default graph):
The Kineo API can be used to create an in-memory or persistent quadstore,
load RDF data into it, and evaluate SPARQL queries over the data:
import Foundation
import SPARQLSyntax
import Kineo
let graph = Term(iri: "http://example.org/default-graph")
let store = MemoryQuadStore()
let url = URL(string: "http://kasei.us/about/foaf.ttl")!
try store.load(url: url, defaultGraph: graph)
let sparql = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT * WHERE { ?person a foaf:Person ; foaf:name ?name }"
let q = try SPARQLParser.parse(query: sparql)
let results = try store.query(q, defaultGraph: graph)
for (i, result) in results.bindings.enumerated() {
print("\(i+1)\t\(result)")
}
There is also an API that exposes the RDF data in terms of graph vertices and edge traversals:
import Foundation
import SPARQLSyntax
import Kineo
let graph = Term(iri: "http://example.org/default-graph")
let store = MemoryQuadStore()
let url = URL(string: "http://kasei.us/about/foaf.ttl")!
try store.load(url: url, defaultGraph: graph)
let graphView = store.graph(graph)
let greg = graphView.vertex(Term(iri: "http://kasei.us/about/#greg"))
let knows = Term(iri: "http://xmlns.com/foaf/0.1/knows")
let name = Term(iri: "http://xmlns.com/foaf/0.1/name")
for v in try greg.outgoing(knows) {
let names = try v.outgoing(name)
if let nameVertex = names.first {
let name = nameVertex.term
print("Greg know \(name)")
}
}
SPARQL Endpoint
Finally, using the companion kineo-endpoint package,
a SPARQL endpoint can be run allowing SPARQL Protocol clients to access the data:
Kineo
A persistent RDF quadstore and SPARQL engine
Build
swift build -c release
Swift Package Manager
You can use the Swift Package Manager to add Kineo to a Swift project by adding it as a dependency in
Package.swift
:Load data
Create a database file (
geo.db
) and load one or more N-Triples or Turtle files:Specifying
-d FILENAME
will load data fromFILENAME
into the default graph. Alternatively, data can be loaded into a specific named graph (similarly, a custom graph name can be used for the query default graph):Query
Querying of the data can be done using SPARQL:
Kineo API
The Kineo API can be used to create an in-memory or persistent quadstore, load RDF data into it, and evaluate SPARQL queries over the data:
There is also an API that exposes the RDF data in terms of graph vertices and edge traversals:
SPARQL Endpoint
Finally, using the companion kineo-endpoint package, a SPARQL endpoint can be run allowing SPARQL Protocol clients to access the data: