Skip to content

Commit

Permalink
Restablized abbot. All files (including abbot_config.xml) are now
Browse files Browse the repository at this point in the history
read from URLs.  See Issues for details.
  • Loading branch information
Stephen Ramsay committed Jan 22, 2012
1 parent 203de62 commit 6f98c28
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .lein-deps-sum
@@ -1 +1 @@
84df5127361c4d9fcfd926f1ba75a713b8892766
d50ad254b6e356457e34849f229a9602479f8088
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject edu.unl/abbot "0.3.1"
(defproject edu.unl/abbot "0.3.2"
:description "Abbot: A Conversion Tool for Text Interoperability"
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
Expand Down
40 changes: 20 additions & 20 deletions resources/xslt/metaStylesheetForRNGschemas.xsl
Expand Up @@ -257,8 +257,8 @@
<xsl:comment>XSLT processor used to create this stylesheet: <xsl:value-of select="system-property('xsl:vendor')"/></xsl:comment>

<!-- ########### begin implementation of the config file ########### -->
<!--<xsl:for-each
select="document('config/abbot_config.xml')/*//transformation[@activate='yes']">
<xsl:for-each
select="document('http://abbot.unl.edu/abbot_config.xml')/*//transformation[@activate='yes']">

<xsl:comment>
<xsl:text>Begin </xsl:text>
Expand Down Expand Up @@ -288,43 +288,43 @@
/>
</xsl:attribute>

<!-\- begin writing the param that gives an ID# to the template for identification in the log -\->
<!-- begin writing the param that gives an ID# to the template for identification in the log -->
<xsl:element name="xsl:param">
<xsl:attribute name="name">
<xsl:text>templateID</xsl:text>
</xsl:attribute>
<xsl:value-of select="generate-id()"/>
</xsl:element>
<!-\- end writing the param that gives an ID# to the template for identification in the log -\->
<!-- end writing the param that gives an ID# to the template for identification in the log -->

<!-\- begin writing the param that describes the template for use in the log -\->
<!-- begin writing the param that describes the template for use in the log -->
<xsl:element name="xsl:param">
<xsl:attribute name="name">desc</xsl:attribute>
<xsl:value-of select="child::desc"/>
</xsl:element>
<!-\- end writing the param that describes the template for use in the log -\->
<!-- end writing the param that describes the template for use in the log -->

<!-\- begin writing the param that IDs the element's ATTRIBUTES for use in the log -\->
<!-- begin writing the param that IDs the element's ATTRIBUTES for use in the log -->
<xsl:element name="xsl:param">
<xsl:attribute name="name">listOfAttributes</xsl:attribute>
<wxsl:value-of select="distinct-values(@*/name())"/>
</xsl:element>
<!-\- end writing the param that IDs the template for use in the log -\->
<!-- end writing the param that IDs the template for use in the log -->

<!-\- begin writing the meta-variable that writes the $elementName variable in the conversion stylesheet -\->
<!-- begin writing the meta-variable that writes the $elementName variable in the conversion stylesheet -->
<wxsl:variable name="elementName">
<wxsl:value-of select="lower-case(name())"/>
</wxsl:variable>
<!-\- end writing the meta-variable that writes the $elementName variable in the conversion stylesheet -\->
<!-- end writing the meta-variable that writes the $elementName variable in the conversion stylesheet -->

<!-\- $$$$$ Begin transformation described in abbot_config.xml $$$$$ -\->
<!-- $$$$$ Begin transformation described in abbot_config.xml $$$$$ -->

<!-\- begin writing the variable that describes this node after transformation -\->
<!-- begin writing the variable that describes this node after transformation -->
<xsl:element name="xsl:variable">
<xsl:attribute name="name">thisNodeAfterTransformation</xsl:attribute>

<emptyNode delete="no"/>
<!-\- 'emptyNode' ensures that this variable is not typed as a string -\->
<!-- 'emptyNode' ensures that this variable is not typed as a string -->

<xsl:choose>

Expand All @@ -335,7 +335,7 @@

<xsl:when
test="child::element/@choice='change' and descendant::attribute/@choice='delete'">
<!-\- for changing an element by DELETING its attribute(s) -\->
<!-- for changing an element by DELETING its attribute(s) -->
<wxsl:element
name="{concat($leftOfVariable,'elementName',$rightOfVariable)}">
<wxsl:apply-templates/>
Expand All @@ -346,7 +346,7 @@
and descendant::attribute/@choice='change'
and descendant::content/@use[starts-with(.,'@')]
and descendant::content/@choice='text'">
<!-\- for deleting an element and replacing it with the value of that element's attribute -\->
<!-- for deleting an element and replacing it with the value of that element's attribute -->
<xsl:element name="xsl:value-of">
<xsl:attribute name="select">
<xsl:value-of select="descendant::content/@use"/>
Expand All @@ -355,7 +355,7 @@
</xsl:when>
<xsl:when
test="child::element/@choice='change' and descendant::attribute/@choice='add'">
<!-\- for changing an element by ADDING an attribute or attributes -\->
<!-- for changing an element by ADDING an attribute or attributes -->
<wxsl:element
name="{concat($leftOfVariable,'elementName',$rightOfVariable)}">
<wxsl:attribute name="{descendant::attribute/@n}">
Expand All @@ -371,17 +371,17 @@
</xsl:choose>
</xsl:element>

<!-\- @@@@ Begin custom log entry. @@@@ -\->
<!-- @@@@ Begin custom log entry. @@@@ -->
<xsl:copy-of select="$logEntry"/>
<!-\- @@@@ End custom log entry. @@@@ -\->
<!-- @@@@ End custom log entry. @@@@ -->

<wxsl:if
test="count($thisNodeAfterTransformation/child::*) &gt; 1 and ($thisNodeAfterTransformation/child::emptyNode)">
<wxsl:copy-of select="$thisNodeAfterTransformation/child::*[name()!='emptyNode']"
/>
</wxsl:if>

<!-\- $$$$$ End transformation described in abbot_config.xml $$$$$ -\->
<!-- $$$$$ End transformation described in abbot_config.xml $$$$$ -->

</xsl:element>

Expand All @@ -390,7 +390,7 @@
<xsl:value-of select="child::desc"/>
</xsl:comment>

</xsl:for-each>-->
</xsl:for-each>

<!-- ########### end implementation of the config file ########### -->

Expand Down
2 changes: 1 addition & 1 deletion src/edu/unl/abbot/cli.clj
Expand Up @@ -36,4 +36,4 @@
(c/optional ["-s" "--single" "Run in single-threaded mode" :default false])
(c/optional ["-i" "--inputdir" "Input directory path" :default (str abbot-home "/input")])
(c/optional ["-o" "--outputdir" "Output directory path" :default (str abbot-home "/output/")]))]
(time (convert-files opts))))
(convert-files opts)))
9 changes: 3 additions & 6 deletions src/edu/unl/abbot/core.clj
Expand Up @@ -42,10 +42,7 @@

