Py2Neo: Cypher Query - graph

I am trying to make the following Cypher query:
start me = node:actors(actor = 'Tom Baker') , you = node:actors(actor = 'Peter Davison') match p = you-[*1..3]-me return p
using the Dr.Who dataset available in the neo4j site. It gives correct results in the Neo4j console as well as correct result in Py2Neo. However now I want to make the query in such a way such that
x='Tom Baker'
y='Peter Davison'
and make the same query using the variables x and y. However I dont know the escape sequence for Py2Neo. I tried the below query
"start me = node:actors(actor = \'.x.\') , you = node:actors(actor = \'.y.\') match p = you-[*1..3]-me return p"
but it didnt work. Any help would be appreciated.

Try to use parameters instead, named parameters in cypher are {name} and you pass a hash/dictionary with the name-value pairs along with the query.
start me = node:actors(actor = {me}) ,
you = node:actors(actor = {you})
match p = you-[*1..3]-me
return p
params: {"me":"Tom Baker","you":"Peter Davison"}

Related

PowerBI - Count Blank Values of specific Columns

My table looks a little like this. The last column is what I'm trying to figure out how to calculate. I can easily do this in Excel - but not sure how to write my formula in PowerBI
I don't think you can count it without specifying the individual columns. if that is what you are looking for. I would do it something like this:
Data Missing =
COUNTBLANK([Project Title])
+ COUNTBLANK([Status])
+ COUNTBLANK([Object])
There may be a more clever way to do this, but a simple DAX expression can do the job.
CountBlanksInRow =
VAR data1blank = IF (ISBLANK(Sheet1[Data 1]), 1, 0)
VAR data2blank = IF (ISBLANK(Sheet1[Data 2]), 1, 0)
VAR data3blank = IF (ISBLANK(Sheet1[Data 3]), 1, 0)
RETURN data1blank + data2blank + data3blank
Rather then using DAX or Measure, The best option is you can create the custom column in Power Query and the code will be as below-
Number.From([Project Title] = null)
+ Number.From([Status] = null)
+ Number.From([Objective] = null)
Here below is the sample code window-

Run [[processors.regex]] over multiple measurements

Is it possible to run the regex preprocessor over multiple measurements like that?
[[processors.regex]]
namepass = ["measure1", "measure2"]
[[processors.regex.fields]]
key = "agent"
pattern = '^.*$'
replacement = "NORMAL"
result_key = "agent_type"
In my case two measurements both have an Access-Log as source ([[inputs.tail]]) but I want to keep them seperate as I want to compare both eventually.
To answer my own question: I'm not sure if this is how it's meant to be but a quickfix would looke like that:
[[processors.regex]]
namepass = ["measure1"]
[[processors.regex.fields]]
key = "agent"
pattern = '^.*$'
replacement = "NORMAL"
result_key = "agent_type"
[[processors.regex]]
namepass = ["measure2"]
[[processors.regex.fields]]
key = "agent"
pattern = '^.*$'
replacement = "NORMAL"
result_key = "agent_type"
Unfortunately it contains duplicated code which is bad.

Code for sorting letters of a word is not working?

For solving this question in Hackerrank,I wrote the following piece of code.It worked well on my machine, but when it was submitted,it is evaluated as a wrong answer.
T = int(input().strip())
arr = []
result = []
for i in range(T):
s = input().strip()
arr.append(s)
for item in arr:
odd = [];even = []
for value in item:
n = item.index(value)
if n%2 ==0:
even.append(value)
if n%2 == 1:
odd.append(value)
p = ''.join(even) ; q = ''.join(odd)
result.append(p + " " + q)
odd.clear();even.clear();
for value in result:
print(value)
Try this test case:
2
aaB
Baa
Your code is giving wrong results. Inner for loop is looping the characters. What if two characters are same? Your code will give wrong index number.

How to print a complex number without percent sign in Scilab?

I tried this
a = 1+3*%i;
disp("a = "+string(a))
I got a = 1+%i*3 , but what I want is a = 1. + 3.i
So is there any method in Scilab to print a complex number without the percent sign?
Similarly to Matlab, you can format the output string by including the real and imaginary parts separately.
mprintf('%g + %gi\n', real(a) , imag(a))
However, that looks pretty ugly when the imaginary part is negative. I suggest writing a formatting function:
function s = complexstring(a)
if imag(a)>=0 then
s = sprintf('%g+%gi', real(a) , imag(a))
else
s = sprintf('%g%gi', real(a) , imag(a))
end
endfunction
Examples:
disp('a = '+complexstring(1+3*%i))
disp('b = '+complexstring(1-3*%i))
Output:
a = 1+3i
b = 1-3i

How would you index a table that is being initialized?

An example of what I desire:
local X = {["Alpha"] = 5, ["Beta"] = this.Alpha+3}
print(X.Beta) --> error: [string "stdin"]:1: attempt to index global 'this' (a nil value)
is there a way to get this working, or a substitute I can use without too much code bloat(I want it to look presentable, so fenv hacks are out of the picture)
if anyone wants to take a crack at lua, repl.it is a good testing webpage for quick scripts
No there is no way to do this because the table does not yet exist and there is no notion of "self" in Lua (except via syntactic sugar for table methods). You have to do it in two steps:
local X = {["Alpha"] = 5}
X["Beta"] = X.Alpha+3
Note that you only need the square brackets if your key is not a string or if it is a string with characters other than any of [a-z][A-Z][0-9]_.
local X = {Alpha = 5}
X.Beta = X.Alpha+3
Update:
Based on what I saw on your pastebin, you probably should do this slightly differently:
local Alpha = 5
local X = {
Alpha = Alpha,
Beta = Alpha+3,
Gamma = someFunction(Alpha),
Eta = Alpha:method()
}
(obviously Alpha has no method because in the example it is a number but you get the idea, just wanted to show if Alpha were an object).

Resources