1
votes

Datamodel is:

> (A:word {word:'word'})-[:NEXT sentence:<s-order> word:<w-order>]->(B:word)
> (S:Sentence)-[:START]->(A:word)

There's an index on :Word(word)

I've added a bunch of words using the CREATE query. So I know that all words I use in a sentence exist as a node of :word in the Graph. When trying to run a Cypher query to create a sentence in the Neo4j Console, Neo4j returns an error:

Found no solution for block with size 7, Stream() were the selected candidates from the table IDPPlanTable(numberOfPlans=95, largestSolved=6)

Edit I've fiddled around a bit with the query to make it more comprehensible (thanks for the tip!). Some of them are still not working:

MATCH (word8:word {word:'de'}),(word24:word {word:'platen'}),
  (word25:word {word:'halen'}),(word26:word {word:'alles'}),
  (word27:word {word:'wel'}),(word28:word {word:'weer'}),
  (word29:word {word:'voor'}),(word18:word {word:'je'}),
  (word30:word {word:'naar'}),(word31:word {word:'boven'}),
  (word32:word {word:'als'}),(word33:word {word:'ze'}),
  (word3353:word {word:'afspeelt'}) 
WITH (word8),(word24),(word25),(word26),(word27),(word28),
     (word29),(word18),(word30),(word31),(word32),(word33),(word3353) 
MERGE (ThisSentence:Sentence {order:3})-[:START]->
(word8)-[nw26:NEXT {sentence:3, word:0}]->
(word24)-[nw27:NEXT {sentence:3, word:1}]->
(word25)-[nw28:NEXT {sentence:3, word:2}]->
(word26)-[nw29:NEXT {sentence:3, word:3}]->
(word27)-[nw30:NEXT {sentence:3, word:4}]->
(word28)-[nw31:NEXT {sentence:3, word:5}]->
(word29)-[nw32:NEXT {sentence:3, word:6}]->
(word18)-[nw33:NEXT {sentence:3, word:7}]->
(word30)-[nw34:NEXT {sentence:3, word:8}]->
(word31)-[nw35:NEXT {sentence:3, word:9}]->
(word32)-[nw36:NEXT {sentence:3, word:10}]->
(word18)-[nw37:NEXT {sentence:3, word:11}]->
(word33)-[nw38:NEXT {sentence:3, word:12}]->(word3353) 
WITH ThisSentence MATCH (PrevSentence) WHERE PrevSentence.order=2 
MERGE (PrevSentence)-[:NEXT]->(ThisSentence) WITH ThisSentence RETURN ThisSentence

Question: Why is this query failing?

Possible answers I've thought of:

It might something to do with a circular create of relations around word18. As you can see it is used twice in the query, creating two incoming and two outgoing, all being different from eachother:

  • 29->18->30
  • 32->18->33

How can I prevent this?

Neo4j version is 3.0.6 CE.

1
Did you try moving the conditions for words from the WHERE clause to the MATCH clause? For example MATCH (word0:word {word: 'albums'}), .... Performance-wise it should not make a difference (but this one is worth checking with PROFILE). Also, I think it improves readability.Gabor Szarnyas
Thanks Gábor! I've completely removed the where clause. This is much more neat. I'm still having trouble running some of the queries though.Stefan
In the second match WITH ThisSentence MATCH (PrevSentence) WHERE PrevSentence.order=2, you do not bind PrevSentence to any specific type (e.g. :Sentence), only filter for an order. This is probably slow to evaluate on a large graph. Another minor suggestion: the WITH clause after the first MATCH is unnecessary. I created an example graph with only the nodes required by your query and it worked fine on an empty database. Can you experiment on an empty database? Maybe on GrapheneDB?Gabor Szarnyas
Thanks @GáborSzárnyas for leading me to the answer :-)Stefan

1 Answers

1
votes

Yes! Answer found... The dataset was reduced to 40 nodes. Which still let the query break. (there were 31 nodes with relations in the dataset and 9 without)
After quite some trail queries, the following working query was found:

MATCH (word8:word {word:'de'}),
(word24:word {word:'platen'}),
(word25:word {word:'halen'}),
(word26:word {word:'alles'}),
(word27:word {word:'wel'}),
(word28:word {word:'weer'}),
(word29:word {word:'voor'}),
(word18:word {word:'je'}),
(word30:word {word:'naar'}),
(word31:word {word:'boven'}),
(word32:word {word:'als'}),
(word33:word {word:'ze'}),
(word3353:word {word:'afspeelt'}), 
(PrevSentence:Sentence {order:2}) 
MERGE (PrevSentence)-[:NEXT]->
  (ThisSentence:Sentence {order:3})-[:START]->(word8)
MERGE (word8)-[nw26:NEXT {sentence:3, word:0}]->(word24)
MERGE (word24)-[nw27:NEXT {sentence:3, word:1}]->(word25)
MERGE (word25)-[nw28:NEXT {sentence:3, word:2}]->(word26)
MERGE (word26)-[nw29:NEXT {sentence:3, word:3}]->(word27)
MERGE (word27)-[nw30:NEXT {sentence:3, word:4}]->(word28)
MERGE (word28)-[nw31:NEXT {sentence:3, word:5}]->(word29)
MERGE (word29)-[nw32:NEXT {sentence:3, word:6}]->(word18)
MERGE (word18)-[nw33:NEXT {sentence:3, word:7}]->(word30)
MERGE (word30)-[nw34:NEXT {sentence:3, word:8}]->(word31)
MERGE (word31)-[nw35:NEXT {sentence:3, word:9}]->(word32)
MERGE (word32)-[nw36:NEXT {sentence:3, word:10}]->(word18)
MERGE (word18)-[nw37:NEXT {sentence:3, word:11}]->(word33)
MERGE (word33)-[nw38:NEXT {sentence:3, word:12}]->(word3353) 

As you can see, it involves breaking the entire chain of relations down to the atomic level. In this case, Neo4j has no problem whatsoever processing the parts.

While an answer was found, I'm still curious why Neo4j could not process the query. Too long a chain of nodes? Too much 'collateral' data in query processing?