# Knowledge management with neo4j

The aim of this page is to create a knowledge management software using the graph database neo4j (and its query language Cypher).
The approach is object-orientated, i.e. the nodes are classes and instances.
Class nodes are violet. Instance nodes are brown. Subclass arrows are red. Instance arrows are gray.
Knowledge is represented by questions and answers. Questions come from classes, and they are shown in blue. Answers typically come from instances, and they are shown in green.

## Q&A as edges

Here questions and answers are modeled as relationships, i.e. they are shown as arrows between between nodes.
The direction of these arrows is not important. They start, where the question is more likely to be asked:
* "Who is responsible for this car?" (rather than "For which cars is this person responsible?")
* "To which country does this city belong?" (rather than "Which cities belong to this country?")
One problem with Q&A as edges is, that the connection between them is flimsy. (See this question in the neo4j forum.)

### car, person

There are two questions, that connect the classes car and person:
* Who is responsible for the car? There must be two people responsible for each car. One person can be responsible for up to five cars.
* Who is the driver? There might be no driver. If there is one, it must be exactly one person, who drives exactly one car.
The cardinalities are not yet part of the code. The aim is, that the software will highlight unanswered questions for a given node. If the question "Who is responsible for Dodge?" were answered only by "Alice", the question for a second responsible person would still be highlighted. (The question for the driver would be shown less prominently, because a driver is not required.)
diagram :

### city, country, sea

All questions are asked by classes, and all answers are given by instances.
diagram :
Now the class French port city is introduced. It answers the question asked by city. The instances inherit the answer.
diagram :

#### queries

questions :
answers :

## Q&A as nodes

The Q&A are reified into nodes. This allows an explicit relationship between them, shown by yellow arrows. This will also allow questions connected to more than two classes – or to only one.

### city, country, sea

questions only :
questions and answers :
And here the subclass French port city is added:
As above, the queries show the Q&A for Marseille:

### car, person

In this example the cardninalities are added to the code.
The query for the questions contains the cardinalities. (That for the answers has not changed.)
answers :
| Dodge | Alice or Bob | Chris |
| ╒═════════════════════╤════════════╕ │questNode.name │farNode.name│ ╞═════════════════════╪════════════╡ │"responsible for car"│"Alice" │ ├─────────────────────┼────────────┤ │"responsible for car"│"Bob" │ ├─────────────────────┼────────────┤ │"driver of car" │"Chris" │ └─────────────────────┴────────────┘ | ╒═════════════════════╤════════════╕ │questNode.name │farNode.name│ ╞═════════════════════╪════════════╡ │"responsible for car"│"Dodge" │ └─────────────────────┴────────────┘ | ╒═══════════════╤════════════╕ │questNode.name │farNode.name│ ╞═══════════════╪════════════╡ │"driver of car"│"Dodge" │ └───────────────┴────────────┘ |