2017-03-12 11 views
2

py2neoバージョン3を使用してきれいなneo4jグラフデータベースにデータをインポートしようとしています。以下のようないくつかのノードタイプを定義しました。私はノードが私のneo4jブラウザに現れているのを見ていませんでした。py2neo v3 AttributeError:オブジェクトには 'db_exists'属性がありません

関連するインポートコードは次のとおりです。レコードがPython変数に正しくロードされていることを確認しました。

for row in data:  
    ds = DataSource() 
    # parse Source of Information column as a list, trimming whitespace 
    ds.uri = list(map(str.strip, row['data_source'].split(','))) 
    ds.description = row['data_source_description'] 
    graph.merge(ds) 

しかし、私はgraph.exists(ds)を行うにしようとしたとき、私はエラー/トレースバックの次のセット戻った:私の驚いたことに

Traceback (most recent call last): 
    File "mydir/venv/lib/python3.5/site-packages/py2neo/database/__init__.py", line 1139, in exists 
    return subgraph.__db_exists__(self) 
AttributeError: 'DataSource' object has no attribute '__db_exists__' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File  "mydir/venv/lib/python3.5/site-packages/py2neo/database/__init__.py", line 478, in exists 
    return self.begin(autocommit=True).exists(subgraph) 
    File "mydir/venv/lib/python3.5/site-packages/py2neo/database/__init__.py", line 1141, in exists 
    raise TypeError("No method defined to determine the existence of object %r" % subgraph) 
TypeError: No method defined to determine the existence of object <DataSource uri=['my_uri']> 

を、私はこの問題を議論する別のフォーラムの記事を見つけることができません。 GraphObjectから継承する問題があると推測していますが、there doesn't seem to be an explicit definition of a __db_exists__ property for GraphObjectのいずれかです。実際に、私がこのプロパティを見つけることができる唯一の場所は、このエラーを生成するときにdefinition of the exists functionです。

私はここで間違っているのを誰も見ることができますか?次のように

ノードクラスの定義は以下のとおりです。

class Content(GraphObject):    # group Person and Institution 
    pass 

class Person(Content): 
    __primarykey__ = 'name' 

    name = Property() 
    in_scholar_names = Property() 
# 
    mentored = RelatedTo('Person') 
    mentored_by = RelatedFrom('Person', 'MENTORED') 
    worked_alongside = Related('Person', 'WORKED_ALONGSIDE') 
    studied_at = RelatedTo('Institution') 
    worked_at = RelatedTo('Institution') 
    tagged = RelatedTo('Tag') 
    member_of = RelatedTo('Institution') 

    last_update = RelatedTo('UpdateLog') 

    def __lt__(self, other): 
     return self.name.split()[-1] < other.name.split()[-1] 

class Institution(Content): 
    __primarykey__ = 'name' 
# 
    name = Property() 
    location = Property() 
    type = Property() 
    carnegie_class = Property() 
# 
    students = RelatedFrom('Person', 'STUDIED_AT') 
    employees = RelatedFrom('Person', 'WORKED_AT') 
    members = RelatedFrom('Person', 'MEMBER_OF') 

    last_update = RelatedTo('UpdateLog') 

    def __lt__(self, other): 
     return self.name < other.name 


class User(GraphObject): 
    __primarykey__ = 'username' 

    username = Property() 
    joined = Property() 
    last_access = Property() 
    active = Property() 

    contributed = RelatedTo('UpdateLog') 


class Provenance(GraphObject):   # group UpdateLog and DataSource 
    pass  
# 
class UpdateLog(Provenance): 
    __primarykey__ = 'id' 

    id = Property() 
    timestamp = Property() 
    query = Property() 

    previous = RelatedTo('UpdateLog', 'LAST_UPDATE') 
    next = RelatedFrom('UpdateLog', 'LAST_UPDATE') 
    based_on = RelatedTo('Provenance', 'BASED_ON') 

    affected_nodes = RelatedFrom('Content', 'LAST_UPDATE') 
    contributed_by = RelatedFrom('User', 'CONTRIBUTED') 

class DataSource(Provenance): 
    __primarykey__ = 'uri' 

    id = Property() 
    description = Property() 
    uri = Property() 

    source_for = RelatedFrom('UpdateLog', 'BASED_ON') 


class Tag(GraphObject): 
    __primarykey__ = 'name' 

    name = Property() 
    description = Property() 

    see_also = Related('Tag') 
    tagged = RelatedFrom('Content') 

答えて

0

さて、私はそれを考え出したと思います。私はFlaskのコンテキストでpy2neoを学んでいました。そこでは、すべてのクラス定義が、特定のノード上の関係のビュー(Webページ)を生成するために重要で有用なものです。

私は現在、実際にノードとリレーションシップを最初に作成するためのデータインポートスクリプトのために、 'Node'と 'Relationship'のバニラクラスを使用する必要があります。関数のパラメータとして使用します。元のコードのこの更新されたバージョンは、上記のエラー、およびgraph.exists(ds)戻り、その後true全く発生しない:

for row in data:  
    ds = Node("DataSource") 
    # parse Source of Information column as a list, trimming whitespace 
    ds['uri'] = list(map(str.strip, row['data_source'].split(','))) 
    ds['description'] = row['data_source_description'] 
    graph.merge(ds) 

ノートの他の二つの発見:

  1. Iので、私のクラスの継承は、そもそも的外れでしたNodeから、ではないGraphObjectGraphObjectがフラスコのコンテキストに戻って継承するための正しいクラスだったにもかかわらず)
  2. Nodeクラスの継承しようとしているはずです、私はトンを持っていますo大括弧とキー名を引用符で囲んだ文字列として、プロパティのdict-style割り当てを使用する。ここでドット表記法は基本的なものではありませんでした。私は、より多くのエラーをスローすることはできませんでした。
関連する問題