This file contains 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
import requests | |
from rdflib import Graph | |
# Fetch data | |
url = 'https://github.com/kuhumcst/DanNet/releases/download/v2021.9.24/dannet-expanded.ttl' | |
r = requests.get(url) | |
open('dannet-expanded.ttl', 'wb').write(r.content) | |
# Build a graph | |
g = Graph() |
This file contains 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
(defn dataurl->mime-type | |
"Extract the mime-type from a data URL." | |
[dataurl] | |
(->> (str/split dataurl #",") | |
(first) | |
(re-find #":(.*?);") | |
(second))) | |
(defn dataurl->image | |
"Extract the image data from a data URL." |
This file contains 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
;; Based on the implementations found here: https://gist.github.com/wuchengwei/b7e1820d39445f431aeaa9c786753d8e | |
(defn dataurl->blob | |
[dataurl] | |
(let [arr (str/split dataurl #",") | |
mime (second (re-find #":(.*?);" (first arr))) | |
bstr (js/atob (second arr)) | |
n (count bstr) | |
u8arr (-> (map (fn [i] (.charCodeAt bstr i)) (range n)) | |
(into-array) | |
(js/Uint8Array.from))] |
This file contains 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
(defn enumerated | |
[xs] | |
(apply str (concat (interleave (drop-last 2 xs) (repeat ", ")) | |
(interpose " og " (take-last 2 xs))))) | |
(do | |
(println (enumerated ["a"])) | |
(println (enumerated ["a" "b"])) | |
(println (enumerated ["a" "b" "c"])) | |
(println (enumerated ["a" "b" "c" "d"]))) |