2017-04-25 3 views
0

私はNeo4jにADグループの文字列でCSVを解析しようとしています。私は、pythonドライバを使用して、簡単な例に従っています。neo4h pythonドライバでのCypher構文エラー

import csv 
from neo4j.v1 import GraphDatabase 

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "neo")) 

def print_friends(tx, name): 
    for record in tx.run("MATCH (a:User) WHERE a.name = $name " 
         "RETURN a.name ORDER BY a.name", name=name): 
     print(record["a.name"]) 

def create_group(tx, name): 
    print "create group: " + name 
    tx.run("MERGE (g:Group {name: $name}) ", {"name": name}) 

def set_group_label(tx, name, label): 
    label = ":" + label 
    print "set label: " + name +" "+ label 
    tx.run("MATCH (g:Group) " 
      "WHERE g.name = $name " 
      "SET g $label", name=name, label=label) 

with open('../transfer/ALLADUsersGroups_201704180501.csv', 'rb') as file: 
    reader = csv.reader(x.replace('\0', '') for x in file) 
    for i, row in enumerate(reader): 
     if i==102435: 
      with driver.session() as session: 
       session.write_transaction(create_group, row[1].split("=")[1]) 
       session.write_transaction(set_group_label, row[1].split("=")[1], row[1].split("=")[0]) 

私はグループのタイプに基づいて新しいラベルを設定しようとしています。 {CN、OU、DCなど}。 私は次のエラーを取得していますが:

neo4j.exceptions.CypherSyntaxError: Unexpected end of input: expected an identifier character, whitespace or a relationship pattern (line 1, column 50 (offset: 49)) 
"MATCH (g:Group) WHERE g.name = $name SET g $label" 
               ^

私が何か間違ったことをやっているが、これはドライバーがおかしいのですか?

私はここからのインストール手順に従ってきたと言う必要があります。Neo4j Driver for Python

答えて

0

ラベルを設定するための構文はそうのような:使用しています:SET g:Thing。しかし、私はCypherがこのような動的ラベルを設定できるとは信じていません。

この特殊なケースでは文字列連結を使用し、クエリの適切な場所にラベル文字列を追加するか、APOC Proceduresを使用して文字列からラベルを動的に追加する必要があります。