Read a graphML file created by yEd into R - r

I have this graphML file, which was created with yworks yEd.
Now I want to read this file into R to plot it via visNetwork. But reading the file into R using the igraph::read_graph function fails:
library(igraph)
example <- igraph::read_graph("data/graphml_example.graphml", format = "graphml")
Warning messages:
1: In read.graph.graphml(file, ...) : At foreign-graphml.c:651
:Ignoring because of a missing or unknown 'attr.type'
attribute
...
This is the graphml file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--Created by yFiles for HTML 2.0.1.4-->
<graphml xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml.html/2.0/ygraphml.xsd " xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:demostyle="http://www.yworks.com/yFilesHTML/demos/FlatDemoStyle/1.0" xmlns:bpmn="http://www.yworks.com/xml/yfiles-for-html/bpmn/2.0" xmlns:demotablestyle="http://www.yworks.com/yFilesHTML/demos/FlatDemoTableStyle/1.0" xmlns:compat="http://www.yworks.com/xml/yfiles-compat-arrows/1.0" xmlns:VuejsNodeStyle="http://www.yworks.com/demos/yfiles-vuejs-node-style/1.0" xmlns:y="http://www.yworks.com/xml/yfiles-common/3.0" xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/3.0" xmlns:yjs="http://www.yworks.com/xml/yfiles-for-html/2.0/xaml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<key id="d0" for="node" attr.type="boolean" attr.name="Expanded" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/folding/Expanded">
<default>true</default>
</key>
<key id="d1" for="node" attr.name="NodeLabels" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/NodeLabels"/>
<key id="d2" for="node" attr.name="NodeGeometry" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/NodeGeometry"/>
<key id="d3" for="all" attr.name="UserTags" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/UserTags"/>
<key id="d4" for="node" attr.name="NodeStyle" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/NodeStyle"/>
<key id="d5" for="node" attr.name="NodeViewState" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/folding/1.1/NodeViewState"/>
<key id="d6" for="edge" attr.name="EdgeLabels" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/EdgeLabels"/>
<key id="d7" for="edge" attr.name="EdgeGeometry" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/EdgeGeometry"/>
<key id="d8" for="edge" attr.name="EdgeStyle" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/EdgeStyle"/>
<key id="d9" for="edge" attr.name="EdgeViewState" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/folding/1.1/EdgeViewState"/>
<key id="d10" for="port" attr.name="PortLocationParameter" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/PortLocationParameter">
<default>
<x:Static Member="y:FreeNodePortLocationModel.NodeCenterAnchored"/>
</default>
</key>
<key id="d11" for="port" attr.name="PortStyle" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/PortStyle">
<default>
<x:Static Member="y:VoidPortStyle.Instance"/>
</default>
</key>
<key id="d12" for="port" attr.name="PortViewState" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/folding/1.1/PortViewState"/>
<key id="d13" attr.name="SharedData" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/SharedData"/>
<data key="d13">
<y:SharedData>
<yjs:Color x:Key="1" value="#FF316C94"/>
<yjs:Color x:Key="2" value="#FF006A70"/>
<yjs:Color x:Key="3" value="#FFC9E2E2"/>
<yjs:Arrow x:Key="4" type="NONE"/>
</y:SharedData>
</data>
<graph id="G" edgedefault="directed">
<node id="n0">
<data key="d1">
<x:List>
<y:Label>
<y:Label.Text>A</y:Label.Text>
<y:Label.LayoutParameter>
<y:RatioAnchoredLabelModelParameter LayoutOffset="45.2981354349738,20.5"/>
</y:Label.LayoutParameter>
<y:Label.Style>
<yjs:DefaultLabelStyle horizontalTextAlignment="CENTER" autoFlip="false" textFill="#FFFFFFFF" textSize="16">
<yjs:DefaultLabelStyle.font>
<yjs:Font fontSize="16" fontFamily="Calibri" fontWeight="BOLD"/>
</yjs:DefaultLabelStyle.font>
</yjs:DefaultLabelStyle>
</y:Label.Style>
</y:Label>
</x:List>
</data>
<data key="d2">
<y:RectD X="1917.9576310558555" Y="2912.1062122893554" Width="214.8931458699476" Height="57"/>
</data>
<data key="d4">
<demostyle:FlowchartNodeStyle type="terminator">
<demostyle:FlowchartNodeStyle.stroke>
<yjs:Stroke fill="#FF000000" miterLimit="1.45" thickness="2"/>
</demostyle:FlowchartNodeStyle.stroke>
<demostyle:FlowchartNodeStyle.fill>
<yjs:LinearGradient spreadMethod="PAD" startPoint="0,0" endPoint="1,1">
<yjs:GradientStop color="{y:GraphMLReference 1}" offset="0"/>
<yjs:GradientStop color="{y:GraphMLReference 1}" offset="1"/>
</yjs:LinearGradient>
</demostyle:FlowchartNodeStyle.fill>
</demostyle:FlowchartNodeStyle>
</data>
<port name="p0"/>
</node>
<node id="n1">
<data key="d1">
<x:List>
<y:Label>
<y:Label.Text>B</y:Label.Text>
<y:Label.LayoutParameter>
<y:RatioAnchoredLabelModelParameter LayoutOffset="68.91532293497403,12.5"/>
</y:Label.LayoutParameter>
<y:Label.Style>
<yjs:DefaultLabelStyle horizontalTextAlignment="CENTER" autoFlip="false" textFill="#FFFFFFFF" textSize="16">
<yjs:DefaultLabelStyle.font>
<yjs:Font fontSize="16" fontFamily="Calibri" fontWeight="BOLD"/>
</yjs:DefaultLabelStyle.font>
</yjs:DefaultLabelStyle>
</y:Label.Style>
</y:Label>
</x:List>
</data>
<data key="d2">
<y:RectD X="1917.9576310558555" Y="2809.9061759957385" Width="214.89314586994806" Height="57"/>
</data>
<data key="d4">
<demostyle:FlowchartNodeStyle type="document">
<demostyle:FlowchartNodeStyle.stroke>
<yjs:Stroke fill="#FF000000" miterLimit="1.45" thickness="2"/>
</demostyle:FlowchartNodeStyle.stroke>
<demostyle:FlowchartNodeStyle.fill>
<yjs:LinearGradient spreadMethod="PAD" startPoint="0,0" endPoint="1,1">
<yjs:GradientStop color="{y:GraphMLReference 2}" offset="0"/>
<yjs:GradientStop color="{y:GraphMLReference 2}" offset="1"/>
</yjs:LinearGradient>
</demostyle:FlowchartNodeStyle.fill>
</demostyle:FlowchartNodeStyle>
</data>
<port name="p0"/>
<port name="p1"/>
<port name="p2"/>
</node>
<node id="n2">
<data key="d1">
<x:List>
<y:Label>
<y:Label.Text>X</y:Label.Text>
<y:Label.LayoutParameter>
<y:RatioAnchoredLabelModelParameter LayoutOffset="62.41922918497403,20.5"/>
</y:Label.LayoutParameter>
<y:Label.Style>
<yjs:DefaultLabelStyle horizontalTextAlignment="CENTER" autoFlip="false" textFill="#FF000000" textSize="16">
<yjs:DefaultLabelStyle.font>
<yjs:Font fontSize="16" fontFamily="Calibri" fontWeight="BOLD"/>
</yjs:DefaultLabelStyle.font>
</yjs:DefaultLabelStyle>
</y:Label.Style>
</y:Label>
</x:List>
</data>
<data key="d2">
<y:RectD X="1917.9576310558555" Y="2702.7061397021216" Width="214.89314586994806" Height="57"/>
</data>
<data key="d4">
<demostyle:FlowchartNodeStyle type="start1">
<demostyle:FlowchartNodeStyle.stroke>
<yjs:Stroke fill="#FF000000" miterLimit="1.45" thickness="2"/>
</demostyle:FlowchartNodeStyle.stroke>
<demostyle:FlowchartNodeStyle.fill>
<yjs:LinearGradient spreadMethod="PAD" startPoint="0,0" endPoint="1,1">
<yjs:GradientStop color="{y:GraphMLReference 3}" offset="0"/>
<yjs:GradientStop color="{y:GraphMLReference 3}" offset="1"/>
</yjs:LinearGradient>
</demostyle:FlowchartNodeStyle.fill>
</demostyle:FlowchartNodeStyle>
</data>
<port name="p0"/>
</node>
<edge id="e0" source="n1" target="n0" sourceport="p0" targetport="p0">
<data key="d7">
<x:List>
<y:Bend Location="2025.4042039908295,2898.850638702741"/>
</x:List>
</data>
<data key="d8">
<yjs:PolylineEdgeStyle sourceArrow="{y:GraphMLReference 4}">
<yjs:PolylineEdgeStyle.stroke>
<yjs:Stroke fill="#FF000000" miterLimit="1.45"/>
</yjs:PolylineEdgeStyle.stroke>
<yjs:PolylineEdgeStyle.targetArrow>
<yjs:Arrow stroke="#FF000000" fill="#FF000000"/>
</yjs:PolylineEdgeStyle.targetArrow>
</yjs:PolylineEdgeStyle>
</data>
</edge>
<edge id="e1" source="n2" target="n1" sourceport="p0" targetport="p2">
<data key="d8">
<yjs:PolylineEdgeStyle sourceArrow="{y:GraphMLReference 4}">
<yjs:PolylineEdgeStyle.stroke>
<yjs:Stroke fill="#FF000000" miterLimit="1.45"/>
</yjs:PolylineEdgeStyle.stroke>
<yjs:PolylineEdgeStyle.targetArrow>
<yjs:Arrow stroke="#FF000000" fill="#FF000000"/>
</yjs:PolylineEdgeStyle.targetArrow>
</yjs:PolylineEdgeStyle>
</data>
</edge>
</graph>
</graphml>
How can I read this into R so that properties like shape and color are preserved?

