paion-data / aristotle

A web servide enables you to create knowledge graph.
https://aristotle-ws.com
3 stars 0 forks source link

Support k-expand #22

Open QubitPi opened 5 days ago

QubitPi commented 5 days ago

Goal

Per our frontend application's need, we need to be able to k-expand a graph node by a user specified number of degree

One of the distinguishing feature of Graph Database compared to traditional databases such as MySQL is its ability to find relationships between data much easier in a much natural way. K-expand is one of such killing features (We will see more in the coming tasks 😉)

The k-expand we are talking about here is the same thing as the Neo4J's expand operation shown below:

page 5

For example, this is a 1-degree (k = 1) expand on "nÀmlich":

[!TIP]

The semantics of the graph below is on German language. It says:

The German word "nÀmlich" has 3 dictionary meanings: same, namely, because

page 6

This is a 2-degrees (k = 2) expand on "nÀmlich":

[!TIP]

  • There is another German word "denn" that can also mean "because" and "Dasselbe" also means "same"
  • Because the database does not found a asynomy for "nĂ€mlich" on "namely", we see no further expansion on the "namely" node

page 8

You get the idea.

The endpoint should be able to allow us to query any graph node with an arbitrary number of expansion. Note that a node expands to another node as long as there is at least one relationship between the two nodes (ignoring relationship direction, type, values, or whatever)

[!IMPORTANT]

What is the range of k?

In some application domain, such as social network, k is pretty small. But we are going beyond that for sure. The precise range is hard to estimate at this moment, but in our database, we have a max k of 6 ~ 10 with each node expands to 3 ~ 5 neighboring nodes.

That being said, having a k of 10,000 is very unlikely, but few 10s~ would be the most probable in the future.

Viewing Our Production Data in Docker

In addition, I've made a Docker image that allows us to see our production data through Neo4J browser. Follow the steps below to see what our production data looks like:

  1. Pull the image and start container:

    docker run \
       --publish=7474:7474 \
       --publish=7687:7687 \
       --env=NEO4J_AUTH=none \
       --env=NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
       -e NEO4JLABS_PLUGINS=\[\"apoc\"\] \
       jack20191124/wilhelm-vocabulary
  2. When container starts, access neo4j through browser at http://localhost:7474

  3. Connect to the database:

    • Both bolt:// and neo4j:// protocols are fine.
    • Choose No authentication for Authentication type
    • Then hit Connect as shown below

    neo4j-docker-connect

We are good to go. We can read and write however we want. For example, here is the k-expand (unlimited k) query that expands "nÀmlich":

MATCH (term:Term{name:'nÀmlich'})
CALL apoc.path.expand(term, "RELATED|DEFINITION", null, 1, -1)
YIELD path
RETURN path, length(path) AS hops
ORDER BY hops;

We should be seeing some graph similar to the following:

german-greek-latin