cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Neo4j Python / Cypher synatax query

CD007
Node Link

Hi

I just can't get the following. I'm using Google co-lab. The commented out line works as expected but after trying various options from threads I still can't get it.  I'm just trying to pass the entity_type variable in after declaring it.

Also once this works I will then want to pass in the following so I assume it would be the same as the value passed to the get_slot method would also be a string entity_type = tracker.get_slot("entity_type")

CD007_0-1666553091531.png

 

Can anyone assist? Thanks.

Chris

5 REPLIES 5

glilienfield
Ninja
Ninja

I don't use the python driver, but from my reading of the documentation, it looks like if you do the following it should work:

result = session.run(query, entity_type = entity_type)

For production, you may want to look at the managed transactions instead of the auto-commit transactions you are using. 

thanks it now gives me the following when i run that

 

<neo4j._sync.work.result.Result object at 0x7f056b850610>

 

In the above, I meant the string that represents the cypher query for the 'query' parameter.

The 'Result' returned is a list of "Records'  You need extract the data from it. 

https://neo4j.com/docs/api/python-driver/current/api.html#result

Thanks - I don't think I'm getting this. I don't use Python regularly. Can you possibly type out what the query should be? The first commented out line gives me what I want so I'm not clear on what I'm meant to type - 

CD007_0-1666628433277.png

 

I'm a Java developer, but I tried to provide some guidance.

If you are expecting a single result, you can try this:

 

result.single()[0]

 

You will need to iterate through the records of a result, if the result has more than one record. Something like this.

    definitions = []
        result = session.run(queryString, entity_type = entity_type)
        for record in result:
            definitions.append(record["x"])