diff --git a/project.clj b/project.clj index 8d1671c3..fe14762e 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject funnyqt "0.19.4" +(defproject funnyqt "0.19.5" :description "A model querying and transformation library for TGraphs and EMF models developed as part of Tassilo Horn's dissertation studies. @@ -10,7 +10,7 @@ excellent Marginalia tool." :dependencies [[org.clojure/clojure "1.6.0"] [org.clojure/core.cache "0.6.3"] - [de.uni-koblenz.ist/jgralab "7.7.10"] + [de.uni-koblenz.ist/jgralab "7.7.11"] [org.clojure/core.logic "0.8.7"] [org.flatland/ordered "1.5.2"] [org.clojure/tools.macro "0.1.5"] diff --git a/resources/xml-schema.pdf b/resources/xml-schema.pdf index 9a8531e0..b97a75ab 100644 Binary files a/resources/xml-schema.pdf and b/resources/xml-schema.pdf differ diff --git a/resources/xml-schema.png b/resources/xml-schema.png index 53d85e26..7b376f41 100644 Binary files a/resources/xml-schema.png and b/resources/xml-schema.png differ diff --git a/resources/xml-schema.tg b/resources/xml-schema.tg index 822d0289..a985c491 100644 --- a/resources/xml-schema.tg +++ b/resources/xml-schema.tg @@ -8,7 +8,7 @@ abstract VertexClass NamespacedElement {nsURI: String, nsPrefix: String}; abstract VertexClass Referent; VertexClass Element: Node, NamespacedElement {name: String, declaredNamespaces: Map}; VertexClass RootElement: Element; -VertexClass Text: Node, Referent {content: String}; +VertexClass CharContent: Node, Referent {content: String}; VertexClass Attribute: NamespacedElement, Referent {name: String, value: String}; EdgeClass HasAttribute from Element (1,1) role element to Attribute (0,*) role attributes aggregation composite; @@ -16,4 +16,4 @@ EdgeClass References from Referent (0,*) role referents to Element (0,*) role ta abstract EdgeClass HasContent from Element (0,1) role parent to Node (0,*) role contents aggregation composite; EdgeClass HasChild: HasContent from Element (0,1) to Element (0,*) role children aggregation composite; -EdgeClass HasText: HasContent from Element (0,1) to Text (0,*) role texts aggregation composite; +EdgeClass HasCharContent: HasContent from Element (0,1) to CharContent (0,*) role charContents aggregation composite; diff --git a/src/funnyqt/xmltg.clj b/src/funnyqt/xmltg.clj index 094b467c..59fbf5c3 100644 --- a/src/funnyqt/xmltg.clj +++ b/src/funnyqt/xmltg.clj @@ -96,7 +96,7 @@ If the XML file has no DTD, you can influence the resolution by providing an (filter-by-name qn (g/adjs e :children)))) (defn siblings - "Returns the sibling Element vertices of Element or Text `e`. + "Returns the sibling Element vertices of Element or CharContent `e`. May be restricted to elements of the given type `qn`, , a qualified name (see `qualified-name`), an expanded (see `expanded-name`) or declared name (see `declared-name`), or a local name. @@ -162,7 +162,7 @@ If the XML file has no DTD, you can influence the resolution by providing an (def ^:dynamic ^:private *id2elem*) ;; map from ID to Element vertex ;; map from Referent vertex to a vector of referenced element IDs (an attr or -;; Text can reference multiple elements in terms of a IDREFS attr name) +;; CharContent can reference multiple elements in terms of a IDREFS attr name) (def ^:dynamic ^:private *referent2refed-ids*) ;; set of Attribute vertices whose value is an EMFFragmentPath expression that ;; has to be resolved after the graph has successfully been created @@ -314,14 +314,14 @@ If the XML file has no DTD, you can influence the resolution by providing an (defn ^:private handle-characters [^Characters ev] (when-not (or (.isIgnorableWhiteSpace ev) (.isWhiteSpace ev)) - (let [txt (tg/create-vertex! *graph* 'Text) + (let [txt (tg/create-vertex! *graph* 'CharContent) data (.getData ev) parent (g/adj *current* :parent) t (if *text-type-fn* (*text-type-fn* (qualified-name parent) (qualified-name *current*) data) "CDATA")] (tg/set-value! txt :content data) - (tg/create-edge! *graph* 'HasText *current* txt) + (tg/create-edge! *graph* 'HasCharContent *current* txt) (when *text-type-fn* (handle-type-semantics t parent txt data))))) @@ -431,15 +431,13 @@ If the XML file has no DTD, you can influence the resolution by providing an (str "xmlns" (when p (str ":" p)) "=\"" u "\"")) (seq (tg/value elem :declaredNamespaces))))] - (if (seq s) - (str " " s) - s))) + (if (seq s) (str " " s) s))) (defn ^:private emit-element [elem] (indent) (let [has-contents (seq (tg/iseq elem 'HasContent :out)) contains-text-first (when-let [i (first (tg/iseq elem 'HasContent :out))] - (g/has-type? i 'HasText))] + (g/has-type? i 'HasCharContent))] (.write *writer* (format "<%s%s%s%s>%s" (declared-name elem) (namespaces-str elem) @@ -450,7 +448,7 @@ If the XML file has no DTD, you can influence the resolution by providing an (when has-contents (binding [*indent-level* (inc *indent-level*)] (doseq [c (g/adjs elem :contents)] - (if (g/has-type? c 'Text) + (if (g/has-type? c 'CharContent) (emit-text c) (emit-element c)))) (when-not *last-node-was-text* diff --git a/test/funnyqt/xmltg_test.clj b/test/funnyqt/xmltg_test.clj index 4251aac6..5d6f0d22 100644 --- a/test/funnyqt/xmltg_test.clj +++ b/test/funnyqt/xmltg_test.clj @@ -11,7 +11,7 @@ (is (== 55 (vcount g 'Element))) (is (== 75 (vcount g 'Node))) (is (== 48 (vcount g 'Attribute))) - (is (== 20 (vcount g 'Text))) + (is (== 20 (vcount g 'CharContent))) (is (== 142 (ecount g))) (is (== 20 (ecount g 'References))) ;; Only the root element has no incoming HasContent edges @@ -29,7 +29,7 @@ (is (== 49 (vcount g 'Element))) (is (== 69 (vcount g 'Node))) (is (== 43 (vcount g 'Attribute))) - (is (== 20 (vcount g 'Text))) + (is (== 20 (vcount g 'CharContent))) (is (== 131 (ecount g))) (is (== 20 (ecount g 'References))) ;; Only the root element has no incoming HasContent edges @@ -79,6 +79,6 @@ "parents" "IDREFS")))] #_(show-graph g) (is (= 18 (vcount g 'Element))) - (is (= 12 (vcount g 'Text))) + (is (= 12 (vcount g 'CharContent))) (is (= 14 (ecount g 'References)))))