Created
October 13, 2025 21:38
-
-
Save tangrammer/7c6a812fedf0e6fd960f160d84cdea3f to your computer and use it in GitHub Desktop.
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 core | |
| (:require [clojure.string :as str])) | |
| (def namespace-registry | |
| {:org.example {::iri "http://example.org/" | |
| ::prefix "ex"} | |
| :org.w3.rdf {::iri "http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
| ::prefix "rdf"} | |
| :org.w3.rdfs {::iri "http://www.w3.org/2000/01/rdf-schema#" | |
| ::prefix "rdfs"} | |
| :com.xmlns.foaf {::iri "http://xmlns.com/foaf/0.1/" | |
| ::prefix "foaf"} | |
| :org.schema {::iri "https://schema.org/" | |
| ::prefix "schema"}}) | |
| [:org.example/john :org.w3.rdf/type :com.xmlns.foaf/Person] | |
| (defn semantic-kw->iri [kw] | |
| (let [ns-part (namespace kw) | |
| name-part (name kw) | |
| ns-config (get namespace-registry (keyword ns-part))] | |
| (str (::iri ns-config) name-part))) | |
| (defn iri->semantic-kw [iri] | |
| (if-let [[ns-kw config] (first (filter #(str/starts-with? iri (::iri (val %))) | |
| namespace-registry))] | |
| (keyword (name ns-kw) | |
| (str/replace iri (::iri config) "")) | |
| ;; Fallback for unknown IRIs | |
| (keyword "unknown.iri" (str (hash iri))))) | |
| ;; Examples | |
| (semantic-kw->iri :org.example/john) | |
| ;; => "http://example.org/john" | |
| (iri->semantic-kw "http://example.org/john") | |
| ;; => :org.example/john | |
| (mapv semantic-kw->iri [:org.example/john :org.w3.rdf/type :com.xmlns.foaf/Person]) | |
| ;;=> | |
| ["http://example.org/john" | |
| "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" | |
| "http://xmlns.com/foaf/0.1/Person"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment