-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
143 lines (132 loc) · 5.05 KB
/
Copy pathtest_setup.py
File metadata and controls
143 lines (132 loc) · 5.05 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""Simple script to add test documents to the knowledge graph for Swift app testing."""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'kg'))
from kg.graph_store import KnowledgeGraphStore
from kg.embeddings import EmbeddingManager
def add_test_documents():
"""Add test documents to the knowledge graph."""
# Initialize components
storage_path = os.path.expanduser("~/.mr_kg_data")
graph_store = KnowledgeGraphStore(storage_path=storage_path)
embedding_manager = EmbeddingManager()
# Test documents data
test_docs = [
{
"name": "John Smith",
"type": "Person",
"description": "Lead developer and consultant who works with Google, Microsoft, and Acme Corporation",
"properties": {
"email": "john.smith@consulting.com",
"phone": "(555) 123-4567",
"role": "Lead Developer"
}
},
{
"name": "Google Inc.",
"type": "Organization",
"description": "Technology company that received AI-Powered Analytics Platform Development proposal",
"properties": {
"industry": "Technology",
"project": "AI-Powered Analytics Platform"
}
},
{
"name": "Microsoft Corporation",
"type": "Organization",
"description": "Technology company that hired John Smith for cloud migration consulting",
"properties": {
"industry": "Technology",
"project": "Cloud Migration"
}
},
{
"name": "Acme Corporation",
"type": "Organization",
"description": "Client company that hired John Smith for e-commerce platform redesign",
"properties": {
"industry": "E-commerce",
"project": "E-commerce Platform Redesign"
}
},
{
"name": "AI-Powered Analytics Platform",
"type": "Project",
"description": "Machine learning platform for Google's internal data analysis needs",
"properties": {
"budget": "$250,000",
"duration": "16 weeks",
"client": "Google Inc."
}
},
{
"name": "Cloud Migration Project",
"type": "Project",
"description": "Software architecture consulting for Microsoft's cloud migration",
"properties": {
"budget": "$96,000",
"duration": "3 months",
"client": "Microsoft Corporation"
}
},
{
"name": "E-commerce Platform Redesign",
"type": "Project",
"description": "Web development services for Acme's e-commerce platform redesign",
"properties": {
"budget": "$75,000",
"duration": "6 months",
"client": "Acme Corporation"
}
}
]
# Add entities
for doc in test_docs:
success = graph_store.add_entity(
name=doc["name"],
entity_type=doc["type"],
properties=doc.get("properties", {}),
description=doc["description"]
)
if success:
print(f"✅ Added: {doc['name']} ({doc['type']})")
# Add embedding for search
embedding_manager.add_entity_embedding(doc["name"], doc["description"])
else:
print(f"❌ Failed to add: {doc['name']}")
# Add relationships
relationships = [
("John Smith", "works_for", "Google Inc."),
("John Smith", "works_for", "Microsoft Corporation"),
("John Smith", "works_for", "Acme Corporation"),
("John Smith", "leads", "AI-Powered Analytics Platform"),
("John Smith", "consults_on", "Cloud Migration Project"),
("John Smith", "develops", "E-commerce Platform Redesign"),
("AI-Powered Analytics Platform", "for", "Google Inc."),
("Cloud Migration Project", "for", "Microsoft Corporation"),
("E-commerce Platform Redesign", "for", "Acme Corporation")
]
for source, rel_type, target in relationships:
success = graph_store.add_relationship(
from_entity=source,
to_entity=target,
relation_type=rel_type,
properties={},
weight=1.0
)
if success:
print(f"✅ Added relationship: {source} --{rel_type}--> {target}")
else:
print(f"❌ Failed to add relationship: {source} --{rel_type}--> {target}")
# Save changes
graph_store.save()
embedding_manager.save()
# Show statistics
stats = graph_store.get_statistics()
print(f"\n📊 Knowledge Graph Statistics:")
print(f" Entities: {stats.get('num_entities', 0)}")
print(f" Relationships: {stats.get('num_relationships', 0)}")
print(f"\n✅ Test data added successfully!")
if __name__ == "__main__":
add_test_documents()