@@ -159,65 +159,79 @@ from hyperdb import HypergraphDB
159
159
hg = HypergraphDB()
160
160
161
161
# Add vertices
162
- hg.add_v(1 , {" name" : " Alice" })
163
- hg.add_v(2 , {" name" : " Bob" })
164
- hg.add_v(3 , {" name" : " Charlie" })
162
+ hg.add_v(1 , {" name" : " Alice" , " age" : 30 , " city" : " New York" })
163
+ hg.add_v(2 , {" name" : " Bob" , " age" : 24 , " city" : " Los Angeles" })
164
+ hg.add_v(3 , {" name" : " Charlie" , " age" : 28 , " city" : " Chicago" })
165
+ hg.add_v(4 , {" name" : " David" , " age" : 35 , " city" : " Miami" })
166
+ hg.add_v(5 , {" name" : " Eve" , " age" : 22 , " city" : " Seattle" })
167
+ hg.add_v(6 , {" name" : " Frank" , " age" : 29 , " city" : " Houston" })
168
+ hg.add_v(7 , {" name" : " Grace" , " age" : 31 , " city" : " Phoenix" })
169
+ hg.add_v(8 , {" name" : " Heidi" , " age" : 27 , " city" : " San Francisco" })
170
+ hg.add_v(9 , {" name" : " Ivan" , " age" : 23 , " city" : " Denver" })
171
+ hg.add_v(10 , {" name" : " Judy" , " age" : 26 , " city" : " Boston" })
165
172
166
173
# Add hyperedges
167
- hg.add_e((1 , 2 ), {" relation" : " knows" })
168
- hg.add_e((1 , 3 , 2 ), {" relation" : " collaborates" })
174
+ hg.add_e((1 , 2 , 3 ), {" type" : " friendship" , " duration" : " 5 years" })
175
+ hg.add_e((1 , 4 ), {" type" : " mentorship" , " topic" : " career advice" })
176
+ hg.add_e((2 , 5 , 6 ), {" type" : " collaboration" , " project" : " AI Research" })
177
+ hg.add_e((4 , 5 , 7 , 9 ), {" type" : " team" , " goal" : " community service" })
178
+ hg.add_e((3 , 8 ), {" type" : " partnership" , " status" : " ongoing" })
179
+ hg.add_e((9 , 10 ), {" type" : " neighbors" , " relationship" : " friendly" })
180
+ hg.add_e((1 , 2 , 3 , 7 ), {" type" : " collaboration" , " field" : " music" })
181
+ hg.add_e((2 , 6 , 9 ), {" type" : " classmates" , " course" : " Data Science" })
169
182
```
170
183
171
184
#### ** 2. Query Vertices and Hyperedges**
172
185
173
186
``` python
174
187
# Get all vertices and hyperedges
175
- print (hg.all_v) # Output: {1, 2, 3}
176
- print (hg.all_e) # Output: {(1, 2), (1, 2, 3)}
188
+ print (hg.all_v) # Output: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
189
+ print (hg.all_e) # Output: {(4, 5, 7, 9), (9, 10), (3, 8), ( 1, 2, 3 ), (2, 6, 9), ( 1, 4), (1, 2, 3, 7), (2, 5, 6 )}
177
190
178
191
# Query a specific vertex
179
- print (hg.v(1 )) # Output: {'name': 'Alice'}
192
+ print (hg.v(1 )) # Output: {'name': 'Alice', 'age': 30, 'city': 'New York' }
180
193
181
194
# Query a specific hyperedge
182
- print (hg.e((1 , 2 ))) # Output: {'relation ': 'knows '}
195
+ print (hg.e((1 , 2 , 3 ))) # Output: {'type ': 'friendship', 'duration': '5 years '}
183
196
```
184
197
185
198
#### ** 3. Update and Remove Vertices/Hyperedges**
186
199
187
200
``` python
188
201
# Update a vertex
189
- hg.update_v(1 , {" name" : " Alice Smith" })
190
- print (hg.v(1 )) # Output: {'name': 'Alice Smith'}
202
+ hg.update_v(1 , {" name" : " Smith" })
203
+ print (hg.v(1 )) # Output: {'name': 'Smith', 'age': 30, 'city': 'New York '}
191
204
192
205
# Remove a vertex
193
- hg.remove_v(2 )
194
- print (hg.all_v) # Output: {1, 3 }
195
- print (hg.all_e) # Output: {(1, 3 )}
206
+ hg.remove_v(3 )
207
+ print (hg.all_v) # Output: {1, 2, 4, 5, 6, 7, 8, 9, 10 }
208
+ print (hg.all_e) # Output: {(4, 5, 7, 9), (9, 10), ( 1, 2, 7), (1, 2), (2, 6, 9), (1, 4), (2, 5, 6 )}
196
209
197
210
# Remove a hyperedge
198
- hg.remove_e((1 , 3 ))
199
- print (hg.all_e) # Output: set()
211
+ hg.remove_e((1 , 4 ))
212
+ print (hg.all_e) # Output: {(4, 5, 7, 9), (9, 10), (1, 2, 7), (1, 2), (2, 6, 9), (2, 5, 6)}
200
213
```
201
214
202
215
#### ** 4. Calculate Degrees**
203
216
204
217
``` python
205
218
# Get the degree of a vertex
206
- print (hg.degree_v(1 )) # Output: 1
219
+ print (hg.degree_v(1 )) # Example Output: 2
207
220
208
221
# Get the degree of a hyperedge
209
- print (hg.degree_e((1 , 2 ))) # Output: 2
222
+ print (hg.degree_e((2 , 5 , 6 ))) # Example Output: 3
210
223
```
211
224
212
225
#### ** 5. Neighbor Queries**
213
226
214
227
``` python
215
228
# Get neighbors of a vertex
216
- hg.add_e((1 , 3 , 4 ), {" relation" : " team" })
217
- print (hg.nbr_v(1 )) # Output: {3, 4}
229
+ print (hg.nbr_v(1 )) # Example Output: {2, 7}
230
+ hg.add_e((1 , 4 , 6 ), {" relation" : " team" })
231
+ print (hg.nbr_v(1 )) # Example Output: {2, 4, 6, 7}
218
232
219
233
# Get incident hyperedges of a vertex
220
- print (hg.nbr_e_of_v(1 )) # Output: {(1, 3, 4 )}
234
+ print (hg.nbr_e_of_v(1 )) # Example Output: {(1, 2, 7), (1, 2), (1, 4, 6 )}
221
235
```
222
236
223
237
#### ** 6. Persistence (Save and Load)**
@@ -228,8 +242,8 @@ hg.save("my_hypergraph.hgdb")
228
242
229
243
# Load the hypergraph from a file
230
244
hg2 = HypergraphDB(storage_file = " my_hypergraph.hgdb" )
231
- print (hg2.all_v) # Output: {1, 3 , 4}
232
- print (hg2.all_e) # Output: {(1, 3, 4 )}
245
+ print (hg2.all_v) # Output: {1, 2 , 4, 5, 6, 7, 8, 9, 10 }
246
+ print (hg2.all_e) # Output: {(4, 5, 7, 9), (9, 10), ( 1, 2, 7), (1, 2), (2, 6, 9), (1, 4, 6), (2, 5, 6 )}
233
247
```
234
248
235
249
0 commit comments