我有一个movies.csv文件,每行有一个特征向量(例如 - id |名称| 0 | 1 | 1 | 0 | 0 | 0 | 1有2个名称和id的功能,7个类型的功能分类)
我希望类Movies中的节点m与类Genres中的节点g建立关系[:HAS_GENRE]。为此,我需要遍历所有的' |'分隔的特征,只有在值为1时才建立关系。
从本质上讲,我想要 -
x = a //where a is the index of the first genre feature
while (x < lim) //lim is the last index of the feature vector
{
if line[x] is 1:
(m{id:toInt(line[0]})-[:HAS_GENRE]->(g{id=line[x]})
}
我该怎么做?
答案 0 :(得分:0)
试试这个
WITH ["Genre1","Genre2",...] as genres
LOAD CSV FROM "file:movies.pdv" using fieldterminator "|" AS row
MERGE (m:Movie {id:row[0]}) ON CREATE SET m.title = row[1]
FOREACH (idx in filter(range(0,size(genres)-1) WHERE row[2+idx]="1") ) |
MERGE (g:Genre {name:genres[idx]})
CREATE (m)-[:HAS_GENRE]->(g)
)
range(0,size(genres)-1)
,