Importing nodes with multiple unites constraints

Hi here is what my data looks like for each patent there is a 1 or more classifications assigned
image
Some there is 1 to many relationship
The classification scheme is hierarchical with section, subsection, group and sub group. You will see that the subgroup entry is basically the concatenation of the higher ones. I would like to keep each level of classification available for easy search so I created uniqueness constraints. I then tried to load only the the classification data to create cpc nodes. and this did not work with this error message.

Merge did not find a matching node c and can not create a new node due to conflicts with existing unique nodes

Any help on the correct way to do this? The plan is to import the codes as nodes and then go back and create the relationships.

CREATE CONSTRAINT ON (c:cpc) ASSERT c.section IS UNIQUE
CREATE CONSTRAINT ON (c:cpc) ASSERT c.subsection IS UNIQUE
CREATE CONSTRAINT ON (c:cpc) ASSERT c.group IS UNIQUE
CREATE CONSTRAINT ON (c:cpc) ASSERT c.subgroup IS UNIQUE

LOAD CSV WITH HEADERS FROM 'file:///CPCList.csv' AS row
MERGE (c:cpc{section:row.section_id,subsection:row.subsection_id,group:row.group_id,subgroup:row.subgroup_id})

Hello @andy.hegedus,

Based on what you are trying to accomplish, I submit that you should approach this differently than a single CPC node. I suggest creating separate nodes and labels for Patents, Sections, Subsections, Groups, and Subgroups. Then by building the relationships between these nodes, you have created your classification scheme. Once that has been created, then you can build relationships with that classification scheme to any of the relevant patents. Here is the approach laid out:

// Create the necessary constraints for each node label
CREATE CONSTRAINT ON (p:Patent) ASSERT p.patent_id IS UNIQUE;
CREATE CONSTRAINT ON (s:Section) ASSERT s.section_id IS UNIQUE;
CREATE CONSTRAINT ON (ss:Subsection) ASSERT s.subsection_id IS UNIQUE;
CREATE CONSTRAINT ON (g:Group) ASSERT g.group_id IS UNIQUE;
CREATE CONSTRAINT ON (sg:Subgroup) ASSERT sg.subgroup_id IS UNIQUE;

Load each set of nodes individually

// Patent nodes
LOAD CSV WITH HEADERS FROM 'file:///CPCList.csv' AS row
WHERE row.patent_id IS NOT NULL
MERGE (p:Patent {patent_id: row.patent_id})
;

// Section nodes
LOAD CSV WITH HEADERS FROM 'file:///CPCList.csv' AS row
WHERE row.section_id IS NOT NULL
MERGE (s:Section {section_id: row.section_id})
;

// Subsection  nodes
LOAD CSV WITH HEADERS FROM 'file:///CPCList.csv' AS row
WHERE row.subsection_id IS NOT NULL
MERGE (ss:Subsection {subsection_id: row.subsection_id})
;

// Group nodes
LOAD CSV WITH HEADERS FROM 'file:///CPCList.csv' AS row
WHERE row.group_id IS NOT NULL
MERGE (g:Group {group_id: row.group_id})
;

// Subgroup nodes
LOAD CSV WITH HEADERS FROM 'file:///CPCList.csv' AS row
WHERE row.subgroup_id IS NOT NULL
MERGE (sg:Subgroup {subgroup_id: row.subgroup_id})
;

Now create classification scheme by creating the relationships between the nodes

// Section, Subsection, Group, Subgroup relationships
LOAD CSV WITH HEADERS FROM 'file:///CPCList.csv' AS row
WHERE row.section_id IS NOT NULL
AND row.subsection_id IS NOT NULL
AND row.subgroup_id IS NOT NULL
AND row.group_id IS NOT NULL
MATCH (p:Patent {patent_id: row.patent_id})
MATCH (s:Section {section_id: row.section_id})
MATCH (ss:Subsection {subsection_id: row.subsection_id})
MATCH (g:Group {group_id: row.group_id})
MATCH (sg:Subgroup {subgroup_id: row.subgroup_id})

MERGE (s)-[:CONTAINS]->(ss)
MERGE (ss)-[:CONTAINS]->(g)
MERGE (g)-[:CONTAINS]->(sg)
;

Let me know if this makes sense to you.

Cheers,

yyyguy

Hi,

Thank you very much.
Generally worked however I got errors in the where ... IS NOT NULL lines.
I don't have missing data so I barreled away without those lines.
Andy

I am glad to be able to help.

yyyguy