Related

Transform XML with xsi:nil="true" into a series of name-value pair

I use this compare script .
The script doesn't support NULL values in fields.
To generate the first XML I use now "FOR XML AUTO, ELEMENTS XSINIL"
<cd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<typ>new</typ>
<Field1>505</Field1>
<Field2 xsi:nil="true" />
<Field3>15</Field3>
<Field4>FA </Field4>
<Field5>0</Field5>
<Field6 xsi:nil="true" />
<Field7 xsi:nil="true" />
<Field8>10</Field8>
<Field9>3</Field9>
<Field10>2</Field10>
...
</cd>
Now this part doesn't work anymore
declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
for $f in cd/#*
return
<data name="{ local-name($f) }" value="{ data($f) }" />
Output is always empty.
Expected output
<data name="typ" value="new" />
<data name="Field1" value="505" />
<data name="Field2" value="NULL" />
<data name="Field3" value="15" />
<data name="Field4" value="FA " />
<data name="Field5" value="0" />
<data name="Field6" value="NULL" />
<data name="Field7" value="NULL" />
<data name="Field8" value="10" />
<data name="Field9" value="3" />
<data name="Field10" value="2" />
...
Where is my error in the XQuery?
Thank you!
If you have an XML with elements, you need to use /* rather than /#*:
declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
for $f in cd/*
return
<data name="{ local-name($f) }" value="{ data($f) }" />

Export Tinkerpop graph using writeGraph() to different OutputStream

The following statement will create a new file on the graph server:
graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(new FileOutputStream("export.graphml"), graph)
I want to use a different OutputStream to see the output directly in my gremlin client. I have tried DataOutputStream() but got a NullPointerException. How would I get the response from writeGraph()?
I originally read this question as wanting to know how to create a remote OutputStream to write from the server back to some local file on the client, which likely has some solution but I'm not sure what the answer is to that. As I happen to look at this question again though the bounty notes that you are interested in "Export of full tinkerpop graph to console" in which case perhaps a different approach will satisfy.
I would simply construct a GraphMLWriter directly using its Builder and then write to a byte[] and return that as a String:
baos = new ByteArrayOutputStream()
graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(baos, graph)
baos.toByteArray()
Here is the full console session though I've elided some of the graphml to help with readability:
gremlin> :remote connect tinkerpop.server conf/remote-objects.yaml session
==>Configured localhost/127.0.0.1:8182-[df3107c1-b25b-4f1c-a1f3-552353e9023d]
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182]-[df3107c1-b25b-4f1c-a1f3-552353e9023d] - type ':remote console' to return to local mode
gremlin> baos = new ByteArrayOutputStream();[]
gremlin> graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(baos, graph);[]
gremlin> new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8)
==><?xml version="1.0" ?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="age" for="node" attr.name="age" attr.type="int"></key>
<key id="labelV" for="node" attr.name="labelV" attr.type="string"></key>
<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
<key id="name" for="node" attr.name="name" attr.type="string"></key>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"></key>
<key id="weight" for="edge" attr.name="weight" attr.type="double"></key>
<graph id="G" edgedefault="directed">
<node id="1">
<data key="labelV">person</data>
<data key="age">29</data>
<data key="name">marko</data>
</node>
...
</graphml>
gremlin> :remote console
==>All scripts will now be evaluated locally - type ':remote console' to return to remote mode for Gremlin Server - [localhost/127.0.0.1:8182]-[df3107c1-b25b-4f1c-a1f3-552353e9023d]
gremlin> result
==>result{object=<?xml version="1.0" ?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="age" for="node" attr.name="age" attr.type="int"></key>
<key id="labelV" for="node" attr.name="labelV" attr.type="string"></key>
<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
<key id="name" for="node" attr.name="name" attr.type="string"></key>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"></key>
<key id="weight" for="edge" attr.name="weight" attr.type="double"></key>
<graph id="G" edgedefault="directed">
<node id="1">
<data key="labelV">person</data>
<data key="age">29</data>
<data key="name">marko</data>
</node>
...
</graphml> class=java.lang.String}
gremlin> result.get(0).getString()
==><?xml version="1.0" ?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="age" for="node" attr.name="age" attr.type="int"></key>
<key id="labelV" for="node" attr.name="labelV" attr.type="string"></key>
<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
<key id="name" for="node" attr.name="name" attr.type="string"></key>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"></key>
<key id="weight" for="edge" attr.name="weight" attr.type="double"></key>
<graph id="G" edgedefault="directed">
<node id="1">
<data key="labelV">person</data>
<data key="age">29</data>
<data key="name">marko</data>
</node>
...
</graph>
</graphml>
gremlin>
My Gremlin Console example sends scripts to the server for execution in a session (thus this approach will also work as a script sent from drivers assuming it is sent as one script or if using session each line can be sent individually). Note that the result of each line returned from the server is stored in a result variable in the console. For this to work properly it is important that you connect with a configuration like the one presented in the default remote-objects.yaml where objects are returned rather than just string representations, though in this case since the ultimate object is a String it might not matter so much. I suppose whether or not it depends on what you intend to do with the result itself once you have it.
Some caveats to consider:
For a large graph this operation will be fairly expensive because not only is it a full graph scan but you're also writing the entire graph to memory before streaming it back.
The use of the Graph API (i.e. graph.io()) and/or direct use of GraphWriter implementations isn't recommended, so I suppose these APIs could disappear in future versions but give that there aren't better solutions at this time there isn't much choice I'm afraid.

No value returned when using identity() in the within step, but values are returned when hardcoded

I'm new to gremlin.
Here's a sample graph
<?xml version='1.0' ?>
<graphml xmlns='http://graphml.graphdrawing.org/xmlns'>
<key id='labelV' for='node' attr.name='labelV' attr.type='string'></key>
<key id='type' for='node' attr.name='type' attr.type='string'></key>
<key id='pick' for='node' attr.name='pick' attr.type='string'></key>
<key id='match' for='node' attr.name='match' attr.type='string'></key>
<key id='pot' for='node' attr.name='pot' attr.type='double'></key>
<key id='stake' for='node' attr.name='stake' attr.type='double'></key>
<key id='labelE' for='edge' attr.name='labelE' attr.type='string'></key>
<graph id='routes' edgedefault='directed'>
<!-- vertices -->
<node id='1'>
<data key='labelV'>transaction</data>
<data key='type'>transaction</data>
<data key='match'>M1</data>
<data key='pos'>H1</data>
<data key='pick'>M1H1</data>
<data key='pot'>100.0</data>
<data key='stake'>10.0</data>
</node>
<node id='2'>
<data key='labelV'>transaction</data>
<data key='type'>transaction</data>
<data key='match'>M1</data>
<data key='pos'>D1</data>
<data key='pick'>M1D1</data>
<data key='pot'>50.0</data>
<data key='stake'>5.0</data>
</node>
<node id='3'>
<data key='labelV'>transaction</data>
<data key='type'>transaction</data>
<data key='match'>M1</data>
<data key='pos'>A1</data>
<data key='pick'>M1A1</data>
<data key='pot'>150.0</data>
<data key='stake'>15.0</data>
</node>
<node id='4'>
<data key='labelV'>transaction</data>
<data key='type'>transaction</data>
<data key='match'>M2</data>
<data key='pos'>A2</data>
<data key='pick'>M2A2</data>
<data key='pot'>75.0</data>
<data key='stake'>10.0</data>
</node>
<node id='5'>
<data key='labelV'>transaction</data>
<data key='type'>transaction</data>
<data key='match'>M3</data>
<data key='pos'>A3</data>
<data key='pick'>M3A3</data>
<data key='pot'>70.0</data>
<data key='stake'>7.0</data>
</node>
<node id='6'>
<data key='labelV'>transaction</data>
<data key='type'>transaction</data>
<data key='match'>M1</data>
<data key='pos'>H1</data>
<data key='pick'>M1H1:M2D2</data>
<data key='pot'>60.0</data>
<data key='stake'>6.0</data>
</node>
<!-- edges -->
<edge id='20' source='1' target='4'>
<data key='labelE'>compatible</data>
</edge>
<edge id='21' source='1' target='5'>
<data key='labelE'>compatible</data>
</edge>
<edge id='22' source='1' target='6'>
<data key='labelE'>compatible</data>
</edge>
<edge id='23' source='2' target='4'>
<data key='labelE'>compatible</data>
</edge>
<edge id='24' source='2' target='5'>
<data key='labelE'>compatible</data>
</edge>
<edge id='25' source='3' target='4'>
<data key='labelE'>compatible</data>
</edge>
<edge id='26' source='3' target='5'>
<data key='labelE'>compatible</data>
</edge>
<edge id='27' source='4' target='1'>
<data key='labelE'>compatible</data>
</edge>
<edge id='28' source='4' target='2'>
<data key='labelE'>compatible</data>
</edge>
<edge id='29' source='4' target='3'>
<data key='labelE'>compatible</data>
</edge>
<edge id='30' source='4' target='5'>
<data key='labelE'>compatible</data>
</edge>
<edge id='31' source='5' target='1'>
<data key='labelE'>compatible</data>
</edge>
<edge id='32' source='5' target='2'>
<data key='labelE'>compatible</data>
</edge>
<edge id='33' source='5' target='3'>
<data key='labelE'>compatible</data>
</edge>
<edge id='34' source='5' target='4'>
<data key='labelE'>compatible</data>
</edge>
<edge id='35' source='5' target='6'>
<data key='labelE'>compatible</data>
</edge>
<edge id='36' source='6' target='1'>
<data key='labelE'>compatible</data>
</edge>
<edge id='37' source='6' target='5'>
<data key='labelE'>compatible</data>
</edge>
</graph>
</graphml>
I can't figure out how to add a property with with multiple values with graphML, so here's the code to add an additional value to V(6)
g.V(6).property(set, 'match', "M2")
The goal is to calculate the maximum pot in the graph by getting each node and its connected vertices, grouping the vertices of that node, by their match values ( grouping two nodes means they have at least one intersecting match value), taking the maximum of each group, and doing the sum for that node. At the end, with take the maximum value of all the nodes. I don't know if this is quite how it should be done but this is what I've tried:
g.E().hasLabel('compatible').outV().dedup().as('s'). //1. get all edges with comptible label
local( //2. for each node
union( //3. get the node and its first level connected vertices
identity(),
out()
)
.as('compat')
.values('match') //4. get the values of the match property
.as('match')
.local( //5. for each key in the list
select('compat') //6. get all vertices in the sub graph that have this value in their match list
.has('match',within(identity())) //7
.order().by("pot", decr).limit(1) //8. get the one with the highest pot value
)
.dedup() //9. remove duplicates
.values('pot')
.sum() //10. sum the values for this node
).max() //11. get the max for all nodes
EXPECTED RESULT:
For each vertex, we should have its BulkSet as follows:
V(5)==>[M1:[v[2],v[3],v[6],v[1]],M2:[v[4],v[6]],M3:[v[5]]]
V(6)==>[M1:[v[6],v[1]],M3:[v[5]]]
V(1)==>[M1:[v[1],v[6]],M2:[v[4], v[6]],M3:[v[5]]]
V(2)==>[M1:[v[2]],M2:[v[4]],M3:[v[5]]]
V(3)==>[M1:[v[3]],M2:[v[4]],M3:[v[5]]]
V(4)==>[M1:[v[1],v[2],v[3]],M2:[v[4]],M3:[v[5]]]
and the map of the maximum pots of each vertex:
V(5) ==> [M1:v[3],M2:v[4],M3:v[5]], Sum(pot) ==> 150 + 75 + 70 = 295
V(6) ==> [M1:v[1],M3:v[5]], Sum(pot) ==> 100 + 70 = 170
V(1) ==> [M1:v[1],M2:[v[4]],M3:v[5]], Sum(pot) ==> 100 + 75 + 70 = 295
V(2) ==> [M1:v[2],M2:v[4],M3:v[5]], Sum(pot) ==> 50 + 75 + 70 = 195
V(3) ==> [M1:v[3],M2:v[4],M3:v[5]], Sum(pot) ==> 150 + 75 + 70 = 295
V(4) ==> [M1:v[3],M2:v[4],M3:v[5]], Sum(pot) ==> 150 + 75 + 70 = 295
The final output should be 295.
The first problem is at 7. If I pass static values such as ['M1', 'M2'] I do get data but get an empty list with identity().
The second problem is at 8. I get multiple nodes instead of just the node with the maximum value.
I assume that your expected result is not quite right (M2 should be part of v[6]'s bulkset). That said, here's what I think the solution looks like:
gremlin> g.V().hasLabel("transaction").
map(union(identity(), out("compatible")).as("v").
values("match").
group().
by().
by(select("v").order().by("pot", decr)))
==>[M1:v[1],M2:v[4],M3:v[5]]
==>[M1:v[2],M2:v[4],M3:v[5]]
==>[M1:v[3],M2:v[4],M3:v[5]]
==>[M1:v[3],M2:v[4],M3:v[5]]
==>[M1:v[3],M2:v[4],M3:v[5]]
==>[M1:v[1],M2:v[6],M3:v[5]]
gremlin> g.V().hasLabel("transaction").
map(union(identity(), out("compatible")).as("v").
values("match").
group().
by().
by(select("v").order().by("pot", decr))).
map(select(values).unfold().values("pot").fold())
==>[100.0,75.0,70.0]
==>[50.0,75.0,70.0]
==>[150.0,75.0,70.0]
==>[150.0,75.0,70.0]
==>[150.0,75.0,70.0]
==>[100.0,60.0,70.0]
gremlin> g.V().hasLabel("transaction").
map(union(identity(), out("compatible")).as("v").
values("match").
group().
by().
by(select("v").order().by("pot", decr))).
map(select(values).unfold().values("pot").sum()).
max()
==>295.0
Worked for me on the example above:
g.V().hasLabel('transaction').local(
union(identity(), out('compatible')).as('v')
.values('match')
.group()
.by()
.by(select('v').values('pot').max()).select(values).unfold().sum()
).max()

How to convert dateTime while transforming XML via XSLT

How should I convert dateTime in XSLT if I get the dateTime in GMT in below format
XML input:
<items>
<item>
<lastname>Lisa</lastname>
<firstname>Rimpell</firstname>
<checkintime>2017-02-05T05:40:00+03:00</checkintime>
<chekouttime>2017-02-05T10:40:00+03:00</chekouttime>
<address></address>
</item>
</items>
XSLT is:
<xsl:template match="/">
<Response>
<Data>
<xsl:call-template name="Buildusers" />
</Data>
</Response>
</xsl:template>
<xsl:template name="Buildusers">
<Rows>
<xsl:for-each select="//items/item">
<Row Action="ADD">
<xsl:value-of select="lastname" />
|<xsl:value-of select="firstname" />
|<xsl:value-of select="checkintime" />
|<xsl:value-of select="chekouttime" />
|<xsl:value-of select="address" />
</Row>
</xsl:for-each>
</Rows>
</xsl:template>
i need to build the rows like below with the conversion of 'dateTime. That is when I get the value of dateTime it should convert and build the row
Expected output:
Lisa|Rimpell|2017-02-05 02:40:00|2017-02-05 07:40:00||
In XSLT 2.0, you can do:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://www.example.com/my"
exclude-result-prefixes="xs my">
<xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8" />
<xsl:strip-space elements="*" />
<xsl:function name="my:adjust-dateTime">
<xsl:param name="dateTime"/>
<xsl:variable name="UTC" select="adjust-dateTime-to-timezone($dateTime, xs:dayTimeDuration('PT0H'))"/>
<xsl:sequence select="format-dateTime($UTC, '[Y0001]-[M01]-[D01] [H01]:[m01]:[s01]')" />
</xsl:function>
<xsl:template match="/items">
<Response>
<Data>
<Rows>
<xsl:for-each select="item">
<Row Action="ADD">
<xsl:value-of select="lastname, firstname, my:adjust-dateTime(checkintime), my:adjust-dateTime(chekouttime), address" separator="|" />
</Row>
</xsl:for-each>
</Rows>
</Data>
</Response>
</xsl:template>
</xsl:stylesheet>
to receive:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Data>
<Rows>
<Row Action="ADD">Lisa|Rimpell|2017-02-05 02:40:00|2017-02-05 07:40:00|</Row>
</Rows>
</Data>
</Response>

How to rename igraph node id when writing to file

I'm trying to write a graph to a file but I'm getting a different node labels than I would like.
Example Code:
g <- graph.star(2)
V(g)$name <- c('homer','marge')
write.graph(g,file = 'g.graphml',format = 'graphml')
Output:
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<!-- Created by igraph -->
<key id="g_name" for="graph" attr.name="name" attr.type="string"/>
<key id="g_mode" for="graph" attr.name="mode" attr.type="string"/>
<key id="g_center" for="graph" attr.name="center" attr.type="double"/>
<key id="v_name" for="node" attr.name="name" attr.type="string"/>
<graph id="G" edgedefault="directed">
<data key="g_name">In-star</data>
<data key="g_mode">in</data>
<data key="g_center">1</data>
<node id="n0"> ###### This should <node id = "homer">
<data key="v_name">homer</data>
</node>
<node id="n1"> ###### This should <node id = "marge">
<data key="v_name">marge</data>
</node>
<edge source="n1" target="n0">
</edge>
</graph>
</graphml>
I would like the "node id" attribute to be the names of the nodes (as shown in comments). Anybody have any ideas? Thanks!
You can't do this currently AFAIK. I am not sure why it is not implemented that way. Can you please open an issue about it at https://github.com/igraph/igraph/issues?state=open ? Thanks.

Resources