-
Notifications
You must be signed in to change notification settings - Fork 7
/
iri.clj
28 lines (25 loc) · 990 Bytes
/
iri.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns com.yetanalytics.datasim.iri
(:require [clojure.spec.alpha :as s])
(:import [org.apache.jena.iri Violation IRIFactory IRI]))
(defonce ^IRIFactory iri-factory
(IRIFactory/semanticWebImplementation))
(defn check-iri-string
"Given a string, check if it is a valid IRI, returning nil if so. Otherwise,
Return violations"
[^String s & {:keys [^Boolean include-warnings?]
:or {include-warnings? false}}]
(let [^IRI iri (.create iri-factory s)]
(when (.hasViolation iri include-warnings?)
(for [^Violation v (iterator-seq (.violations iri include-warnings?))]
{:code (.getViolationCode v)
:type (if (.isError v)
::error
::warning)
:component (.component v)
:message-short (.getShortMessage v)
:message-long (.getLongMessage v)
;; :specification (.getSpecificationURL v) ;; NYI
}))))
(def iri-spec
(s/and string?
#(nil? (check-iri-string %))))