Popular New Releases in Graph Database
janusgraph
0.6.1
typedb
TypeDB 2.8.1
grakn
Grakn Core 2.0.2
RedisGraph
v2.8.11
neo4j-apoc-procedures
4.4.0.3
Popular Libraries in Graph Database
by neo4j java
9857 NOASSERTION
Graphs for Everyone
by thinkaurelius java
5134 Apache-2.0
Distributed Graph Database
by JanusGraph java
4397 NOASSERTION
JanusGraph: an open-source, distributed graph database
by liuhuanyong python
3118
A tutorial and implement of disease centered Medical knowledge graph and qa system based on it。知识图谱构建,自动问答,基于kg的自动问答。以疾病为中心的一定规模医药领域知识图谱,并以该知识图谱完成自动问答与分析服务。
by vaticle java
3056 AGPL-3.0
TypeDB: a strongly-typed database
by graknlabs java
2628 AGPL-3.0
Grakn Core: The Knowledge Graph
by tinkerpop java
1891 NOASSERTION
A Graph Traversal Language (no longer active - see Apache TinkerPop)
by RedisGraph c
1595 NOASSERTION
A graph database as a Redis module
by eBay go
1579 Apache-2.0
A distributed knowledge graph store
Trending New libraries in Graph Database
by pykeen python
805 MIT
🤖 A Python library for learning and evaluating knowledge graph embeddings
by apache c
551 Apache-2.0
Graph database optimized for fast analysis and real-time data processing. It is provided as an extension to PostgreSQL.
by unigraph-dev typescript
412 MIT
A local-first and universal knowledge graph, personal search engine, and workspace for your life.
by liuhuanyong python
410
ChineseSemanticKB,chinese semantic knowledge base, 面向中文处理的12类、百万规模的语义常用词典,包括34万抽象语义库、34万反义语义库、43万同义语义库等,可支持句子扩展、转写、事件抽象与泛化等多种应用场景。
by aws jupyter notebook
388 NOASSERTION
Library extending Jupyter notebooks to integrate with Apache TinkerPop, openCypher, and RDF SPARQL.
by wangle1218 python
272
Knowledge Graph,Question Answering System,基于知识图谱和向量检索的医疗诊断问答系统
by jwzhanggy python
244
Source code of Graph-Bert
by usc-isi-i2 jupyter notebook
228 MIT
Knowledge Graph Toolkit
by nju-websoft python
173 GPL-3.0
A Benchmarking Study of Embedding-based Entity Alignment for Knowledge Graphs, VLDB 2020
Top Authors in Graph Database
1
17 Libraries
711
2
17 Libraries
1220
3
17 Libraries
1071
4
15 Libraries
3477
5
10 Libraries
955
6
9 Libraries
67
7
9 Libraries
78
8
8 Libraries
183
9
8 Libraries
2483
10
7 Libraries
419
1
17 Libraries
711
2
17 Libraries
1220
3
17 Libraries
1071
4
15 Libraries
3477
5
10 Libraries
955
6
9 Libraries
67
7
9 Libraries
78
8
8 Libraries
183
9
8 Libraries
2483
10
7 Libraries
419
Trending Kits in Graph Database
Java Graph databases libraries are a relatively new database technology that has been gaining popularity in the last couple of years. They are especially useful for storing and querying relationships between entities. They have certain advantages over traditional relational databases, such as their ability to quickly traverse large graphs and answer complex queries with low latency. Neo4j is the most popular and mature option. It has all the basic features you need to get started, including support for multiple indexes, relationships and queries. It also offers a REST API that allows you to query your data from the browser or a client application. OrientDB is a newer alternative that offers an object-relational mapping (ORM) layer on top of its native graph database engine for easier integration with existing applications. This approach makes it easier to migrate from relational databases like MySQL or PostgreSQL into OrientDB, but it also means that some features may be missing from the graph database layer itself (for example, there's no support for transactions). Titan has a similar ORM layer as OrientDB but also supports advanced features such as transactional queries and automatic sharding across multiple nodes in a cluster. Some of the most widely used open source Java Graph databases libraries among developers include:
JavaScript Graph Database libraries are a new platform for building real-time data applications. The most common use case is to build an application that displays social graphs, such as Facebook, Twitter and LinkedIn. A JavaScript graph database library is a library that allows you to store and query a graph structure. These are useful for many applications, including social network sites and games. FortuneJS is a simple, lightweight GraphQL server with built-in clustering capabilities. FortuneJS uses MongoDB as its storage layer. LevelGraph is a JavaScript library for querying graph databases using SPARQL and JSON-LD. LevelGraph has a number of different backends including Neo4j, OrientDB, RethinkDB and MongoDB. Graphexp is an open-source JavaScript library for creating and querying graphs using Gremlin-style traversal expressions. Graphexp supports Neo4j and OrientDB as backend databases. A few of the most popular open source JavaScript Graph Database libraries for developers are:
Cartography is another Python library that makes it easy to render maps in your applications. It comes with support for OpenStreetMap and Google Maps, but you can also use custom tilesets if you want more control over how things look. Neomodel is a Python library that lets you store models in Neo4j and query them using Cypher, the graph database query language developed by Neo4j. This means that instead of writing SQL queries, you'll be able to write Cypher queries directly against your data, which should make it easier to build up complex relationships between different entities in your application. The Python graph database ecosystem is a combination of several different libraries that can be used to store and query graphs. Python Graph Database libraries are great for building graph-based applications. They provide an easy and intuitive way to store and process graphs in your application. Popular open source Python graph database libraries for developers include:
Ruby Graph Database libraries like activegraph, rgl, pacer and others provide a simple way to build a graph database. These libraries allow you to store graphs in Ruby objects without having to write any code for the storage or query layer. You can even use Ruby to query your graph data! ActiveGraph is an open source Ruby library for working with graphs. It provides functionality for reading from and writing to CSV files, but doesn't have any built-in graph storage capabilities. RGL is another open source library for storing graph data in CSV files. It's similar to ActiveGraph in that it doesn't provide any built-in graph storage capabilities, but it does include methods for creating and querying graphs over CSV files. Pacer is a Ruby gem that allows you to easily store and query graphs in PostgreSQL by using SQL queries such as "SELECT * FROM users." Developers tend to use some of the following open source Ruby Graph Database libraries:
C# Graph databases are becoming more popular, and with good reason. They can be faster than relational databases for certain use cases, and they can be easier to use for certain others. There are a number of different graph database libraries for C# developers. GraphView is a C# library for manipulation of graph data using the property graph model. It supports both directed and undirected graphs, and provides functionality such as adding and removing nodes and edges, preserving topological order, finding shortest paths through the graph, querying for subgraphs or nodes within a given area, etc. sones is a C# library to handle the SQLite3 Database File format (which is in fact just a plaintext file). Provides basic SQLite3 support (insert/update/delete) as well as full text search capabilities. fallen-8 is a library which aims to provide a simple interface to the Neo4j REST API which allows you to store, retrieve, update and delete any type of object from your Neo4j server. The syntax is based on LINQ so it should be familiar to most C# developers who want to use Neo4j in their projects. There are several popular open source C# Graph databases libraries available for developers:
C++ Graph Database libraries are used to build graph databases. They provide the functionality needed to create, query and update graphs in a database. The use of C++ graph database libraries is a great way to build complex data-centric applications. The combination of a graph database and the powerful C++ language provides an excellent framework for building highly concurrent and scalable applications. C++ Graph Database libraries like nebula, SFrame, NGT are the way to go for creating large-scale graph databases. They provide efficient ways of storing and querying large amounts of data. These libraries provide an excellent platform to build distributed graph database systems. Nebula is a modern C++ graph database with SQL support and an open source alternative to Neo4j. It’s an easy-to-use library that makes it easy for developers to store and query graphs in their applications without having to worry about schema design or why they would want to use a graph database in their application. SFrame is a Apache Spark-based library for building distributed graph-oriented workloads on top of Apache Spark clusters. SFrame provides utility methods for loading and storing graphs in form of DataFrames, which can then be manipulated using SQL queries or any other Spark APIs such as functional transformations or machine learning algorithms. Popular open source C++ Graph Database libraries include:
A PHP Graph Database library is a PHP library that provides an API for interacting with a graph database. A graph database is a database where data is stored in the form of nodes and edges (relationships). A PHP Graph Database library provides a way to work with the data in such a way that it can be queried and modified quickly. Serializer is a library that allows you to send graph data from PHP applications to nodes or edges of the graph database. OpenGraph is a library that allows you to send graph data from PHP applications to nodes or edges of the graph database. It is an open source project that allows you to connect with any existing backend technology with ease. It has support for MySQL, PostgreSQL, MongoDB and Redis databases. NeoEloquent is an ORM (Object Relational Mapper) for Neo4j which can be used in your projects. Popular open source PHP Graph Database libraries among developers include:
Gogrpah is a graph library for Go that allows you to create and query graphs in your application. The Go database libraries are no exception. You can use the database libraries in your application to access data from different databases like MySQL, PostgreSQL, MongoDB etc. Dgraph is an open source, distributed graph database written in Go. Dgraph is a scalable, distributed, fault tolerant, native graph database. It's built from the ground up for efficiency and performance. Cayley is an open-source graph database developed by Facebook. Cayley uses an expressive query language that enables developers to express complex queries with ease. Simple-Graph is a simple graph database implemented with Go's testing package. It's designed to be simple, fast, and reliable, which makes it easy to deploy at scale.Eliasdb is a pure-Go embedded key/value store with JSON documents, indexes and queries. It is an open source distributed graph database that stores data in native binary format instead of JSON or BSON files like other solutions do today. Many developers depend on the following open source Go Graph Database libraries:
Trending Discussions on Graph Database
Can I create a knowledge graph in Memgraph?
Using a graph database to store and retrieve sorted users by personality scores
idiomatic way to atomically create a table that as a record that is associated to other tables
Gremlin query language - how to limit/filter path or start from specific verticle in chain?
SQL Graph Database VS Cosmos Gremlin graph DB
AWS Neptune performance / Comparing to Neo4j AuraDB
@Async method inside synchronized method Java
NEO4J find records that not exist in other pattern result
Check if Neighbors have subset of connected nodes
Cytoscape Integration with Neo4j
QUESTION
Can I create a knowledge graph in Memgraph?
Asked 2022-Mar-28 at 11:17I know that knowledge graphs are represented in RDF, but I am wondering whether Memgraph as a graph database can store this kind of data?
ANSWER
Answered 2022-Mar-28 at 11:17While Memgraph is not an RDF store, it is capable of handling this kind of data with the labeled property graph model (LPG). LPG is represented by a set of nodes, relationships, properties (key-value attributes) and labels. RDF statements can be directly treated as nodes, relationships and properties of the graph, which are explored using the Cypher query language. Therefore, both RDF and LPG allow the creation of a knowledge graph.
QUESTION
Using a graph database to store and retrieve sorted users by personality scores
Asked 2022-Mar-13 at 07:12I am interested in storing a set of users that have personality scores. I would like to get them to be more connected (closer?) to each other based on formulas that are applied to their scores. The more similar the users are, the more connected or closer to each other they are (like in a cluster). The closest nodes are to one-another, the more similar they are.
I currently do this over multiple steps (some in SQL and other in code) from a relational database.
Most posts out there and documentation seems to focus on how to get started and what the advantages are at a high level compared to relational databases.
I am wondering if Graph databases are better suited for this and would do most of the heavy lifting out of the box or more natively. Any details are greatly appreciated.
ANSWER
Answered 2022-Mar-13 at 07:12You could consider modeling it like this:
Where a vertex type/label named Score_range was introduced, together with the label User(with property score).
User vertices are connected to Score_range vertex like User with score: 101 is connected to Score_range(vertexID=100) which stands for [100, 110).
Thus, those vertices with closer score are more connected/clusterred in this graph, and in your applicaiton, you need to make connection changes when the score are recaculated/changed to the graph database.
Then, either to run cluster algorithm(i.e. Louvain) on the whole graph or graph query to find path between any two user nodes(i.e. FIND PATH in Nebula Graph, an opensource distributed graph database speaks opencypher), the closeness will be reflected.
But, I think due to this connection/closness is actually numerical/sortable, simply handling this closeness relationship may not need a graph database from the context you already provided.
QUESTION
idiomatic way to atomically create a table that as a record that is associated to other tables
Asked 2022-Feb-23 at 17:11I am coming from graph databases and postgres is still super foreign to me.
I have the following tables
1CREATE TYPE runnerenum AS ENUM ('runner');
2
3CREATE TABLE IF NOT EXISTS collections (
4 collectionid UUID PRIMARY KEY,
5 name VARCHAR(256) UNIQUE NOT NULL,
6 runner runnerenum NOT NULL,
7 runconfig JSONB
8);
9
10CREATE TABLE IF NOT EXISTS namedexprs(
11 namedexprid UUID PRIMARY KEY,
12 name VARCHAR(256) UNIQUE NOT NULL,
13 -- exprid UUID NOT NULL REFERENCES expressions(exprid),
14 collectionid UUID NOT NULL REFERENCES collections(collectionid) ON DELETE CASCADE
15);
16
17CREATE TABLE IF NOT EXISTS expressions(
18 exprid UUID PRIMARY KEY,
19 ast JSONB NOT NULL,
20 namedexprid UUID NOT NULL REFERENCES namedexprs(namedexprid) ON DELETE CASCADE
21);
22
My question is what is the idiomatic way to create a collections
atomically (while also creating associated expressions
and namedexprs
). Currently I am executing three separate queries and getting errors because of a foreign key violation.
ANSWER
Answered 2022-Feb-23 at 17:11Example of using DEFERRABLE
:
1CREATE TYPE runnerenum AS ENUM ('runner');
2
3CREATE TABLE IF NOT EXISTS collections (
4 collectionid UUID PRIMARY KEY,
5 name VARCHAR(256) UNIQUE NOT NULL,
6 runner runnerenum NOT NULL,
7 runconfig JSONB
8);
9
10CREATE TABLE IF NOT EXISTS namedexprs(
11 namedexprid UUID PRIMARY KEY,
12 name VARCHAR(256) UNIQUE NOT NULL,
13 -- exprid UUID NOT NULL REFERENCES expressions(exprid),
14 collectionid UUID NOT NULL REFERENCES collections(collectionid) ON DELETE CASCADE
15);
16
17CREATE TABLE IF NOT EXISTS expressions(
18 exprid UUID PRIMARY KEY,
19 ast JSONB NOT NULL,
20 namedexprid UUID NOT NULL REFERENCES namedexprs(namedexprid) ON DELETE CASCADE
21);
22CREATE TABLE parent_tbl (
23 parent_id integer PRIMARY KEY,
24 parent_val varchar UNIQUE
25);
26
27
28CREATE TABLE child_tbl (
29 child_id integer PRIMARY KEY,
30 parent_fk varchar REFERENCES parent_tbl (parent_val)
31 ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
32 child_val varchar
33);
34
35
36
37\d child_tbl
38 Table "public.child_tbl"
39 Column | Type | Collation | Nullable | Default
40-----------+-------------------+-----------+----------+---------
41 child_id | integer | | not null |
42 parent_fk | character varying | | |
43 child_val | character varying | | |
44Indexes:
45 "child_tbl_pkey" PRIMARY KEY, btree (child_id)
46Foreign-key constraints:
47 "child_tbl_parent_fk_fkey" FOREIGN KEY (parent_fk) REFERENCES parent_tbl(parent_val) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
48
49BEGIN;
50INSERT INTO child_tbl VALUES (1, 'dog', 'cat');
51
52SELECT * FROM child_tbl ;
53 child_id | parent_fk | child_val
54----------+-----------+-----------
55 1 | dog | cat
56(1 row)
57
58SELECT * FROM parent_tbl ;
59 parent_id | parent_val
60-----------+------------
61(0 rows)
62
63INSERT INTO parent_tbl VALUES (1, 'dog');
64
65SELECT * FROM parent_tbl ;
66 parent_id | parent_val
67-----------+------------
68 1 | dog
69
70COMMIT;
71
The key to using DEFERRABLE
is that the individual data entry statements need to be bundled into the same transaction, the BEGIN;/COMMIT;
. This allows DEFERRABLE INITIALLY DEFERRED
to work as the constraint check is deferred until the end of the transaction. For more ways you can manipulate this see SET CONSTRAINTS.
QUESTION
Gremlin query language - how to limit/filter path or start from specific verticle in chain?
Asked 2022-Feb-12 at 21:05I am new to the graph databases and Gremlin. What I am trying to achieve is to ask a simple question to the database. Provided id of the Entity and id of the File, I want to find all other entites who have access to this file via the Share and return the result with the property "type" of the share. Here is the graph itself:
What I tried:
g.V("Enity:1").out("Created").hasLabel("Share").where(out("Shared").hasId("File:1")).in("Access").path()
This returns me:
1[
2 {
3 //Omitted empty aray
4 "objects": [
5 {
6 "id": "dseg:/Entity/1",
7 "label": "Entity",
8 "type": "vertex",
9 "properties": {}
10 },
11 {
12 "id": "dseg:/Share/1",
13 "label": "Share",
14 "type": "vertex",
15 "properties": {}
16 },
17 {
18 "id": "dseg:/Entity/1",
19 "label": "Entity",
20 "type": "vertex",
21 "properties": {}
22 }
23 ]
24 },
25 {
26 //Omitted empty aray
27 "objects": [
28 {
29 "id": "dseg:/Entity/1",
30 "label": "Entity",
31 "type": "vertex",
32 "properties": {}
33 },
34 {
35 "id": "dseg:/Share/1",
36 "label": "Share",
37 "type": "vertex",
38 "properties": {}
39 },
40 {
41 "id": "dseg:/Entity/3",
42 "label": "Entity",
43 "type": "vertex",
44 "properties": {}
45 }
46 ]
47 }
48]
49
It shows the path taken from the entry point(Entity:1) to the target(s) Entity 2 and 3
My question with technical details: Is there a way to start gathering path() after Entity:1 or intermediate verticle I chose, so that in result I will get only Share + Entity who has Access to it?
ANSWER
Answered 2022-Feb-12 at 21:05You just need to tell path step where to start from. You can do something like this:
1[
2 {
3 //Omitted empty aray
4 "objects": [
5 {
6 "id": "dseg:/Entity/1",
7 "label": "Entity",
8 "type": "vertex",
9 "properties": {}
10 },
11 {
12 "id": "dseg:/Share/1",
13 "label": "Share",
14 "type": "vertex",
15 "properties": {}
16 },
17 {
18 "id": "dseg:/Entity/1",
19 "label": "Entity",
20 "type": "vertex",
21 "properties": {}
22 }
23 ]
24 },
25 {
26 //Omitted empty aray
27 "objects": [
28 {
29 "id": "dseg:/Entity/1",
30 "label": "Entity",
31 "type": "vertex",
32 "properties": {}
33 },
34 {
35 "id": "dseg:/Share/1",
36 "label": "Share",
37 "type": "vertex",
38 "properties": {}
39 },
40 {
41 "id": "dseg:/Entity/3",
42 "label": "Entity",
43 "type": "vertex",
44 "properties": {}
45 }
46 ]
47 }
48]
49gremlin> g.V("entity:1").
50......1> out("Created").
51......2> hasLabel("Share").
52......3> where(out("Shared").hasId("File:1")).as('a').
53......4> in("Access").
54......5> path().from('a').by('Type').by()
55==>[RO,v[entity:2]]
56==>[RO,v[entity:3]]
57
Another way to do this is :
1[
2 {
3 //Omitted empty aray
4 "objects": [
5 {
6 "id": "dseg:/Entity/1",
7 "label": "Entity",
8 "type": "vertex",
9 "properties": {}
10 },
11 {
12 "id": "dseg:/Share/1",
13 "label": "Share",
14 "type": "vertex",
15 "properties": {}
16 },
17 {
18 "id": "dseg:/Entity/1",
19 "label": "Entity",
20 "type": "vertex",
21 "properties": {}
22 }
23 ]
24 },
25 {
26 //Omitted empty aray
27 "objects": [
28 {
29 "id": "dseg:/Entity/1",
30 "label": "Entity",
31 "type": "vertex",
32 "properties": {}
33 },
34 {
35 "id": "dseg:/Share/1",
36 "label": "Share",
37 "type": "vertex",
38 "properties": {}
39 },
40 {
41 "id": "dseg:/Entity/3",
42 "label": "Entity",
43 "type": "vertex",
44 "properties": {}
45 }
46 ]
47 }
48]
49gremlin> g.V("entity:1").
50......1> out("Created").
51......2> hasLabel("Share").
52......3> where(out("Shared").hasId("File:1")).as('a').
53......4> in("Access").
54......5> path().from('a').by('Type').by()
55==>[RO,v[entity:2]]
56==>[RO,v[entity:3]]
57gremlin> g.V().
58......1> hasLabel('Share').
59......2> where(out('Shared').hasId('File:1')).
60......3> where(__.in('Created').hasId('entity:1')).
61......4> in('Access').
62......5> path().by('Type').by()
63==>[RO,v[entity:2]]
64==>[RO,v[entity:3]]
65
QUESTION
SQL Graph Database VS Cosmos Gremlin graph DB
Asked 2022-Feb-09 at 07:07I have been thinking about what are the pros and cons of SQL Graph Database and Cosmos Graph Database, as far as I understand, SQL graph database is using nodes and vertex, but it still stores all of the information in tables.
So my question would be if the graph data can be handled by graph Db, what are the advantages of using SQL graph database? What is the added value of it compared with the original graph Database ?
ANSWER
Answered 2022-Feb-09 at 07:07SQL Graph Database and Cosmos Graph Database both are almost same kind of services, just the structure of handling the data is different. As such there are no advantages and disadvantages, but choosing the right service based on your use-case is the key factor.
Azure Cosmos DB's Gremlin API combines the power of graph database algorithms with highly scalable, managed infrastructure to provide a unique, flexible solution to most common data problems associated with lack of flexibility and relational approaches.
So, by using Azure Cosmos DB Gremlin API, you will get more leverage on the datasets with additional features. On the top of that, all the prerequisites will be taken care by CosmosDB while creating the database using Gremlin API.
In SQL Graph DB, nodes and edges are in tabular form, whereas in Cosmos DB it is in JSON like format.
I would highly encourage you to analyze how these databases support graph database models and the mechanism to exploit the maximum potential of these database systems for the right use-cases.
Please refer below articles to get the better understanding of both the services.
QUESTION
AWS Neptune performance / Comparing to Neo4j AuraDB
Asked 2022-Feb-01 at 14:30We use Neo4j AuraDB for our graph database but there we have issues with data upload. So, we decided to move to AWS Neptune using the migration tool.
We have 3.7M nodes and 11.2M relations in our database. The DB instance is db.r5.large with 2 CPUs and 16GiB RAM.
The same AWS Neptune OpenCypher queries are much slower than AuraDB Cypher queries (about 7-10 times slower). Also, we tried to rewrite the queries to Gremlin and test performance but it is still very slow. We have node and lookup indexes on AuraDB but we can't create them on AWS Neptune as it handles them automatically.
Is there any way to reach better performance on AWS Neptune?
UPDATE:
Example of Gremlin query:
g.V().hasLabel('Member').has('address', eq('${address}')).outE('HAS').as('member_has').inV().as('token').hasLabel('Token').inE('HAS').as('other_member_has').outV().as('other_member').hasLabel('Member').where(__.select('member_has').where(neq('other_member_has'))).select('other_member', 'token').group().by(__.select('other_member').local(__.properties().group().by(__.key()).by(__.map(__.value())))).by(__.fold().project('member', 'number_of_tokens').by(__.unfold().select('other_member').choose(neq('cypher.null'), __.local(__.properties().group().by(__.key()).by(__.map(__.value()))))).by(__.unfold().select('token').count())).unfold().select(values).order().by(__.select('number_of_tokens'), desc).limit(20)
Example of Cypher query:
MATCH (member:Member { address: '${address}' })-[:HAS]->(token:Token)<-[:HAS]-(other_member:Member) RETURN PROPERTIES(other_member) as member, COUNT(token) AS number_of_tokens ORDER BY number_of_tokens DESC LIMIT 20
ANSWER
Answered 2022-Feb-01 at 14:30As discussed in the comments, as of this moment, the openCypher support is a preview, not quite GA level. The more recent engine versions do have some significant improvements but more are yet to be delivered. As to the Gremlin query, tools that convert Cypher to Gremlin tend to build quite complex queries. I think the Gremlin equivalent to the Cypher query is going to look something like this.
1g.V().has('Member','address', address).as('m').
2 out('HAS').hasLabel('Token').as('t').
3 in('HAS').hasLabel('Member').as('om').
4 where(neq('m')).
5 group().
6 by('om').
7 by(select('t').count()).
8 order(local).
9 by(values,desc).
10 limit(20)
11
12
and if you want all of the properties just add a valueMap
as in:
1g.V().has('Member','address', address).as('m').
2 out('HAS').hasLabel('Token').as('t').
3 in('HAS').hasLabel('Member').as('om').
4 where(neq('m')).
5 group().
6 by('om').
7 by(select('t').count()).
8 order(local).
9 by(values,desc).
10 limit(20)
11
12g.V().has('Member','address', address).as('m').
13 out('HAS').hasLabel('Token').as('t').
14 in('HAS').hasLabel('Member').as('om').
15 where(neq('m')).
16 group().
17 by(select('om').valueMap(true)).
18 by(select('t').count()).
19 order(local).
20 by(values,desc).
21 limit(20)
22
QUESTION
@Async method inside synchronized method Java
Asked 2022-Jan-26 at 12:47To summarize the problem, I am trying to call some method which is annotated with @async in a synchronized method. Reason for using @async was because I wish to return the response of the post method (to reduce waiting time on client’s side) and continue doing some post processing work (resetting certain properties). However, as the POST method involve altering a graph database, I declare the method with synchronized keyword to prevent altering of the graph database while another computation is going on. The result of this seem to be that two threads are entering the synchronized method, which shouldn’t be occurring?
1@RestController
2public class Controller {
3
4@PostMapping(path = “/compute”)
5public synchronized String compute() {
6
7System.out.println(“===== > In thread: “ + Thread.currentThread().getName());
8
9System.out.print(“===== > Doing some work in compute”);
10
11ResetService.reset()
12Return(“===== > done computing”)
13}
14
15
16@Service
17public class ResetService {@Async public void reset (){
18
19System.out.println(“===== > resetting in thread: “ + Thread.currentThread().getName());
20#(resetting some properties in neo4j graph database)
21resetMethod();
22System.out.print(“===== > Done Resetting”);
23}
24
This will give me an output similar to something like this:
===== > In Thread: http-nio-10080-exec-2
===== > Doing some work in compute
===== > done computing
=====> Resetting in Thread: Async-1
===== > In Thread: http-nio-10080-exec-3
===== > Doing some work in compute
===== > Done Resetting
My understanding of Synchronized method is that it only allows a single thread to enter the method at any time. But it seems like there are two threads running the Synchronized compute method at the same time. I tried to come up with some reasons for this and the two main ones I could think of are:
Due to different instances of the Controller class, however I recalled reading somewhere that a RESTController is a singleton scope by default, so it shouldn’t be due to this?
Context switching? Does synchronized method allow for context switching from one thread to another?
I apologise if any part of my question is confusing as I am relatively new to Java Spring/Spring Boot especially the concept of concurrency, multithreading etc. Please do let me know if you need me to clarify any part of my question.
ANSWER
Answered 2022-Jan-26 at 12:45When you call the asynchronous method reset()
within the synchronized method compute()
the latter method will not wait for reset()
to finish. Instead it will spawn a new thread that handles the code execution of reset()
and then immediately proceeds to the next line Return(“===== > done computing”)
. After that the method will complete. When it completes a new thread will be allowed to call compute()
, even when the reset()
call of the previous thread that entered compute()
is still running in the separate thread.
So to be more clear, The method compute()
is not entered by two threads simultaneously. It only looks that way because part of the text prints from thread http-nio-10080-exec-3
come before the Done Resetting
print of thread Async-1
. So your code is working as intended.
QUESTION
NEO4J find records that not exist in other pattern result
Asked 2022-Jan-19 at 10:25I'm new to Graph Database world, i just started to learn neo4j.
For example. I have a list of all video and a list of user watched video. How do I write pattern to query a list of not watched video based on specifed user id ?
ANSWER
Answered 2022-Jan-19 at 10:25I assume that your labelled property model looks something like this:
- Some nodes with label "USER" for the users
- Some nodes with label "MOVIE" for the movies
- Some Relations of type "Has_Watched" to indicate a user has seen the movie
Then you can do something like this:
1MATCH (user:USER)
2WHERE user.Id = $yourId
3MATCH (movie:MOVIE)
4WITH user, movie
5MATCH (user)
6WHERE IsEmpty((user)-[:HAS_WATCHED]->(movie))
7RETURN movie
8
So basically you get your user by ID and you get all movies. Then you only look for the movies that are not connected via a relationship of type "HAS_WATCHED".
QUESTION
Check if Neighbors have subset of connected nodes
Asked 2022-Jan-13 at 18:57I currently have a Neo4J Graph Database that stores 4 different kind of nodes that are connected via edges. Yellow/Red nodes that are connected to blue nodes and the yellow/red nodes have green nodes connected that give additional info on them.
What I want to do is to check if the selected node(either yellow or red) has a neighbor that is connected via the blue node, has a subset of common connected green nodes.
For example if I select the lower red node the upper red node would be returned as they both share the same far left green node neighbor which is a subset of the green node neighbors of the selected red node.
I currently have the following Cypher query, where the table nodes are the yellow and red nodes and the keyNode are the green nodes. The blue node is the objectType.
1MATCH(table:TABLE)
2where table.Name = $name
3MATCH (table)-[keyRel:IS_DEFINED_BY_KEY]->(keyNode)
4MATCH (table)<-[createRel:IS_CREATED_IN]-(objectType)-[createRel2:IS_CREATED_IN]->(createTables)
5MATCH (createTables)-[keyRel2:IS_DEFINED_BY_KEY]->(addKey)
6
So at the end of the current query I have the searched/selected table, its neighboring green nodes, the yellow/red nodes that are connected via the blue node and the green nodes that are connected to them.
With that I now want to only return the connected yellow/red nodes that are connected to a subset of green nodes. So in the example only the upper red node.
Has anybody an idea how I can achieve this?
ANSWER
Answered 2022-Jan-13 at 18:57I think I have found a solution.
I thought it the other way around. So instead of searching via the blue node that is connected to both my nodes I went via the green node.
The green neighbors of the other nodes can only be a subset of the selected nodes green neighbors if all of the other nodes neighbors are also connected to the selected node. You can find the used cypher query below. The interesting part where the subset is tested is:
Match (table) WHERE NOT ALL(t2key in t2keys WHERE (table)-[:IS_DEFINED_BY_KEY]->(t2key)).
1MATCH(table:TABLE)
2where table.Name = $name
3MATCH (table)-[keyRel:IS_DEFINED_BY_KEY]->(keyNode)
4MATCH (table)<-[createRel:IS_CREATED_IN]-(objectType)-[createRel2:IS_CREATED_IN]->(createTables)
5MATCH (createTables)-[keyRel2:IS_DEFINED_BY_KEY]->(addKey)
6MATCH(table:TABLE)
7where table.Name = $name
8Match (table)<-[:IS_CREATED_IN]-(objectType)
9
10WITH Distinct table, objectType
11
12MATCH (table)-[:IS_DEFINED_BY_KEY]->(keyNode)
13
14MATCH (keyNode)<-[:IS_DEFINED_BY_KEY]-(T2:RECORDTABLE)
15WHERE (T2.Neo4JId)<>(table.Neo4JId) and Exists ((objectType)-[:IS_CREATED_IN]->(T2))
16
17MATCH (T2)-[:IS_DEFINED_BY_KEY]->(T2Key)
18
19WITH table, collect(T2Key) as t2keys
20
21// RETURN DISTINCT table, t2keys
22Match (table)
23WHERE NOT ALL(t2key in t2keys WHERE (table)-[:IS_DEFINED_BY_KEY]->(t2key))
24
25Return table
26
QUESTION
Cytoscape Integration with Neo4j
Asked 2022-Jan-13 at 16:27I'm trying to build a webpage on which embed a visualization window for my local graph database. The graph database I'm using is Neo4j and for visualization I'm trying to use Cytoscape. Until now, I embedded a test graph in a webpage thanks to Cytoscape.js by putting some nodes and relationships directly in the JavaScript code. The only thing I still have problem with is the connection between Cytoscape and my local Neo4j Database. Which would be the best way to do this?
ANSWER
Answered 2022-Jan-13 at 16:27Typically, I answer Cytoscape desktop (not Cytoscape.js) questions, but I have built a web site (see https://spoke.rbvi.ucsf.edu) that does exactly what you are proposing. For a number of reasons, we implemented it with an intermediate REST interface so that we don't have to expose our Neo4J database. The REST interface does all of the queries and spits out cytoscape.js JSON formatted networks...
-- scooter
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Graph Database
Tutorials and Learning Resources are not available at this moment for Graph Database