Use of Neo4j

Statement: I learned from the video of Zhang Shuguang Wuhan University Station B

1. Install the software

Many steps on the Internet can be followed

2. Open the software

Win+R ->cmd enter neo4j.bat console to start the
browser enter http://localhost:7474/browser/

3. Create a simple stock knowledge graph

1. Establish a node for several stocks

Cypher command to create a node:
create(Variable:Lable{Key1:Value1,Key2,Value2}) return Variable
Create a stock node:
create(n:Stock{name:'Ange Yeast',code:'600298' ,launchDate:date("2000-08-18")})return n
create nodes of several stocks at once
create(n:Stock{name:'China Merchants Bank',code:'600036',launchDate:date("2002 -04-09")}),(:Stock{name:'中科创达',code:'300496',launchDate:date("2015-12-10")}),(:Stock{name:' Huagong Technology',code:'000988',launchDate:date("2000-06-08")}),(:Stock{name:'Guosen Securities',code:'002736',launchDate:date("2014-12 -29”)})

2. Establish two nodes of Shanghai Stock Exchange and Shenzhen Stock Exchange

create(n:SecuritiesExchange{name:'Shanghai Stock Exchange'}),(:SecuritiesExchange{name:'Shenzhen Stock Exchange'})return n;

3. Establish nodes for the names of provinces and cities

create(n:Province(name:'Hubei')),(:Province(name:'Beijing')),(:Province(name:'Guangdong'))return n;

4. Establish a relationship between stocks and stock exchanges

Create the relationship between the stock node'Ange Yeast' and the stock exchange node'Shanghai Stock Exchange'
MATCH(a:Stock),(b:SecuritiesExchange)
WHERE a.name='Ange Yeast' AND b.name='Shanghai Stock exchange'
CREATE(a)-[r:Exchange]->(b)RETURN r
can also create relationships between other stock nodes and stock exchange nodes

5. Establish the relationship between stocks and provinces and cities

Create the relationship between stock node and province node
MATCH(a:Stock),(b:Province)
WHERE a.name='Ange Yeast' AND b.name='Hubei'
CREATE(a)-[r:Area]- >(b) RETURN r
can also create relationships between other stock nodes and provincial and municipal nodes

6. Query nodes and relationships

Query the nodes of a certain stock: MATCH(a: Stock) WHERE a.name='Ange Yeast' RETURN a
Query all nodes of a certain label: MATCH(a: Stock) RETURN a
Query between two nodes Relationship: MATCH(:Stock(name:'Ange Yeast'))-(r)->(:Province(name:'Hubei')) RETURN type®
Get the type of relationship through the function type: MATCH(:Stock{ name:'Ange Yeast'})-[r]->()RETURN type®

7. Delete nodes and relationships

Delete stock node: If the node has a relationship, delete the relationship first, and then delete the node.
MATCH(a:Stock)WHERE a.name='Zhongke Chuangda'
DELETE a to
delete a node with a label:
MATCH(n:Stock)DELETE n to
delete all nodes MATCH(n)DELETE n to
delete the relationship between two nodes: MATCH(:Stock{name:'Angel Yeast'})-[r]->(:Province{name:'Hubei'})DELETE r
Delete the relationship of a node: MATCH(:Stock{name:'Angel Yeast'})-[r]->()DELETE r
delete all relations of a tag: MATCH(:Stock)-[r]->()DELETE r

8. Update graphics

The set clause is used to update the label of the node and the attribute of the entity; the remove clause is used to delete the attribute of the entity and the attribute of the node;
increase the node attribute: MATCH(a:Stock)WHERE a.name='Ange Yeast 'SET a.abbreviation='AQJM' RETURN a
Delete node attributes: MATCH(a:Stock) WHERE a.name='Ange Yeast' REMOVE a.abbreviation

Guess you like

Origin blog.csdn.net/mogbox/article/details/112227458