RdfClj

; ; ;{{{ ((defn rdf [] (handle "rdf" (fn [request response] (do (.setContentType response "text/plain") (let [ wikiName (.substring (.getRequestURI request) (.length "/rdf/")) ; "RainerWasserfuhr" pageIndex (str " " (fetch-url-s "http://mindbroker.de/pageIndex.jsp") " ") ; TODO: might be cached p (fetch-url (str "http://mindbroker.de/wiki/" wikiName "?skin=raw")) l (line-seq (new java.io.LineNumberReader (new java.io.StringReader p))) f (re-find #"(\* ([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*):)+" p) ] (str (if (.equals "true" (.getParameter request "showPrefixes")) ; see http://mindbroker.de/wiki/NameSpace " @prefix : . @prefix dc: . @prefix foaf: . @prefix owl: . @prefix ldg: . @prefix ldgv: . @prefix rdf: . @prefix rdfs: . foaf:homepage rdf:type owl:ObjectProperty. foaf:OnlineAccount rdf:type owl:Class. foaf:account rdf:type owl:ObjectProperty. foaf:holdsAccount rdf:type owl:ObjectProperty. :ProFessor rdf:type owl:Class. :ProFessor rdfs:subClassOf :PerSon. :PerSon rdf:type owl:Class. :ErZaehlung rdf:type owl:Class. :MindPeople rdfs:subClassOf :PerSon. :MindPeople rdf:type owl:Class. :SingularityMind rdfs:subClassOf :PerSon. :UnternehmensGruender rdfs:subClassOf :PerSon. ") ((defn props [lines prop account] (if (not-empty lines) (if prop (let [ reg #"\* ([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*): ([^$]*)" line (first lines) fl (re-find reg line) tag (second fl) values (get fl 2) ] (if (not-empty tag) (str (if (or (.equals "IsA" tag) (.equals "MindTags" tag)) (apply str (map (fn [cl] (str ":" wikiName " a :" cl ".\n")) (.split (.replace values "," " ") " ")))) (if (or (.equals "BornIn" tag) (.equals "JahrGang" tag)) ; DePrecated, but still has to be supported (str ":" wikiName " :BornIn " values ".\n")) (if (or (.equals "DiedIn" tag) (.equals "LebensEnde" tag)) ; DePrecated, but still has to be supported (str ":" wikiName " :DiedIn " values ".\n")) (if (.equals "BirthDay" tag) (str ":" wikiName " foaf:birthday \"" values "\".\n")) (if (.equals "PageNumber" tag) (str ":" wikiName " :PageNumber " values ".\n")) (if (.equals "PagePath" tag) (str ":" wikiName " :PagePath (" (apply str (map (fn [cl] (str ":" cl " ")) (.split values " "))) ").\n")) ;ToDo: handle WantedPages (if (.equals "InterWiki" tag) (let [ reg #"\[([^\]]*)" iws (re-seq reg values) ] (apply str (map (fn [iw] (str ":" wikiName " :interWiki \"" (second iw) "\".\n")) iws)))) (if (.equals "HomePage" tag) (str ":" wikiName " foaf:homepage <" (.replace (.replace values "[" "") "]" "") ">.\n")) (if (.equals "OpenStreetMap" tag) (str ":" wikiName " owl:sameAs .\n")) (if (.equals "KindOf" tag) (str ":" wikiName " rdfs:subClassOf " values "\n")) (props (rest lines) true false)) (props lines false true)) ) (if account (if (.equals "||AusLand" (first lines)) (props (rest lines) false true) (let [ reg #"\|\[([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*):([^\]]*)" line (first lines) fl (re-find reg line) accountS (second fl) accountName (get fl 2) ] (if (not-empty accountS) (str " :" wikiName " foaf:holdsAccount [ a foaf:OnlineAccount; foaf:name \"" accountS "\"; foaf:accountName \"" accountName "\"].\n" (props (rest lines) false true)) (props lines false false) ))) (let [ reg #"([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]+)" line (first lines) fl (re-find reg line) ] (str (apply str (map (fn [x] (if (.contains pageIndex (str " " x " ")) (str ":" wikiName " :LinkedTo :" x ".\n") (str ":" wikiName " :WantedPage \"" x "\".\n") )) (rest fl))) (props (rest lines) false false) ) )) ))) l true false)) ))) (fn [] "") ))) ;}}}