我在查詢中使用了一系列嵌套的FOREACH循環,該功能在我們用於測試的匹配數據集的許多Neo4j安裝上正常運行。隨着Cypher 2.0.1的最近更改,我的查詢不起作用。如何將我的Neo4j查詢的語法從Cypher 2.0.1恢復到Cypher 2.0.0?
我最初的直覺是取代/var/lib/neo4j/lib/neo4j-cypher-2.0.0.jar
文件,但我不想搞砸了。有什麼想法嗎?
樣品圖:http://console.neo4j.org/?id=ktrcwx
這裏的查詢(我強調 「**」 表示發生錯誤的位置):
$ MATCH (total:Recipe)
> WITH count(DISTINCT total) AS tots, timestamp() AS time
> MATCH (ia:Ingredient)<-[:HAS_INGREDIENT]-(recab:Recipe)-[recHasB:HAS_INGREDIENT]->(ib:Ingredient)
> WHERE id(ia)=5167
> WITH DISTINCT ib AS idB, count(DISTINCT recab) AS recAB , count(DISTINCT recHasB) AS recB, tots, time
> MATCH (i:Ingredient)<-[:HAS_INGREDIENT]-(r:Recipe)
> WHERE id(i)=5167
> WITH [i, count(DISTINCT r.id), idB, recAB, recB, tots, time] AS c
> FOREACH (row IN c |
> FOREACH (i1 in **c[0] |**
> FOREACH (recA in c[1] |
> FOREACH (i2 in c[2]|
> FOREACH (recAB in c[3] |
> FOREACH (recB in c[4] |
> FOREACH (totalRec in c[5] |
> CREATE (i1:Ingredient)-[pm1:PMI]->(i2: Ingredient)
> SET startNode(pm1).pmiTime = c[6], endNode(pm1).pmiTime = c[6], pm1.weight = log((totalRec*recAB) /(recA*recB)), pm1.pmiTime= c[6]
> CREATE (i1:Ingredient)<-[pm2:PMI]-(i2: Ingredient)
> SET startNode(pm2).pmiTime = c[6], endNode(pm2).pmiTime = c[6], pm2.weight = log((totalRec*recAB) /(recA*recB)), pm2.pmiTime= c[6]
> )
> )
> )
> )
> )
> )
> );
這裏的錯誤:
SyntaxException: Type mismatch: expected Collection<T> but was Any (line 10, column 25)" FOREACH (i1 in c[0] |"
這裏的功能類路徑:
Neo4j Server is running at pid 4347
NEO4J_HOME: /var/lib/neo4j
NEO4J_SERVER_PORT: 7474
NEO4J_INSTANCE: /var/lib/neo4j
JAVA_HOME:
JAVA_OPTS: -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
CLASSPATH: /var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:/var/lib/neo4j/lib/geronimo-jta_1.1_spec-1.1.1.jar:/var/lib/neo4j/lib/lucene-core-3.6.2.jar:/var/lib/neo4j/lib/neo4j-cypher-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-commons-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-1.9-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-2.0-2.0.0.jar:/var/lib/neo4j/lib/neo4j-graph-algo-2.0.0.jar:/var/lib/neo4j/lib/neo4j-graph-matching-2.0.0.jar:/var/lib/neo4j/lib/neo4j-jmx-2.0.0.jar:/var/lib/neo4j/lib/neo4j-kernel-2.0.0.jar:/var/lib/neo4j/lib/neo4j-lucene-index-2.0.0.jar:/var/lib/neo4j/lib/neo4j-shell-2.0.0.jar:/var/lib/neo4j/lib/neo4j-udc-2.0.0.jar:/var/lib/neo4j/lib/org.apache.servicemix.bundles.jline-0.9.94_1.jar:/var/lib/neo4j/lib/parboiled-core-1.1.6.jar:/var/lib/neo4j/lib/parboiled-scala_2.10-1.1.6.jar:/var/lib/neo4j/lib/scala-library-2.10.3.jar:/var/lib/neo4j/lib/server-api-2.0.0.jar:/var/lib/neo4j/system/lib/asm-3.1.jar:/var/lib/neo4j/system/lib/bcprov-jdk16-140.jar:/var/lib/neo4j/system/lib/commons-beanutils-1.8.0.jar:/var/lib/neo4j/system/lib/commons-beanutils-core-1.8.0.jar:/var/lib/neo4j/system/lib/commons-collections-3.2.1.jar:/var/lib/neo4j/system/lib/commons-compiler-2.6.1.jar:/var/lib/neo4j/system/lib/commons-configuration-1.6.jar:/var/lib/neo4j/system/lib/commons-digester-1.8.1.jar:/var/lib/neo4j/system/lib/commons-io-1.4.jar:/var/lib/neo4j/system/lib/commons-lang-2.4.jar:/var/lib/neo4j/system/lib/commons-logging-1.1.1.jar:/var/lib/neo4j/system/lib/jackson-core-asl-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-jaxrs-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-mapper-asl-1.9.7.jar:/var/lib/neo4j/system/lib/janino-2.6.1.jar:/var/lib/neo4j/system/lib/javax.servlet-3.0.0.v201112011016.jar:/var/lib/neo4j/system/lib/jcl-over-slf4j-1.6.1.jar:/var/lib/neo4j/system/lib/jersey-core-1.9.jar:/var/lib/neo4j/system/lib/jersey-multipart-1.9.jar:/var/lib/neo4j/system/lib/jersey-server-1.9.jar:/var/lib/neo4j/system/lib/jetty-http-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-io-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-security-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-server-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-servlet-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-util-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-webapp-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-xml-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jsr311-api-1.1.2.r612.jar:/var/lib/neo4j/system/lib/logback-access-1.0.9.jar:/var/lib/neo4j/system/lib/logback-classic-1.0.9.jar:/var/lib/neo4j/system/lib/logback-core-1.0.9.jar:/var/lib/neo4j/system/lib/mimepull-1.6.jar:/var/lib/neo4j/system/lib/neo4j-browser-2.0.0.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.0.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.0-static-web.jar:/var/lib/neo4j/system/lib/rhino-1.7R3.jar:/var/lib/neo4j/system/lib/rrd4j-2.0.7.jar:/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:/var/lib/neo4j/conf/
這裏的失靈類路徑:
Neo4j Server is running at pid 1361
NEO4J_HOME: /var/lib/neo4j
NEO4J_SERVER_PORT: 7474
NEO4J_INSTANCE: /var/lib/neo4j
JAVA_HOME:
JAVA_OPTS: -server -XX:+DisableExplicitGC - Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
CLASSPATH: /var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:/var/lib/neo4j/lib/geronimo-jta_1.1_spec-1.1.1.jar:/var/lib/neo4j/lib/lucene-core-3.6.2.jar:/var/lib/neo4j/lib/neo4j-cypher-2.0.1.jar:/var/lib/neo4j/lib/neo4j-cypher-commons-2.0.1.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-1.9-2.0.1.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-2.0-2.0.1.jar:/var/lib/neo4j/lib/neo4j-graph-algo-2.0.1.jar:/var/lib/neo4j/lib/neo4j-graph-matching-2.0.1.jar:/var/lib/neo4j/lib/neo4j-jmx-2.0.1.jar:/var/lib/neo4j/lib/neo4j-kernel-2.0.1.jar:/var/lib/neo4j/lib/neo4j-lucene-index-2.0.1.jar:/var/lib/neo4j/lib/neo4j-shell-2.0.1.jar:/var/lib/neo4j/lib/neo4j-udc-2.0.1.jar:/var/lib/neo4j/lib/org.apache.servicemix.bundles.jline-0.9.94_1.jar:/var/lib/neo4j/lib/parboiled-core-1.1.6.jar:/var/lib/neo4j/lib/parboiled-scala_2.10-1.1.6.jar:/var/lib/neo4j/lib/scala-library-2.10.3.jar:/var/lib/neo4j/lib/server-api-2.0.1.jar:/var/lib/neo4j/system/lib/asm-3.1.jar:/var/lib/neo4j/system/lib/bcprov-jdk16-140.jar:/var/lib/neo4j/system/lib/commons-beanutils-1.8.0.jar:/var/lib/neo4j/system/lib/commons-beanutils-core-1.8.0.jar:/var/lib/neo4j/system/lib/commons-collections-3.2.1.jar:/var/lib/neo4j/system/lib/commons-compiler-2.6.1.jar:/var/lib/neo4j/system/lib/commons-configuration-1.6.jar:/var/lib/neo4j/system/lib/commons-digester-1.8.1.jar:/var/lib/neo4j/system/lib/commons-io-1.4.jar:/var/lib/neo4j/system/lib/commons-lang-2.4.jar:/var/lib/neo4j/system/lib/commons-logging-1.1.1.jar:/var/lib/neo4j/system/lib/jackson-core-asl-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-jaxrs-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-mapper-asl-1.9.7.jar:/var/lib/neo4j/system/lib/janino-2.6.1.jar:/var/lib/neo4j/system/lib/javax.servlet-3.0.0.v201112011016.jar:/var/lib/neo4j/system/lib/jcl-over-slf4j-1.6.1.jar:/var/lib/neo4j/system/lib/jersey-core-1.9.jar:/var/lib/neo4j/system/lib/jersey-multipart-1.9.jar:/var/lib/neo4j/system/lib/jersey-server-1.9.jar:/var/lib/neo4j/system/lib/jetty-http-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-io-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-security-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-server-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-servlet-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-util-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-webapp-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-xml-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jsr311-api-1.1.2.r612.jar:/var/lib/neo4j/system/lib/logback-access-1.0.9.jar:/var/lib/neo4j/system/lib/logback-classic-1.0.9.jar:/var/lib/neo4j/system/lib/logback-core-1.0.9.jar:/var/lib/neo4j/system/lib/mimepull-1.6.jar:/var/lib/neo4j/system/lib/neo4j-browser-2.0.1.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.1.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.1-static-web.jar:/var/lib/neo4j/system/lib/rhino-1.7R3.jar:/var/lib/neo4j/system/lib/rrd4j-2.0.7.jar:/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:/var/lib/neo4j/conf/
的預期結果注: 對於集合中的每一行,查詢應該創建2個關係:(i1)-[:PMI]->(i2)
和(i2)-[:PMI]->(i1)
。 [:PMI]
關係的權重是Log()
函數中的數學運算。該圖是(:Ingredient)
和(:Recipe)
節點。此查詢將創建(i1:Ingredient)
和(i2:Ingredient)
之間的關係,該關係發生在包含(i1)
的配方中。這使我瞭解配料配對的可能性。
解釋查詢應該做什麼可能會有幫助。我想你會發現有更簡潔的方式來表達你想要的東西,這對2.0.1來說可以很好地工作。 –
對於集合中的每一行,查詢都應創建一個關係:A-> B和A <-B。這些關係的權重是Log()函數中的數學。 圖表爲:配料和配方節點。此查詢將創建A:配料與每個配方中包含的每個B:配料之間的關係,這使得我可以瞭解配料配對的概率。 我敢肯定,有更簡潔的方法來使這項工作,我很感激在該領域的輸入,但我的問題是爲什麼這個查詢正確創建關係在2.0.0而不是2.0.1。 – lazaruslarue
這在2.0.1中不起作用的原因是它依賴於2.0.0版本中存在的錯誤,並且此後已被修復。在上面的例子中,'c'集合是所有不同類型事物的混合體,因此Cypher的整體類型爲「Collection」 - 這意味着裏面的每個東西只是一個'Any'(最不實用的類型)。 2.0.0中的錯誤是,任何類型爲「Any」的東西實際上在任何地方都被接受(即Any的類型檢查失敗)。 –