When I convert part of a query into a subquery that I want to call multiple times, the previously successful results now come up empty. What am I overlooking that causes the query to fail after that conversion?
When this code runs:
// /\* find sentences \*/
match (s1:Sentence) where s1.sentence \= $sentenceText
// /\* Find sentences' words \*/
match (s1)-\[r1:HAS\_WORD\]-(w1:Word) where w1.word \=~ '.\*\[a-z\].\*' and w1.stopword\=false
with s1,w1,s1 as s,w1 as w order by w1.count
// /\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*/
// /\* Down-select to the most important (least common) words \*/
// /\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*/
with s,w
with s,reduce( words \= \[\], n in collect(w) | words + \[n\]) as words, sum(w.count) as total
with s,words,total,reduce( f \=\[0,{}\], n in words |
case when 1.0\* f\[0\]/total < 0.10 then
case when f\[0\]=0 then \[f\[0\] + n.count,\[n\]\]
else \[f\[0\] + n.count,f\[1\]+\[n\]\]
end
else f
end) as frac
with s,words,total,reverse(tail(reverse(frac\[1\]))) as important
// /\* Make list of words assigned probability score of 100% \*/
unwind important as w
with distinct \[w,1.0\] as importantScore,s,words,total,important
return distinct s,collect(importantScore) as list,words,total,important
I correctly get
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ββββββββ€βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β"s" β"list" β"words" β"total"β"important" β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββͺβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββͺβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββͺββββββββͺβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ‘
β{"sentence":"This is a test of the end of the line ... / or not!","levβ[[{"count":1,"stopword":false,"word":"this"},1.0],[{"count":2,"stopworβ[{"count":1,"stopword":false,"word":"this"},{"count":2,"stopword":falsβ538 β[{"count":1,"stopword":false,"word":"this"},{"count":2,"stopword":falsβ
βel":"L0","count":10,"topic":"NONE","source":"console","idInSrc":""} βd":false,"word":"of"},1.0],[{"count":2,"stopword":false,"word":"or"},1βe,"word":"of"},{"count":2,"stopword":false,"word":"or"},{"count":2,"stβ βe,"word":"of"},{"count":2,"stopword":false,"word":"or"},{"count":2,"stβ
β β.0],[{"count":2,"stopword":false,"word":"the"},1.0],[{"count":2,"stopwβopword":false,"word":"the"},{"count":2,"stopword":false,"word":"not"},β βopword":false,"word":"the"},{"count":2,"stopword":false,"word":"not"},β
β βord":false,"word":"not"},1.0],[{"count":2,"stopword":false,"word":"is"β{"count":2,"stopword":false,"word":"is"},{"count":2,"stopword":false,"β β{"count":2,"stopword":false,"word":"is"},{"count":2,"stopword":false,"β
β β},1.0],[{"count":2,"stopword":false,"word":"a"},1.0],[{"count":36,"stoβword":"a"},{"count":36,"stopword":false,"word":"line"},{"count":56,"stβ βword":"a"},{"count":36,"stopword":false,"word":"line"}] β
β βpword":false,"word":"line"},1.0]] βopword":false,"word":"end"},{"count":433,"stopword":false,"word":"testβ β β
β β β"}] β β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
But when implemented as a subquery that I want to reuse:
// /* find sentences */
match (s1:Sentence) where s1.sentence = $sentenceText
// /* Find sentences' words */
match (s1)-[r1:HAS_WORD]-(w1:Word) where w1.word =~ '.*[a-z].*' and w1.stopword=false
with s1,w1,s1 as s,w1 as w order by w1.count
// /* **************************************************************** */
// /* Down-select to the most important (least common) words */
// /* **************************************************************** */
CALL {
with s,w
with s,reduce( words = , n in collect(w) | words + [n]) as words, sum(w.count) as total
with s,words,total,reduce( f =[0,{}], n in words |
case when 1.0* f[0]/total < 0.10 then
case when f[0]=0 then [f[0] + n.count,[n]]
else [f[0] + n.count,f[1]+[n]]
end
else f
end) as frac
with s,words,total,reverse(tail(reverse(frac[1]))) as important
// /* Make list of words assigned probability score of 100% */
unwind important as w
with distinct [w,1.0] as importantScore,s,words,total,important
return distinct collect(importantScore) as list,words,total,important
}
// /* **************************************************************** */
with s1,important as words1,list as list1,total as total1
return s1,words1,list1,total1
I get:
(no changes, no records)