(defn convert-files [arg-map]
"Apply the conversion stylesheet to the input files"
(let [output-dir (:outputdir arg-map)
schema (:schema arg-map)
config (:config arg-map)
conversion-stylesheet (stylesheet schema config)]
(let [output-dir (:outputdir arg-map)]
(if (:single arg-map)
(doall (map #(spit (str output-dir (.getName %)) (convert conversion-stylesheet %)) (input-files (:inputdir arg-map))))
(doall (pmap #(spit (str output-dir (.getName %)) (convert conversion-stylesheet %)) (input-files (:inputdir arg-map)))))))
(doall (map #(spit (str output-dir (.getName %)) (convert %)) (input-files (:inputdir arg-map))))
(doall (pmap #(spit (str output-dir (.getName %)) (convert %)) (input-files (:inputdir arg-map)))))))
23 changes: 10 additions & 13 deletions src/edu/unl/abbot/stylesheets.clj
Expand Up @@ -21,26 +21,23 @@

(ns edu.unl.abbot.stylesheets
(:use edu.unl.abbot.utils)
(:require [saxon :as sax])
(:require [clojure.xml :as xml])
(:require [clojure.zip :as zip])
(:require [clojure.contrib.zip-filter.xml :as zf])
(:require [clojure.contrib.prxml :as px]))
(:require [saxon :as sax]))

;; Creates the "conversion stylesheet" (the stylesheet that does the
;; actual conversion) from the "meta-stylesheet"
;;
;; Templates from abbot_config.xml are read into the meta-stylesheet
;; at runtime (by the meta-stylesheet itself).

(defn stylesheet [schema config]
(let [meta-url "http://abbot.unl.edu/metaStylesheetForRNGschemas.xsl"
rng-file (sax/compile-xml (slurp schema))
config-file (xml/parse config)
meta-file (xml/parse meta-url)]
(px/prxml meta-file)
(sax/compile-xslt (sax/compile-xslt (px/prxml (with-out-str meta-file))) rng-file)))
; (def foo (assoc-in stable [:content] (concat (get-in stable [:content]) (get-in add [:content]))))

(defn convert [conversion-stylesheet xml-file]
(def conversion-stylesheet
(let [schema-url "http://abbot.unl.edu/tei-xl.rng"
rng-file (sax/compile-xml (java.net.URL. schema-url))
meta-url "http://abbot.unl.edu/metaStylesheetForRNGschemas.xsl"
meta-stylesheet (sax/compile-xslt (java.net.URL. meta-url))]
(sax/compile-xslt (meta-stylesheet rng-file))))

(defn convert [xml-file]
(let [xmlfile (sax/compile-xml xml-file)]
(conversion-stylesheet xmlfile)))

0 comments on commit 6f98c28

Please sign in to comment.