Skip to content

Commit

Permalink
rename Text/HasText/texts to CharContent/HasCharContent/charContents …
Browse files Browse the repository at this point in the history
…in xml schema; release 0.19.5
  • Loading branch information
tsdh committed Apr 2, 2014
1 parent 5c6aa0d commit ba0c8fe
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions 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.
Expand All @@ -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"]
Expand Down
Binary file modified resources/xml-schema.pdf
Binary file not shown.
Binary file modified resources/xml-schema.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions resources/xml-schema.tg
Expand Up @@ -8,12 +8,12 @@ abstract VertexClass NamespacedElement {nsURI: String, nsPrefix: String};
abstract VertexClass Referent;
VertexClass Element: Node, NamespacedElement {name: String, declaredNamespaces: Map<String, String>};
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;
EdgeClass References from Referent (0,*) role referents to Element (0,*) role targets;

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;
16 changes: 7 additions & 9 deletions src/funnyqt/xmltg.clj
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))))

Expand Down Expand Up @@ -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)
Expand All @@ -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*
Expand Down
6 changes: 3 additions & 3 deletions test/funnyqt/xmltg_test.clj
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)))))

0 comments on commit ba0c8fe

Please sign in to comment.