Class: TensorStream::Graphml
- Inherits:
-
Serializer
- Object
- Serializer
- TensorStream::Graphml
- Defined in:
- lib/tensor_stream/graph_serializers/graphml.rb
Instance Method Summary collapse
- #get_string(tensor, session = nil) ⇒ Object
-
#initialize ⇒ Graphml
constructor
A new instance of Graphml.
Methods inherited from Serializer
Constructor Details
#initialize ⇒ Graphml
Returns a new instance of Graphml.
3 4 |
# File 'lib/tensor_stream/graph_serializers/graphml.rb', line 3 def initialize end |
Instance Method Details
#get_string(tensor, session = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tensor_stream/graph_serializers/graphml.rb', line 6 def get_string(tensor, session = nil) tensor = TensorStream.convert_to_tensor(tensor) unless tensor.is_a?(Tensor) @session = session @name = tensor.name @last_session_context = session ? session.last_session_context : {} groups = {} arr_buf = [] arr_buf << '<?xml version="1.0" encoding="UTF-8"?>' arr_buf << '<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">' arr_buf << '<key id="d0" for="node" attr.name="label" attr.type="string"/>' arr_buf << '<key id="d1" for="node" attr.name="formula" attr.type="string"/>' arr_buf << '<key id="d2" for="node" attr.name="color" attr.type="string"/>' arr_buf << '<key id="d3" for="node" attr.name="value" attr.type="string"/>' arr_buf << '<key attr.name="description" attr.type="string" for="edge" id="d12"/>' arr_buf << '<key for="edge" id="d13" yfiles.type="edgegraphics"/>' arr_buf << '<key for="node" id="d9" yfiles.type="nodegraphics"/>' arr_buf << "<graph id=\"g_#{_gml_string(tensor.name)}\" edgedefault=\"directed\">" arr_buf << "<node id=\"out\">" arr_buf << "<data key=\"d0\">out</data>" arr_buf << "<data key=\"d2\">red</data>" arr_buf << "<data key=\"d9\">" arr_buf << "<y:ShapeNode>" arr_buf << " <y:Fill color=\"#FF0000\" transparent=\"false\"/>" arr_buf << " <y:NodeLabel alignment=\"center\">out</y:NodeLabel>" arr_buf << "</y:ShapeNode>" arr_buf << "</data>" arr_buf << "</node>" to_graph_ml(tensor, arr_buf, {}, groups) # dump groups groups.each do |k, g| arr_buf << create_group(k, k, g) end output_edge(tensor, "out", arr_buf) arr_buf << "</graph>" arr_buf << "</graphml>" arr_buf.flatten.join("\n") end |