Knowledge Graph Export Recipes¶
Advanced Tutorial
Duration: 30-40 minutes | Level: Advanced | Prerequisites: Knowledge Graphs tutorial
Step-by-step recipes for exporting FCC knowledge graphs in OWL, RDF Turtle, SKOS, and JSON-LD formats.
Prerequisites¶
Recipe 1: RDF Turtle Export¶
Turtle is the most human-readable RDF format, ideal for reviewing graph structure.
from fcc._resources import get_personas_dir
from fcc.personas.registry import PersonaRegistry
from fcc.knowledge.builders import build_full_fcc_graph
from fcc.knowledge.exporters import export_graph
from fcc.knowledge.schema import default_ontology
# Build the graph
registry = PersonaRegistry.from_yaml_directory(get_personas_dir())
graph = build_full_fcc_graph(persona_registry=registry)
# Export as Turtle
export_graph(graph, "fcc_knowledge.ttl", format="turtle", ontology=default_ontology())
print(f"Exported {graph.node_count} nodes, {graph.edge_count} edges to Turtle")
Sample Output¶
@prefix fcc: <https://fcc.example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
fcc:persona/RC a fcc:Persona ;
fcc:label "Research Crafter" ;
fcc:category "core" ;
fcc:fcc_phase "find" .
Recipe 2: JSON-LD Export¶
JSON-LD is ideal for web applications and API responses.
Sample Output¶
{
"@context": {
"fcc": "https://fcc.example.org/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@graph": [
{
"@id": "fcc:persona/RC",
"@type": "fcc:Persona",
"fcc:label": "Research Crafter"
}
]
}
Recipe 3: SKOS Export¶
SKOS (Simple Knowledge Organization System) is ideal for taxonomy and vocabulary alignment.
When to Use SKOS¶
- Aligning FCC personas with external taxonomies
- Publishing persona hierarchies as linked data
- Integration with library/knowledge management systems
Recipe 4: N-Triples Export¶
N-Triples is the simplest RDF format — one triple per line, ideal for streaming and bulk loading.
Recipe 5: Selective Export (Subgraph)¶
Export only a subset of the graph.
from fcc.knowledge.models import NodeType
# Get only persona and category nodes
persona_nodes = {n.node_id for n in graph.nodes_by_type(NodeType.PERSONA)}
category_nodes = {n.node_id for n in graph.nodes_by_type(NodeType.CATEGORY)}
subgraph = graph.subgraph(persona_nodes | category_nodes)
export_graph(subgraph, "fcc_personas_only.ttl", format="turtle")
print(f"Exported subgraph: {subgraph.node_count} nodes, {subgraph.edge_count} edges")
Recipe 6: Federation Export¶
Export federated graphs with cross-namespace links.
from fcc.knowledge.federation import FederatedKnowledgeGraph
federated = FederatedKnowledgeGraph()
federated.register_local(graph)
# Merge and export
merged = federated.merge_federated()
export_graph(merged, "fcc_federated.ttl", format="turtle")
Format Comparison¶
| Format | Human-Readable | File Size | Web-Friendly | Streaming |
|---|---|---|---|---|
| Turtle | Excellent | Medium | No | No |
| JSON-LD | Good | Large | Yes | No |
| SKOS | Good | Medium | No | No |
| N-Triples | Poor | Large | No | Yes |