Help on Load CSV and Model -I am new at this

Hi,

Brand new here and did a class a week ago in SF. Though it was really light on data import. I have watched Nicole's video several times and attempting to pull in a small amount of data (~2500 rows). I have attached a smaller file with the data to play along.

Data File has 5 columns
Alta is the id of the patent that belongs to company
Citation is the id of a patent that has a relationship to the Alta patent
Note both "Alta" and "Citation" are the same type of nodes - patents
CiteType defines the direction of the relationship with two values
prior means the "Citation" patent is the source of the relationship and Alta is target
forward means Alta is source and citation is the target
Category determines a property of the relationship (applicant or examiner)
Organization is the company that owns the "citation" patent

What I was thinking of as a model:
Nodes are Patents and include both the "Alta" column and "Citation" column and they are unique.
Organizations are nodes and Unique
There are two relationships:

  1. Assigns the patent to the organization
  2. Cites which describe patent to patent relationships with a direction and property (by who).

The data is a bit more complex for a first try, but this is what I am interested on working on.
What I think I need to do is:
I figured out I have to put the file in a specific directory. A bit confusing relative to the video.
Create constraints on Organizations with Name as property
Create constraint on node that contains Patents which has patent number as ID. How do I do this with the two columns?
How do I handle the direction of a relationship (Cite) based on a column CiteType?
Any and all help will be most appreciated.
Andy
IP Test.txt (891 Bytes)

Hi @andy.hegedus,

Thanks, but better for us will be publish snippet of your code.

Here is what I have thus far:
Created Patents and used the Alta and Citation Columns to populate the nodes. From the count it looks like this worked as expected.
Created company nodes and populated -seemed to work
created relationships between company and citation with an assigned_to relationship.
Created Relationships between patents in "Alta" column to company "Alta Devices".

What I am looking at now is how to set the direction of a relationship based on input column. Do I use a CASE statement and then merge statements in each clause?

CREATE CONSTRAINT ON (p:patent) ASSERT p.PatNum IS UNIQUE

LOAD CSV WITH HEADERS FROM 'file:///ALTABase.csv' AS row
MERGE (p:patent{PatNum:row.Citation})

LOAD CSV WITH HEADERS FROM 'file:///ALTABase.csv' AS row
MERGE (p:patent{PatNum:row.Alta})

LOAD CSV WITH HEADERS FROM 'file:///ALTABase.csv' AS row
MATCH (p:patent{PatNum:row.Citation})
MATCH (o:company{name:row.Organization})
MERGE (p)-[:Assigned_To]->(o)

CREATE CONSTRAINT ON (p:company) ASSERT p.name IS UNIQUE
LOAD CSV WITH HEADERS FROM 'file:///ALTABase.csv' AS row
MERGE (p:company{name:row.Organization})

LOAD CSV WITH HEADERS FROM 'file:///ALTABase.csv' AS row
MATCH (p:patent{PatNum:row.Alta})
MATCH (o:company{name:'Alta Devices'})
MERGE (p)-[:Assigned_To]->(o)

Hi this is what I am trying and get an error
Invalid input 'S': expected 'l/L' (line 4, column 3 (offset: 131))
"CASE row.CiteType WHEN 'Prior' THEN"
(edit)
It looks like CASE only returns values and cannot be used to branch. How would branch on the comparison test?

LOAD CSV WITH HEADERS FROM 'file:///ALTABase.csv' AS row
MATCH (a:patent{PatNum:row.Alta})
MATCH (c:patent{PatNum:row.Citation})
CASE row.CiteType WHEN 'Prior' THEN
MERGE (c)-[r:Reads_On]->(a)
ELSE
MERGE (a)-[r:Reads_On]->(c)
END
SET r.by_who =row.Category

Replace this:

CASE row.CiteType WHEN 'Prior' THEN
MERGE (c)-[r:Reads_On]->(a)
ELSE
MERGE (a)-[r:Reads_On]->(c)
END
SET r.by_who =row.Category

with

FOREACH(ignoreMe IN CASE WHEN row.CiteType = 'Prior'THEN [1] ELSE END |

MERGE (c)-[:Reads_On {by_who: row.Category}]->(a)

)

FOREACH(ignoreMe IN CASE WHEN row.CiteType <> 'Prior'THEN [1] ELSE END |

MERGE (a)-[:Reads_On {by_who: row.Category}]->(c)

)