Neo4j

From dataspects::Wiki
Jump to navigation Jump to search
https://neo4j.com/docs/operations-manual/current/reference/procedures/

Check version

Neo4j

CALL dbms.components()
YIELD name, versions, edition
UNWIND versions AS version
RETURN name, version, edition

APOC

root@neo:/var/lib/neo4j# ls plugins/

Cypher

MATCH (d:Dashboard)--(r:Recipe)
RETURN *
MATCH (d:Dashboard)-[p:HasInternalLink]->(r:Recipe)
RETURN d,r
MATCH (d:Dashboard)-[p]->(r:Recipe{hasEntityTitle:'Add/edit subject types'})
RETURN d,r
MATCH (d:Dashboard)--(r:Recipe)
OPTIONAL MATCH (r)--(s:SystemComponent)
RETURN *
MATCH (d:Dashboard)--(r:Recipe)
MATCH (r)--(s:SystemComponent)
MATCH (s)--(x)
OPTIONAL MATCH (d)--(f:Tool)
RETURN *
// Nodes that are connected
    MATCH (n)-->(m) RETURN n, m LIMIT 25
    // and showing relationships
        MATCH (n)-[r]->(m) RETURN n,r,m LIMIT 25

// Which nodes DO point to m.Pagename='Template:METADATA'?
    MATCH (n)-[r]->(m) WHERE m.Pagename='Template:METADATA' RETURN n,r,m LIMIT 25

// Which nodes DO NOT point to m.Pagename='Template:METADATA'?
    MATCH (n)-[r]->(m) WHERE m.Pagename<>'Template:METADATA' RETURN n,r,m LIMIT 25

// Which nodes DO NOT have a property "HasEntityTitle"?
    MATCH (n) WHERE NOT EXISTS(n.HasEntityTitle) RETURN n

// Match by node labels
    MATCH (n) WHERE n:EntityType AND n:Node RETURN labels(n) LIMIT 1
    MATCH (n) WHERE n:EntityType OR n:Node RETURN labels(n) LIMIT 1
    MATCH (n) WHERE NOT n:EntityType AND n:Node RETURN labels(n) LIMIT 1

// Match nodes that link to same type nodes
    MATCH (n)-[r]->(m) WHERE labels(n) = labels(m) RETURN n,r,m

// Find things that are carried out by some role
    MATCH p=()-[r:IsCarriedOutByRole]->(m:Role) RETURN p
    // and find things that are carried out by things not being a role explicitly (QUALAS)
    MATCH p=()-[r:IsCarriedOutByRole]->(m) WHERE NOT m:Role RETURN p

// Return distinct relationships and their volumes
    MATCH ()-[r]-() RETURN type(r), count(r)
    // for relationship types other than SMW standards
        MATCH ()-[r]-() WHERE NOT type(r) IN ["HasInternalLink", "HasTemplate"] RETURN type(r), count(r)

// Terminological ontology
    MATCH p=(a)-[r]->(b)
    WHERE r.PredicateClass = "domainSpecific" // "domainAgnosticMeta"
    RETURN count(p) as numberOfInstances,
        a.HasEntityType as subjectType,
        type(r) as predicate,
        r.PredicateClass as predicateClass,
        b.HasEntityType as objectType,
        collect(ID(r)) AS relationships
    ORDER BY predicate, numberOfInstances DESC, subjectType
    // add ", p" to return to get a visualizing graph

// Get statements by relationship IDs
    MATCH p=(a)-[r]->(b)
    WHERE ID(r) IN [1713, 1398, 2122, 1754]
    RETURN labels(a)[1] + ' "' + a.HasEntityTitle + '"' as subject,
    type(r) as predicate,
    labels(b)[1] + ' "' + b.HasEntityTitle + '"' as object

Add an entity into a context

MERGE (e:Entity:Procedure {
  name: "https://entities.dataspects.com/searchSignalsAnnotsMatches"
})
SET e.dam__HasEntityTitle = "SearchSignals <> Annotations Matching"
SET e.dsm__showAvatar = "dataspectsavatar.png"
SET e.dam__HasComment = ""
SET e.dsm__UsesReactComponents = [
  "MatchSearchSignalsToEntityAnnotations"
]
SET e.aspectConfig = []
SET e.opensOnLoad = false
SET e.resourceSiloURI = "https://entities.dataspects.com/"
WITH e AS e
MATCH (o:Entity { name: "https://entities.dataspects.com/Search" })
MERGE (e)-[p:HasContext]->(o)