File size: 4,516 Bytes
fb9a4be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Scripts

Load the Eedi Misconceptions Graph into a graph database in one command.

| Script | What it does | Needs |
| --- | --- | --- |
| `csv_to_jsonl.py` | Converts the two CSVs into property-graph JSONL (`nodes.jsonl`, `relationships.jsonl`) | Python 3.8+ only |
| `load_eedi_graph.py` | Loads the JSONL into Neo4j (local or Aura); builds the JSONL first with `--download` | `pip install neo4j python-dotenv`, Neo4j 5+ |

## Quick start

```bash
pip install neo4j python-dotenv
python scripts/load_eedi_graph.py --download
```

The CSVs are read from `data/` if you've cloned this repo. Otherwise they're downloaded from the `v1.0` release (pick a revision with `--tag`). You can also download just the two scripts and run them on their own.

## Connecting to Neo4j

Copy `.env.example` to `.env` and fill in your details. Credentials are read from environment variables, or from the nearest `.env` file in the script's folder or any folder above it (failing that, the folder you run it from, or above):

```bash
NEO4J_URI=bolt://localhost:7687      # or neo4j+s://xxxx.databases.neo4j.io for Aura
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=...
NEO4J_DATABASE_EEDI=eedi-v1          # optional; this is the default
```

To keep several instances in one `.env`, add a suffix, e.g. `NEO4J_URI_LOCAL`, `NEO4J_PASSWORD_LOCAL`, and choose with `--target LOCAL`. When more than one is configured, the script refuses to guess.

The database is created if it doesn't exist. This needs Neo4j Enterprise, which Neo4j Desktop includes. Aura (including the free tier) and Community edition have a single database, so pass `--database neo4j` to load into it. The graph fits comfortably within Aura Free's limits.

## Useful options

| Option | Effect |
| --- | --- |
| `--download` | (Re)build the JSONL from the CSVs before loading |
| `--target NAME` | Use the `NEO4J_*_NAME` variables |
| `--database NAME` | Load into this database (default `eedi-v1`) |
| `--wipe` | Delete everything in the database first |
| `--allow-nonempty` | Merge into a database that already has data |
| `--no-derived` | Skip the derived count properties |

By default the loader refuses to write to a database that already contains data.

## Graph model

```
(:Subject)-[:SUBJECT_CONTAINS_TOPIC]->(:Topic)-[:TOPIC_CONTAINS_SUBTOPIC]->(:SubTopic)
(:SubTopic)-[:SUBTOPIC_CONTAINS_CONSTRUCT]->(:Construct)
(:Construct)-[:CONSTRUCT_HAS_MISCONCEPTION {percentage}]->(:Misconception)
```

| Label | Node id | Properties |
| --- | --- | --- |
| `Subject` | `eedi:subject:32` | `subjectSubjectId`, `name` |
| `Topic` | `eedi:topic:144` | `topicSubjectId`, `name` |
| `SubTopic` | `eedi:subtopic:202` | `subTopicSubjectId`, `name` |
| `Construct` | `eedi:construct:27` | `constructId`, `name`, `misconceptionCount`\* |
| `Misconception` | `eedi:misconception:13708` | `misconceptionId`, `name`, `constructCount`\*, `subTopicCount`\*, `topicCount`\*, `subjectCount`\* |

\* Computed by the loader, not present in the CSVs.

- **Field definitions:** properties are the CSV columns in camelCase (`ConstructId` → `constructId`, `ConstructName` → `name`). See [`docs/data-dictionary.md`](../docs/data-dictionary.md) for what each field means.
- **Node ids include the type.** Construct ids overlap with Subject/Topic/SubTopic ids, so the type prefix keeps every id unique. In Neo4j the id is stored as `uri`, and every node also has the label `EediNode`.
- **`percentage`** is `PercentageMisconceptionExistsInThisConstruct`: the share of a misconception's taggings that fall in that construct. It sums to 100 per misconception.
- **Full-text search** on names: `CALL db.index.fulltext.queryNodes('eedi_text', 'place value')`.

Version 1.0 loads 10,665 nodes and 21,838 relationships, and the loader checks these counts when it finishes.

## Example queries

Misconceptions that appear in all four subjects:

```cypher
MATCH (m:Misconception) WHERE m.subjectCount = 4
RETURN m.name, m.topicCount ORDER BY m.topicCount DESC
```

Where a misconception shows up:

```cypher
MATCH (m:Misconception {misconceptionId: 13708})<-[r:CONSTRUCT_HAS_MISCONCEPTION]-(c:Construct)
      <-[:SUBTOPIC_CONTAINS_CONSTRUCT]-(st:SubTopic)
RETURN st.name, c.name, r.percentage ORDER BY r.percentage DESC
```

## Licence

The data is CC BY 4.0. See the [main README](../README.md#licence) for attribution. The JSONL is a format conversion of the CSVs, so the same licence and attribution apply.

The scripts themselves are licensed under the MIT Licence (see [`LICENSE`](LICENSE)).