Import / Export

The knowledgespaces.io module reads and writes CSV and JSON files compatible with existing KST tools and R packages.

CSV formats

Skill map matrix

,skill1,skill2,skill3
item1,1,0,1
item2,0,1,0
from knowledgespaces.io import read_skill_map, write_skill_map

sm = read_skill_map("skill_map_matrix.csv")
write_skill_map(sm, "output_skill_map.csv")

Prerequisite matrix

,item_a,item_b,item_c
item_a,0,1,0
item_b,0,0,1
item_c,0,0,0

Row i, column j = 1 means item i is a prerequisite of item j.

from knowledgespaces.io import read_relation, write_relation

rel = read_relation("prerequisites_matrix.csv")
write_relation(rel, "output_prerequisites.csv")

Knowledge structure

state_size,state_id,item_a,item_b,item_c
0,0,0,0,0
1,1,1,0,0
2,2,1,1,0
3,3,1,1,1
from knowledgespaces.io import read_structure, write_structure

ks = read_structure("learning_space.csv")
write_structure(ks, "output_structure.csv")

JSON

JSON provides full serialization including structural properties:

from knowledgespaces.io import write_structure_json, read_structure_json

write_structure_json(ks, "structure.json")
loaded = read_structure_json("structure.json")

All types are supported: KnowledgeStructure, SurmiseRelation, SkillMap.

Validation

All readers validate input strictly:

  • Column counts must match headers

  • Values must be binary (0 or 1)

  • Labels must be unique (no duplicate headers or rows)

  • Prerequisite matrices must have matching row and column labels

  • JSON schemas are validated with clear error messages