|
1 | 1 | # knowledge_dictionary |
2 | | -A python dictionary template for storing serialisable metadata |
| 2 | + |
| 3 | +A Python dictionary template for storing serializable metadata. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Install from source: |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install -e . |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### Using Templates |
| 16 | + |
| 17 | +Import and use predefined dictionary templates: |
| 18 | + |
| 19 | +```python |
| 20 | +from knowledge_dictionary import KNOWLEDGE_TEMPLATE, MINIMAL_TEMPLATE, EXTENDED_TEMPLATE |
| 21 | + |
| 22 | +# Use a template directly |
| 23 | +my_data = KNOWLEDGE_TEMPLATE.copy() |
| 24 | +my_data['metadata']['author'] = 'John Doe' |
| 25 | +my_data['content']['title'] = 'My Knowledge' |
| 26 | +``` |
| 27 | + |
| 28 | +### Using KnowledgeDict Class |
| 29 | + |
| 30 | +Work with knowledge dictionaries using the KnowledgeDict class: |
| 31 | + |
| 32 | +```python |
| 33 | +from knowledge_dictionary import KnowledgeDict |
| 34 | + |
| 35 | +# Create a new knowledge dictionary |
| 36 | +kd = KnowledgeDict(template="knowledge") |
| 37 | + |
| 38 | +# Set values using dot notation |
| 39 | +kd.set("metadata.author", "John Doe") |
| 40 | +kd.set("content.title", "My Knowledge") |
| 41 | +kd.set("content.description", "A collection of important information") |
| 42 | + |
| 43 | +# Get values |
| 44 | +author = kd.get("metadata.author") |
| 45 | +title = kd.get("content.title") |
| 46 | + |
| 47 | +# Convert to standard dictionary |
| 48 | +data = kd.to_dict() |
| 49 | + |
| 50 | +# Serialize to JSON |
| 51 | +json_str = kd.to_json(indent=2) |
| 52 | + |
| 53 | +# Save to file |
| 54 | +kd.save("my_knowledge.json") |
| 55 | + |
| 56 | +# Load from file |
| 57 | +kd_loaded = KnowledgeDict.load("my_knowledge.json") |
| 58 | +``` |
| 59 | + |
| 60 | +## Available Templates |
| 61 | + |
| 62 | +- **KNOWLEDGE_TEMPLATE**: Standard template with metadata, content, and schema sections |
| 63 | +- **MINIMAL_TEMPLATE**: Minimal template with just title, description, and data |
| 64 | +- **EXTENDED_TEMPLATE**: Extended template with additional provenance tracking |
| 65 | + |
| 66 | +## License |
| 67 | + |
| 68 | +MIT License |
0 commit comments