Neo4j: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
(8 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
http://193.26.158.116:7474/ | |||
CALL apoc.load.json("file:///locations.json") YIELD value | === run neo4j === | ||
<syntaxhighlight lang="bash"> | |||
docker pull neo4j:latest | |||
docker run -d \ | |||
--name neo4j \ | |||
-p 7474:7474 -p 7687:7687 \ | |||
-v $HOME/neo4j/data:/data \ | |||
-v $HOME/neo4j/import:/import \ | |||
-e NEO4J_AUTH=neo4j/password \ | |||
-e NEO4JLABS_PLUGINS='["apoc", "graph-data-science"]' \ | |||
-e NEO4J_dbms_security_procedures_unrestricted=gds.*,apoc.* \ | |||
-e NEO4J_apoc_import_file_enabled=true \ | |||
-e NEO4J_apoc_import_file_use__neo4j__config=true \ | |||
neo4j:latest | |||
</syntaxhighlight> | |||
=== import data from json file === | |||
<syntaxhighlight lang="cypher"> | |||
CALL apoc.load.json("file:///locations.json") YIELD value | |||
// Create the Location node | |||
MERGE (l:Location {id: value.id}) | |||
SET l.name = value.name | |||
// Create Regest nodes and relationships | |||
WITH l, value | |||
UNWIND value.lemmaID AS regestId | |||
MERGE (r:Regest {id: regestId}) | |||
MERGE (l)-[:MENTIONED_IN]->(r); | |||
</syntaxhighlight> | |||
=== Find clusters === | |||
<syntaxhighlight lang="cypher"> | |||
CALL gds.graph.project( | |||
'myGraph', | |||
['Person', 'Regest', 'Location'], | |||
{ | |||
ALL: { | |||
type: '*', | |||
orientation: 'UNDIRECTED' | |||
} | |||
} | |||
); | |||
</syntaxhighlight><syntaxhighlight lang="cypher"> | |||
CALL gds.wcc.stream('myGraph') | |||
YIELD nodeId, componentId | |||
RETURN componentId, count(*) AS size | |||
ORDER BY size DESC | |||
LIMIT 1; | |||
</syntaxhighlight><syntaxhighlight lang="cypher"> | |||
CALL gds.wcc.stream('myGraph') | |||
YIELD nodeId, componentId | |||
WHERE componentId = 0 | |||
RETURN gds.util.asNode(nodeId) AS node; | |||
</syntaxhighlight> | |||
=== Keep Cluster Info: '''Persist Component IDs''' === | |||
<syntaxhighlight lang="cypher"> | |||
CALL gds.wcc.write('myGraph', { | |||
writeProperty: 'componentId' | |||
}) | |||
YIELD nodePropertiesWritten, componentCount; | |||
</syntaxhighlight><syntaxhighlight lang="cypher"> | |||
CALL gds.graph.drop('myGraph'); | |||
</syntaxhighlight><syntaxhighlight lang="cypher"> | |||
MATCH (n) | |||
REMOVE n.componentId; | |||
</syntaxhighlight> | |||
=== Explore clusters via Property componentID === | |||
<syntaxhighlight lang="cypher"> | |||
MATCH (n) | |||
RETURN n.componentId AS component, count(*) AS size | |||
ORDER BY size DESC | |||
LIMIT 1; | |||
</syntaxhighlight><syntaxhighlight lang="cypher"> | |||
MATCH (r:Regest) | |||
WHERE r.componentId = 0 | |||
RETURN r; | |||
</syntaxhighlight> |
Aktuelle Version vom 11. Juni 2025, 21:52 Uhr
run neo4j
docker pull neo4j:latest
docker run -d \
--name neo4j \
-p 7474:7474 -p 7687:7687 \
-v $HOME/neo4j/data:/data \
-v $HOME/neo4j/import:/import \
-e NEO4J_AUTH=neo4j/password \
-e NEO4JLABS_PLUGINS='["apoc", "graph-data-science"]' \
-e NEO4J_dbms_security_procedures_unrestricted=gds.*,apoc.* \
-e NEO4J_apoc_import_file_enabled=true \
-e NEO4J_apoc_import_file_use__neo4j__config=true \
neo4j:latest
import data from json file
CALL apoc.load.json("file:///locations.json") YIELD value
// Create the Location node
MERGE (l:Location {id: value.id})
SET l.name = value.name
// Create Regest nodes and relationships
WITH l, value
UNWIND value.lemmaID AS regestId
MERGE (r:Regest {id: regestId})
MERGE (l)-[:MENTIONED_IN]->(r);
Find clusters
CALL gds.graph.project(
'myGraph',
['Person', 'Regest', 'Location'],
{
ALL: {
type: '*',
orientation: 'UNDIRECTED'
}
}
);
CALL gds.wcc.stream('myGraph')
YIELD nodeId, componentId
RETURN componentId, count(*) AS size
ORDER BY size DESC
LIMIT 1;
CALL gds.wcc.stream('myGraph')
YIELD nodeId, componentId
WHERE componentId = 0
RETURN gds.util.asNode(nodeId) AS node;
Keep Cluster Info: Persist Component IDs
CALL gds.wcc.write('myGraph', {
writeProperty: 'componentId'
})
YIELD nodePropertiesWritten, componentCount;
CALL gds.graph.drop('myGraph');
MATCH (n)
REMOVE n.componentId;
Explore clusters via Property componentID
MATCH (n)
RETURN n.componentId AS component, count(*) AS size
ORDER BY size DESC
LIMIT 1;
MATCH (r:Regest)
WHERE r.componentId = 0
RETURN r;