Returning multiple values from one step using 'select', 'by' in Gremline - gremlin

My graph schema looks like this:
(Location)<-[:INVENTOR_LOCATED_IN]-(Inventor)-[:INVENTOR_OF]->(Patent)
I'm trying to return multiple values from each step in the query path. Here's the query I have so far that runs correctly:
g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location','state',textContains('IN'))).as('a').
bothE().bothV().hasLabel('Inventor').as('b').
bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
select('a,', 'b', 'c').
by('state').by('name_first').by('title').
fold();
What I would like to do is for each step return two node properties. I tried the following but it returns an error:
g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
bothE().bothV().hasLabel('Inventor').as('b').
bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
select('a,', 'b', 'c').
by('city', 'state').by('name_first', 'name_last').by('title', 'abstract').
fold();
Can anyone suggest syntax that will allow me to return multiple properties from each node in the path?

The by(key) is meant to be a sort of shorthand for values(key) which means if you have more than one value you could do:
g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
bothE().bothV().hasLabel('Inventor').as('b').
bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
select('a,', 'b', 'c').
by(values('city', 'state').fold()).
by(values('name_first', 'name_last').fold()).
by(values('title', 'abstract').fold()).
fold()
You might also consider forms of elementMap(), valueMap(), or project() as alternatives. Since by() takes a Traversal you have a lot of flexibility.

Related

Problem finding the right syntax for group() and by() commands

I have the following Gremlin code:
g.V('body4608', 'body491')
.repeat(
__.as('body')
.in().aggregate('allVertices')
.bothE().as('edges')
.otherV().as('otherV')
.where('otherV', within('allVertices')).as('vertices')
.dedup()
)
.until(
__.count().is(1))
// .group()
// .by(__.select('body').id())
// .by(select('vertices').id().dedup().fold()).as('gVertices')
.group()
.by(__.select('body').id())
.by(select('edges').label().fold()).as('gEdges')
Each of the group() commands work individually where the output look like this for the 'edges':
`{'body4608': ['add', 'add', 'start', 'push', 'push_task_through', 'add'],
'body491': ['can_claim_task_for', 'is_in', 'Additionally_should_familiarize', 'can_claim_task_for', 'are_assigned_to', 'are', 'are_assigned_to', 'completes', 'can_use']}
What I would like to achieve is to include the words from the group that currently is commented out in the list of words from the 'edge' group so that I will have a combined list of words for each 'body'

Obtain lists of plot marker and line styles in Octave

Is there a way to programmatically obtain the list of marker and line styles available for plotting in Octave?
Ideally, I would do something like
mslist = whatever_function_for_marker_styles;
lslist = whatever_function_for_line_styles;
for i = 1:np
plot(x, y(i,:), 'marker', mslist(i), 'linestyle', lslist(i))
endfor
Notes:
I would add some mod functions to cycle across the lists.
I know the size of both lists may not be the same, so they may shift from one another upon cycling.
The easiest way would be to get the symbols from the manual and put them in a cell array:
mslist = {'+', 'o', '*', '.', 'x', 's', 'd', '^', 'v', '>', '<', 'p', 'h'};
lslist = {'-', '--', ':', '-.'};
You can loop over them with a standard for-loop and access them by index using curly brackets, e.g. lslist{i}. The symbols are in Section 15.2.1 of the manual (https://octave.org/doc/v6.1.0/Two_002dDimensional-Plots.html#Two_002dDimensional-Plots). An ordinary vector would work for mslist instead of a cell array as all the symbols are single characters, but not for lslist where some of them are two characters long.
I agree with Howard that doing it 'entirely' programmatically is probably overkill.
However, if you do want to do that, my bet would be to parse the 'help' output for the 'plot' command, which is guaranteed to mention these points, and has a reasonable guarantee that it will remain in the same format even if more markers are added in the future etc.
I won't parse the whole thing, but if you were to do this, you'd probably start like this:
plotdoc = help('plot');
[plotdoc_head , plotdoc_rest] = deal( strsplit( plotdoc , ' linestyle' ){:} );
[plotdoc_lines , plotdoc_rest] = deal( strsplit( plotdoc_rest, ' marker' ){:} );
[plotdoc_markers, plotdoc_rest] = deal( strsplit( plotdoc_rest, ' color' ){:} );
[plotdoc_colors , plotdoc_rest] = deal( strsplit( plotdoc_rest, '";displayname;"' ){:} );
or something along those lines, and then use regexp or strfind / strtoken / strplit creatively to obtain the necessary tokens in each category.

Gremlin: inject() and has() not working together as expected

I need to create vertices without duplication based on a list passed to inject(), the list is very large so I need to use inject(). I tried this but it didn't work:
g.inject(["Macka", "Pedro", "Albert"]).unfold().map(
coalesce(
V().has("name", identity()),
addV("user").property("name", identity())
)
)
You can try here:
https://gremlify.com/765qiupxinw
Why this doesn't work?
It seems that V().has() is returning all vertices, why?
I think in this case you should use where step and not has:
g.inject(["Macka", "Pedro", "Albert"]).unfold().as('n').map(
coalesce(
V().where(eq('n')).by('name').by(),
addV("user").property("name", identity())
)
)
example: https://gremlify.com/06q0zxgd2uam

U-SQL How can i execute Linqu solution that return my Dictionary

I'm have a list with string types and i want to get each one that have maximum of occurence element grouped by another column. I'm trying to do this by linqu expression but it doesn't work. Is it possible to run my code that i show below ?
#test=(from a in #data
group a by new {a.PostCode}
into obj
select obj).ToDictionary(x => x.Key,x=>x.ToList()
.Select(y=>y.Statistic).GroupBy(s => s)
.OrderByDescending(s => s.Count())
.First().Key);

COUNTIF phpexcel Wrong number of arguments

I'm using formulas in phpexcel and I have a problem using the countif
Wrong number of arguments for COUNTIFS() function: 4 given, 2 expected
But in the documentation countif is:
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
I have for exemple:
COUNTIFS(C$17:D$46,$B55,C$16:D$45,$B55)
It works when I directly use it on excel, is there a way to catch the error and keep the formula ?
Change the definition of COUNTIFS in the /Classes/PHPExcel/Calculation.php file (around lines 499 to 502).
Currently it reads:
'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'argumentCount' => '2'
),
add a comma after the argument count to make it
'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'argumentCount' => '2,'
),
Note that the COUNTIFS() function isn't actually implemented, so you can't do a getCalculatedValue() on any cell using the function to get the correct result, but it will then save correctly using the Excel2007 Writer.
COUNTIFS in phpexcel is not yet implemented.

Resources