Skip to content

Instantly share code, notes, and snippets.

@hcayless
Last active March 18, 2016 13:18
Show Gist options
  • Select an option

  • Save hcayless/f36b34d500ee996e6e1f to your computer and use it in GitHub Desktop.

Select an option

Save hcayless/f36b34d500ee996e6e1f to your computer and use it in GitHub Desktop.
(defn get-filename
"Resolves the filename of the local XML file associated with the given URL."
[url]
(try (if (.contains url "ddbdp/")
(let [identifier (.split (substring-before (substring-after url "http://papyri.info/ddbdp/") "/source") ";")]
(if (= (second identifier) "")
(str filepath "/DDB_EpiDoc_XML/" (first identifier) "/" (first identifier) "."
(.replace (.replace (.replace (.replace (last identifier) "," "-") "/" "_") "%2F" "_") "%2C" "-") ".xml")
(str filepath "/DDB_EpiDoc_XML/" (first identifier) "/" (first identifier) "." (second identifier)
"/" (first identifier) "." (second identifier) "."
(.replace (.replace (.replace (.replace (last identifier) "," "-") "/" "_") "%2F" "_") "%2C" "-") ".xml")))
(if (.contains url "hgv/")
(let [identifier (substring-before (substring-after url "http://papyri.info/hgv/") "/source")
id-int (Integer/parseInt (.replaceAll identifier "[a-z]" ""))]
(str filepath "/HGV_meta_EpiDoc/HGV" (ceil (/ id-int 1000)) "/" identifier ".xml"))
(if (.contains url "dclp/")
(let [identifier (substring-before (substring-after url "dclp.zaw.uni-heidelberg.de/dclp/") "/source")
id-int (Integer/parseInt (.replaceAll identifier "[a-z]" ""))]
(str filepath "/DCLP/" (ceil (/ id-int 1000)) "/" identifier ".xml"))
(when (.contains url "apis/")
(let [identifier (.split (substring-before (substring-after url "http://papyri.info/apis/") "/source") "\\.")]
(str filepath "/APIS/" (first identifier) "/xml/" (first identifier) "." (second identifier) "." (last identifier) ".xml"))))))
(catch Exception e
(when-not (nil? e)
(println (str (.getMessage e) " processing " url "."))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment