Created
July 8, 2020 07:48
-
-
Save EmmanuelOga/631155161d465e01a11ebf212613395a to your computer and use it in GitHub Desktop.
Run a Jena Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns rainbowfish.jena | |
| (:require [clojure.java.io :as io] | |
| [rainbowfish.config :as config]) | |
| (:import [org.apache.jena.fuseki.main FusekiServer] | |
| [org.apache.jena.system Txn] | |
| [org.apache.jena.query DatasetFactory QueryExecutionFactory ResultSetFormatter] | |
| [org.apache.jena.rdf.model Model ModelFactory])) | |
| (defonce | |
| ^{:doc "Instance of the Jena server for the lifetime of the program."} | |
| server (atom nil)) | |
| (defn stop [] | |
| (swap! | |
| server | |
| (fn [old-server] | |
| (when old-server (.stop old-server)) | |
| nil))) | |
| (defn restart [] | |
| (swap! | |
| server | |
| (fn [old-server] | |
| (let [options (config/config)] | |
| (when old-server (.stop old-server)) | |
| (let [ds (DatasetFactory/createTxnMem) | |
| fuseki (-> (FusekiServer/create) | |
| (.add "/ds" ds) | |
| (.build))] | |
| (.start fuseki) | |
| ;; Just some sample code: print some spos. | |
| (try | |
| (Txn/executeRead | |
| ds | |
| (fn [] | |
| (let [qx (QueryExecutionFactory/create "SELECT ?s ?p ?o { ?s ?p ?o. }" ds)] | |
| (ResultSetFormatter/out (.execSelect qx))))) | |
| (catch Exception e (println e))) | |
| fuseki))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment