tom
tom

Reputation: 307

ClientError: Cannot merge the following node because of null property value

I am trying to extract relationships from a set of scientific journals. I am definitely a CYPHER noob. My code is based upon this article: https://towardsdatascience.com/extract-knowledge-from-text-end-to-end-information-extraction-pipeline-with-spacy-and-neo4j-502b2b1e0754. Unfortunately, I found extracting the titles inconsistent at best so I use a look up table for the title and authors. The following code works to put just the relationship information into a NEO4J database:

    import_query = """
UNWIND $data AS row
MERGE (h:Entity {id: CASE WHEN NOT row.head_span.id = 'id-less' THEN 
row.head_span.id ELSE row.head_span.text END})
ON CREATE SET h.text = row.head_span.text
MERGE (t:Entity {id: CASE WHEN NOT row.tail_span.id = 'id-less' THEN 
row.tail_span.id ELSE row.tail_span.text END})
ON CREATE SET t.text = row.tail_span.text
WITH row, h, t
CALL apoc.merge.relationship(h, toUpper(replace(row.relation,' ', '_')),
  {},
  {},
  t,
  {}
)
YIELD rel
RETURN distinct 'done' AS result;
"""

However, when I adapted it to include the title and author information as can be seen below,

query("""
MERGE (a:Author{name:$author})
MERGE (b:Article{title:$title})
MERGE (a)-[:WROTE]->(b)
""", {'title':title, 'author':author})

query =("""
MATCH (a:Article)
UNWIND $data AS row
MERGE (h:Entity {id: CASE WHEN NOT row.head_span.id = 'id-less' THEN 
row.head_span.id ELSE row.head_span.text END})
ON CREATE SET h.text = row.head_span.text
MERGE (t:Entity {id: CASE WHEN NOT row.tail_span.id = 'id-less' THEN 
row.tail_span.id ELSE row.tail_span.text END})
ON CREATE SET t.text = row.tail_span.text
WITH a,row, h, t
CALL apoc.merge.relationship(h, toUpper(replace(row.relation,' ', '_')),
  {},
  {},
  t,
  {}
)
YIELD rel
RETURN distinct 'done' AS result;
""")

I get the error:

ClientError: Cannot merge the following node because of null property value for 'name': (:Author {name: null})

Any ideas on what I am doing wrong? Thank you!!

Upvotes: 0

Views: 98

Answers (1)

Graphileon
Graphileon

Reputation: 5385

One way to work around this is to add a dummy value

MERGE (a:Author {name: COALESCE($author,'dummyValue')})

and do some housekeeping at the end

MATCH (a:Author  {name:'dummyValue'})
DETACH DELETE a

Upvotes: 1

Related Questions