Commit e870800d authored by Florent Terrones's avatar Florent Terrones
Browse files

2006-05-09 Florent Terrones <terron_f@lrde.epita.fr>

	Add an xml format for a label node, part I.

	* src/vaucanson.xml: Add content for a label node.
	* include/vaucanson/xml/tools.hxx: Change the parsing of the XML input
	so as to correctly read a label written as a node.
parent aa4435b2
2006-05-09 Florent Terrones <terron_f@lrde.epita.fr>
Add an xml format for a label node, part I.
* src/vaucanson.xml: Add content for a label node.
* include/vaucanson/xml/tools.hxx: Change the parsing of the XML input
so as to read correctly a label written as a node.
2006-05-08 Michal Cadilhac <michael.cadilhac@lrde.epita.fr>
* include/vaucanson/xml/xerces_parser.hxx: Precise where the XSD must
......
......@@ -263,8 +263,102 @@ namespace vcsn
{ return "product"; }
# define VCSN_XML_NO_TYPE ""
# define VCSN_XML_SUM_TYPE "+"
# define VCSN_XML_PRODUCT_TYPE "."
template <class T>
std::string
get_rec_xml_series(xercesc::DOMNode* n, T& aut,
std::string op_type = VCSN_XML_NO_TYPE,
std::string res = "")
{
xercesc::DOMElement* element_n;
std::string next_op_type;
if (!n)
return res;
for (; n; n = n->getNextSibling())
{
if (n->getNodeType() == xercesc::DOMNode::ELEMENT_NODE)
{
element_n = (static_cast<const xercesc::DOMElement*>(n));
if (xml2str(n->getNodeName()) == "sum")
next_op_type = VCSN_XML_SUM_TYPE;
if (xml2str(n->getNodeName()) == "product")
next_op_type = VCSN_XML_PRODUCT_TYPE;
// Add weight (and opening brace if complex expression)
if (element_n->hasAttribute(STR2XML("weight")))
res += xml2str(element_n->getAttribute(STR2XML("weight")))
+ " ";
// Add opening prace if attribute or complex starified/weighted
// expression or sum in product
if ((element_n->hasAttribute(STR2XML("parenthesis")) &&
xml2str(element_n->getAttribute(STR2XML("parenthesis")))
== "true")
|| ((((element_n->hasAttribute(STR2XML("star")))
&& (xml2str(element_n->getAttribute(STR2XML("star")))
== "true"))
||(element_n->hasAttribute(STR2XML("weight"))))
&& (xml2str(n->getNodeName()) != "word"))
|| ((xml2str(n->getNodeName()) == "sum")
&& (op_type == VCSN_XML_PRODUCT_TYPE)))
res += "(";
// Word, zero or identity
if (xml2str(n->getNodeName()) == "word")
res += xml2str(element_n->getAttribute(STR2XML("value")));
if (xml2str(n->getNodeName()) == "zero")
res += "1";
if (xml2str(n->getNodeName()) == "identity")
res += "0";
// Recursive call
if (n->hasChildNodes())
res += get_rec_xml_series(n->getFirstChild(),
aut, next_op_type);
// Add closing brace if parenthesis attribute
if ((element_n->hasAttribute(STR2XML("parenthesis")) &&
xml2str(element_n->getAttribute(STR2XML("parenthesis")))
== "true")
// Or star/weight...
|| ((((element_n->hasAttribute(STR2XML("star")))
&& (xml2str(element_n->getAttribute(STR2XML("star")))
== "true"))
|| (element_n->hasAttribute(STR2XML("weight"))))
// ...in a complex expression
&& (xml2str(n->getNodeName()) != "word"))
// Or a sum in a product
|| ((xml2str(n->getNodeName()) == "sum")
&& (op_type == VCSN_XML_PRODUCT_TYPE))
// Or a product in a sum
|| ((xml2str(n->getNodeName()) == "product")
&& (op_type == VCSN_XML_SUM_TYPE)))
res += ")";
// Add star
if (element_n->hasAttribute(STR2XML("star"))
&& (xml2str(element_n->getAttribute(STR2XML("star")))
== "true"))
res += "*";
// Add operator
if ((n->getNextSibling())
&& (n->getNextSibling()->getNextSibling()))
res += op_type;
}
}
return res;
}
/**
* Get series from a XML node.
* Get series from a XML label node.
*
* @return series_set_elt_t
*
......@@ -282,13 +376,23 @@ namespace vcsn
rat::exp<typename T::monoid_elt_value_t,
typename T::semiring_elt_value_t> krat_exp_impl_t;
typedef Element<typename T::series_set_t, krat_exp_impl_t> krat_exp_t;
std::string str_res;
krat_exp_t res (aut.structure().series());
if (xml2str(node->getAttribute(STR2XML("label"))) == "")
return
vcsn::algebra::identity_as<typename T::series_set_elt_t::value_t>
::of(aut.structure().series());
parse(xml2str(node->getAttribute(STR2XML("label"))), res);
xercesc::DOMNode* n = node->getFirstChild();
if (n && n->getNextSibling()
&& (xml2str(n->getNextSibling()->getNodeName()) == "label"))
str_res = get_rec_xml_series(n, aut);
if (str_res == "")
{
if (xml2str(node->getAttribute(STR2XML("label"))) == "")
return
vcsn::algebra::identity_as<typename T::series_set_elt_t::value_t>
::of(aut.structure().series());
else
parse(xml2str(node->getAttribute(STR2XML("label"))), res);
}
else
parse(str_res, res);
return res;
}
......@@ -393,36 +497,57 @@ namespace vcsn
automaton_t bout = make_automaton(alphabet2);
rat_exp_t i_exp(bin.structure().series());
rat_exp_t o_exp(bout.structure().series());
std::string in, out;
std::pair<bool, std::string> i_res;
std::pair<bool, std::string> o_res;
if (node->hasAttribute(STR2XML("label")))
{
std::string label = xml2str(node->getAttribute(STR2XML("label")));
std::string in, out;
unsigned int pos = label.find("|");
if (pos != std::string::npos)
xercesc::DOMNode* n = node->getFirstChild();
if (n)
for (; n; n = n->getNextSibling())
{
in = label.substr(0, pos);
out = label.substr(pos + 1);
i_res = parse(in, i_exp);
o_res = parse(out, o_exp);
if (xml2str(n->getNodeName()) == "in" && n->getFirstChild())
{
in = get_rec_xml_series(n->getFirstChild(), a);
i_res = parse(in, i_exp);
}
if (xml2str(n->getNodeName()) == "out" && n->getFirstChild())
{
out = get_rec_xml_series(n->getFirstChild(), a);
o_res = parse(out, o_exp);
}
}
else
i_res = parse(label, i_exp);
if (node->hasAttribute(STR2XML("weight")))
o_res = parse(xml2str(node->getAttribute(STR2XML("weight"))),
o_exp);
}
// No expression tag
else
{
if (node->hasAttribute(STR2XML("in")))
i_res = parse(xml2str(node->getAttribute(STR2XML("in"))),
i_exp);
if (node->hasAttribute(STR2XML("out")))
o_res = parse(xml2str(node->getAttribute(STR2XML("out"))),
o_exp);
if (node->hasAttribute(STR2XML("label")))
{
std::string label = xml2str(node->getAttribute(STR2XML("label")));
unsigned int pos = label.find("|");
if (pos != std::string::npos)
{
in = label.substr(0, pos);
out = label.substr(pos + 1);
i_res = parse(in, i_exp);
o_res = parse(out, o_exp);
}
else
i_res = parse(label, i_exp);
if (node->hasAttribute(STR2XML("weight")))
o_res = parse(xml2str(node->getAttribute(STR2XML("weight"))),
o_exp);
}
// No expression tag, no label attribute.
else
{
if (node->hasAttribute(STR2XML("in")))
i_res = parse(xml2str(node->getAttribute(STR2XML("in"))),
i_exp);
if (node->hasAttribute(STR2XML("out")))
o_res = parse(xml2str(node->getAttribute(STR2XML("out"))),
o_exp);
}
}
assoc_exp(a, i_exp, o_exp, res, i_res.first, o_res.first);
}
......
......@@ -5,9 +5,80 @@ xmlns="http://vaucanson.lrde.epita.fr"
elementFormDefault="qualified">
<!--
vaucanson.xsd version 0.3.
vaucanson.xsd version 0.3.1
-->
<!--
The following tags are used for the <expression_label> tag.
-->
<!--
Attribute group used to factorize some code.
-->
<xs:attributeGroup name="expression_attributes">
<xs:attribute name="star" type="xs:boolean"/>
<xs:attribute name="parenthesis" type="xs:boolean"/>
<xs:attribute name="weight" type="xs:decimal"/>
</xs:attributeGroup>
<!--
Terminal tags of the expression grammar.
-->
<xs:complexType name="word">
<xs:attribute name="value" type="xs:string" use="required"/>
<xs:attributeGroup ref="expression_attributes"/>
</xs:complexType>
<xs:complexType name="zero_val">
<xs:attribute name="weight" type="xs:decimal"/>
</xs:complexType>
<xs:complexType name="identity_val">
<xs:attribute name="weight" type="xs:decimal"/>
</xs:complexType>
<!--
<sum> tag properties. Used to represent a product in the regular expression.
The members of a sum can be any tag out of the <product>, <sum>, <zero>,
<identity> and <word> ones.
Caution, only these tags should be inserted where the <xs:any> tag stands.
-->
<xs:complexType name="sum">
<xs:choice>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xs:choice>
<xs:attributeGroup ref="expression_attributes"/>
</xs:complexType>
<!--
<product> tag properties. Used to represent a product in the regular expression.
The members of a product can be any tag out of the <product>, <sum>, <zero>,
<identity> and <word> ones.
Caution, only these tags should be inserted where the <xs:any> tag stands.
-->
<xs:complexType name="product">
<xs:choice>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xs:choice>
<xs:attributeGroup ref="expression_attributes"/>
</xs:complexType>
<!--
<expression_label> tag properties. Used to clearly define the content of a
label by using <product>, <sum>, <zero>, <identity> and <word> tags.
-->
<xs:complexType name="expression_label">
<xs:choice>
<xs:element name="word" type="word" minOccurs="0"/>
<xs:element name="sum" type="sum" minOccurs="0"/>
<xs:element name="product" type="product" minOccurs="0"/>
<xs:element name="zero" type="zero_val" minOccurs="0"/>
<xs:element name="identity" type="identity_val" minOccurs="0"/>
</xs:choice>
<xs:attributeGroup ref="expression_attributes"/>
</xs:complexType>
<!--
<geometry> tag properties. Used to set the geometry properties of each
element.
......@@ -249,7 +320,7 @@ The monoid type is broken in two parts, for automata and transducers.
<!--
<label_type> tag properties. This tag encapsulates semiring and monoid
<type> tag properties. This tag encapsulates semiring and monoid
definitions to entirely define the algebraic structure the automaton /
transducer is working on. This tag is optionnal if you want to use
default values. You can specify only one of the monoid / semiring tag,
......@@ -335,6 +406,7 @@ labeled with the identity on the monoid.
<xs:sequence>
<xs:element name="geometry" type="geometry_trans" minOccurs="0"/>
<xs:element name="drawing" type="drawing" minOccurs="0"/>
<xs:element name="label" type="expression_label" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="src" type="xs:string" use="required"/>
<xs:attribute name="dst" type="xs:string" use="required"/>
......@@ -347,6 +419,8 @@ labeled with the identity on the monoid.
<xs:sequence>
<xs:element name="geometry" type="geometry_trans" minOccurs="0"/>
<xs:element name="drawing" type="drawing" minOccurs="0"/>
<xs:element name="in" type="expression_label" minOccurs="0"/>
<xs:element name="out" type="expression_label" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="src" type="xs:string" use="required"/>
<xs:attribute name="dst" type="xs:string" use="required"/>
......@@ -407,6 +481,7 @@ and drawing properties.
<xs:sequence>
<xs:element name="geometry" type="geometry_trans" minOccurs="0"/>
<xs:element name="drawing" type="drawing" minOccurs="0"/>
<xs:element name="label" type="expression_label" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="state" type="xs:string" use="required"/>
<xs:attribute name="label" type="xs:string"/>
......@@ -433,6 +508,7 @@ and drawing properties.
<xs:sequence>
<xs:element name="geometry" type="geometry_trans" minOccurs="0"/>
<xs:element name="drawing" type="drawing" minOccurs="0"/>
<xs:element name="label" type="expression_label" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="state" type="xs:string" use="required"/>
<xs:attribute name="label" type="xs:string"/>
......
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