Commit 0a0bbdc6 authored by Florent Terrones's avatar Florent Terrones
Browse files

2006-10-26 Florent Terrones <terron_f@lrde.epita.fr>

	* data/vaucanson.xsd: Split the `expressionAttributes' into two
	attribute groups: `atomAttributes' and `nodeAttributes'.
	Add left and right weights for nodes of an expression.
	Refine the drawing tag.
	* doc/xml/xml_proposal.tex: Update accordingly.
	* include/vaucanson/algebra/implementation/series/rat/xml_exp_visitor.hh,
	* include/vaucanson/algebra/implementation/series/rat/xml_exp_visitor.hxx:
	Add the support of left and right weights for output. Fix a bug	about
	weights.
	* include/vaucanson/algebra/implementation/series/rat/exp.hh,
	* include/vaucanson/algebra/implementation/series/rat/exp.hxx: Minor fix.
	* include/vaucanson/xml/tools.hxx: Add the support of left and right
	weights for input.
	* src/tests/xml/xml_label_node_tester.cc: Enhance the tests on weights.
	* src/tests/xml/label_node_ref.xml,
	* src/tests/xml/label_node_ref.dot: Update accordingly.
parent 6056fa56
2006-10-26 Florent Terrones <terron_f@lrde.epita.fr>
* data/vaucanson.xsd: Split the `expressionAttributes' into two
attribute groups: `atomAttributes' and `nodeAttributes'.
Add left and right weights for nodes of an expression.
Refine the drawing tag.
* doc/xml/xml_proposal.tex: Update accordingly.
* include/vaucanson/algebra/implementation/series/rat/xml_exp_visitor.hh,
* include/vaucanson/algebra/implementation/series/rat/xml_exp_visitor.hxx:
Add the support of left and right weights for output. Fix a bug about
weights.
* include/vaucanson/algebra/implementation/series/rat/exp.hh,
* include/vaucanson/algebra/implementation/series/rat/exp.hxx: Minor fix.
* include/vaucanson/xml/tools.hxx: Add the support of left and right
weights for input.
* src/tests/xml/xml_label_node_tester.cc: Enhance the tests on weights.
* src/tests/xml/label_node_ref.xml,
* src/tests/xml/label_node_ref.dot: Update accordingly.
2006-10-18 Florent Terrones <terron_f@lrde.epita.fr>
* include/vaucanson/algorithms/domain.hh,
......
......@@ -13,27 +13,33 @@ vaucanson.xsd version 0.3.2
-->
<!--
Attribute group used to factor some code.
Attribute group used for node expressions.
-->
<xs:attributeGroup name="expressionAttributes">
<xs:attribute name="parenthesis" type="xs:boolean"/>
<xs:attributeGroup name="nodeAttributes">
<xs:attribute name="leftWeight" type="xs:string"/>
<xs:attribute name="rightWeight" type="xs:string"/>
</xs:attributeGroup>
<!--
Attribute group used for the terminal tags of the expression grammar.
-->
<xs:attributeGroup name="atomAttributes">
<xs:attribute name="weight" type="xs:string"/>
</xs:attributeGroup>
<!--
Terminal tags of the expression grammar.
-->
<xs:complexType name="word">
<xs:complexType name="atom">
<xs:attribute name="value" type="xs:string" use="required"/>
<xs:attributeGroup ref="expressionAttributes"/>
<xs:attributeGroup ref="atomAttributes"/>
</xs:complexType>
<xs:complexType name="zeroVal">
<xs:attribute name="weight" type="xs:string"/>
</xs:complexType>
<xs:complexType name="identityVal">
<xs:attribute name="weight" type="xs:string"/>
<xs:attributeGroup ref="atomAttributes"/>
</xs:complexType>
<!--
......@@ -44,7 +50,7 @@ vaucanson.xsd version 0.3.2
-->
<xs:complexType name="star">
<xs:group ref="expressionLabelGroup"/>
<xs:attributeGroup ref="expressionAttributes"/>
<xs:attributeGroup ref="nodeAttributes"/>
</xs:complexType>
<!--
......@@ -56,7 +62,7 @@ vaucanson.xsd version 0.3.2
<xs:sequence minOccurs="2" maxOccurs="2">
<xs:group ref="expressionLabelGroup"/>
</xs:sequence>
<xs:attributeGroup ref="expressionAttributes"/>
<xs:attributeGroup ref="nodeAttributes"/>
</xs:complexType>
<!--
......@@ -68,7 +74,7 @@ vaucanson.xsd version 0.3.2
<xs:sequence minOccurs="2" maxOccurs="2">
<xs:group ref="expressionLabelGroup"/>
</xs:sequence>
<xs:attributeGroup ref="expressionAttributes"/>
<xs:attributeGroup ref="nodeAttributes"/>
</xs:complexType>
<!--
......@@ -78,7 +84,7 @@ label by using <product>, <sum>, <zero>, <identity> and <word> tags.
<xs:group name="expressionLabelGroup">
<xs:choice>
<xs:element name="star" type="star"/>
<xs:element name="word" type="word"/>
<xs:element name="word" type="atom"/>
<xs:element name="sum" type="sum"/>
<xs:element name="product" type="product"/>
<xs:element name="zero" type="zeroVal"/>
......@@ -88,7 +94,7 @@ label by using <product>, <sum>, <zero>, <identity> and <word> tags.
<xs:complexType name="expressionLabel">
<xs:group ref="expressionLabelGroup"/>
<xs:attributeGroup ref="expressionAttributes"/>
</xs:complexType>
......@@ -131,14 +137,23 @@ transitionType for states or coordinates for transitions.
<!--
<drawing> tag properties. Used to define useful properties that can be
used for XML to latex translation.
used for XML to latex translation. The entire list of possible attributes is
very long, the following ones are given as examples.
An optional "any" attribute is used, to let the user use personal attributes.
-->
<xs:complexType name="drawing" mixed="true">
<xs:attribute name="stateColor" type="xs:string"/>
<xs:attribute name="stateFillColor" type="xs:string"/>
<xs:attribute name="transitionLabelColor" type="xs:string"/>
<xs:attribute name="stateLabelColor" type="xs:string"/>
<xs:attribute name="stateLineWidth" type="xs:string"/>
<xs:attribute name="stateLineStyle">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="solid|dashed|dotted|none"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="arcAngle" type="xs:decimal"/>
<xs:anyAttribute/>
</xs:complexType>
......
......@@ -809,7 +809,7 @@ the possibility to make them explicit.
Since it's not possible to exhaustively name all needed attributes
users may need, the proposal offers a very limited set of properties. For
example, \xattr{stateFillColor} or \xattr{transitionLabelColor} usage are
example, \xattr{stateFillColor} or \xattr{stateLineStyle} usage are
shown in \autoref{drawing1}. These attributes use a string representation to
describe their values. Providing more attributes will be one of our future
works.
......@@ -827,7 +827,7 @@ set of drawing properties.
\begin{alltt}
<transducer>
<geometry x="-5" y="0"/>
<drawing stateFillColor="black" transitionLabelColor="dashed"/>
<drawing stateFillColor="black" stateLineStyle="dashed"/>
<content>
<states>
<state name="s0">
......
......@@ -93,7 +93,7 @@ namespace vcsn {
size_t length() const;
xercesc::DOMElement* xml_tree(xercesc::DOMDocument* doc,
char* node_name) const;
const char* node_name) const;
/// Get the root node of the expression.
//@{
......
......@@ -130,7 +130,7 @@ namespace vcsn {
template<typename LetterT, typename WeightT>
xercesc::DOMElement* exp<LetterT, WeightT>::xml_tree(
xercesc::DOMDocument* doc, char* node_name) const
xercesc::DOMDocument* doc, const char* node_name) const
{
XmlExpVisitor<monoid_elt_value_t, semiring_elt_value_t> v(doc, node_name);
accept(v);
......
......@@ -43,7 +43,7 @@ namespace vcsn {
class XmlExpVisitor : public ConstNodeVisitor<M_, W_>
{
public:
XmlExpVisitor(xercesc::DOMDocument* doc, char* node_name);
XmlExpVisitor(xercesc::DOMDocument* doc, const char* node_name);
virtual void
product(const Node<M_, W_>* left_, const Node<M_, W_>* right_);
......@@ -79,6 +79,7 @@ namespace vcsn {
xercesc::DOMDocument* doc_;
xercesc::DOMElement* label_;
xercesc::DOMElement* current_;
std::string weight_;
};
} // rat
......
......@@ -30,7 +30,7 @@ namespace vcsn {
using xml::transcode;
template<typename M_, typename W_>
XmlExpVisitor<M_,W_>::XmlExpVisitor(xercesc::DOMDocument* doc, char* node_name) :
XmlExpVisitor<M_,W_>::XmlExpVisitor(xercesc::DOMDocument* doc, const char* node_name) :
doc_(doc),
label_(doc_->createElement(transcode(node_name))),
current_(label_)
......@@ -94,7 +94,7 @@ namespace vcsn {
{
std::stringstream ss;
ss << w;
current_->setAttribute(transcode("weight"), transcode(ss.str()));
weight_ = ss.str();
weight_or_star(node);
}
......@@ -104,7 +104,6 @@ namespace vcsn {
{
std::stringstream ss;
ss << w;
current_->setAttribute(transcode("weight"), transcode(ss.str()));
weight_or_star(node);
}
......@@ -116,21 +115,31 @@ namespace vcsn {
ss << m;
xercesc::DOMElement* word = doc_->createElement(transcode("word"));
word->setAttribute(transcode("value"), transcode(ss.str()));
if (weight_.size())
{
word->setAttribute(transcode("weight"), transcode(weight_));
weight_ = "";
}
current_->appendChild(word);
}
template<typename M_, typename W_>
void XmlExpVisitor<M_, W_>::zero()
{
xercesc::DOMElement* zero = doc_->createElement(transcode("zeroVal"));
xercesc::DOMElement* zero = doc_->createElement(transcode("zero"));
current_->appendChild(zero);
}
template<typename M_, typename W_>
void XmlExpVisitor<M_, W_>::one()
{
xercesc::DOMElement* identity = doc_->createElement(transcode("identityVal"));
xercesc::DOMElement* identity = doc_->createElement(transcode("identity"));
current_->appendChild(identity);
if (weight_.size())
{
identity->setAttribute(transcode("weight"), transcode(weight_));
weight_ = "";
}
}
template<typename M_, typename W_>
......
......@@ -429,9 +429,45 @@ namespace vcsn
return s;
}
// Used by get_rec_xml_series to get the eventual weigths of an expression
// element.
template <class T>
Element<typename T::series_set_t, rat::exp<typename T::monoid_elt_value_t,
typename T::semiring_elt_value_t> >
void get_weight_attribute(typename T::semiring_elt_value_t& weight,
xercesc::DOMElement* element,
const char* attribute_name)
{
if (has_attribute(element, attribute_name))
{
std::stringstream ss;
ss << get_attribute(element, attribute_name);
ss >> weight;
}
}
// Used by get_rec_xml_series to set the weights to the krat_exp that will
// be returned.
template <class T>
Element<typename T::series_set_t,
rat::exp<typename T::monoid_elt_value_t,
typename T::semiring_elt_value_t> >
weighted_krat_exp(Element<typename T::series_set_t,
rat::exp<typename T::monoid_elt_value_t,
typename T::semiring_elt_value_t> >& krat_exp,
typename T::semiring_elt_value_t& weight,
typename T::semiring_elt_value_t& rweight)
{
if (weight != typename T::semiring_elt_t ())
krat_exp = typename T::semiring_elt_t (weight) * krat_exp;
if (rweight != typename T::semiring_elt_t ())
krat_exp = krat_exp * (typename T::semiring_elt_t) rweight;
return krat_exp;
}
template <class T>
Element<typename T::series_set_t,
rat::exp<typename T::monoid_elt_value_t,
typename T::semiring_elt_value_t> >
get_rec_xml_series(xercesc::DOMNode* n, T& aut)
{
typedef rat::exp<typename T::monoid_elt_value_t,
......@@ -440,6 +476,8 @@ namespace vcsn
krat_exp_t krat_exp (aut.structure().series());
typename T::semiring_elt_value_t weight =
typename T::semiring_elt_value_t();
typename T::semiring_elt_value_t rweight =
typename T::semiring_elt_value_t();
xercesc::DOMElement* element_n;
xercesc::DOMNode* ntmp;
......@@ -459,13 +497,11 @@ namespace vcsn
(xml2str(n->getNodeName()) == "out"))
return get_rec_xml_series(n->getFirstChild(), aut);
// Add weight
if (has_attribute(element_n, "weight"))
{
std::stringstream ss;
ss << get_attribute(element_n, "weight");
ss >> weight;
}
// Add weights. It is a weight (leafs) or left and right weights
// (nodes).
get_weight_attribute<T>(weight, element_n, "weight");
get_weight_attribute<T>(weight, element_n, "leftWeight");
get_weight_attribute<T>(rweight, element_n, "rightWeight");
// Explore the terms of a sum
if (xml2str(n->getNodeName()) == "sum")
......@@ -477,8 +513,7 @@ namespace vcsn
ntmp && ntmp->getNextSibling();
ntmp = ntmp->getNextSibling()->getNextSibling())
krat_exp += get_rec_xml_series(ntmp, aut);
return (weight != typename T::semiring_elt_t ())?
typename T::semiring_elt_t (weight) * krat_exp : krat_exp;
return weighted_krat_exp<T>(krat_exp, weight, rweight);
}
// Explore the terms of a product
......@@ -491,8 +526,7 @@ namespace vcsn
ntmp && ntmp->getNextSibling();
ntmp = ntmp->getNextSibling()->getNextSibling())
krat_exp *= get_rec_xml_series(ntmp, aut);
return (weight != typename T::semiring_elt_t ())?
typename T::semiring_elt_t (weight) * krat_exp : krat_exp;
return weighted_krat_exp<T>(krat_exp, weight, rweight);
}
// Word, zero or identity
......@@ -513,8 +547,7 @@ namespace vcsn
if (xml2str(n->getNodeName()) == "star")
krat_exp = (get_rec_xml_series(n->getFirstChild(), aut)).star();
return (weight != typename T::semiring_elt_t ())?
typename T::semiring_elt_t (weight) * krat_exp : krat_exp;
return weighted_krat_exp<T>(krat_exp, weight, rweight);
}
}
return krat_exp;
......
digraph vcsn {
label="A { 3 states, 2 transitions, #I = 1, #T = 1 }";
label="A { 3 states, 5 transitions, #I = 1, #T = 1 }";
node [shape=circle];
"A1" [style=invis,label="",width=.01,height=.01];
"A1" -> "A0" [label="1"];
......@@ -8,6 +8,9 @@ node [shape=circle];
"A2" -> "A3" [label="1"];
"A2" [label="1"];
"A4" [label="2"];
"A0" -> "A2" [label="a+b"];
"A2" -> "A4" [label="aa+ab+ba+bb"];
"A0" -> "A0" [label="(6 a)+(6 b)+(15 c)+(15 d)"];
"A0" -> "A2" [label="(6 a)+(5 b)"];
"A0" -> "A4" [label="aa+(3 b)"];
"A2" -> "A0" [label="(5 ab)"];
"A2" -> "A2" [label="(5 a)+(5 b)"];
}
......@@ -3,8 +3,10 @@
<monoid generators="letters" type="free">
<generator value="a"/>
<generator value="b"/>
<generator value="c"/>
<generator value="d"/>
</monoid>
<semiring operations="numerical" set="B"/>
<semiring operations="numerical" set="Z"/>
</labelType>
<content>
<states>
......@@ -13,30 +15,59 @@
<state name="s2"/>
</states>
<transitions>
<transition src="s0" dst="s0">
<label>
<sum>
<sum>
<sum>
<word value="a" weight="6"/>
<word value="b" weight="6"/>
</sum>
<word value="c" weight="15"/>
</sum>
<word value="d" weight="15"/>
</sum>
</label>
</transition>
<transition src="s0" dst="s1">
<label>
<sum>
<word value="a"/>
<word value="b"/>
<word value="a" weight="6"/>
<word value="b" weight="5"/>
</sum>
</label>
</transition>
<transition src="s1" dst="s2">
<transition src="s0" dst="s2">
<label>
<sum>
<sum>
<sum>
<word value="aa"/>
<word value="ab"/>
</sum>
<word value="ba"/>
</sum>
<word value="bb"/>
<word value="aa"/>
<word value="b" weight="3"/>
</sum>
</label>
</transition>
<initial state="s0"/>
<final state="s1"/>
<transition src="s1" dst="s0">
<label>
<word value="ab" weight="5"/>
</label>
</transition>
<transition src="s1" dst="s1">
<label>
<sum>
<word value="a" weight="5"/>
<word value="b" weight="5"/>
</sum>
</label>
</transition>
<initial state="s0">
<label>
<identity/>
</label>
</initial>
<final state="s1">
<label>
<identity/>
</label>
</final>
</transitions>
</content>
</automaton>
......@@ -16,7 +16,7 @@
//
#include <iostream>
#include <string>
#include <vaucanson/boolean_automaton.hh>
#include <vaucanson/z_automaton.hh>
#include <vaucanson/tools/dot_dump.hh>
#include <vaucanson/xml/XML.hh>
......@@ -28,11 +28,13 @@ int main(int argc, char** argv)
if (argc > 1 && ! strcmp(argv[1], "output"))
{
using namespace boolean_automaton;
using namespace z_automaton;
alphabet_t alpha;
alpha.insert('a');
alpha.insert('b');
alpha.insert('c');
alpha.insert('d');
automaton_t a = make_automaton(alpha);
......@@ -43,14 +45,17 @@ int main(int argc, char** argv)
a.set_initial(s0);
a.set_final(s1);
a.add_series_transition(s0, s1, make_rat_exp(alpha, "a+b"));
a.add_series_transition(s1, s2, make_rat_exp(alpha, "(a+b).(a+b)"));
a.add_series_transition(s0, s0, make_rat_exp(alpha, "3 ((2 (a+b))+(5 (c+d)))"));
a.add_series_transition(s0, s1, make_rat_exp(alpha, "6 a+5 b"));
a.add_series_transition(s0, s2, make_rat_exp(alpha, "a.a+3 b"));
a.add_series_transition(s1, s0, make_rat_exp(alpha, "5 (a.b)"));
a.add_series_transition(s1, s1, make_rat_exp(alpha, "5 (a+b)"));
std::cout << automaton_saver(a, io::string_out(), xml::XML("", true));
}
else
{
using namespace boolean_automaton;
using namespace z_automaton;
alphabet_t alpha;
automaton_t a = make_automaton(alpha);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment