Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何计算数组中的字符串频率(cypher,neo4j)_Neo4j_Cypher - Fatal编程技术网

如何计算数组中的字符串频率(cypher,neo4j)

如何计算数组中的字符串频率(cypher,neo4j),neo4j,cypher,Neo4j,Cypher,我有一个字符串数组,我想计算在数组中找到一个字符串的次数 例如: ["Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the P

我有一个字符串数组,我想计算在数组中找到一个字符串的次数

例如:

["Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Gone with the Wind", "Gone with the Wind", "Gone with the Wind", "Gone with the Wind",""Shopaholic to the Stars (Shopaholic, #7)"", "The Farm", "The Farm", "Men Explain Things to Me", "The Valley of Fear", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", "Mastering the Art of French Cooking", "Play With Me", "Play With Me", "Play With Me", "The Perfect Play", "The Perfect Play", "The Perfect Play", "Dream a Little Dream", "Natural Born Charmer", "Collected Poems", "The Friend Zone"]
我想返回书的名称以及在数组中出现的次数

例如:

  • 《哈利波特与凤凰社》第5集
  • 魔戒团契-1

等等。

您可以使用展开,然后使用计数进行聚合:

UNWIND ["Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Gone with the Wind", "Gone with the Wind", "Gone with the Wind", "Gone with the Wind","Shopaholic to the Stars (Shopaholic, #7)", "The Farm", "The Farm", "Men Explain Things to Me", "The Valley of Fear", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", "Mastering the Art of French Cooking", "Play With Me", "Play With Me", "Play With Me", "The Perfect Play", "The Perfect Play", "The Perfect Play", "Dream a Little Dream", "Natural Born Charmer", "Collected Poems", "The Friend Zone"]  as book

RETURN book, count(*) as book_cnt

您可以使用“展开”,然后使用“计数”进行聚合:

UNWIND ["Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Harry Potter and the Order of the Phoenix", "Gone with the Wind", "Gone with the Wind", "Gone with the Wind", "Gone with the Wind","Shopaholic to the Stars (Shopaholic, #7)", "The Farm", "The Farm", "Men Explain Things to Me", "The Valley of Fear", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", " The Fellowship of the Ring", "Mastering the Art of French Cooking", "Play With Me", "Play With Me", "Play With Me", "The Perfect Play", "The Perfect Play", "The Perfect Play", "Dream a Little Dream", "Natural Born Charmer", "Collected Poems", "The Friend Zone"]  as book

RETURN book, count(*) as book_cnt
该库提供了一些在这里很有用的功能,特别是
apoc.coll.executions()

假设您正在传入参数,$bookToFind是您要查找的书籍的字符串,$bookList是书籍的列表(尽管这可能来自您的某个图形),您可以使用:

RETURN apoc.coll.occurrences($bookList, $bookToFind) as occurrences
或者,如果你想获得所有书籍的频率,而不仅仅是某一本,你可以在藏书中使用
apoc.coll.frequencies()
,它会返回一个地图列表,每个地图由一个
项目和列表中该项目的
计数组成。

图书馆提供了一个在这里有用的地图,特别是
apoc.coll.executions()

假设您正在传入参数,$bookToFind是您要查找的书籍的字符串,$bookList是书籍的列表(尽管这可能来自您的某个图形),您可以使用:

RETURN apoc.coll.occurrences($bookList, $bookToFind) as occurrences
或者,如果您想获得所有书籍的频率,而不仅仅是某一本,您可以在集合中使用
apoc.coll.frequencies()
,这将返回一个地图列表,每个地图由列表中该项目的
项和
计数组成