File size: 228,632 Bytes
f7ab812
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "import getpass\n",
    "import os\n",
    "from langchain_community.graphs import Neo4jGraph\n",
    "from graphdatascience import GraphDataScience\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_core.output_parsers import StrOutputParser\n",
    "#from src.llm import get_llm\n",
    "\n",
    "import os\n",
    "import getpass\n",
    "from neo4j import GraphDatabase, Result\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import tiktoken\n",
    "import numpy as np\n",
    "from langchain_openai import OpenAIEmbeddings, ChatOpenAI\n",
    "from langchain_community.vectorstores import Neo4jVector\n",
    "from langchain_community.graphs import Neo4jGraph\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_core.output_parsers import StrOutputParser\n",
    "# from llama_index.core.schema import TextNode\n",
    "# from llama_index.core.vector_stores.utils import node_to_metadata_dict\n",
    "# from llama_index.vector_stores.neo4jvector import Neo4jVectorStore\n",
    "# from llama_index.core import VectorStoreIndex\n",
    "from tqdm import tqdm\n",
    "#from src.shared.common_fn import load_embedding_model\n",
    "\n",
    "import dotenv\n",
    "from typing import Dict, Any\n",
    "from concurrent.futures import ThreadPoolExecutor, as_completed\n",
    "from tqdm import tqdm\n",
    "#from src.llm import get_llm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "def env_parse(file):\n",
    "    credentials = {}\n",
    "    with open(file, 'r') as f:\n",
    "        for line in f:\n",
    "            if line[0] == '#':\n",
    "                continue\n",
    "            line = line.split('=')\n",
    "            credentials[line[0]] = line[1].strip()\n",
    "    return credentials\n",
    "credentials = env_parse('Neo4j-f34533c1-Created-2024-11-18.txt')\n",
    "url = credentials['NEO4J_URI']\n",
    "username = credentials['NEO4J_USERNAME']\n",
    "password = credentials['NEO4J_PASSWORD']\n",
    "url = url.replace('neo4j+s://', 'neo4j+ssc://')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.environ[\"NEO4J_URI\"] = url\n",
    "os.environ[\"NEO4J_USERNAME\"] = username\n",
    "os.environ[\"NEO4J_PASSWORD\"] = password\n",
    "\n",
    "dotenv.load_dotenv('.env.example')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#0000]  _: <POOL> created, routing address IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#0000]  _: <WORKSPACE> resolve home database\n",
      "[#0000]  _: <POOL> attempting to update routing table from IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#0000]  _: <RESOLVE> in: f34533c1.databases.neo4j.io:7687\n",
      "[#0000]  _: <RESOLVE> dns resolver out: 35.241.237.34:7687\n",
      "[#0000]  _: <POOL> _acquire router connection, database=None, address=ResolvedIPv4Address(('35.241.237.34', 7687))\n",
      "[#0000]  _: <POOL> trying to hand out new connection\n",
      "[#0000]  C: <OPEN> 35.241.237.34:7687\n",
      "[#E075]  C: <SECURE> f34533c1.databases.neo4j.io\n",
      "[#E075]  C: <MAGIC> 0x6060B017\n",
      "[#E075]  C: <HANDSHAKE> 0x00070705 0x00020404 0x00000104 0x00000003\n",
      "[#E075]  S: <HANDSHAKE> 0x00000605\n",
      "[#E075]  C: HELLO {'user_agent': 'neo4j-graphdatascience-v1.12', 'routing': {'address': 'f34533c1.databases.neo4j.io:7687'}, 'bolt_agent': {'product': 'neo4j-python/5.26.0', 'platform': 'Darwin 23.6.0; arm64', 'language': 'Python/3.11.6-final-0', 'language_details': 'CPython; 3.11.6-final-0 (v3.11.6:8b6ee5ba3b, Oct  2 2023 11:18:21) [Clang 13.0.0 (clang-1300.0.29.30)]'}}\n",
      "[#E075]  _: <CONNECTION> client state: CONNECTED > AUTHENTICATION\n",
      "[#E075]  C: LOGON {'scheme': 'basic', 'principal': 'neo4j', 'credentials': '*******'}\n",
      "[#E075]  _: <CONNECTION> client state: AUTHENTICATION > READY\n",
      "[#E075]  S: SUCCESS {'server': 'Neo4j/5.25-aura', 'connection_id': 'bolt-62679', 'hints': {'connection.recv_timeout_seconds': 60, 'telemetry.enabled': True}}\n",
      "[#E075]  _: <CONNECTION> server state: CONNECTED > AUTHENTICATION\n",
      "[#E075]  S: SUCCESS {}\n",
      "[#E075]  _: <CONNECTION> server state: AUTHENTICATION > READY\n",
      "[#E075]  C: ROUTE {'address': 'f34533c1.databases.neo4j.io:7687'} () {}\n",
      "[#E075]  S: SUCCESS {'rt': {'servers': [{'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'WRITE'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'READ'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'ROUTE'}], 'ttl': 10, 'db': 'neo4j'}}\n",
      "[#E075]  _: <POOL> released bolt-62679\n",
      "[#0000]  _: <ROUTING> updated table=RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=773166.308083666, ttl=10)\n",
      "[#0000]  _: <POOL> update routing table from address=ResolvedIPv4Address(('35.241.237.34', 7687)) (RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=773166.308083666, ttl=10))\n",
      "[#0000]  _: <POOL> acquire routing connection, access_mode='READ', database='neo4j'\n",
      "[#0000]  _: <POOL> routing aged?, database=None\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=773166.163261125, ttl=0, perf_time=773166.308928333 => False\n",
      "[#0000]  _: <POOL> routing aged?, database=neo4j\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=773166.308083666, ttl=10, perf_time=773166.3093025 => False\n",
      "[#0000]  _: <ROUTING> checking table freshness (readonly=True): table expired=False, has_server_for_mode=True, table routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))} => True\n",
      "[#0000]  _: <POOL> using existing routing table RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=773166.308083666, ttl=10)\n",
      "[#0000]  _: <POOL> acquire address, database='neo4j' address=IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#0000]  _: <POOL> trying to hand out new connection\n",
      "[#0000]  _: <RESOLVE> in: f34533c1.databases.neo4j.io:7687\n",
      "[#0000]  _: <RESOLVE> dns resolver out: 35.241.237.34:7687\n",
      "[#0000]  C: <OPEN> 35.241.237.34:7687\n",
      "[#E076]  C: <SECURE> f34533c1.databases.neo4j.io\n",
      "[#E076]  C: <MAGIC> 0x6060B017\n",
      "[#E076]  C: <HANDSHAKE> 0x00070705 0x00020404 0x00000104 0x00000003\n",
      "[#E076]  S: <HANDSHAKE> 0x00000605\n",
      "[#E076]  C: HELLO {'user_agent': 'neo4j-graphdatascience-v1.12', 'routing': {'address': 'f34533c1.databases.neo4j.io:7687'}, 'bolt_agent': {'product': 'neo4j-python/5.26.0', 'platform': 'Darwin 23.6.0; arm64', 'language': 'Python/3.11.6-final-0', 'language_details': 'CPython; 3.11.6-final-0 (v3.11.6:8b6ee5ba3b, Oct  2 2023 11:18:21) [Clang 13.0.0 (clang-1300.0.29.30)]'}}\n",
      "[#E076]  _: <CONNECTION> client state: CONNECTED > AUTHENTICATION\n",
      "[#E076]  C: LOGON {'scheme': 'basic', 'principal': 'neo4j', 'credentials': '*******'}\n",
      "[#E076]  _: <CONNECTION> client state: AUTHENTICATION > READY\n",
      "[#E076]  S: SUCCESS {'server': 'Neo4j/5.25-aura', 'connection_id': 'bolt-62680', 'hints': {'connection.recv_timeout_seconds': 60, 'telemetry.enabled': True}}\n",
      "[#E076]  _: <CONNECTION> server state: CONNECTED > AUTHENTICATION\n",
      "[#E076]  S: SUCCESS {}\n",
      "[#E076]  _: <CONNECTION> server state: AUTHENTICATION > READY\n",
      "[#E076]  _: <POOL> released bolt-62680\n",
      "[#0000]  _: <WORKSPACE> resolve home database\n",
      "[#0000]  _: <POOL> attempting to update routing table from IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#0000]  _: <RESOLVE> in: f34533c1.databases.neo4j.io:7687\n",
      "[#0000]  _: <RESOLVE> dns resolver out: 35.241.237.34:7687\n",
      "[#0000]  _: <POOL> _acquire router connection, database=None, address=ResolvedIPv4Address(('35.241.237.34', 7687))\n",
      "[#E075]  _: <POOL> picked existing connection bolt-62679\n",
      "[#E075]  _: <POOL> checked re_auth auth=None updated=False force=False\n",
      "[#E075]  _: <POOL> handing out existing connection\n",
      "[#E075]  C: ROUTE {'address': 'f34533c1.databases.neo4j.io:7687'} () {}\n",
      "[#E075]  S: SUCCESS {'rt': {'servers': [{'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'WRITE'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'READ'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'ROUTE'}], 'ttl': 10, 'db': 'neo4j'}}\n",
      "[#E075]  _: <POOL> released bolt-62679\n",
      "[#0000]  _: <ROUTING> updated table=RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=773166.436566166, ttl=10)\n",
      "[#0000]  _: <POOL> update routing table from address=ResolvedIPv4Address(('35.241.237.34', 7687)) (RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=773166.436566166, ttl=10))\n",
      "[#0000]  _: <POOL> acquire routing connection, access_mode='WRITE', database='neo4j'\n",
      "[#0000]  _: <POOL> routing aged?, database=None\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=773166.163261125, ttl=0, perf_time=773166.437789833 => False\n",
      "[#0000]  _: <POOL> routing aged?, database=neo4j\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=773166.436566166, ttl=10, perf_time=773166.438235625 => False\n",
      "[#0000]  _: <ROUTING> checking table freshness (readonly=False): table expired=False, has_server_for_mode=True, table routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))} => True\n",
      "[#0000]  _: <POOL> using existing routing table RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=773166.436566166, ttl=10)\n",
      "[#0000]  _: <POOL> acquire address, database='neo4j' address=IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#E076]  _: <POOL> picked existing connection bolt-62680\n",
      "[#E076]  _: <POOL> checked re_auth auth=None updated=False force=False\n",
      "[#E076]  _: <POOL> handing out existing connection\n",
      "[#E076]  C: TELEMETRY 2  # (<TelemetryAPI.AUTO_COMMIT: 2>)\n",
      "[#E076]  C: RUN 'RETURN gds.version()' {} {'db': 'neo4j'}\n",
      "[#E076]  _: <CONNECTION> client state: READY > STREAMING\n",
      "[#E076]  C: PULL {'n': 1000}\n",
      "[#E076]  S: SUCCESS {}\n",
      "[#E076]  S: FAILURE {'code': 'Neo.ClientError.Statement.SyntaxError', 'message': 'Unknown function \\'gds.version\\' (line 1, column 8 (offset: 7))\\n\"RETURN gds.version()\"\\n        ^'}\n",
      "[#E076]  C: RESET\n",
      "[#E076]  _: <CONNECTION> client state: STREAMING > READY\n",
      "[#E076]  S: IGNORED\n",
      "[#E076]  S: SUCCESS {}\n",
      "[#E076]  _: <CONNECTION> server state: FAILED > READY\n",
      "[#E076]  _: <POOL> released bolt-62680\n",
      "[#0000]  _: <POOL> close\n",
      "[#E075]  C: GOODBYE\n",
      "[#E075]  C: <CLOSE>\n",
      "[#E076]  C: GOODBYE\n",
      "[#E076]  C: <CLOSE>\n"
     ]
    },
    {
     "ename": "GdsNotFound",
     "evalue": "The Graph Data Science library is not correctly installed on the Neo4j server.\n                    Please refer to https://neo4j.com/docs/graph-data-science/current/installation/.\n                    ",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mCypherSyntaxError\u001b[0m                         Traceback (most recent call last)",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphdatascience/query_runner/neo4j_query_runner.py:197\u001b[0m, in \u001b[0;36mNeo4jQueryRunner.server_version\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    196\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 197\u001b[0m     server_version_string \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_cypher\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mRETURN gds.version()\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcustom_error\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39msqueeze()\n\u001b[1;32m    198\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_server_version \u001b[38;5;241m=\u001b[39m ServerVersion\u001b[38;5;241m.\u001b[39mfrom_string(server_version_string)\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphdatascience/query_runner/neo4j_query_runner.py:126\u001b[0m, in \u001b[0;36mNeo4jQueryRunner.run_cypher\u001b[0;34m(self, query, params, database, custom_error)\u001b[0m\n\u001b[1;32m    125\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 126\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    128\u001b[0m \u001b[38;5;66;03m# Though pandas support may be experimental in the `neo4j` package, it should always\u001b[39;00m\n\u001b[1;32m    129\u001b[0m \u001b[38;5;66;03m# be supported in the `graphdatascience` package.\u001b[39;00m\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphdatascience/query_runner/neo4j_query_runner.py:121\u001b[0m, in \u001b[0;36mNeo4jQueryRunner.run_cypher\u001b[0;34m(self, query, params, database, custom_error)\u001b[0m\n\u001b[1;32m    120\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 121\u001b[0m     result \u001b[38;5;241m=\u001b[39m \u001b[43msession\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mquery\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    122\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/neo4j/_sync/work/session.py:327\u001b[0m, in \u001b[0;36mSession.run\u001b[0;34m(self, query, parameters, **kwargs)\u001b[0m\n\u001b[1;32m    326\u001b[0m parameters \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mdict\u001b[39m(parameters \u001b[38;5;129;01mor\u001b[39;00m {}, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m--> 327\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_auto_result\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_run\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    328\u001b[0m \u001b[43m    \u001b[49m\u001b[43mquery\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    329\u001b[0m \u001b[43m    \u001b[49m\u001b[43mparameters\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    330\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_config\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdatabase\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    331\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_config\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimpersonated_user\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    332\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_config\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdefault_access_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    333\u001b[0m \u001b[43m    \u001b[49m\u001b[43mbookmarks\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    334\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_config\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnotifications_min_severity\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    335\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_config\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnotifications_disabled_classifications\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    336\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    338\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_auto_result\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/neo4j/_sync/work/result.py:231\u001b[0m, in \u001b[0;36mResult._run\u001b[0;34m(self, query, parameters, db, imp_user, access_mode, bookmarks, notifications_min_severity, notifications_disabled_classifications)\u001b[0m\n\u001b[1;32m    230\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_connection\u001b[38;5;241m.\u001b[39msend_all()\n\u001b[0;32m--> 231\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_attach\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/neo4j/_sync/work/result.py:425\u001b[0m, in \u001b[0;36mResult._attach\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    424\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_attached \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m:\n\u001b[0;32m--> 425\u001b[0m     \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_connection\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfetch_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:184\u001b[0m, in \u001b[0;36mConnectionErrorHandler.__getattr__.<locals>.outer.<locals>.inner\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    183\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 184\u001b[0m     \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    185\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m (Neo4jError, ServiceUnavailable, SessionExpired) \u001b[38;5;28;01mas\u001b[39;00m exc:\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/neo4j/_sync/io/_bolt.py:994\u001b[0m, in \u001b[0;36mBolt.fetch_message\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    991\u001b[0m tag, fields \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minbox\u001b[38;5;241m.\u001b[39mpop(\n\u001b[1;32m    992\u001b[0m     hydration_hooks\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mresponses[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mhydration_hooks\n\u001b[1;32m    993\u001b[0m )\n\u001b[0;32m--> 994\u001b[0m res \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_process_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtag\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfields\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    995\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39midle_since \u001b[38;5;241m=\u001b[39m monotonic()\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/neo4j/_sync/io/_bolt5.py:496\u001b[0m, in \u001b[0;36mBolt5x0._process_message\u001b[0;34m(self, tag, fields)\u001b[0m\n\u001b[1;32m    495\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 496\u001b[0m     \u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mon_failure\u001b[49m\u001b[43m(\u001b[49m\u001b[43msummary_metadata\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    497\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m (ServiceUnavailable, DatabaseUnavailable):\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:254\u001b[0m, in \u001b[0;36mResponse.on_failure\u001b[0;34m(self, metadata)\u001b[0m\n\u001b[1;32m    253\u001b[0m Util\u001b[38;5;241m.\u001b[39mcallback(handler)\n\u001b[0;32m--> 254\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_hydrate_error(metadata)\n",
      "\u001b[0;31mCypherSyntaxError\u001b[0m: {code: Neo.ClientError.Statement.SyntaxError} {message: Unknown function 'gds.version' (line 1, column 8 (offset: 7))\n\"RETURN gds.version()\"\n        ^}",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mGdsNotFound\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[33], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m gds \u001b[38;5;241m=\u001b[39m \u001b[43mGraphDataScience\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m      2\u001b[0m \u001b[43m    \u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menviron\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mNEO4J_URI\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m      3\u001b[0m \u001b[43m    \u001b[49m\u001b[43mauth\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menviron\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mNEO4J_USERNAME\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menviron\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mNEO4J_PASSWORD\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m      4\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m      6\u001b[0m graph \u001b[38;5;241m=\u001b[39m Neo4jGraph() \n\u001b[1;32m      8\u001b[0m driver \u001b[38;5;241m=\u001b[39m GraphDatabase\u001b[38;5;241m.\u001b[39mdriver(os\u001b[38;5;241m.\u001b[39menviron[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNEO4J_URI\u001b[39m\u001b[38;5;124m\"\u001b[39m], auth\u001b[38;5;241m=\u001b[39m(os\u001b[38;5;241m.\u001b[39menviron[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNEO4J_USERNAME\u001b[39m\u001b[38;5;124m\"\u001b[39m], os\u001b[38;5;241m.\u001b[39menviron[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNEO4J_PASSWORD\u001b[39m\u001b[38;5;124m\"\u001b[39m]))\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphdatascience/graph_data_science.py:80\u001b[0m, in \u001b[0;36mGraphDataScience.__init__\u001b[0;34m(self, endpoint, auth, aura_ds, database, arrow, arrow_disable_server_verification, arrow_tls_root_certs, bookmarks, show_progress)\u001b[0m\n\u001b[1;32m     77\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m     78\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_query_runner \u001b[38;5;241m=\u001b[39m Neo4jQueryRunner\u001b[38;5;241m.\u001b[39mcreate(endpoint, auth, aura_ds, database, bookmarks, show_progress)\n\u001b[0;32m---> 80\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_server_version \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_query_runner\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mserver_version\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     82\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_server_version \u001b[38;5;241m<\u001b[39m ServerVersion\u001b[38;5;241m.\u001b[39mfrom_string(__min_server_version__):\n\u001b[1;32m     83\u001b[0m     warnings\u001b[38;5;241m.\u001b[39mwarn(\n\u001b[1;32m     84\u001b[0m         \u001b[38;5;167;01mDeprecationWarning\u001b[39;00m(\n\u001b[1;32m     85\u001b[0m             \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mClient does not support the given server version `\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_server_version\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m`.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     88\u001b[0m         )\n\u001b[1;32m     89\u001b[0m     )\n",
      "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphdatascience/query_runner/neo4j_query_runner.py:208\u001b[0m, in \u001b[0;36mNeo4jQueryRunner.server_version\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    204\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_driver\u001b[38;5;241m.\u001b[39mclose()\n\u001b[1;32m    205\u001b[0m     \u001b[38;5;66;03m# if isinstance(endpoint, str):\u001b[39;00m\n\u001b[1;32m    206\u001b[0m     \u001b[38;5;66;03m#    driver.close()\u001b[39;00m\n\u001b[0;32m--> 208\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m GdsNotFound(\n\u001b[1;32m    209\u001b[0m \u001b[38;5;250m        \u001b[39m\u001b[38;5;124;03m\"\"\"The Graph Data Science library is not correctly installed on the Neo4j server.\u001b[39;00m\n\u001b[1;32m    210\u001b[0m \u001b[38;5;124;03m        Please refer to https://neo4j.com/docs/graph-data-science/current/installation/.\u001b[39;00m\n\u001b[1;32m    211\u001b[0m \u001b[38;5;124;03m        \"\"\"\u001b[39;00m\n\u001b[1;32m    212\u001b[0m     )\n\u001b[1;32m    214\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m UnableToConnectError(e)\n",
      "\u001b[0;31mGdsNotFound\u001b[0m: The Graph Data Science library is not correctly installed on the Neo4j server.\n                    Please refer to https://neo4j.com/docs/graph-data-science/current/installation/.\n                    "
     ]
    }
   ],
   "source": [
    "gds = GraphDataScience(\n",
    "    os.environ[\"NEO4J_URI\"],\n",
    "    auth=(os.environ[\"NEO4J_USERNAME\"], os.environ[\"NEO4J_PASSWORD\"])\n",
    ")\n",
    "\n",
    "graph = Neo4jGraph() \n",
    "\n",
    "driver = GraphDatabase.driver(os.environ[\"NEO4J_URI\"], auth=(os.environ[\"NEO4J_USERNAME\"], os.environ[\"NEO4J_PASSWORD\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#0000]  _: <POOL> acquire routing connection, access_mode='WRITE', database='neo4j'\n",
      "[#0000]  _: <POOL> routing aged?, database=None\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=770809.556646708, ttl=0, perf_time=770815.468037708 => False\n",
      "[#0000]  _: <POOL> routing aged?, database=neo4j\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=770809.732773416, ttl=10, perf_time=770815.469153333 => False\n",
      "[#0000]  _: <ROUTING> checking table freshness (readonly=False): table expired=False, has_server_for_mode=True, table routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))} => True\n",
      "[#0000]  _: <POOL> using existing routing table RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=770809.732773416, ttl=10)\n",
      "[#0000]  _: <POOL> acquire address, database='neo4j' address=IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#E630]  _: <POOL> picked existing connection bolt-41724\n",
      "[#E630]  _: <POOL> checked re_auth auth=None updated=False force=False\n",
      "[#E630]  _: <POOL> handing out existing connection\n",
      "[#E630]  C: TELEMETRY 3  # (<TelemetryAPI.DRIVER: 3>)\n",
      "[#E630]  C: BEGIN {'db': 'neo4j', 'bookmarks': ['FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA=']}\n",
      "[#E630]  _: <CONNECTION> client state: READY > TX_READY_OR_TX_STREAMING\n",
      "[#E630]  C: RUN '\\nMATCH (n:`__Entity__`)\\nRETURN \"node\" AS type,\\n       count(*) AS total_count,\\n       count(n.description) AS non_null_descriptions\\nUNION ALL\\nMATCH (n)-[r:!MENTIONS]->()\\nRETURN \"relationship\" AS type,\\n       count(*) AS total_count,\\n       count(r.description) AS non_null_descriptions\\n' {} {}\n",
      "[#E630]  C: PULL {'n': 1000}\n",
      "[#E630]  S: SUCCESS {}\n",
      "[#E630]  S: SUCCESS {}\n",
      "[#E630]  _: <CONNECTION> server state: READY > TX_READY_OR_TX_STREAMING\n",
      "[#E630]  S: SUCCESS {'t_first': 86, 'fields': ['type', 'total_count', 'non_null_descriptions'], 'qid': 0}\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: SUCCESS {'statuses': [{'gql_status': '01G11', 'neo4j_code': 'Neo.ClientNotification.Statement.AggregationSkippedNull', 'status_description': 'warn: null value eliminated in set function', 'diagnostic_record': {'_classification': 'UNRECOGNIZED', '_severity': 'WARNING'}, 'description': 'null value eliminated in set function.', 'title': 'The query contains an aggregation function that skips null values.'}, {'gql_status': '00000', 'status_description': 'note: successful completion'}], 'type': 'r', 't_last': 9, 'db': 'neo4j'}\n",
      "[#E630]  C: COMMIT\n",
      "[#E630]  _: <CONNECTION> client state: TX_READY_OR_TX_STREAMING > READY\n",
      "[#E630]  S: SUCCESS {'bookmark': 'FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA='}\n",
      "[#E630]  _: <CONNECTION> server state: TX_READY_OR_TX_STREAMING > READY\n",
      "[#E630]  _: <POOL> released bolt-41724\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[{'type': 'node', 'total_count': 46, 'non_null_descriptions': 0},\n",
       " {'type': 'relationship', 'total_count': 732, 'non_null_descriptions': 0}]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.query(\"\"\"\n",
    "MATCH (n:`__Entity__`)\n",
    "RETURN \"node\" AS type,\n",
    "       count(*) AS total_count,\n",
    "       count(n.description) AS non_null_descriptions\n",
    "UNION ALL\n",
    "MATCH (n)-[r:!MENTIONS]->()\n",
    "RETURN \"relationship\" AS type,\n",
    "       count(*) AS total_count,\n",
    "       count(r.description) AS non_null_descriptions\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#0000]  _: <POOL> acquire routing connection, access_mode='WRITE', database='neo4j'\n",
      "[#0000]  _: <POOL> routing aged?, database=neo4j\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=770929.350779, ttl=10, perf_time=770942.773201291 => False\n",
      "[#0000]  _: <ROUTING> checking table freshness (readonly=False): table expired=True, has_server_for_mode=True, table routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))} => False\n",
      "[#0000]  _: <POOL> attempting to update routing table from IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#0000]  _: <RESOLVE> in: f34533c1.databases.neo4j.io:7687\n",
      "[#0000]  _: <RESOLVE> dns resolver out: 35.241.237.34:7687\n",
      "[#0000]  _: <POOL> _acquire router connection, database='neo4j', address=ResolvedIPv4Address(('35.241.237.34', 7687))\n",
      "[#E62F]  _: <POOL> picked existing connection bolt-41723\n",
      "[#E62F]  _: <POOL> checked re_auth auth=None updated=False force=False\n",
      "[#E62F]  _: <POOL> handing out existing connection\n",
      "[#E62F]  C: ROUTE {'address': 'f34533c1.databases.neo4j.io:7687'} ('FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA=',) {'db': 'neo4j'}\n",
      "[#E62F]  S: SUCCESS {'rt': {'servers': [{'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'WRITE'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'READ'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'ROUTE'}], 'ttl': 10, 'db': 'neo4j'}}\n",
      "[#E62F]  _: <POOL> released bolt-41723\n",
      "[#0000]  _: <ROUTING> updated table=RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=770942.789623125, ttl=10)\n",
      "[#0000]  _: <POOL> update routing table from address=ResolvedIPv4Address(('35.241.237.34', 7687)) (RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=770942.789623125, ttl=10))\n",
      "[#0000]  _: <POOL> acquire address, database='neo4j' address=IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#E630]  _: <POOL> picked existing connection bolt-41724\n",
      "[#E630]  _: <POOL> checked re_auth auth=None updated=False force=False\n",
      "[#E630]  _: <POOL> handing out existing connection\n",
      "[#E630]  C: TELEMETRY 3  # (<TelemetryAPI.DRIVER: 3>)\n",
      "[#E630]  C: BEGIN {'db': 'neo4j', 'bookmarks': ['FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA=']}\n",
      "[#E630]  _: <CONNECTION> client state: READY > TX_READY_OR_TX_STREAMING\n",
      "[#E630]  C: RUN '\\nCALL db.labels() YIELD label\\nRETURN label, count(*) AS count\\n' {} {}\n",
      "[#E630]  C: PULL {'n': 1000}\n",
      "[#E630]  S: SUCCESS {}\n",
      "[#E630]  S: SUCCESS {}\n",
      "[#E630]  _: <CONNECTION> server state: READY > TX_READY_OR_TX_STREAMING\n",
      "[#E630]  S: SUCCESS {'t_first': 22, 'fields': ['label', 'count'], 'qid': 0}\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: SUCCESS {'statuses': [{'gql_status': '00000', 'status_description': 'note: successful completion'}], 'type': 'r', 't_last': 1, 'db': 'neo4j'}\n",
      "[#E630]  C: COMMIT\n",
      "[#E630]  _: <CONNECTION> client state: TX_READY_OR_TX_STREAMING > READY\n",
      "[#E630]  S: SUCCESS {'bookmark': 'FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA='}\n",
      "[#E630]  _: <CONNECTION> server state: TX_READY_OR_TX_STREAMING > READY\n",
      "[#E630]  _: <POOL> released bolt-41724\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[{'label': 'TextNode', 'count': 1},\n",
       " {'label': 'vector', 'count': 1},\n",
       " {'label': 'Document', 'count': 1},\n",
       " {'label': 'Chunk', 'count': 1},\n",
       " {'label': '__Entity__', 'count': 1},\n",
       " {'label': 'Symptom', 'count': 1},\n",
       " {'label': 'Transmission', 'count': 1},\n",
       " {'label': 'Location', 'count': 1},\n",
       " {'label': 'Event', 'count': 1},\n",
       " {'label': 'Person', 'count': 1},\n",
       " {'label': 'Organization', 'count': 1},\n",
       " {'label': 'Disease', 'count': 1},\n",
       " {'label': 'Position', 'count': 1},\n",
       " {'label': 'Group', 'count': 1},\n",
       " {'label': 'Number', 'count': 1},\n",
       " {'label': 'Percentage', 'count': 1},\n",
       " {'label': 'Vaccination', 'count': 1},\n",
       " {'label': 'Statistic', 'count': 1},\n",
       " {'label': 'Vaccine', 'count': 1},\n",
       " {'label': 'Year', 'count': 1},\n",
       " {'label': 'Country', 'count': 1},\n",
       " {'label': 'Session', 'count': 1},\n",
       " {'label': 'Message', 'count': 1},\n",
       " {'label': 'Region', 'count': 1},\n",
       " {'label': 'Condition', 'count': 1},\n",
       " {'label': 'Program', 'count': 1},\n",
       " {'label': 'Network', 'count': 1},\n",
       " {'label': 'Initiative', 'count': 1},\n",
       " {'label': 'Concept', 'count': 1},\n",
       " {'label': 'Publication', 'count': 1},\n",
       " {'label': 'Resolution', 'count': 1},\n",
       " {'label': 'Study', 'count': 1},\n",
       " {'label': 'Disease_strain', 'count': 1},\n",
       " {'label': 'Action', 'count': 1},\n",
       " {'label': 'Demographic', 'count': 1},\n",
       " {'label': 'Complication', 'count': 1},\n",
       " {'label': 'Disease strain', 'count': 1},\n",
       " {'label': 'Medical intervention', 'count': 1},\n",
       " {'label': 'Virus', 'count': 1},\n",
       " {'label': 'Animal', 'count': 1},\n",
       " {'label': 'Node', 'count': 1},\n",
       " {'label': 'Entity', 'count': 1},\n",
       " {'label': 'Genomic_feature', 'count': 1},\n",
       " {'label': 'Activity', 'count': 1},\n",
       " {'label': 'Place', 'count': 1},\n",
       " {'label': 'Population', 'count': 1}]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.query(\"\"\"\n",
    "CALL db.labels() YIELD label\n",
    "RETURN label, count(*) AS count\n",
    "\"\"\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[#0000]  _: <POOL> acquire routing connection, access_mode='WRITE', database='neo4j'\n",
      "[#0000]  _: <POOL> routing aged?, database=neo4j\n",
      "[#0000]  _: <ROUTING> purge check: last_updated_time=770942.789623125, ttl=10, perf_time=770957.523592875 => False\n",
      "[#0000]  _: <ROUTING> checking table freshness (readonly=False): table expired=True, has_server_for_mode=True, table routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))} => False\n",
      "[#0000]  _: <POOL> attempting to update routing table from IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#0000]  _: <RESOLVE> in: f34533c1.databases.neo4j.io:7687\n",
      "[#0000]  _: <RESOLVE> dns resolver out: 35.241.237.34:7687\n",
      "[#0000]  _: <POOL> _acquire router connection, database='neo4j', address=ResolvedIPv4Address(('35.241.237.34', 7687))\n",
      "[#E62F]  _: <POOL> picked existing connection bolt-41723\n",
      "[#E62F]  _: <POOL> checked re_auth auth=None updated=False force=False\n",
      "[#E62F]  _: <POOL> handing out existing connection\n",
      "[#E62F]  C: ROUTE {'address': 'f34533c1.databases.neo4j.io:7687'} ('FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA=',) {'db': 'neo4j'}\n",
      "[#E62F]  S: SUCCESS {'rt': {'servers': [{'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'WRITE'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'READ'}, {'addresses': ['f34533c1.databases.neo4j.io:7687'], 'role': 'ROUTE'}], 'ttl': 10, 'db': 'neo4j'}}\n",
      "[#E62F]  _: <POOL> released bolt-41723\n",
      "[#0000]  _: <ROUTING> updated table=RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=770957.542428166, ttl=10)\n",
      "[#0000]  _: <POOL> update routing table from address=ResolvedIPv4Address(('35.241.237.34', 7687)) (RoutingTable(database='neo4j', routers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, readers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, writers={IPv4Address(('f34533c1.databases.neo4j.io', 7687))}, last_updated_time=770957.542428166, ttl=10))\n",
      "[#0000]  _: <POOL> acquire address, database='neo4j' address=IPv4Address(('f34533c1.databases.neo4j.io', 7687))\n",
      "[#E630]  _: <POOL> picked existing connection bolt-41724\n",
      "[#E630]  _: <POOL> checked re_auth auth=None updated=False force=False\n",
      "[#E630]  _: <POOL> handing out existing connection\n",
      "[#E630]  C: TELEMETRY 3  # (<TelemetryAPI.DRIVER: 3>)\n",
      "[#E630]  C: BEGIN {'db': 'neo4j', 'bookmarks': ['FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA=']}\n",
      "[#E630]  _: <CONNECTION> client state: READY > TX_READY_OR_TX_STREAMING\n",
      "[#E630]  C: RUN '\\nCALL db.relationshipTypes() YIELD relationshipType\\nRETURN relationshipType, count(*) AS count\\n' {} {}\n",
      "[#E630]  C: PULL {'n': 1000}\n",
      "[#E630]  S: SUCCESS {}\n",
      "[#E630]  S: SUCCESS {}\n",
      "[#E630]  _: <CONNECTION> server state: READY > TX_READY_OR_TX_STREAMING\n",
      "[#E630]  S: SUCCESS {'t_first': 20, 'fields': ['relationshipType', 'count'], 'qid': 0}\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: RECORD * 1\n",
      "[#E630]  S: SUCCESS {'statuses': [{'gql_status': '00000', 'status_description': 'note: successful completion'}], 'type': 'r', 't_last': 3, 'db': 'neo4j'}\n",
      "[#E630]  C: COMMIT\n",
      "[#E630]  _: <CONNECTION> client state: TX_READY_OR_TX_STREAMING > READY\n",
      "[#E630]  S: SUCCESS {'bookmark': 'FB:kcwQj/3vBULJSNqfgsCc8BWClckCBZA='}\n",
      "[#E630]  _: <CONNECTION> server state: TX_READY_OR_TX_STREAMING > READY\n",
      "[#E630]  _: <POOL> released bolt-41724\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[{'relationshipType': 'PART_OF', 'count': 1},\n",
       " {'relationshipType': 'FIRST_CHUNK', 'count': 1},\n",
       " {'relationshipType': 'NEXT_CHUNK', 'count': 1},\n",
       " {'relationshipType': 'SIMILAR', 'count': 1},\n",
       " {'relationshipType': 'MENTIONS', 'count': 1},\n",
       " {'relationshipType': 'REPORTED', 'count': 1},\n",
       " {'relationshipType': 'ACQUIRED', 'count': 1},\n",
       " {'relationshipType': 'TRAVELED_TO', 'count': 1},\n",
       " {'relationshipType': 'TREATED_IN', 'count': 1},\n",
       " {'relationshipType': 'ISOLATING_AT', 'count': 1},\n",
       " {'relationshipType': 'SPREADING_IN', 'count': 1},\n",
       " {'relationshipType': 'TRANSFERRED_THROUGH', 'count': 1},\n",
       " {'relationshipType': 'HAS_SYMPTOM', 'count': 1},\n",
       " {'relationshipType': 'DECLARED', 'count': 1},\n",
       " {'relationshipType': 'ENDEMIC_TO', 'count': 1},\n",
       " {'relationshipType': 'REPORTED_CASES', 'count': 1},\n",
       " {'relationshipType': 'ROLE', 'count': 1},\n",
       " {'relationshipType': 'CONFIRMED_CASES', 'count': 1},\n",
       " {'relationshipType': 'PREVENTS', 'count': 1},\n",
       " {'relationshipType': 'REQUESTED', 'count': 1},\n",
       " {'relationshipType': 'TARGET_YEAR', 'count': 1},\n",
       " {'relationshipType': 'FOCUS_REGION', 'count': 1},\n",
       " {'relationshipType': 'HAS_CASES', 'count': 1},\n",
       " {'relationshipType': 'HAS_DEATHS', 'count': 1},\n",
       " {'relationshipType': 'PERCENTAGE_OF_CASES', 'count': 1},\n",
       " {'relationshipType': 'PERCENTAGE_OF_DEATHS', 'count': 1},\n",
       " {'relationshipType': 'HAS_ENTITY', 'count': 1},\n",
       " {'relationshipType': 'LAST_MESSAGE', 'count': 1},\n",
       " {'relationshipType': 'NEXT', 'count': 1},\n",
       " {'relationshipType': 'REPORTEDCASE', 'count': 1},\n",
       " {'relationshipType': 'INFECTEDWITH', 'count': 1},\n",
       " {'relationshipType': 'ACQUIREDDISEASE', 'count': 1},\n",
       " {'relationshipType': 'TREATEDIN', 'count': 1},\n",
       " {'relationshipType': 'ISOLATINGIN', 'count': 1},\n",
       " {'relationshipType': 'SPREADINGSINCE', 'count': 1},\n",
       " {'relationshipType': 'DECLAREDGLOBALHEALTHEMERGENCY', 'count': 1},\n",
       " {'relationshipType': 'ENDEMICTO', 'count': 1},\n",
       " {'relationshipType': 'SPREADINGIN', 'count': 1},\n",
       " {'relationshipType': 'SPREADINGATLOWLEVELS', 'count': 1},\n",
       " {'relationshipType': 'REPORTEDINTRAVELERS', 'count': 1},\n",
       " {'relationshipType': 'HASCASES', 'count': 1},\n",
       " {'relationshipType': 'VACCINECALL', 'count': 1},\n",
       " {'relationshipType': 'CASES', 'count': 1},\n",
       " {'relationshipType': 'INCREASE', 'count': 1},\n",
       " {'relationshipType': 'ESTIMATION', 'count': 1},\n",
       " {'relationshipType': 'PREVENTION', 'count': 1},\n",
       " {'relationshipType': 'UNVACCINATEDCHILDREN', 'count': 1},\n",
       " {'relationshipType': 'FIRSTDOSECOVERAGE', 'count': 1},\n",
       " {'relationshipType': 'SECONDDOSECOVERAGE', 'count': 1},\n",
       " {'relationshipType': 'REQUIREDCOVERAGE', 'count': 1},\n",
       " {'relationshipType': 'STATEMENT', 'count': 1},\n",
       " {'relationshipType': 'DEATHS', 'count': 1},\n",
       " {'relationshipType': 'OUTBREAKS', 'count': 1},\n",
       " {'relationshipType': 'EPIDEMIC', 'count': 1},\n",
       " {'relationshipType': 'DEATHTOLL', 'count': 1},\n",
       " {'relationshipType': 'AFFECTEDGROUP', 'count': 1},\n",
       " {'relationshipType': 'HIGHRISKGROUP', 'count': 1},\n",
       " {'relationshipType': 'COMPLICATION', 'count': 1},\n",
       " {'relationshipType': 'THREATENS', 'count': 1},\n",
       " {'relationshipType': 'ELIMINATED', 'count': 1},\n",
       " {'relationshipType': 'FREEFROM', 'count': 1},\n",
       " {'relationshipType': 'OPERATES', 'count': 1},\n",
       " {'relationshipType': 'FOUNDED', 'count': 1},\n",
       " {'relationshipType': 'AIMSTOEND', 'count': 1},\n",
       " {'relationshipType': 'MEMBER', 'count': 1},\n",
       " {'relationshipType': 'FOLLOWSGUIDELINES', 'count': 1},\n",
       " {'relationshipType': 'FIGHTSAGAINST', 'count': 1},\n",
       " {'relationshipType': 'RESPONDSTO', 'count': 1},\n",
       " {'relationshipType': 'MEMBEROF', 'count': 1},\n",
       " {'relationshipType': 'DEFINEDBY', 'count': 1},\n",
       " {'relationshipType': 'PROVIDESINFORMATIONON', 'count': 1},\n",
       " {'relationshipType': 'PUBLISHESDATAON', 'count': 1},\n",
       " {'relationshipType': 'HIGHLIGHTS', 'count': 1},\n",
       " {'relationshipType': 'CONDUCTSANALYSIS', 'count': 1},\n",
       " {'relationshipType': 'SUPPORTSANALYSIS', 'count': 1},\n",
       " {'relationshipType': 'COMMENTSON', 'count': 1},\n",
       " {'relationshipType': 'CONTRIBUTESTO', 'count': 1},\n",
       " {'relationshipType': 'SHOULDENSUREPREVENTIONANDTREATMENT', 'count': 1},\n",
       " {'relationshipType': 'HASHIGHPREVALENCE', 'count': 1},\n",
       " {'relationshipType': 'HASLOWTREATMENTCOVERAGE', 'count': 1},\n",
       " {'relationshipType': 'AIMSTOCOMBAT', 'count': 1},\n",
       " {'relationshipType': 'ENGAGEIN', 'count': 1},\n",
       " {'relationshipType': 'LAUNCH', 'count': 1},\n",
       " {'relationshipType': 'MONITOR', 'count': 1},\n",
       " {'relationshipType': 'LOWTREATMENTCOVERAGE', 'count': 1},\n",
       " {'relationshipType': 'TARGETS', 'count': 1},\n",
       " {'relationshipType': 'CAUSEDBY', 'count': 1},\n",
       " {'relationshipType': 'ADOPTEDBY', 'count': 1},\n",
       " {'relationshipType': 'SETBY', 'count': 1},\n",
       " {'relationshipType': 'HOSTEDBY', 'count': 1},\n",
       " {'relationshipType': 'CONDUCTEDBY', 'count': 1},\n",
       " {'relationshipType': 'COLLABORATEDWITH', 'count': 1},\n",
       " {'relationshipType': 'ACQUIREDIN', 'count': 1},\n",
       " {'relationshipType': 'REPORTEDCASES', 'count': 1},\n",
       " {'relationshipType': 'SUSPECTEDCASES', 'count': 1},\n",
       " {'relationshipType': 'DECLAREDGLOBALHEALTHEMERGENCYFOR', 'count': 1},\n",
       " {'relationshipType': 'COMMENTEDON', 'count': 1},\n",
       " {'relationshipType': 'CALLSFORVACCINEDOSES', 'count': 1},\n",
       " {'relationshipType': 'HASSUSPECTEDCASES', 'count': 1},\n",
       " {'relationshipType': 'HASDEATHS', 'count': 1},\n",
       " {'relationshipType': 'CASESREPORTED', 'count': 1},\n",
       " {'relationshipType': 'CASESINCREASE', 'count': 1},\n",
       " {'relationshipType': 'PREVENTSDISEASE', 'count': 1},\n",
       " {'relationshipType': 'CHILDRENWITHOUTFIRSTDOSE', 'count': 1},\n",
       " {'relationshipType': 'ADVOCATES', 'count': 1},\n",
       " {'relationshipType': 'EPIDEMICSREPORTED', 'count': 1},\n",
       " {'relationshipType': 'SIGNIFICANTEPIDEMICS', 'count': 1},\n",
       " {'relationshipType': 'NOSIGNIFICANTEPIDEMICS', 'count': 1},\n",
       " {'relationshipType': 'DEATHSREPORTED', 'count': 1},\n",
       " {'relationshipType': 'DEATHSREDUCTION', 'count': 1},\n",
       " {'relationshipType': 'EPIDEMICOCCURREDIN', 'count': 1},\n",
       " {'relationshipType': 'CAUSEDDEATHS', 'count': 1},\n",
       " {'relationshipType': 'PRIMARILYAFFECTED', 'count': 1},\n",
       " {'relationshipType': 'CANCAUSE', 'count': 1},\n",
       " {'relationshipType': 'ELIMINATEDMEASLESIN', 'count': 1},\n",
       " {'relationshipType': 'PUBLISHEDJOINTREPORT', 'count': 1},\n",
       " {'relationshipType': 'FOUNDINGMEMBER', 'count': 1},\n",
       " {'relationshipType': 'PARTOF', 'count': 1},\n",
       " {'relationshipType': 'PARTNER', 'count': 1},\n",
       " {'relationshipType': 'HASMEMBER', 'count': 1},\n",
       " {'relationshipType': 'AFFECTEDBY', 'count': 1},\n",
       " {'relationshipType': 'WORKSON', 'count': 1},\n",
       " {'relationshipType': 'SUPPORTS', 'count': 1},\n",
       " {'relationshipType': 'PUBLISHEDON', 'count': 1},\n",
       " {'relationshipType': 'SUPPORTEDBY', 'count': 1},\n",
       " {'relationshipType': 'LEADS', 'count': 1},\n",
       " {'relationshipType': 'COMPAREDTO', 'count': 1},\n",
       " {'relationshipType': 'REPORTEDIN', 'count': 1},\n",
       " {'relationshipType': 'LOCATEDIN', 'count': 1},\n",
       " {'relationshipType': 'COMMITTEDTOFIGHTING', 'count': 1},\n",
       " {'relationshipType': 'LAUNCHES', 'count': 1},\n",
       " {'relationshipType': 'AIMSTOPREVENT', 'count': 1},\n",
       " {'relationshipType': 'ORGANIZEDBY', 'count': 1},\n",
       " {'relationshipType': 'TRAVELEDTO', 'count': 1},\n",
       " {'relationshipType': 'DECLAREDEMERGENCY', 'count': 1},\n",
       " {'relationshipType': 'HOLDSPOSITION', 'count': 1},\n",
       " {'relationshipType': 'CALLEDFOR', 'count': 1},\n",
       " {'relationshipType': 'TARGETEDFOR', 'count': 1},\n",
       " {'relationshipType': 'DETECTEDIN', 'count': 1},\n",
       " {'relationshipType': 'HOSPITALIZEDIN', 'count': 1},\n",
       " {'relationshipType': 'MUTATIONDETECTEDIN', 'count': 1},\n",
       " {'relationshipType': 'WORKSIN', 'count': 1},\n",
       " {'relationshipType': 'CIRCULATINGIN', 'count': 1},\n",
       " {'relationshipType': 'HOSPITALIZEDAT', 'count': 1},\n",
       " {'relationshipType': 'SPECULATESON', 'count': 1},\n",
       " {'relationshipType': 'WORKSTODETECT', 'count': 1},\n",
       " {'relationshipType': 'COMPARESTO', 'count': 1},\n",
       " {'relationshipType': 'HOPESTOCONTAIN', 'count': 1},\n",
       " {'relationshipType': 'DISCUSSES', 'count': 1},\n",
       " {'relationshipType': 'EXPRESSESCONCERN', 'count': 1},\n",
       " {'relationshipType': 'WARNSABOUT', 'count': 1},\n",
       " {'relationshipType': 'OCCURSIN', 'count': 1},\n",
       " {'relationshipType': 'MUTATEDIN', 'count': 1},\n",
       " {'relationshipType': 'CAUSES', 'count': 1},\n",
       " {'relationshipType': 'WORKSAT', 'count': 1},\n",
       " {'relationshipType': 'HASCASESIN', 'count': 1},\n",
       " {'relationshipType': 'SICKENS', 'count': 1},\n",
       " {'relationshipType': 'AFFILIATEDWITH', 'count': 1},\n",
       " {'relationshipType': 'VARIANTOF', 'count': 1},\n",
       " {'relationshipType': 'SICKENEDBY', 'count': 1},\n",
       " {'relationshipType': 'MUTATIONCOMPARISON', 'count': 1},\n",
       " {'relationshipType': 'DETECTEDTHROUGH', 'count': 1},\n",
       " {'relationshipType': 'CONDUCTEDAT', 'count': 1},\n",
       " {'relationshipType': 'OUTBREAKLOCATION', 'count': 1},\n",
       " {'relationshipType': 'NOEXPOSURE', 'count': 1},\n",
       " {'relationshipType': 'HASCONTACT', 'count': 1},\n",
       " {'relationshipType': 'POTENTIALCONTACT', 'count': 1},\n",
       " {'relationshipType': 'DETECT', 'count': 1},\n",
       " {'relationshipType': 'RESISTANTTOTESTING', 'count': 1},\n",
       " {'relationshipType': 'KEPTINDARK', 'count': 1},\n",
       " {'relationshipType': 'REASONFOR', 'count': 1},\n",
       " {'relationshipType': 'UNAWAREOF', 'count': 1},\n",
       " {'relationshipType': 'HOPETODIEOUT', 'count': 1},\n",
       " {'relationshipType': 'CONCERNAMONG', 'count': 1},\n",
       " {'relationshipType': 'RISKOFTRANSMISSION', 'count': 1},\n",
       " {'relationshipType': 'VARIATIONOF', 'count': 1},\n",
       " {'relationshipType': 'POTENTIALMUTATION', 'count': 1},\n",
       " {'relationshipType': 'AFFECTS', 'count': 1},\n",
       " {'relationshipType': 'STUDIEDBY', 'count': 1},\n",
       " {'relationshipType': 'SICKENED', 'count': 1},\n",
       " {'relationshipType': 'MUTATIONNOTDETECTEDIN', 'count': 1},\n",
       " {'relationshipType': 'SURVEILLEDIN', 'count': 1},\n",
       " {'relationshipType': 'TESTEDIN', 'count': 1},\n",
       " {'relationshipType': 'HADCONTACT', 'count': 1},\n",
       " {'relationshipType': 'INCLUDES', 'count': 1},\n",
       " {'relationshipType': 'ENCOUNTERED', 'count': 1},\n",
       " {'relationshipType': 'PASSEDON', 'count': 1},\n",
       " {'relationshipType': 'INFECTED', 'count': 1},\n",
       " {'relationshipType': 'COMMENTED', 'count': 1},\n",
       " {'relationshipType': 'CONTACT', 'count': 1},\n",
       " {'relationshipType': 'COMPARED', 'count': 1},\n",
       " {'relationshipType': 'ASSOCIATEDWITH', 'count': 1},\n",
       " {'relationshipType': 'FOR', 'count': 1},\n",
       " {'relationshipType': 'KEPTINTHEDARKABOUT', 'count': 1},\n",
       " {'relationshipType': 'HOPEWILLDIEOUT', 'count': 1},\n",
       " {'relationshipType': 'DISCUSSED', 'count': 1},\n",
       " {'relationshipType': 'WARNEDABOUT', 'count': 1},\n",
       " {'relationshipType': 'HASUNDETECTEDCASES', 'count': 1},\n",
       " {'relationshipType': 'MUTATEDDURING', 'count': 1},\n",
       " {'relationshipType': 'STUDIES', 'count': 1},\n",
       " {'relationshipType': 'CIRCULATESIN', 'count': 1},\n",
       " {'relationshipType': 'FIRSTFOUNDIN', 'count': 1},\n",
       " {'relationshipType': 'SURVEILLANCEFOR', 'count': 1},\n",
       " {'relationshipType': 'TESTINGFOR', 'count': 1},\n",
       " {'relationshipType': 'OUTBREAKIN', 'count': 1},\n",
       " {'relationshipType': 'CONTACTWITH', 'count': 1},\n",
       " {'relationshipType': 'RISKTO', 'count': 1},\n",
       " {'relationshipType': 'HOSPITALIZEDWITH', 'count': 1},\n",
       " {'relationshipType': 'HASCONDITION', 'count': 1},\n",
       " {'relationshipType': 'HASPOTENTIALMUTATION', 'count': 1},\n",
       " {'relationshipType': 'DETECTCASES', 'count': 1},\n",
       " {'relationshipType': 'RESISTANTTO', 'count': 1},\n",
       " {'relationshipType': 'RISKOFSPREAD', 'count': 1}]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.query(\"\"\"\n",
    "CALL db.relationshipTypes() YIELD relationshipType\n",
    "RETURN relationshipType, count(*) AS count\n",
    "\"\"\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.FeatureDeprecationWarning} {category: DEPRECATION} {title: This feature is deprecated and will be removed in future versions.} {description: The query used a deprecated field from a procedure. ('schema' returned by 'gds.graph.list' is deprecated.)} {position: line: 1, column: 1, offset: 0} for query: 'CALL gds.graph.list()'\n"
     ]
    }
   ],
   "source": [
    "available_graphs = gds.graph.list()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "available_graphs.drop([0,1],inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>degreeDistribution</th>\n",
       "      <th>graphName</th>\n",
       "      <th>database</th>\n",
       "      <th>databaseLocation</th>\n",
       "      <th>memoryUsage</th>\n",
       "      <th>sizeInBytes</th>\n",
       "      <th>nodeCount</th>\n",
       "      <th>relationshipCount</th>\n",
       "      <th>configuration</th>\n",
       "      <th>density</th>\n",
       "      <th>creationTime</th>\n",
       "      <th>modificationTime</th>\n",
       "      <th>schema</th>\n",
       "      <th>schemaWithOrientation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [degreeDistribution, graphName, database, databaseLocation, memoryUsage, sizeInBytes, nodeCount, relationshipCount, configuration, density, creationTime, modificationTime, schema, schemaWithOrientation]\n",
       "Index: []"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "available_graphs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "available_graphs[\"graphName\"].str.contains('communities', regex=False).any()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.FeatureDeprecationWarning} {category: DEPRECATION} {title: This feature is deprecated and will be removed in future versions.} {description: The query used a deprecated field from a procedure. ('schema' returned by 'gds.graph.drop' is deprecated.)} {position: line: 1, column: 1, offset: 0} for query: 'CALL gds.graph.drop($graph_name, $fail_if_missing, $db_name)'\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "graphName                                                      communities\n",
       "database                                                             neo4j\n",
       "databaseLocation                                                     local\n",
       "memoryUsage                                                               \n",
       "sizeInBytes                                                             -1\n",
       "nodeCount                                                              185\n",
       "relationshipCount                                                      366\n",
       "configuration            {'relationshipProjection': {'_ALL_': {'aggrega...\n",
       "density                                                           0.010752\n",
       "creationTime                           2024-08-19T12:41:43.997435629+00:00\n",
       "modificationTime                       2024-08-19T12:41:44.127124307+00:00\n",
       "schema                   {'graphProperties': {}, 'nodes': {'__Entity__'...\n",
       "schemaWithOrientation    {'graphProperties': {}, 'nodes': {'__Entity__'...\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gds.graph.drop(\"communities\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "G, result = gds.graph.project(\n",
    "    \"communities\",  #  Graph name\n",
    "    \"__Entity__\",  #  Node projection\n",
    "    {\n",
    "        \"_ALL_\": {\n",
    "            \"type\": \"*\",\n",
    "            \"orientation\": \"UNDIRECTED\",\n",
    "            \"properties\": {\"weight\": {\"property\": \"*\", \"aggregation\": \"COUNT\"}},\n",
    "        }\n",
    "    },\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "nodeProjection            {'__Entity__': {'label': '__Entity__', 'proper...\n",
       "relationshipProjection    {'_ALL_': {'aggregation': 'DEFAULT', 'orientat...\n",
       "graphName                                                       communities\n",
       "nodeCount                                                               185\n",
       "relationshipCount                                                       366\n",
       "projectMillis                                                            15\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.FeatureDeprecationWarning} {category: DEPRECATION} {title: This feature is deprecated and will be removed in future versions.} {description: The query used a deprecated field from a procedure. ('schema' returned by 'gds.graph.list' is deprecated.)} {position: line: 1, column: 106, offset: 105} for query: 'CALL gds.graph.list($graph_name) YIELD graphName, nodeCount, relationshipCount, database, configuration, schema, memoryUsage'\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Graph({'graphName': 'communities', 'nodeCount': 185, 'relationshipCount': 366, 'database': 'neo4j', 'configuration': {'relationshipProjection': {'_ALL_': {'aggregation': 'DEFAULT', 'orientation': 'UNDIRECTED', 'indexInverse': False, 'properties': {'weight': {'aggregation': 'COUNT', 'property': '*', 'defaultValue': None}}, 'type': '*'}}, 'readConcurrency': 4, 'relationshipProperties': {}, 'nodeProperties': {}, 'jobId': 'ced0b057-a717-48d8-8b90-842f6f2aa001', 'nodeProjection': {'__Entity__': {'label': '__Entity__', 'properties': {}}}, 'logProgress': True, 'creationTime': neo4j.time.DateTime(2024, 8, 19, 13, 10, 3, 641071700, tzinfo=<UTC>), 'validateRelationships': False, 'sudo': False}, 'schema': {'graphProperties': {}, 'nodes': {'__Entity__': {}}, 'relationships': {'_ALL_': {'weight': 'Float (DefaultValue(NaN), PERSISTENT, Aggregation.COUNT)'}}}, 'memoryUsage': '2316 KiB'})"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "G"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMMUNITY_PROJECT_NAME'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"community_project_name\".upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Component count: 14\n",
      "Component distribution: {'min': 1, 'p5': 1, 'max': 155, 'p999': 155, 'p99': 155, 'p1': 1, 'p10': 1, 'p90': 3, 'p50': 1, 'p25': 1, 'p75': 2, 'p95': 155, 'mean': 12.285714285714286}\n"
     ]
    }
   ],
   "source": [
    "wcc = gds.wcc.stats(G)\n",
    "print(f\"Component count: {wcc['componentCount']}\")\n",
    "print(f\"Component distribution: {wcc['componentDistribution']}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "writeMillis                                                              5\n",
       "nodePropertiesWritten                                                  172\n",
       "ranLevels                                                                2\n",
       "didConverge                                                           True\n",
       "nodeCount                                                              172\n",
       "communityCount                                                          22\n",
       "communityDistribution    {'min': 1, 'p5': 1, 'max': 64, 'p999': 64, 'p9...\n",
       "modularity                                                        0.678705\n",
       "modularities                      [0.6566821889989846, 0.6787052274080039]\n",
       "postProcessingMillis                                                     3\n",
       "preProcessingMillis                                                      0\n",
       "computeMillis                                                           33\n",
       "configuration            {'writeProperty': 'communities', 'theta': 0.01...\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gds.leiden.write(\n",
    "    G,\n",
    "    writeProperty=\"communities\",\n",
    "    includeIntermediateCommunities=True,\n",
    "    relationshipWeightProperty=\"weight\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.query(\"CREATE CONSTRAINT IF NOT EXISTS FOR (c:__Community__) REQUIRE c.id IS UNIQUE;\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'count(*)': 344}]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.query(\"\"\"\n",
    "MATCH (e:`__Entity__`)\n",
    "UNWIND range(0, size(e.communities) - 1 , 1) AS index\n",
    "CALL {\n",
    "  WITH e, index\n",
    "  WITH e, index\n",
    "  WHERE index = 0\n",
    "  MERGE (c:`__Community__` {id: toString(index) + '-' + toString(e.communities[index])})\n",
    "  ON CREATE SET c.level = index\n",
    "  MERGE (e)-[:IN_COMMUNITY]->(c)\n",
    "  RETURN count(*) AS count_0\n",
    "}\n",
    "CALL {\n",
    "  WITH e, index\n",
    "  WITH e, index\n",
    "  WHERE index > 0\n",
    "  MERGE (current:`__Community__` {id: toString(index) + '-' + toString(e.communities[index])})\n",
    "  ON CREATE SET current.level = index\n",
    "  MERGE (previous:`__Community__` {id: toString(index - 1) + '-' + toString(e.communities[index - 1])})\n",
    "  ON CREATE SET previous.level = index - 1\n",
    "  MERGE (previous)-[:IN_COMMUNITY]->(current)\n",
    "  RETURN count(*) AS count_1\n",
    "}\n",
    "RETURN count(*)\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.query(\"\"\"\n",
    "MATCH (c:__Community__)<-[:IN_COMMUNITY*]-(:__Entity__)<-[:MENTIONS]-(d:Document)\n",
    "WITH c, count(distinct d) AS rank\n",
    "SET c.community_rank = rank;\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Level</th>\n",
       "      <th>Number of communities</th>\n",
       "      <th>25th Percentile</th>\n",
       "      <th>50th Percentile</th>\n",
       "      <th>75th Percentile</th>\n",
       "      <th>90th Percentile</th>\n",
       "      <th>99th Percentile</th>\n",
       "      <th>Max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>28</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.75</td>\n",
       "      <td>13.9</td>\n",
       "      <td>49.66</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>22</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.50</td>\n",
       "      <td>17.8</td>\n",
       "      <td>54.55</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Level  Number of communities  25th Percentile  50th Percentile  \\\n",
       "0     0                     28              1.0              2.0   \n",
       "1     1                     22              1.0              2.0   \n",
       "\n",
       "   75th Percentile  90th Percentile  99th Percentile  Max  \n",
       "0             3.75             13.9            49.66   61  \n",
       "1             8.50             17.8            54.55   64  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "community_size = graph.query(\n",
    "    \"\"\"\n",
    "MATCH (c:__Community__)<-[:IN_COMMUNITY*]-(e:__Entity__)\n",
    "WITH c, count(distinct e) AS entities\n",
    "RETURN split(c.id, '-')[0] AS level, entities\n",
    "\"\"\"\n",
    ")\n",
    "community_size_df = pd.DataFrame.from_records(community_size)\n",
    "percentiles_data = []\n",
    "for level in community_size_df[\"level\"].unique():\n",
    "    subset = community_size_df[community_size_df[\"level\"] == level][\"entities\"]\n",
    "    num_communities = len(subset)\n",
    "    percentiles = np.percentile(subset, [25, 50, 75, 90, 99])\n",
    "    percentiles_data.append(\n",
    "        [\n",
    "            level,\n",
    "            num_communities,\n",
    "            percentiles[0],\n",
    "            percentiles[1],\n",
    "            percentiles[2],\n",
    "            percentiles[3],\n",
    "            percentiles[4],\n",
    "            max(subset)\n",
    "        ]\n",
    "    )\n",
    "\n",
    "# Create a DataFrame with the percentiles\n",
    "percentiles_df = pd.DataFrame(\n",
    "    percentiles_data,\n",
    "    columns=[\n",
    "        \"Level\",\n",
    "        \"Number of communities\",\n",
    "        \"25th Percentile\",\n",
    "        \"50th Percentile\",\n",
    "        \"75th Percentile\",\n",
    "        \"90th Percentile\",\n",
    "        \"99th Percentile\",\n",
    "        \"Max\"\n",
    "    ],\n",
    ")\n",
    "percentiles_df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### community summaries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "community_info = graph.query(\"\"\"\n",
    "MATCH (c:`__Community__`)<-[:IN_COMMUNITY*]-(e:__Entity__)\n",
    "WHERE c.level IN [0,1,4]\n",
    "WITH c, collect(e ) AS nodes\n",
    "WHERE size(nodes) > 1\n",
    "CALL apoc.path.subgraphAll(nodes[0], {\n",
    "\twhitelistNodes:nodes\n",
    "})\n",
    "YIELD relationships\n",
    "RETURN c.id AS communityId,\n",
    "       [n in nodes | {id: n.id, description: n.description, type: [el in labels(n) WHERE el <> '__Entity__'][0]}] AS nodes,\n",
    "       [r in relationships | {start: startNode(r).id, type: type(r), end: endNode(r).id, description: r.description}] AS rels\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'communityId': '0-36',\n",
       "  'nodes': [{'id': 'India',\n",
       "    'description': 'Officially the Republic of India, located in South Asia.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Supreme Court Of India',\n",
       "    'description': 'Head of the independent judiciary.',\n",
       "    'type': 'Judiciary'},\n",
       "   {'id': 'Indian National Congress',\n",
       "    'description': 'Dominated Indian politics until 1977.',\n",
       "    'type': 'Political party'},\n",
       "   {'id': 'Sindhu',\n",
       "    'description': 'Name of the Indus River, from which the name India is derived.',\n",
       "    'type': 'River'},\n",
       "   {'id': 'Food And Agriculture Organization Of The United Nations',\n",
       "    'description': \"Estimates India's forest cover.\",\n",
       "    'type': 'Organization'},\n",
       "   {'id': '2013 Forest Survey Of India',\n",
       "    'description': \"States India's forest cover increased to 69.8 million hectares by 2012.\",\n",
       "    'type': 'Report'},\n",
       "   {'id': 'Yajnavalkya Smriti',\n",
       "    'description': 'Prohibited the cutting of trees.',\n",
       "    'type': 'Literature'},\n",
       "   {'id': 'Kautalyas Arthashastra',\n",
       "    'description': 'Discusses the need for forest administration.',\n",
       "    'type': 'Literature'},\n",
       "   {'id': 'Crown Land (Encroachment) Ordinance',\n",
       "    'description': \"Promulgated in 1840 targeting forests in Britain's Asian colonies.\",\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Indian Forest Act Of 1865',\n",
       "    'description': \"Established the government's claims over forests.\",\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Forest Act Of 1878',\n",
       "    'description': 'Gave the British government control over all wastelands, including forests.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Sir Dietrich Brandis',\n",
       "    'description': 'Inspector General of Forests in India from 1864 to 1883.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Indian Ocean',\n",
       "    'description': 'Ocean bounded by India on the north.',\n",
       "    'type': 'Ocean'},\n",
       "   {'id': 'Sri Lanka',\n",
       "    'description': 'Country in the vicinity of India in the Indian Ocean.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Maldives',\n",
       "    'description': 'Country in the vicinity of India in the Indian Ocean.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Myanmar',\n",
       "    'description': 'Country sharing land border with India to the east.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Himalayan Mountain Range',\n",
       "    'description': 'Defines the northern frontiers of India.',\n",
       "    'type': 'Mountain range'},\n",
       "   {'id': 'China',\n",
       "    'description': 'Country sharing land border with India to the north.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Bhutan',\n",
       "    'description': 'Country sharing land border with India to the north.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Nepal',\n",
       "    'description': 'Country sharing land border with India to the north.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Pakistan',\n",
       "    'description': 'Country sharing land border with India to the west.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Bangladesh',\n",
       "    'description': 'Country sharing land border with India to the east.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Ganges',\n",
       "    'description': 'The longest river originating in India.',\n",
       "    'type': 'River'},\n",
       "   {'id': 'Western Ghats',\n",
       "    'description': 'One of the three biodiversity hotspots in India.',\n",
       "    'type': 'Biodiversity hotspot'},\n",
       "   {'id': 'Eastern Himalayas',\n",
       "    'description': 'One of the three biodiversity hotspots in India.',\n",
       "    'type': 'Biodiversity hotspot'},\n",
       "   {'id': 'Indo-Burma Hotspot',\n",
       "    'description': 'One of the three biodiversity hotspots in India.',\n",
       "    'type': 'Biodiversity hotspot'},\n",
       "   {'id': 'Forests',\n",
       "    'description': 'Covers about 24.6% of the total land area.',\n",
       "    'type': 'Ecosystem'},\n",
       "   {'id': 'Indomalayan Realm',\n",
       "    'description': 'Geographical realm that includes India.',\n",
       "    'type': 'Realm'},\n",
       "   {'id': 'World', 'description': None, 'type': None},\n",
       "   {'id': 'Public_Sector', 'description': None, 'type': None},\n",
       "   {'id': 'Gdp', 'description': None, 'type': None},\n",
       "   {'id': 'Economic_Liberalisation', 'description': None, 'type': None},\n",
       "   {'id': 'Gdp_Growth', 'description': None, 'type': None},\n",
       "   {'id': 'Consumer_Market', 'description': None, 'type': None},\n",
       "   {'id': 'Wto', 'description': None, 'type': None},\n",
       "   {'id': 'Ease_Of_Business_Index', 'description': None, 'type': None},\n",
       "   {'id': 'Global_Competitiveness_Index', 'description': None, 'type': None},\n",
       "   {'id': 'Billionaires', 'description': None, 'type': None},\n",
       "   {'id': 'Welfare_State', 'description': None, 'type': None},\n",
       "   {'id': 'Socialist_State', 'description': None, 'type': None},\n",
       "   {'id': 'Social_Welfare_Spending', 'description': None, 'type': None},\n",
       "   {'id': 'Labour_Force', 'description': None, 'type': None},\n",
       "   {'id': 'Fdi', 'description': None, 'type': None},\n",
       "   {'id': 'Free_Trade_Agreements', 'description': None, 'type': None},\n",
       "   {'id': 'Service_Sector', 'description': None, 'type': None},\n",
       "   {'id': 'Stock_Exchanges', 'description': None, 'type': None},\n",
       "   {'id': 'Manufacturing', 'description': None, 'type': None},\n",
       "   {'id': 'Population', 'description': None, 'type': None},\n",
       "   {'id': 'Unemployment', 'description': None, 'type': None},\n",
       "   {'id': 'Savings_Rate', 'description': None, 'type': None},\n",
       "   {'id': 'Arabian Sea',\n",
       "    'description': 'Sea bounded by India on the northwest.',\n",
       "    'type': 'Sea'},\n",
       "   {'id': 'Bay Of Bengal',\n",
       "    'description': 'Bay bounded by India on the southeast.',\n",
       "    'type': 'Bay'},\n",
       "   {'id': 'Africa',\n",
       "    'description': 'Continent from which modern humans arrived on the Indian subcontinent.',\n",
       "    'type': 'Continent'},\n",
       "   {'id': 'Indus Valley Civilisation',\n",
       "    'description': 'Civilisation that evolved from settled life in the western margins of the Indus river basin.',\n",
       "    'type': 'Civilization'},\n",
       "   {'id': 'Sanskrit',\n",
       "    'description': 'Indo-European language that diffused into India from the northwest.',\n",
       "    'type': 'Language'},\n",
       "   {'id': 'Rigveda',\n",
       "    'description': 'Ancient hymns recording the dawning of Hinduism in India.',\n",
       "    'type': 'Text'},\n",
       "   {'id': 'Hinduism',\n",
       "    'description': 'Major religion in India, with roots in the Rigveda.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Buddhism',\n",
       "    'description': 'Religion that arose in India, proclaiming social orders unlinked to heredity.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Jainism',\n",
       "    'description': 'Religion that arose in India, proclaiming social orders unlinked to heredity.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Mughal Empire',\n",
       "    'description': 'Empire that began in 1526, known for its architecture and relative peace.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Indian Republic',\n",
       "    'description': 'India has been a federal republic since 1950.',\n",
       "    'type': 'Government'}],\n",
       "  'rels': [{'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'IS_PART_OF',\n",
       "    'end': 'Indomalayan Realm'},\n",
       "   {'start': 'India',\n",
       "    'description': 'About 1,900 public sector companies with complete control and ownership of railways, highways, and majority control in various industries.',\n",
       "    'type': 'HAS',\n",
       "    'end': 'Public_Sector'},\n",
       "   {'start': 'India',\n",
       "    'description': \"One of the world's highest number of billionaires.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Billionaires'},\n",
       "   {'start': 'India',\n",
       "    'description': \"World's second-largest labour force with 586 million workers.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Labour_Force'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Has free trade agreements with several nations and blocs.',\n",
       "    'type': 'HAS',\n",
       "    'end': 'Free_Trade_Agreements'},\n",
       "   {'start': 'India',\n",
       "    'description': \"Bombay Stock Exchange and National Stock Exchange are among the world's largest stock exchanges.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Stock_Exchanges'},\n",
       "   {'start': 'India',\n",
       "    'description': \"Nearly 65% of India's population is rural.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Population'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'RELATES_TO',\n",
       "    'end': 'Rigveda'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Member of the World Trade Organization since 1 January 1995.',\n",
       "    'type': 'MEMBER_OF',\n",
       "    'end': 'Wto'},\n",
       "   {'start': 'India',\n",
       "    'description': 'High unemployment and rising income inequality.',\n",
       "    'type': 'FACES',\n",
       "    'end': 'Unemployment'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Adopted broad economic liberalisation in 1991.',\n",
       "    'type': 'ADOPTED',\n",
       "    'end': 'Economic_Liberalisation'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Often considered a welfare state.',\n",
       "    'type': 'CONSIDERED_AS',\n",
       "    'end': 'Welfare_State'},\n",
       "   {'start': 'India', 'description': None, 'type': 'NEAR', 'end': 'Sri Lanka'},\n",
       "   {'start': 'India', 'description': None, 'type': 'NEAR', 'end': 'Maldives'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Indian Ocean'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Myanmar'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Himalayan Mountain Range'},\n",
       "   {'start': 'India', 'description': None, 'type': 'BORDERS', 'end': 'China'},\n",
       "   {'start': 'India', 'description': None, 'type': 'BORDERS', 'end': 'Bhutan'},\n",
       "   {'start': 'India', 'description': None, 'type': 'BORDERS', 'end': 'Nepal'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Pakistan'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Bangladesh'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Arabian Sea'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Bay Of Bengal'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'SEPARATED_BY',\n",
       "    'end': 'Sri Lanka'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'DERIVED_FROM',\n",
       "    'end': 'Sindhu'},\n",
       "   {'start': 'India',\n",
       "    'description': \"Estimates India's forest cover.\",\n",
       "    'type': 'ESTIMATES',\n",
       "    'end': 'Food And Agriculture Organization Of The United Nations'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Makes up more than 50% of GDP.',\n",
       "    'type': 'MAKES_UP',\n",
       "    'end': 'Service_Sector'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Fifth-largest economy by nominal GDP and third-largest by purchasing power parity (PPP).',\n",
       "    'type': 'RANKS_AS',\n",
       "    'end': 'World'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Fourth-largest consumer market in the world.',\n",
       "    'type': 'RANKS_AS',\n",
       "    'end': 'Consumer_Market'},\n",
       "   {'start': 'India',\n",
       "    'description': \"World's sixth-largest manufacturer, representing 2.6% of global manufacturing output.\",\n",
       "    'type': 'RANKS_AS',\n",
       "    'end': 'Manufacturing'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Officially declared a socialist state as per the constitution.',\n",
       "    'type': 'DECLARED_AS',\n",
       "    'end': 'Socialist_State'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Hinduism'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Buddhism'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Jainism'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'GOVERNED_AS',\n",
       "    'end': 'Indian Republic'},\n",
       "   {'start': 'India',\n",
       "    'description': '136th by GDP (nominal) and 125th by GDP (PPP) on a per capita income basis.',\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Gdp'},\n",
       "   {'start': 'India',\n",
       "    'description': '63rd on the Ease of Doing Business index.',\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Ease_Of_Business_Index'},\n",
       "   {'start': 'India',\n",
       "    'description': '40th on the Global Competitiveness Index.',\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Global_Competitiveness_Index'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'SHARES_BORDERS_WITH',\n",
       "    'end': 'Myanmar'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Overall social welfare spending stood at 8.6% of GDP in 2021-22.',\n",
       "    'type': 'SPENDING',\n",
       "    'end': 'Social_Welfare_Spending'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_EVENT',\n",
       "    'end': 'Mughal Empire'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGINATES_IN',\n",
       "    'end': 'Ganges'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_BIODIVERSITY_HOTSPOT',\n",
       "    'end': 'Western Ghats'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_BIODIVERSITY_HOTSPOT',\n",
       "    'end': 'Eastern Himalayas'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_BIODIVERSITY_HOTSPOT',\n",
       "    'end': 'Indo-Burma Hotspot'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_ECOSYSTEM',\n",
       "    'end': 'Forests'},\n",
       "   {'start': 'India',\n",
       "    'description': '6% to 7% since the start of the 21st century.',\n",
       "    'type': 'AVERAGE_ANNUAL_GROWTH',\n",
       "    'end': 'Gdp_Growth'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Foreign direct investment in 2021-22 was $82 billion.',\n",
       "    'type': 'FOREIGN_DIRECT_INVESTMENT',\n",
       "    'end': 'Fdi'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Gross domestic savings rate stood at 29.3% of GDP in 2022.',\n",
       "    'type': 'GROSS_DOMESTIC_SAVINGS_RATE',\n",
       "    'end': 'Savings_Rate'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HUMAN_ORIGIN',\n",
       "    'end': 'Africa'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_DEVELOPMENT',\n",
       "    'end': 'Indus Valley Civilisation'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'LANGUAGE_DIFFUSION',\n",
       "    'end': 'Sanskrit'},\n",
       "   {'start': 'Kautalyas Arthashastra',\n",
       "    'description': 'Discusses the need for forest administration.',\n",
       "    'type': 'DISCUSSES',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Indian Forest Act Of 1865',\n",
       "    'description': \"Establishes government's claims over forests.\",\n",
       "    'type': 'ESTABLISHES',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Crown Land (Encroachment) Ordinance',\n",
       "    'description': \"Targets forests in Britain's Asian colonies.\",\n",
       "    'type': 'TARGETS',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Yajnavalkya Smriti',\n",
       "    'description': 'Prohibits the cutting of trees.',\n",
       "    'type': 'PROHIBITS',\n",
       "    'end': 'India'},\n",
       "   {'start': '2013 Forest Survey Of India',\n",
       "    'description': 'Reports on forest cover increase.',\n",
       "    'type': 'REPORTS_ON',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Supreme Court Of India',\n",
       "    'description': None,\n",
       "    'type': 'PART_OF_JUDICIARY',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Indian National Congress',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICALLY_DOMINANT_PARTY',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Forest Act Of 1878',\n",
       "    'description': 'Gives control over all wastelands, including forests.',\n",
       "    'type': 'GIVES_CONTROL',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Sir Dietrich Brandis',\n",
       "    'description': 'Inspector General of Forests in India from 1864 to 1883.',\n",
       "    'type': 'INSPECTOR_GENERAL_OF',\n",
       "    'end': 'India'}]},\n",
       " {'communityId': '0-34',\n",
       "  'nodes': [{'id': 'Constitution Of India',\n",
       "    'description': 'The supreme law of India, laying down the framework for government institutions and fundamental rights.',\n",
       "    'type': 'Document'},\n",
       "   {'id': 'Parliament',\n",
       "    'description': 'Cannot override the Constitution of India.',\n",
       "    'type': 'Institution'},\n",
       "   {'id': 'Government Of India Act 1935',\n",
       "    'description': 'Replaced by the Constitution of India.',\n",
       "    'type': 'Document'},\n",
       "   {'id': 'Constituent Assembly',\n",
       "    'description': 'Tasked with drafting the Constitution of India.',\n",
       "    'type': 'Government body'},\n",
       "   {'id': 'M. N. Roy',\n",
       "    'description': 'Proposed the framework for the Constitution of India.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Republic Day',\n",
       "    'description': 'Celebrated on 26 January in India to honor the Constitution.',\n",
       "    'type': 'Event'},\n",
       "   {'id': 'Old Parliament House',\n",
       "    'description': 'Preserves the original 1950 Constitution in a nitrogen-filled case.',\n",
       "    'type': 'Location'},\n",
       "   {'id': 'British Government',\n",
       "    'description': 'Responsible for the external security of India during its dominion status.',\n",
       "    'type': 'Institution'},\n",
       "   {'id': 'Indian Independence Act 1947',\n",
       "    'description': 'Repealed by the Constitution of India.',\n",
       "    'type': 'Document'},\n",
       "   {'id': 'Articles Of The Constitution',\n",
       "    'description': 'Articles 5, 6, 7, 8, 9, 60, 324, 366, 367, 379, 380, 388, 391, 392, 393, and 394 came into force on 26 November 1949.',\n",
       "    'type': 'Document'}],\n",
       "  'rels': [{'start': 'Constitution Of India',\n",
       "    'description': 'The Constitution is based on the proposal suggested by M. N. Roy.',\n",
       "    'type': 'BASED_ON',\n",
       "    'end': 'M. N. Roy'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'The original 1950 Constitution is preserved in a nitrogen-filled case.',\n",
       "    'type': 'PRESERVED_IN',\n",
       "    'end': 'Old Parliament House'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'Celebrated on 26 January.',\n",
       "    'type': 'CELEBRATED_ON',\n",
       "    'end': 'Republic Day'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'Parliament cannot override the Constitution.',\n",
       "    'type': 'CANNOT_OVERRIDE',\n",
       "    'end': 'Parliament'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'Certain articles came into force on 26 November 1949.',\n",
       "    'type': 'CAME_INTO_FORCE',\n",
       "    'end': 'Articles Of The Constitution'},\n",
       "   {'start': 'Government Of India Act 1935',\n",
       "    'description': 'Replaced by the Constitution of India.',\n",
       "    'type': 'REPLACED_BY',\n",
       "    'end': 'Constitution Of India'},\n",
       "   {'start': 'British Government',\n",
       "    'description': 'Responsible for the external security of India during its dominion status.',\n",
       "    'type': 'RESPONSIBLE_FOR',\n",
       "    'end': 'Constitution Of India'},\n",
       "   {'start': 'Indian Independence Act 1947',\n",
       "    'description': 'Repealed by the Constitution of India.',\n",
       "    'type': 'REPEALED_BY',\n",
       "    'end': 'Constitution Of India'},\n",
       "   {'start': 'Constituent Assembly',\n",
       "    'description': None,\n",
       "    'type': 'DRAFTED_BY',\n",
       "    'end': 'Constitution Of India'}]},\n",
       " {'communityId': '0-25',\n",
       "  'nodes': [{'id': 'President Of India',\n",
       "    'description': 'The Supreme Commander of the Indian Armed Forces.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Nda',\n",
       "    'description': 'A coalition of the BJP and its allies governing India since 2014.',\n",
       "    'type': 'Political alliance'},\n",
       "   {'id': 'Government Of India',\n",
       "    'description': 'Established a system of national parks and protected areas.',\n",
       "    'type': 'Government'},\n",
       "   {'id': 'Narendra Modi',\n",
       "    'description': 'Current Prime Minister of India since 26 May 2014.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'New Delhi',\n",
       "    'description': 'The seat of the Government of India.',\n",
       "    'type': 'Location'},\n",
       "   {'id': 'Supreme Court',\n",
       "    'description': 'The highest judicial forum and final court of appeal under the Constitution of India.',\n",
       "    'type': 'Judiciary'},\n",
       "   {'id': 'Indian Councils Act 1909',\n",
       "    'description': 'Introduced elections to the Imperial Legislative Council.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Government Of India Act 1919',\n",
       "    'description': 'Expanded the Imperial Legislative Council.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'National Parks',\n",
       "    'description': 'Established in 1935 and expanded to nearly 1022 by 2023.',\n",
       "    'type': 'Protected area'},\n",
       "   {'id': 'Wildlife Protection Act Of 1972',\n",
       "    'description': 'Enacted for the protection of wildlife.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Project Tiger',\n",
       "    'description': 'Special project for the protection of critical species.',\n",
       "    'type': 'Conservation project'},\n",
       "   {'id': 'Project Elephant',\n",
       "    'description': 'Special project for the protection of critical species.',\n",
       "    'type': 'Conservation project'},\n",
       "   {'id': 'Project Dolphin',\n",
       "    'description': 'Special project for the protection of critical species.',\n",
       "    'type': 'Conservation project'}],\n",
       "  'rels': [{'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'INITIATED',\n",
       "    'end': 'Project Tiger'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'INITIATED',\n",
       "    'end': 'Project Elephant'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'INITIATED',\n",
       "    'end': 'Project Dolphin'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'GOVERNED_BY',\n",
       "    'end': 'Nda'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'ENACTED',\n",
       "    'end': 'Wildlife Protection Act Of 1972'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'ESTABLISHED',\n",
       "    'end': 'National Parks'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'LEAD_BY',\n",
       "    'end': 'Narendra Modi'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'RESPONSIBLE_TO',\n",
       "    'end': 'Supreme Court'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'SEATED_IN',\n",
       "    'end': 'New Delhi'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'HEAD_OF_STATE',\n",
       "    'end': 'President Of India'},\n",
       "   {'start': 'Indian Councils Act 1909',\n",
       "    'description': None,\n",
       "    'type': 'INFLUENCED',\n",
       "    'end': 'Government Of India'},\n",
       "   {'start': 'Government Of India Act 1919',\n",
       "    'description': None,\n",
       "    'type': 'INFLUENCED',\n",
       "    'end': 'Government Of India'}]},\n",
       " {'communityId': '0-112',\n",
       "  'nodes': [{'id': 'Prime Minister Of India',\n",
       "    'description': 'Holds executive authority and responsibility for national security.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Indian Armed Forces',\n",
       "    'description': 'The military forces of the Republic of India.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Army',\n",
       "    'description': 'One of the three professional uniformed services of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Navy',\n",
       "    'description': 'One of the three professional uniformed services of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Air Force',\n",
       "    'description': 'One of the three professional uniformed services of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Central Armed Police Forces',\n",
       "    'description': 'Supports the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Coast Guard',\n",
       "    'description': 'Supports the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Special Frontier Force',\n",
       "    'description': 'Supports the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Strategic Forces Command',\n",
       "    'description': 'An inter-service command of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Andaman And Nicobar Command',\n",
       "    'description': 'An inter-service command of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Integrated Defence Staff',\n",
       "    'description': 'An inter-service command of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Ministry Of Defence',\n",
       "    'description': 'Manages the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Global Firepower Index',\n",
       "    'description': 'Ranks the military forces globally.',\n",
       "    'type': 'Report'},\n",
       "   {'id': 'Armed Forces Flag Day',\n",
       "    'description': 'Honors armed forces and military personnel annually.',\n",
       "    'type': 'Event'},\n",
       "   {'id': 'Mauryan Empire',\n",
       "    'description': 'An ancient Indian empire known for its powerful military.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Chola Empire',\n",
       "    'description': 'Known for foreign trade and maritime activity.',\n",
       "    'type': 'Empire'}],\n",
       "  'rels': [{'start': 'Prime Minister Of India',\n",
       "    'description': None,\n",
       "    'type': 'EXECUTIVE_AUTHORITY',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Indian Army'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Indian Navy'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Indian Air Force'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Central Armed Police Forces'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Indian Coast Guard'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Special Frontier Force'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Strategic Forces Command'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Andaman And Nicobar Command'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Integrated Defence Staff'},\n",
       "   {'start': 'Ministry Of Defence',\n",
       "    'description': None,\n",
       "    'type': 'MANAGES',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Global Firepower Index',\n",
       "    'description': None,\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Armed Forces Flag Day',\n",
       "    'description': None,\n",
       "    'type': 'HONORS',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Mauryan Empire',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_REFERENCE',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Chola Empire',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_REFERENCE',\n",
       "    'end': 'Indian Armed Forces'}]},\n",
       " {'communityId': '0-27',\n",
       "  'nodes': [{'id': 'Rajya Sabha',\n",
       "    'description': 'The mostly indirectly elected upper house of Parliament.',\n",
       "    'type': 'Government body'},\n",
       "   {'id': 'Lok Sabha',\n",
       "    'description': 'The directly elected lower house of Parliament.',\n",
       "    'type': 'Government body'},\n",
       "   {'id': 'Union Council Of Ministers',\n",
       "    'description': 'The executive decision-making committee of the government.',\n",
       "    'type': 'Government body'}],\n",
       "  'rels': [{'start': 'Union Council Of Ministers',\n",
       "    'description': None,\n",
       "    'type': 'RESPONSIBLE_TO',\n",
       "    'end': 'Rajya Sabha'},\n",
       "   {'start': 'Union Council Of Ministers',\n",
       "    'description': None,\n",
       "    'type': 'RESPONSIBLE_TO',\n",
       "    'end': 'Lok Sabha'}]},\n",
       " {'communityId': '0-11',\n",
       "  'nodes': [{'id': 'Republic Of India',\n",
       "    'description': 'Has two principal official short names, India and Bharat.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Hindustan',\n",
       "    'description': 'Commonly used name for the Republic of India.',\n",
       "    'type': 'Name'}],\n",
       "  'rels': [{'start': 'Republic Of India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_NAME',\n",
       "    'end': 'Hindustan'}]},\n",
       " {'communityId': '0-15',\n",
       "  'nodes': [{'id': 'Bharat',\n",
       "    'description': 'Another principal official short name of the Republic of India.',\n",
       "    'type': 'Name'},\n",
       "   {'id': 'Dushyanta',\n",
       "    'description': 'Father of Bharata, associated with the name Bhāratavarṣa.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Mahabharata',\n",
       "    'description': 'Epic associated with the name Bharata.',\n",
       "    'type': 'Literature'}],\n",
       "  'rels': [{'start': 'Bharat',\n",
       "    'description': None,\n",
       "    'type': 'ASSOCIATED_WITH',\n",
       "    'end': 'Dushyanta'},\n",
       "   {'start': 'Bharat',\n",
       "    'description': None,\n",
       "    'type': 'ASSOCIATED_WITH',\n",
       "    'end': 'Mahabharata'}]},\n",
       " {'communityId': '0-14',\n",
       "  'nodes': [{'id': 'Bhāratavarṣa',\n",
       "    'description': 'Term used in the first century AD, derived from the name of the Vedic community of Bharatas.',\n",
       "    'type': 'Historical term'},\n",
       "   {'id': 'Bharatas',\n",
       "    'description': 'Mentioned in the Rigveda as one of the principal kingdoms of the Aryavarta.',\n",
       "    'type': 'Vedic community'}],\n",
       "  'rels': [{'start': 'Bhāratavarṣa',\n",
       "    'description': None,\n",
       "    'type': 'DERIVED_FROM',\n",
       "    'end': 'Bharatas'}]},\n",
       " {'communityId': '0-39',\n",
       "  'nodes': [{'id': 'Thailand',\n",
       "    'description': \"Shares maritime borders with India's Andaman and Nicobar Islands.\",\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Indonesia',\n",
       "    'description': \"Shares maritime borders with India's Andaman and Nicobar Islands.\",\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Andaman And Nicobar Islands',\n",
       "    'description': 'Islands of India sharing a maritime border with Thailand, Myanmar, and Indonesia.',\n",
       "    'type': 'Island'}],\n",
       "  'rels': [{'start': 'Andaman And Nicobar Islands',\n",
       "    'description': None,\n",
       "    'type': 'MARITIME_BORDER',\n",
       "    'end': 'Thailand'},\n",
       "   {'start': 'Andaman And Nicobar Islands',\n",
       "    'description': None,\n",
       "    'type': 'MARITIME_BORDER',\n",
       "    'end': 'Indonesia'}]},\n",
       " {'communityId': '0-52',\n",
       "  'nodes': [{'id': 'Constituent Assembly Of India',\n",
       "    'description': 'Adopted the Constitution of India on 26 November 1949.',\n",
       "    'type': 'Institution'},\n",
       "   {'id': 'Sardar Patel',\n",
       "    'description': 'Convinced princely states to sign articles of integration with India.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'V. P. Menon',\n",
       "    'description': 'Convinced princely states to sign articles of integration with India.',\n",
       "    'type': 'Person'}],\n",
       "  'rels': [{'start': 'Sardar Patel',\n",
       "    'description': 'Convinced princely states to sign articles of integration.',\n",
       "    'type': 'CONVINCED',\n",
       "    'end': 'Constituent Assembly Of India'},\n",
       "   {'start': 'V. P. Menon',\n",
       "    'description': 'Convinced princely states to sign articles of integration.',\n",
       "    'type': 'CONVINCED',\n",
       "    'end': 'Constituent Assembly Of India'}]},\n",
       " {'communityId': '0-78',\n",
       "  'nodes': [{'id': 'Fauna Species',\n",
       "    'description': 'India has an estimated 92,873 species of fauna.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Insects',\n",
       "    'description': 'Major category with 63,423 recorded species.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Mammals Count',\n",
       "    'description': '423 mammals in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Birds Count',\n",
       "    'description': '1,233 birds in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Reptiles Count',\n",
       "    'description': '526 reptiles in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Amphibians Count',\n",
       "    'description': '342 amphibians in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Fish Count',\n",
       "    'description': '3,022 fish in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Mammals',\n",
       "    'description': '12.6% of mammals are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Birds',\n",
       "    'description': '4.5% of birds are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Reptiles',\n",
       "    'description': '45.8% of reptiles are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Amphibians',\n",
       "    'description': '55.8% of amphibians are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Large Animals',\n",
       "    'description': 'Includes Indian elephant, Indian rhinoceros, and Gaur.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Big Cats',\n",
       "    'description': 'Includes tiger and lion.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Cat Family',\n",
       "    'description': 'Includes Bengal tiger, Asiatic lion, Indian leopard, snow leopard, and clouded leopard.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Representative Species',\n",
       "    'description': 'Includes blackbuck, nilgai, bharal, barasingha, Nilgiri tahr, and Nilgiri langur.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Aquatic Mammals',\n",
       "    'description': 'Includes dolphins, whales, porpoises, and dugong.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Reptiles Species',\n",
       "    'description': 'Includes gharial and saltwater crocodiles.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Birds Species',\n",
       "    'description': 'Includes peafowl, pheasants, geese, ducks, mynas, parakeets, pigeons, cranes, hornbills, and sunbirds.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Bird Species',\n",
       "    'description': 'Includes great Indian hornbill, great Indian bustard, nicobar pigeon, ruddy shelduck, Himalayan monal, and Himalayan quail.',\n",
       "    'type': 'Fauna'}],\n",
       "  'rels': [{'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Insects'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Mammals Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Birds Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Reptiles Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Amphibians Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Fish Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Mammals'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Birds'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Reptiles'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Amphibians'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Large Animals'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Big Cats'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Cat Family'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Representative Species'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Aquatic Mammals'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Reptiles Species'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Birds Species'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Bird Species'}]},\n",
       " {'communityId': '0-110',\n",
       "  'nodes': [{'id': 'Plant Species',\n",
       "    'description': 'About 29,015 species of plants.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Flowering Plants Count',\n",
       "    'description': '17,926 species of flowering plants.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Endemic Plant Species',\n",
       "    'description': '6,842 species are endemic to India.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Algae', 'description': '7,244 species.', 'type': 'Flora'},\n",
       "   {'id': 'Bryophytes', 'description': '2,504 species.', 'type': 'Flora'},\n",
       "   {'id': 'Pteridophytes', 'description': '1,267 species.', 'type': 'Flora'},\n",
       "   {'id': 'Gymnosperms', 'description': '74 species.', 'type': 'Flora'},\n",
       "   {'id': 'Fungal Diversity',\n",
       "    'description': 'Over 27,000 recorded species.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Flora', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Plant Species'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Flowering Plants Count'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Plant Species'},\n",
       "   {'start': 'Flora', 'description': None, 'type': 'INCLUDES', 'end': 'Algae'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Bryophytes'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Pteridophytes'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Gymnosperms'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Fungal Diversity'}]},\n",
       " {'communityId': '0-105',\n",
       "  'nodes': [{'id': 'Threatened Species',\n",
       "    'description': '172 IUCN-designated threatened species.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Mammals',\n",
       "    'description': '39 species of mammals.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Birds',\n",
       "    'description': '72 species of birds.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Reptiles',\n",
       "    'description': '17 species of reptiles.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Amphibians',\n",
       "    'description': '3 species of amphibians.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Fish',\n",
       "    'description': '2 species of fish.',\n",
       "    'type': 'Fauna'}],\n",
       "  'rels': [{'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Mammals'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Birds'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Reptiles'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Amphibians'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Fish'}]},\n",
       " {'communityId': '0-125',\n",
       "  'nodes': [{'id': 'Department Of Defence Production',\n",
       "    'description': 'Responsible for indigenous production of equipment for the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Make In India Initiative',\n",
       "    'description': 'Seeks to indigenise manufacturing and reduce dependence on imports for defence.',\n",
       "    'type': 'Program'}],\n",
       "  'rels': [{'start': 'Make In India Initiative',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTS',\n",
       "    'end': 'Department Of Defence Production'}]},\n",
       " {'communityId': '0-169',\n",
       "  'nodes': [{'id': 'Maurya Empire',\n",
       "    'description': 'Ancient empire based in the Ganges Basin.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Gupta Empire',\n",
       "    'description': 'Ancient empire based in the Ganges Basin.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Ganges Basin', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'Ganges Basin',\n",
       "    'description': None,\n",
       "    'type': 'BASED_IN',\n",
       "    'end': 'Maurya Empire'},\n",
       "   {'start': 'Ganges Basin',\n",
       "    'description': None,\n",
       "    'type': 'BASED_IN',\n",
       "    'end': 'Gupta Empire'}]},\n",
       " {'communityId': '0-170',\n",
       "  'nodes': [{'id': 'Vijayanagara Empire',\n",
       "    'description': 'Empire in south India that created a composite Hindu culture.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'South India', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'South India',\n",
       "    'description': None,\n",
       "    'type': 'BASED_IN',\n",
       "    'end': 'Vijayanagara Empire'}]},\n",
       " {'communityId': '0-171',\n",
       "  'nodes': [{'id': 'Sikhism',\n",
       "    'description': 'Religion that emerged in the Punjab, rejecting institutionalised religion.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Punjab', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'Punjab',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Sikhism'}]},\n",
       " {'communityId': '0-167',\n",
       "  'nodes': [{'id': 'British East India Company',\n",
       "    'description': 'Company that expanded rule in India, turning it into a colonial economy.',\n",
       "    'type': 'Company'},\n",
       "   {'id': 'British Crown',\n",
       "    'description': 'Began rule in India in 1858.',\n",
       "    'type': 'Government'},\n",
       "   {'id': 'Indian Independence',\n",
       "    'description': 'Event in 1947 when India was partitioned into two independent dominions.',\n",
       "    'type': 'Event'}],\n",
       "  'rels': [{'start': 'British East India Company',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_EVENT',\n",
       "    'end': 'British Crown'},\n",
       "   {'start': 'British Crown',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_EVENT',\n",
       "    'end': 'Indian Independence'}]},\n",
       " {'communityId': '1-23',\n",
       "  'nodes': [{'id': 'India',\n",
       "    'description': 'Officially the Republic of India, located in South Asia.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Supreme Court Of India',\n",
       "    'description': 'Head of the independent judiciary.',\n",
       "    'type': 'Judiciary'},\n",
       "   {'id': 'Indian National Congress',\n",
       "    'description': 'Dominated Indian politics until 1977.',\n",
       "    'type': 'Political party'},\n",
       "   {'id': 'Sindhu',\n",
       "    'description': 'Name of the Indus River, from which the name India is derived.',\n",
       "    'type': 'River'},\n",
       "   {'id': 'Food And Agriculture Organization Of The United Nations',\n",
       "    'description': \"Estimates India's forest cover.\",\n",
       "    'type': 'Organization'},\n",
       "   {'id': '2013 Forest Survey Of India',\n",
       "    'description': \"States India's forest cover increased to 69.8 million hectares by 2012.\",\n",
       "    'type': 'Report'},\n",
       "   {'id': 'Yajnavalkya Smriti',\n",
       "    'description': 'Prohibited the cutting of trees.',\n",
       "    'type': 'Literature'},\n",
       "   {'id': 'Kautalyas Arthashastra',\n",
       "    'description': 'Discusses the need for forest administration.',\n",
       "    'type': 'Literature'},\n",
       "   {'id': 'Crown Land (Encroachment) Ordinance',\n",
       "    'description': \"Promulgated in 1840 targeting forests in Britain's Asian colonies.\",\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Indian Forest Act Of 1865',\n",
       "    'description': \"Established the government's claims over forests.\",\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Forest Act Of 1878',\n",
       "    'description': 'Gave the British government control over all wastelands, including forests.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Sir Dietrich Brandis',\n",
       "    'description': 'Inspector General of Forests in India from 1864 to 1883.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Indian Ocean',\n",
       "    'description': 'Ocean bounded by India on the north.',\n",
       "    'type': 'Ocean'},\n",
       "   {'id': 'Sri Lanka',\n",
       "    'description': 'Country in the vicinity of India in the Indian Ocean.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Maldives',\n",
       "    'description': 'Country in the vicinity of India in the Indian Ocean.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Myanmar',\n",
       "    'description': 'Country sharing land border with India to the east.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Himalayan Mountain Range',\n",
       "    'description': 'Defines the northern frontiers of India.',\n",
       "    'type': 'Mountain range'},\n",
       "   {'id': 'China',\n",
       "    'description': 'Country sharing land border with India to the north.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Bhutan',\n",
       "    'description': 'Country sharing land border with India to the north.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Nepal',\n",
       "    'description': 'Country sharing land border with India to the north.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Pakistan',\n",
       "    'description': 'Country sharing land border with India to the west.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Bangladesh',\n",
       "    'description': 'Country sharing land border with India to the east.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Ganges',\n",
       "    'description': 'The longest river originating in India.',\n",
       "    'type': 'River'},\n",
       "   {'id': 'Western Ghats',\n",
       "    'description': 'One of the three biodiversity hotspots in India.',\n",
       "    'type': 'Biodiversity hotspot'},\n",
       "   {'id': 'Eastern Himalayas',\n",
       "    'description': 'One of the three biodiversity hotspots in India.',\n",
       "    'type': 'Biodiversity hotspot'},\n",
       "   {'id': 'Indo-Burma Hotspot',\n",
       "    'description': 'One of the three biodiversity hotspots in India.',\n",
       "    'type': 'Biodiversity hotspot'},\n",
       "   {'id': 'Forests',\n",
       "    'description': 'Covers about 24.6% of the total land area.',\n",
       "    'type': 'Ecosystem'},\n",
       "   {'id': 'Indomalayan Realm',\n",
       "    'description': 'Geographical realm that includes India.',\n",
       "    'type': 'Realm'},\n",
       "   {'id': 'World', 'description': None, 'type': None},\n",
       "   {'id': 'Public_Sector', 'description': None, 'type': None},\n",
       "   {'id': 'Gdp', 'description': None, 'type': None},\n",
       "   {'id': 'Economic_Liberalisation', 'description': None, 'type': None},\n",
       "   {'id': 'Gdp_Growth', 'description': None, 'type': None},\n",
       "   {'id': 'Consumer_Market', 'description': None, 'type': None},\n",
       "   {'id': 'Wto', 'description': None, 'type': None},\n",
       "   {'id': 'Ease_Of_Business_Index', 'description': None, 'type': None},\n",
       "   {'id': 'Global_Competitiveness_Index', 'description': None, 'type': None},\n",
       "   {'id': 'Billionaires', 'description': None, 'type': None},\n",
       "   {'id': 'Welfare_State', 'description': None, 'type': None},\n",
       "   {'id': 'Socialist_State', 'description': None, 'type': None},\n",
       "   {'id': 'Social_Welfare_Spending', 'description': None, 'type': None},\n",
       "   {'id': 'Labour_Force', 'description': None, 'type': None},\n",
       "   {'id': 'Fdi', 'description': None, 'type': None},\n",
       "   {'id': 'Free_Trade_Agreements', 'description': None, 'type': None},\n",
       "   {'id': 'Service_Sector', 'description': None, 'type': None},\n",
       "   {'id': 'Stock_Exchanges', 'description': None, 'type': None},\n",
       "   {'id': 'Manufacturing', 'description': None, 'type': None},\n",
       "   {'id': 'Population', 'description': None, 'type': None},\n",
       "   {'id': 'Unemployment', 'description': None, 'type': None},\n",
       "   {'id': 'Savings_Rate', 'description': None, 'type': None},\n",
       "   {'id': 'Arabian Sea',\n",
       "    'description': 'Sea bounded by India on the northwest.',\n",
       "    'type': 'Sea'},\n",
       "   {'id': 'Bay Of Bengal',\n",
       "    'description': 'Bay bounded by India on the southeast.',\n",
       "    'type': 'Bay'},\n",
       "   {'id': 'Africa',\n",
       "    'description': 'Continent from which modern humans arrived on the Indian subcontinent.',\n",
       "    'type': 'Continent'},\n",
       "   {'id': 'Indus Valley Civilisation',\n",
       "    'description': 'Civilisation that evolved from settled life in the western margins of the Indus river basin.',\n",
       "    'type': 'Civilization'},\n",
       "   {'id': 'Sanskrit',\n",
       "    'description': 'Indo-European language that diffused into India from the northwest.',\n",
       "    'type': 'Language'},\n",
       "   {'id': 'Rigveda',\n",
       "    'description': 'Ancient hymns recording the dawning of Hinduism in India.',\n",
       "    'type': 'Text'},\n",
       "   {'id': 'Hinduism',\n",
       "    'description': 'Major religion in India, with roots in the Rigveda.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Buddhism',\n",
       "    'description': 'Religion that arose in India, proclaiming social orders unlinked to heredity.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Jainism',\n",
       "    'description': 'Religion that arose in India, proclaiming social orders unlinked to heredity.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Mughal Empire',\n",
       "    'description': 'Empire that began in 1526, known for its architecture and relative peace.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Indian Republic',\n",
       "    'description': 'India has been a federal republic since 1950.',\n",
       "    'type': 'Government'},\n",
       "   {'id': 'Thailand',\n",
       "    'description': \"Shares maritime borders with India's Andaman and Nicobar Islands.\",\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Indonesia',\n",
       "    'description': \"Shares maritime borders with India's Andaman and Nicobar Islands.\",\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Andaman And Nicobar Islands',\n",
       "    'description': 'Islands of India sharing a maritime border with Thailand, Myanmar, and Indonesia.',\n",
       "    'type': 'Island'}],\n",
       "  'rels': [{'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'IS_PART_OF',\n",
       "    'end': 'Indomalayan Realm'},\n",
       "   {'start': 'India',\n",
       "    'description': 'About 1,900 public sector companies with complete control and ownership of railways, highways, and majority control in various industries.',\n",
       "    'type': 'HAS',\n",
       "    'end': 'Public_Sector'},\n",
       "   {'start': 'India',\n",
       "    'description': \"One of the world's highest number of billionaires.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Billionaires'},\n",
       "   {'start': 'India',\n",
       "    'description': \"World's second-largest labour force with 586 million workers.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Labour_Force'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Has free trade agreements with several nations and blocs.',\n",
       "    'type': 'HAS',\n",
       "    'end': 'Free_Trade_Agreements'},\n",
       "   {'start': 'India',\n",
       "    'description': \"Bombay Stock Exchange and National Stock Exchange are among the world's largest stock exchanges.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Stock_Exchanges'},\n",
       "   {'start': 'India',\n",
       "    'description': \"Nearly 65% of India's population is rural.\",\n",
       "    'type': 'HAS',\n",
       "    'end': 'Population'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'RELATES_TO',\n",
       "    'end': 'Rigveda'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Member of the World Trade Organization since 1 January 1995.',\n",
       "    'type': 'MEMBER_OF',\n",
       "    'end': 'Wto'},\n",
       "   {'start': 'India',\n",
       "    'description': 'High unemployment and rising income inequality.',\n",
       "    'type': 'FACES',\n",
       "    'end': 'Unemployment'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Adopted broad economic liberalisation in 1991.',\n",
       "    'type': 'ADOPTED',\n",
       "    'end': 'Economic_Liberalisation'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Often considered a welfare state.',\n",
       "    'type': 'CONSIDERED_AS',\n",
       "    'end': 'Welfare_State'},\n",
       "   {'start': 'India', 'description': None, 'type': 'NEAR', 'end': 'Sri Lanka'},\n",
       "   {'start': 'India', 'description': None, 'type': 'NEAR', 'end': 'Maldives'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Indian Ocean'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Myanmar'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Himalayan Mountain Range'},\n",
       "   {'start': 'India', 'description': None, 'type': 'BORDERS', 'end': 'China'},\n",
       "   {'start': 'India', 'description': None, 'type': 'BORDERS', 'end': 'Bhutan'},\n",
       "   {'start': 'India', 'description': None, 'type': 'BORDERS', 'end': 'Nepal'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Pakistan'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Bangladesh'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Arabian Sea'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'BORDERS',\n",
       "    'end': 'Bay Of Bengal'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'SEPARATED_BY',\n",
       "    'end': 'Sri Lanka'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'DERIVED_FROM',\n",
       "    'end': 'Sindhu'},\n",
       "   {'start': 'India',\n",
       "    'description': \"Estimates India's forest cover.\",\n",
       "    'type': 'ESTIMATES',\n",
       "    'end': 'Food And Agriculture Organization Of The United Nations'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Makes up more than 50% of GDP.',\n",
       "    'type': 'MAKES_UP',\n",
       "    'end': 'Service_Sector'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Fifth-largest economy by nominal GDP and third-largest by purchasing power parity (PPP).',\n",
       "    'type': 'RANKS_AS',\n",
       "    'end': 'World'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Fourth-largest consumer market in the world.',\n",
       "    'type': 'RANKS_AS',\n",
       "    'end': 'Consumer_Market'},\n",
       "   {'start': 'India',\n",
       "    'description': \"World's sixth-largest manufacturer, representing 2.6% of global manufacturing output.\",\n",
       "    'type': 'RANKS_AS',\n",
       "    'end': 'Manufacturing'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Officially declared a socialist state as per the constitution.',\n",
       "    'type': 'DECLARED_AS',\n",
       "    'end': 'Socialist_State'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Hinduism'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Buddhism'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Jainism'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'GOVERNED_AS',\n",
       "    'end': 'Indian Republic'},\n",
       "   {'start': 'India',\n",
       "    'description': '136th by GDP (nominal) and 125th by GDP (PPP) on a per capita income basis.',\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Gdp'},\n",
       "   {'start': 'India',\n",
       "    'description': '63rd on the Ease of Doing Business index.',\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Ease_Of_Business_Index'},\n",
       "   {'start': 'India',\n",
       "    'description': '40th on the Global Competitiveness Index.',\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Global_Competitiveness_Index'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'SHARES_BORDERS_WITH',\n",
       "    'end': 'Myanmar'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'SHARES_BORDERS_WITH',\n",
       "    'end': 'Thailand'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'SHARES_BORDERS_WITH',\n",
       "    'end': 'Indonesia'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Overall social welfare spending stood at 8.6% of GDP in 2021-22.',\n",
       "    'type': 'SPENDING',\n",
       "    'end': 'Social_Welfare_Spending'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_EVENT',\n",
       "    'end': 'Mughal Empire'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'ORIGINATES_IN',\n",
       "    'end': 'Ganges'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_BIODIVERSITY_HOTSPOT',\n",
       "    'end': 'Western Ghats'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_BIODIVERSITY_HOTSPOT',\n",
       "    'end': 'Eastern Himalayas'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_BIODIVERSITY_HOTSPOT',\n",
       "    'end': 'Indo-Burma Hotspot'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_ECOSYSTEM',\n",
       "    'end': 'Forests'},\n",
       "   {'start': 'India',\n",
       "    'description': '6% to 7% since the start of the 21st century.',\n",
       "    'type': 'AVERAGE_ANNUAL_GROWTH',\n",
       "    'end': 'Gdp_Growth'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Foreign direct investment in 2021-22 was $82 billion.',\n",
       "    'type': 'FOREIGN_DIRECT_INVESTMENT',\n",
       "    'end': 'Fdi'},\n",
       "   {'start': 'India',\n",
       "    'description': 'Gross domestic savings rate stood at 29.3% of GDP in 2022.',\n",
       "    'type': 'GROSS_DOMESTIC_SAVINGS_RATE',\n",
       "    'end': 'Savings_Rate'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HUMAN_ORIGIN',\n",
       "    'end': 'Africa'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_DEVELOPMENT',\n",
       "    'end': 'Indus Valley Civilisation'},\n",
       "   {'start': 'India',\n",
       "    'description': None,\n",
       "    'type': 'LANGUAGE_DIFFUSION',\n",
       "    'end': 'Sanskrit'},\n",
       "   {'start': 'Kautalyas Arthashastra',\n",
       "    'description': 'Discusses the need for forest administration.',\n",
       "    'type': 'DISCUSSES',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Indian Forest Act Of 1865',\n",
       "    'description': \"Establishes government's claims over forests.\",\n",
       "    'type': 'ESTABLISHES',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Crown Land (Encroachment) Ordinance',\n",
       "    'description': \"Targets forests in Britain's Asian colonies.\",\n",
       "    'type': 'TARGETS',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Yajnavalkya Smriti',\n",
       "    'description': 'Prohibits the cutting of trees.',\n",
       "    'type': 'PROHIBITS',\n",
       "    'end': 'India'},\n",
       "   {'start': '2013 Forest Survey Of India',\n",
       "    'description': 'Reports on forest cover increase.',\n",
       "    'type': 'REPORTS_ON',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Supreme Court Of India',\n",
       "    'description': None,\n",
       "    'type': 'PART_OF_JUDICIARY',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Indian National Congress',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICALLY_DOMINANT_PARTY',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Forest Act Of 1878',\n",
       "    'description': 'Gives control over all wastelands, including forests.',\n",
       "    'type': 'GIVES_CONTROL',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Sir Dietrich Brandis',\n",
       "    'description': 'Inspector General of Forests in India from 1864 to 1883.',\n",
       "    'type': 'INSPECTOR_GENERAL_OF',\n",
       "    'end': 'India'},\n",
       "   {'start': 'Andaman And Nicobar Islands',\n",
       "    'description': None,\n",
       "    'type': 'MARITIME_BORDER',\n",
       "    'end': 'Myanmar'},\n",
       "   {'start': 'Andaman And Nicobar Islands',\n",
       "    'description': None,\n",
       "    'type': 'MARITIME_BORDER',\n",
       "    'end': 'Thailand'},\n",
       "   {'start': 'Andaman And Nicobar Islands',\n",
       "    'description': None,\n",
       "    'type': 'MARITIME_BORDER',\n",
       "    'end': 'Indonesia'}]},\n",
       " {'communityId': '1-7',\n",
       "  'nodes': [{'id': 'Constitution Of India',\n",
       "    'description': 'The supreme law of India, laying down the framework for government institutions and fundamental rights.',\n",
       "    'type': 'Document'},\n",
       "   {'id': 'Parliament',\n",
       "    'description': 'Cannot override the Constitution of India.',\n",
       "    'type': 'Institution'},\n",
       "   {'id': 'Government Of India Act 1935',\n",
       "    'description': 'Replaced by the Constitution of India.',\n",
       "    'type': 'Document'},\n",
       "   {'id': 'Constituent Assembly',\n",
       "    'description': 'Tasked with drafting the Constitution of India.',\n",
       "    'type': 'Government body'},\n",
       "   {'id': 'M. N. Roy',\n",
       "    'description': 'Proposed the framework for the Constitution of India.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Republic Day',\n",
       "    'description': 'Celebrated on 26 January in India to honor the Constitution.',\n",
       "    'type': 'Event'},\n",
       "   {'id': 'Old Parliament House',\n",
       "    'description': 'Preserves the original 1950 Constitution in a nitrogen-filled case.',\n",
       "    'type': 'Location'},\n",
       "   {'id': 'British Government',\n",
       "    'description': 'Responsible for the external security of India during its dominion status.',\n",
       "    'type': 'Institution'},\n",
       "   {'id': 'Indian Independence Act 1947',\n",
       "    'description': 'Repealed by the Constitution of India.',\n",
       "    'type': 'Document'},\n",
       "   {'id': 'Articles Of The Constitution',\n",
       "    'description': 'Articles 5, 6, 7, 8, 9, 60, 324, 366, 367, 379, 380, 388, 391, 392, 393, and 394 came into force on 26 November 1949.',\n",
       "    'type': 'Document'},\n",
       "   {'id': 'Constituent Assembly Of India',\n",
       "    'description': 'Adopted the Constitution of India on 26 November 1949.',\n",
       "    'type': 'Institution'},\n",
       "   {'id': 'Sardar Patel',\n",
       "    'description': 'Convinced princely states to sign articles of integration with India.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'V. P. Menon',\n",
       "    'description': 'Convinced princely states to sign articles of integration with India.',\n",
       "    'type': 'Person'}],\n",
       "  'rels': [{'start': 'Constitution Of India',\n",
       "    'description': 'The Constitution is based on the proposal suggested by M. N. Roy.',\n",
       "    'type': 'BASED_ON',\n",
       "    'end': 'M. N. Roy'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'Adopted by the Constituent Assembly on 26 November 1949.',\n",
       "    'type': 'ADOPTED_BY',\n",
       "    'end': 'Constituent Assembly Of India'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'The original 1950 Constitution is preserved in a nitrogen-filled case.',\n",
       "    'type': 'PRESERVED_IN',\n",
       "    'end': 'Old Parliament House'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'Celebrated on 26 January.',\n",
       "    'type': 'CELEBRATED_ON',\n",
       "    'end': 'Republic Day'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'Parliament cannot override the Constitution.',\n",
       "    'type': 'CANNOT_OVERRIDE',\n",
       "    'end': 'Parliament'},\n",
       "   {'start': 'Constitution Of India',\n",
       "    'description': 'Certain articles came into force on 26 November 1949.',\n",
       "    'type': 'CAME_INTO_FORCE',\n",
       "    'end': 'Articles Of The Constitution'},\n",
       "   {'start': 'Government Of India Act 1935',\n",
       "    'description': 'Replaced by the Constitution of India.',\n",
       "    'type': 'REPLACED_BY',\n",
       "    'end': 'Constitution Of India'},\n",
       "   {'start': 'British Government',\n",
       "    'description': 'Responsible for the external security of India during its dominion status.',\n",
       "    'type': 'RESPONSIBLE_FOR',\n",
       "    'end': 'Constitution Of India'},\n",
       "   {'start': 'Indian Independence Act 1947',\n",
       "    'description': 'Repealed by the Constitution of India.',\n",
       "    'type': 'REPEALED_BY',\n",
       "    'end': 'Constitution Of India'},\n",
       "   {'start': 'Constituent Assembly',\n",
       "    'description': None,\n",
       "    'type': 'DRAFTED_BY',\n",
       "    'end': 'Constitution Of India'},\n",
       "   {'start': 'Sardar Patel',\n",
       "    'description': 'Convinced princely states to sign articles of integration.',\n",
       "    'type': 'CONVINCED',\n",
       "    'end': 'Constituent Assembly Of India'},\n",
       "   {'start': 'V. P. Menon',\n",
       "    'description': 'Convinced princely states to sign articles of integration.',\n",
       "    'type': 'CONVINCED',\n",
       "    'end': 'Constituent Assembly Of India'}]},\n",
       " {'communityId': '1-4',\n",
       "  'nodes': [{'id': 'President Of India',\n",
       "    'description': 'The Supreme Commander of the Indian Armed Forces.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Nda',\n",
       "    'description': 'A coalition of the BJP and its allies governing India since 2014.',\n",
       "    'type': 'Political alliance'},\n",
       "   {'id': 'Government Of India',\n",
       "    'description': 'Established a system of national parks and protected areas.',\n",
       "    'type': 'Government'},\n",
       "   {'id': 'Narendra Modi',\n",
       "    'description': 'Current Prime Minister of India since 26 May 2014.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'New Delhi',\n",
       "    'description': 'The seat of the Government of India.',\n",
       "    'type': 'Location'},\n",
       "   {'id': 'Supreme Court',\n",
       "    'description': 'The highest judicial forum and final court of appeal under the Constitution of India.',\n",
       "    'type': 'Judiciary'},\n",
       "   {'id': 'Indian Councils Act 1909',\n",
       "    'description': 'Introduced elections to the Imperial Legislative Council.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Government Of India Act 1919',\n",
       "    'description': 'Expanded the Imperial Legislative Council.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'National Parks',\n",
       "    'description': 'Established in 1935 and expanded to nearly 1022 by 2023.',\n",
       "    'type': 'Protected area'},\n",
       "   {'id': 'Wildlife Protection Act Of 1972',\n",
       "    'description': 'Enacted for the protection of wildlife.',\n",
       "    'type': 'Legislation'},\n",
       "   {'id': 'Project Tiger',\n",
       "    'description': 'Special project for the protection of critical species.',\n",
       "    'type': 'Conservation project'},\n",
       "   {'id': 'Project Elephant',\n",
       "    'description': 'Special project for the protection of critical species.',\n",
       "    'type': 'Conservation project'},\n",
       "   {'id': 'Project Dolphin',\n",
       "    'description': 'Special project for the protection of critical species.',\n",
       "    'type': 'Conservation project'},\n",
       "   {'id': 'Rajya Sabha',\n",
       "    'description': 'The mostly indirectly elected upper house of Parliament.',\n",
       "    'type': 'Government body'},\n",
       "   {'id': 'Lok Sabha',\n",
       "    'description': 'The directly elected lower house of Parliament.',\n",
       "    'type': 'Government body'},\n",
       "   {'id': 'Union Council Of Ministers',\n",
       "    'description': 'The executive decision-making committee of the government.',\n",
       "    'type': 'Government body'}],\n",
       "  'rels': [{'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'INITIATED',\n",
       "    'end': 'Project Tiger'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'INITIATED',\n",
       "    'end': 'Project Elephant'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'INITIATED',\n",
       "    'end': 'Project Dolphin'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'GOVERNED_BY',\n",
       "    'end': 'Nda'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'COMPOSED_OF',\n",
       "    'end': 'Union Council Of Ministers'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'ENACTED',\n",
       "    'end': 'Wildlife Protection Act Of 1972'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'ESTABLISHED',\n",
       "    'end': 'National Parks'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'LEAD_BY',\n",
       "    'end': 'Narendra Modi'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'RESPONSIBLE_TO',\n",
       "    'end': 'Supreme Court'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'SEATED_IN',\n",
       "    'end': 'New Delhi'},\n",
       "   {'start': 'Government Of India',\n",
       "    'description': None,\n",
       "    'type': 'HEAD_OF_STATE',\n",
       "    'end': 'President Of India'},\n",
       "   {'start': 'Indian Councils Act 1909',\n",
       "    'description': None,\n",
       "    'type': 'INFLUENCED',\n",
       "    'end': 'Government Of India'},\n",
       "   {'start': 'Government Of India Act 1919',\n",
       "    'description': None,\n",
       "    'type': 'INFLUENCED',\n",
       "    'end': 'Government Of India'},\n",
       "   {'start': 'Union Council Of Ministers',\n",
       "    'description': None,\n",
       "    'type': 'RESPONSIBLE_TO',\n",
       "    'end': 'Rajya Sabha'},\n",
       "   {'start': 'Union Council Of Ministers',\n",
       "    'description': None,\n",
       "    'type': 'RESPONSIBLE_TO',\n",
       "    'end': 'Lok Sabha'}]},\n",
       " {'communityId': '1-22',\n",
       "  'nodes': [{'id': 'Prime Minister Of India',\n",
       "    'description': 'Holds executive authority and responsibility for national security.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Indian Armed Forces',\n",
       "    'description': 'The military forces of the Republic of India.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Army',\n",
       "    'description': 'One of the three professional uniformed services of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Navy',\n",
       "    'description': 'One of the three professional uniformed services of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Air Force',\n",
       "    'description': 'One of the three professional uniformed services of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Central Armed Police Forces',\n",
       "    'description': 'Supports the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Indian Coast Guard',\n",
       "    'description': 'Supports the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Special Frontier Force',\n",
       "    'description': 'Supports the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Strategic Forces Command',\n",
       "    'description': 'An inter-service command of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Andaman And Nicobar Command',\n",
       "    'description': 'An inter-service command of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Integrated Defence Staff',\n",
       "    'description': 'An inter-service command of the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Ministry Of Defence',\n",
       "    'description': 'Manages the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Global Firepower Index',\n",
       "    'description': 'Ranks the military forces globally.',\n",
       "    'type': 'Report'},\n",
       "   {'id': 'Armed Forces Flag Day',\n",
       "    'description': 'Honors armed forces and military personnel annually.',\n",
       "    'type': 'Event'},\n",
       "   {'id': 'Mauryan Empire',\n",
       "    'description': 'An ancient Indian empire known for its powerful military.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Chola Empire',\n",
       "    'description': 'Known for foreign trade and maritime activity.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Department Of Defence Production',\n",
       "    'description': 'Responsible for indigenous production of equipment for the Indian Armed Forces.',\n",
       "    'type': 'Organization'},\n",
       "   {'id': 'Make In India Initiative',\n",
       "    'description': 'Seeks to indigenise manufacturing and reduce dependence on imports for defence.',\n",
       "    'type': 'Program'}],\n",
       "  'rels': [{'start': 'Prime Minister Of India',\n",
       "    'description': None,\n",
       "    'type': 'EXECUTIVE_AUTHORITY',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Indian Army'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Indian Navy'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Indian Air Force'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Central Armed Police Forces'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Indian Coast Guard'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Special Frontier Force'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Strategic Forces Command'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Andaman And Nicobar Command'},\n",
       "   {'start': 'Indian Armed Forces',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTED_BY',\n",
       "    'end': 'Integrated Defence Staff'},\n",
       "   {'start': 'Ministry Of Defence',\n",
       "    'description': None,\n",
       "    'type': 'MANAGES',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Global Firepower Index',\n",
       "    'description': None,\n",
       "    'type': 'RANKS',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Armed Forces Flag Day',\n",
       "    'description': None,\n",
       "    'type': 'HONORS',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Department Of Defence Production',\n",
       "    'description': None,\n",
       "    'type': 'PRODUCES_EQUIPMENT_FOR',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Mauryan Empire',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_REFERENCE',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Chola Empire',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_REFERENCE',\n",
       "    'end': 'Indian Armed Forces'},\n",
       "   {'start': 'Make In India Initiative',\n",
       "    'description': None,\n",
       "    'type': 'SUPPORTS',\n",
       "    'end': 'Department Of Defence Production'}]},\n",
       " {'communityId': '1-2',\n",
       "  'nodes': [{'id': 'Republic Of India',\n",
       "    'description': 'Has two principal official short names, India and Bharat.',\n",
       "    'type': 'Country'},\n",
       "   {'id': 'Hindustan',\n",
       "    'description': 'Commonly used name for the Republic of India.',\n",
       "    'type': 'Name'},\n",
       "   {'id': 'Bharat',\n",
       "    'description': 'Another principal official short name of the Republic of India.',\n",
       "    'type': 'Name'},\n",
       "   {'id': 'Dushyanta',\n",
       "    'description': 'Father of Bharata, associated with the name Bhāratavarṣa.',\n",
       "    'type': 'Person'},\n",
       "   {'id': 'Mahabharata',\n",
       "    'description': 'Epic associated with the name Bharata.',\n",
       "    'type': 'Literature'},\n",
       "   {'id': 'Bhāratavarṣa',\n",
       "    'description': 'Term used in the first century AD, derived from the name of the Vedic community of Bharatas.',\n",
       "    'type': 'Historical term'},\n",
       "   {'id': 'Bharatas',\n",
       "    'description': 'Mentioned in the Rigveda as one of the principal kingdoms of the Aryavarta.',\n",
       "    'type': 'Vedic community'}],\n",
       "  'rels': [{'start': 'Republic Of India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_NAME',\n",
       "    'end': 'Bharat'},\n",
       "   {'start': 'Republic Of India',\n",
       "    'description': None,\n",
       "    'type': 'HAS_NAME',\n",
       "    'end': 'Hindustan'},\n",
       "   {'start': 'Bharat',\n",
       "    'description': None,\n",
       "    'type': 'ASSOCIATED_WITH',\n",
       "    'end': 'Dushyanta'},\n",
       "   {'start': 'Bharat',\n",
       "    'description': None,\n",
       "    'type': 'ASSOCIATED_WITH',\n",
       "    'end': 'Mahabharata'},\n",
       "   {'start': 'Bharat',\n",
       "    'description': None,\n",
       "    'type': 'DERIVED_FROM',\n",
       "    'end': 'Bhāratavarṣa'},\n",
       "   {'start': 'Bhāratavarṣa',\n",
       "    'description': None,\n",
       "    'type': 'DERIVED_FROM',\n",
       "    'end': 'Bharatas'}]},\n",
       " {'communityId': '1-18',\n",
       "  'nodes': [{'id': 'Fauna Species',\n",
       "    'description': 'India has an estimated 92,873 species of fauna.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Insects',\n",
       "    'description': 'Major category with 63,423 recorded species.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Mammals Count',\n",
       "    'description': '423 mammals in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Birds Count',\n",
       "    'description': '1,233 birds in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Reptiles Count',\n",
       "    'description': '526 reptiles in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Amphibians Count',\n",
       "    'description': '342 amphibians in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Fish Count',\n",
       "    'description': '3,022 fish in India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Mammals',\n",
       "    'description': '12.6% of mammals are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Birds',\n",
       "    'description': '4.5% of birds are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Reptiles',\n",
       "    'description': '45.8% of reptiles are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Amphibians',\n",
       "    'description': '55.8% of amphibians are endemic to India.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Large Animals',\n",
       "    'description': 'Includes Indian elephant, Indian rhinoceros, and Gaur.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Big Cats',\n",
       "    'description': 'Includes tiger and lion.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Cat Family',\n",
       "    'description': 'Includes Bengal tiger, Asiatic lion, Indian leopard, snow leopard, and clouded leopard.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Representative Species',\n",
       "    'description': 'Includes blackbuck, nilgai, bharal, barasingha, Nilgiri tahr, and Nilgiri langur.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Aquatic Mammals',\n",
       "    'description': 'Includes dolphins, whales, porpoises, and dugong.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Reptiles Species',\n",
       "    'description': 'Includes gharial and saltwater crocodiles.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Birds Species',\n",
       "    'description': 'Includes peafowl, pheasants, geese, ducks, mynas, parakeets, pigeons, cranes, hornbills, and sunbirds.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Endemic Bird Species',\n",
       "    'description': 'Includes great Indian hornbill, great Indian bustard, nicobar pigeon, ruddy shelduck, Himalayan monal, and Himalayan quail.',\n",
       "    'type': 'Fauna'}],\n",
       "  'rels': [{'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Insects'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Mammals Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Birds Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Reptiles Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Amphibians Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Fish Count'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Mammals'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Birds'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Reptiles'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Amphibians'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Large Animals'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Big Cats'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Cat Family'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Representative Species'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Aquatic Mammals'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Reptiles Species'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Birds Species'},\n",
       "   {'start': 'Fauna Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Bird Species'}]},\n",
       " {'communityId': '1-20',\n",
       "  'nodes': [{'id': 'Plant Species',\n",
       "    'description': 'About 29,015 species of plants.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Flowering Plants Count',\n",
       "    'description': '17,926 species of flowering plants.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Endemic Plant Species',\n",
       "    'description': '6,842 species are endemic to India.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Algae', 'description': '7,244 species.', 'type': 'Flora'},\n",
       "   {'id': 'Bryophytes', 'description': '2,504 species.', 'type': 'Flora'},\n",
       "   {'id': 'Pteridophytes', 'description': '1,267 species.', 'type': 'Flora'},\n",
       "   {'id': 'Gymnosperms', 'description': '74 species.', 'type': 'Flora'},\n",
       "   {'id': 'Fungal Diversity',\n",
       "    'description': 'Over 27,000 recorded species.',\n",
       "    'type': 'Flora'},\n",
       "   {'id': 'Flora', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Plant Species'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Flowering Plants Count'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Endemic Plant Species'},\n",
       "   {'start': 'Flora', 'description': None, 'type': 'INCLUDES', 'end': 'Algae'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Bryophytes'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Pteridophytes'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Gymnosperms'},\n",
       "   {'start': 'Flora',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Fungal Diversity'}]},\n",
       " {'communityId': '1-19',\n",
       "  'nodes': [{'id': 'Threatened Species',\n",
       "    'description': '172 IUCN-designated threatened species.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Mammals',\n",
       "    'description': '39 species of mammals.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Birds',\n",
       "    'description': '72 species of birds.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Reptiles',\n",
       "    'description': '17 species of reptiles.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Amphibians',\n",
       "    'description': '3 species of amphibians.',\n",
       "    'type': 'Fauna'},\n",
       "   {'id': 'Threatened Fish',\n",
       "    'description': '2 species of fish.',\n",
       "    'type': 'Fauna'}],\n",
       "  'rels': [{'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Mammals'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Birds'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Reptiles'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Amphibians'},\n",
       "   {'start': 'Threatened Species',\n",
       "    'description': None,\n",
       "    'type': 'INCLUDES',\n",
       "    'end': 'Threatened Fish'}]},\n",
       " {'communityId': '1-25',\n",
       "  'nodes': [{'id': 'Maurya Empire',\n",
       "    'description': 'Ancient empire based in the Ganges Basin.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Gupta Empire',\n",
       "    'description': 'Ancient empire based in the Ganges Basin.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'Ganges Basin', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'Ganges Basin',\n",
       "    'description': None,\n",
       "    'type': 'BASED_IN',\n",
       "    'end': 'Maurya Empire'},\n",
       "   {'start': 'Ganges Basin',\n",
       "    'description': None,\n",
       "    'type': 'BASED_IN',\n",
       "    'end': 'Gupta Empire'}]},\n",
       " {'communityId': '1-26',\n",
       "  'nodes': [{'id': 'Vijayanagara Empire',\n",
       "    'description': 'Empire in south India that created a composite Hindu culture.',\n",
       "    'type': 'Empire'},\n",
       "   {'id': 'South India', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'South India',\n",
       "    'description': None,\n",
       "    'type': 'BASED_IN',\n",
       "    'end': 'Vijayanagara Empire'}]},\n",
       " {'communityId': '1-27',\n",
       "  'nodes': [{'id': 'Sikhism',\n",
       "    'description': 'Religion that emerged in the Punjab, rejecting institutionalised religion.',\n",
       "    'type': 'Religion'},\n",
       "   {'id': 'Punjab', 'description': None, 'type': None}],\n",
       "  'rels': [{'start': 'Punjab',\n",
       "    'description': None,\n",
       "    'type': 'ORIGIN_OF',\n",
       "    'end': 'Sikhism'}]},\n",
       " {'communityId': '1-24',\n",
       "  'nodes': [{'id': 'British East India Company',\n",
       "    'description': 'Company that expanded rule in India, turning it into a colonial economy.',\n",
       "    'type': 'Company'},\n",
       "   {'id': 'British Crown',\n",
       "    'description': 'Began rule in India in 1858.',\n",
       "    'type': 'Government'},\n",
       "   {'id': 'Indian Independence',\n",
       "    'description': 'Event in 1947 when India was partitioned into two independent dominions.',\n",
       "    'type': 'Event'}],\n",
       "  'rels': [{'start': 'British East India Company',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_EVENT',\n",
       "    'end': 'British Crown'},\n",
       "   {'start': 'British Crown',\n",
       "    'description': None,\n",
       "    'type': 'HISTORICAL_EVENT',\n",
       "    'end': 'Indian Independence'}]}]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "community_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "community_template = \"\"\"Based on the provided nodes and relationships that belong to the same graph community,\n",
    "generate a natural language summary of the provided information:\n",
    "{community_info}\n",
    "\n",
    "Summary:\"\"\"  \n",
    "model = \"openai-gpt-4o\"\n",
    "llm, model_name = get_llm(model)\n",
    "community_prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\n",
    "            \"system\",\n",
    "            \"Given an input triples, generate the information summary. No pre-amble.\",\n",
    "        ),\n",
    "        (\"human\", community_template),\n",
    "    ]\n",
    ")\n",
    "\n",
    "community_chain = community_prompt | llm | StrOutputParser()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def prepare_string(data):\n",
    "    nodes_str = \"Nodes are:\\n\"\n",
    "    for node in data['nodes']:\n",
    "        node_id = node['id']\n",
    "        node_type = node['type']\n",
    "        if 'description' in node and node['description']:\n",
    "            node_description = f\", description: {node['description']}\"\n",
    "        else:\n",
    "            node_description = \"\"\n",
    "        nodes_str += f\"id: {node_id}, type: {node_type}{node_description}\\n\"\n",
    "\n",
    "    rels_str = \"Relationships are:\\n\"\n",
    "    for rel in data['rels']:\n",
    "        start = rel['start']\n",
    "        end = rel['end']\n",
    "        rel_type = rel['type']\n",
    "        if 'description' in rel and rel['description']:\n",
    "            description = f\", description: {rel['description']}\"\n",
    "        else:\n",
    "            description = \"\"\n",
    "        rels_str += f\"({start})-[:{rel_type}]->({end}){description}\\n\"\n",
    "\n",
    "    return nodes_str + \"\\n\" + rels_str\n",
    "\n",
    "def process_community(community):\n",
    "    stringify_info = prepare_string(community)\n",
    "    summary = community_chain.invoke({'community_info': stringify_info})\n",
    "    return {\"community\": community['communityId'], \"summary\": summary}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nodes are:\n",
      "id: India, type: Country, description: Officially the Republic of India, located in South Asia.\n",
      "id: Supreme Court Of India, type: Judiciary, description: Head of the independent judiciary.\n",
      "id: Indian National Congress, type: Political party, description: Dominated Indian politics until 1977.\n",
      "id: Sindhu, type: River, description: Name of the Indus River, from which the name India is derived.\n",
      "id: Food And Agriculture Organization Of The United Nations, type: Organization, description: Estimates India's forest cover.\n",
      "id: 2013 Forest Survey Of India, type: Report, description: States India's forest cover increased to 69.8 million hectares by 2012.\n",
      "id: Yajnavalkya Smriti, type: Literature, description: Prohibited the cutting of trees.\n",
      "id: Kautalyas Arthashastra, type: Literature, description: Discusses the need for forest administration.\n",
      "id: Crown Land (Encroachment) Ordinance, type: Legislation, description: Promulgated in 1840 targeting forests in Britain's Asian colonies.\n",
      "id: Indian Forest Act Of 1865, type: Legislation, description: Established the government's claims over forests.\n",
      "id: Forest Act Of 1878, type: Legislation, description: Gave the British government control over all wastelands, including forests.\n",
      "id: Sir Dietrich Brandis, type: Person, description: Inspector General of Forests in India from 1864 to 1883.\n",
      "id: Indian Ocean, type: Ocean, description: Ocean bounded by India on the north.\n",
      "id: Sri Lanka, type: Country, description: Country in the vicinity of India in the Indian Ocean.\n",
      "id: Maldives, type: Country, description: Country in the vicinity of India in the Indian Ocean.\n",
      "id: Myanmar, type: Country, description: Country sharing land border with India to the east.\n",
      "id: Himalayan Mountain Range, type: Mountain range, description: Defines the northern frontiers of India.\n",
      "id: China, type: Country, description: Country sharing land border with India to the north.\n",
      "id: Bhutan, type: Country, description: Country sharing land border with India to the north.\n",
      "id: Nepal, type: Country, description: Country sharing land border with India to the north.\n",
      "id: Pakistan, type: Country, description: Country sharing land border with India to the west.\n",
      "id: Bangladesh, type: Country, description: Country sharing land border with India to the east.\n",
      "id: Ganges, type: River, description: The longest river originating in India.\n",
      "id: Western Ghats, type: Biodiversity hotspot, description: One of the three biodiversity hotspots in India.\n",
      "id: Eastern Himalayas, type: Biodiversity hotspot, description: One of the three biodiversity hotspots in India.\n",
      "id: Indo-Burma Hotspot, type: Biodiversity hotspot, description: One of the three biodiversity hotspots in India.\n",
      "id: Forests, type: Ecosystem, description: Covers about 24.6% of the total land area.\n",
      "id: Indomalayan Realm, type: Realm, description: Geographical realm that includes India.\n",
      "id: World, type: None\n",
      "id: Public_Sector, type: None\n",
      "id: Gdp, type: None\n",
      "id: Economic_Liberalisation, type: None\n",
      "id: Gdp_Growth, type: None\n",
      "id: Consumer_Market, type: None\n",
      "id: Wto, type: None\n",
      "id: Ease_Of_Business_Index, type: None\n",
      "id: Global_Competitiveness_Index, type: None\n",
      "id: Billionaires, type: None\n",
      "id: Welfare_State, type: None\n",
      "id: Socialist_State, type: None\n",
      "id: Social_Welfare_Spending, type: None\n",
      "id: Labour_Force, type: None\n",
      "id: Fdi, type: None\n",
      "id: Free_Trade_Agreements, type: None\n",
      "id: Service_Sector, type: None\n",
      "id: Stock_Exchanges, type: None\n",
      "id: Manufacturing, type: None\n",
      "id: Population, type: None\n",
      "id: Unemployment, type: None\n",
      "id: Savings_Rate, type: None\n",
      "id: Arabian Sea, type: Sea, description: Sea bounded by India on the northwest.\n",
      "id: Bay Of Bengal, type: Bay, description: Bay bounded by India on the southeast.\n",
      "id: Africa, type: Continent, description: Continent from which modern humans arrived on the Indian subcontinent.\n",
      "id: Indus Valley Civilisation, type: Civilization, description: Civilisation that evolved from settled life in the western margins of the Indus river basin.\n",
      "id: Sanskrit, type: Language, description: Indo-European language that diffused into India from the northwest.\n",
      "id: Rigveda, type: Text, description: Ancient hymns recording the dawning of Hinduism in India.\n",
      "id: Hinduism, type: Religion, description: Major religion in India, with roots in the Rigveda.\n",
      "id: Buddhism, type: Religion, description: Religion that arose in India, proclaiming social orders unlinked to heredity.\n",
      "id: Jainism, type: Religion, description: Religion that arose in India, proclaiming social orders unlinked to heredity.\n",
      "id: Mughal Empire, type: Empire, description: Empire that began in 1526, known for its architecture and relative peace.\n",
      "id: Indian Republic, type: Government, description: India has been a federal republic since 1950.\n",
      "\n",
      "Relationships are:\n",
      "(India)-[:IS_PART_OF]->(Indomalayan Realm)\n",
      "(India)-[:HAS]->(Public_Sector), description: About 1,900 public sector companies with complete control and ownership of railways, highways, and majority control in various industries.\n",
      "(India)-[:HAS]->(Billionaires), description: One of the world's highest number of billionaires.\n",
      "(India)-[:HAS]->(Labour_Force), description: World's second-largest labour force with 586 million workers.\n",
      "(India)-[:HAS]->(Free_Trade_Agreements), description: Has free trade agreements with several nations and blocs.\n",
      "(India)-[:HAS]->(Stock_Exchanges), description: Bombay Stock Exchange and National Stock Exchange are among the world's largest stock exchanges.\n",
      "(India)-[:HAS]->(Population), description: Nearly 65% of India's population is rural.\n",
      "(India)-[:RELATES_TO]->(Rigveda)\n",
      "(India)-[:MEMBER_OF]->(Wto), description: Member of the World Trade Organization since 1 January 1995.\n",
      "(India)-[:FACES]->(Unemployment), description: High unemployment and rising income inequality.\n",
      "(India)-[:ADOPTED]->(Economic_Liberalisation), description: Adopted broad economic liberalisation in 1991.\n",
      "(India)-[:CONSIDERED_AS]->(Welfare_State), description: Often considered a welfare state.\n",
      "(India)-[:NEAR]->(Sri Lanka)\n",
      "(India)-[:NEAR]->(Maldives)\n",
      "(India)-[:BORDERS]->(Indian Ocean)\n",
      "(India)-[:BORDERS]->(Myanmar)\n",
      "(India)-[:BORDERS]->(Himalayan Mountain Range)\n",
      "(India)-[:BORDERS]->(China)\n",
      "(India)-[:BORDERS]->(Bhutan)\n",
      "(India)-[:BORDERS]->(Nepal)\n",
      "(India)-[:BORDERS]->(Pakistan)\n",
      "(India)-[:BORDERS]->(Bangladesh)\n",
      "(India)-[:BORDERS]->(Arabian Sea)\n",
      "(India)-[:BORDERS]->(Bay Of Bengal)\n",
      "(India)-[:SEPARATED_BY]->(Sri Lanka)\n",
      "(India)-[:DERIVED_FROM]->(Sindhu)\n",
      "(India)-[:ESTIMATES]->(Food And Agriculture Organization Of The United Nations), description: Estimates India's forest cover.\n",
      "(India)-[:MAKES_UP]->(Service_Sector), description: Makes up more than 50% of GDP.\n",
      "(India)-[:RANKS_AS]->(World), description: Fifth-largest economy by nominal GDP and third-largest by purchasing power parity (PPP).\n",
      "(India)-[:RANKS_AS]->(Consumer_Market), description: Fourth-largest consumer market in the world.\n",
      "(India)-[:RANKS_AS]->(Manufacturing), description: World's sixth-largest manufacturer, representing 2.6% of global manufacturing output.\n",
      "(India)-[:DECLARED_AS]->(Socialist_State), description: Officially declared a socialist state as per the constitution.\n",
      "(India)-[:ORIGIN_OF]->(Hinduism)\n",
      "(India)-[:ORIGIN_OF]->(Buddhism)\n",
      "(India)-[:ORIGIN_OF]->(Jainism)\n",
      "(India)-[:GOVERNED_AS]->(Indian Republic)\n",
      "(India)-[:RANKS]->(Gdp), description: 136th by GDP (nominal) and 125th by GDP (PPP) on a per capita income basis.\n",
      "(India)-[:RANKS]->(Ease_Of_Business_Index), description: 63rd on the Ease of Doing Business index.\n",
      "(India)-[:RANKS]->(Global_Competitiveness_Index), description: 40th on the Global Competitiveness Index.\n",
      "(India)-[:SHARES_BORDERS_WITH]->(Myanmar)\n",
      "(India)-[:SPENDING]->(Social_Welfare_Spending), description: Overall social welfare spending stood at 8.6% of GDP in 2021-22.\n",
      "(India)-[:HISTORICAL_EVENT]->(Mughal Empire)\n",
      "(India)-[:ORIGINATES_IN]->(Ganges)\n",
      "(India)-[:HAS_BIODIVERSITY_HOTSPOT]->(Western Ghats)\n",
      "(India)-[:HAS_BIODIVERSITY_HOTSPOT]->(Eastern Himalayas)\n",
      "(India)-[:HAS_BIODIVERSITY_HOTSPOT]->(Indo-Burma Hotspot)\n",
      "(India)-[:HAS_ECOSYSTEM]->(Forests)\n",
      "(India)-[:AVERAGE_ANNUAL_GROWTH]->(Gdp_Growth), description: 6% to 7% since the start of the 21st century.\n",
      "(India)-[:FOREIGN_DIRECT_INVESTMENT]->(Fdi), description: Foreign direct investment in 2021-22 was $82 billion.\n",
      "(India)-[:GROSS_DOMESTIC_SAVINGS_RATE]->(Savings_Rate), description: Gross domestic savings rate stood at 29.3% of GDP in 2022.\n",
      "(India)-[:HUMAN_ORIGIN]->(Africa)\n",
      "(India)-[:HISTORICAL_DEVELOPMENT]->(Indus Valley Civilisation)\n",
      "(India)-[:LANGUAGE_DIFFUSION]->(Sanskrit)\n",
      "(Kautalyas Arthashastra)-[:DISCUSSES]->(India), description: Discusses the need for forest administration.\n",
      "(Indian Forest Act Of 1865)-[:ESTABLISHES]->(India), description: Establishes government's claims over forests.\n",
      "(Crown Land (Encroachment) Ordinance)-[:TARGETS]->(India), description: Targets forests in Britain's Asian colonies.\n",
      "(Yajnavalkya Smriti)-[:PROHIBITS]->(India), description: Prohibits the cutting of trees.\n",
      "(2013 Forest Survey Of India)-[:REPORTS_ON]->(India), description: Reports on forest cover increase.\n",
      "(Supreme Court Of India)-[:PART_OF_JUDICIARY]->(India)\n",
      "(Indian National Congress)-[:HISTORICALLY_DOMINANT_PARTY]->(India)\n",
      "(Forest Act Of 1878)-[:GIVES_CONTROL]->(India), description: Gives control over all wastelands, including forests.\n",
      "(Sir Dietrich Brandis)-[:INSPECTOR_GENERAL_OF]->(India), description: Inspector General of Forests in India from 1864 to 1883.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(prepare_string(community_info[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing communities:   0%|          | 0/30 [00:00<?, ?it/s]"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing communities: 100%|██████████| 30/30 [00:20<00:00,  1.48it/s]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "MAX_WORKERS = 10\n",
    "summaries = []\n",
    "with ThreadPoolExecutor() as executor:\n",
    "    futures = {executor.submit(process_community, community): community for community in community_info}\n",
    "\n",
    "    for future in tqdm(as_completed(futures), total=len(futures), desc=\"Processing communities\"):\n",
    "        summaries.append(future.result())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Store summaries\n",
    "graph.query(\"\"\"\n",
    "UNWIND $data AS row\n",
    "MERGE (c:__Community__ {id:row.community})\n",
    "SET c.summary = row.summary\n",
    "\"\"\", params={\"data\": summaries})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def db_query(cypher: str, params: Dict[str, Any] = {}) -> pd.DataFrame:\n",
    "    \"\"\"Executes a Cypher statement and returns a DataFrame\"\"\"\n",
    "    return driver.execute_query(\n",
    "        cypher, parameters_=params, result_transformer_=Result.to_df\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Calculate before \n",
    "db_query(\n",
    "    \"\"\"\n",
    "MATCH (n:`__Community__`)<-[:IN_COMMUNITY]-()<-[:HAS_ENTITY]-(c)\n",
    "WITH n, count(distinct c) AS chunkCount\n",
    "SET n.weight = chunkCount\"\"\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## local and global search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "index_name = \"entity_local\"\n",
    "\n",
    "# db_query(\n",
    "#     \"\"\"\n",
    "# CREATE VECTOR INDEX \"\"\"\n",
    "#     + index_name\n",
    "#     + \"\"\" IF NOT EXISTS FOR (e:__Entity__) ON e.embedding\n",
    "# OPTIONS {indexConfig: {\n",
    "#  `vector.dimensions`: 384,\n",
    "#  `vector.similarity_function`: 'cosine'\n",
    "# }}\n",
    "# \"\"\"\n",
    "# )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "topChunks = 3\n",
    "topCommunities = 3\n",
    "topOutsideRels = 10\n",
    "topInsideRels = 10\n",
    "topEntities = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "lc_retrieval_query = \"\"\"\n",
    "WITH collect(node) as nodes\n",
    "// Entity - Text Unit Mapping\n",
    "WITH\n",
    "collect {\n",
    "    UNWIND nodes as n\n",
    "    MATCH (n)<-[:HAS_ENTITY]->(c:Chunk)\n",
    "    WITH c, count(distinct n) as freq\n",
    "    RETURN c.text AS chunkText\n",
    "    ORDER BY freq DESC\n",
    "    LIMIT $topChunks\n",
    "} AS text_mapping,\n",
    "// Entity - Report Mapping\n",
    "collect {\n",
    "    UNWIND nodes as n\n",
    "    MATCH (n)-[:IN_COMMUNITY]->(c:__Community__)\n",
    "    WITH c, c.rank as rank, c.weight AS weight\n",
    "    RETURN c.summary \n",
    "    ORDER BY rank, weight DESC\n",
    "    LIMIT $topCommunities\n",
    "} AS report_mapping,\n",
    "// Outside Relationships \n",
    "collect {\n",
    "    UNWIND nodes as n\n",
    "    MATCH (n)-[r:RELATED]-(m) \n",
    "    WHERE NOT m IN nodes\n",
    "    RETURN r.description AS descriptionText\n",
    "    ORDER BY r.rank, r.weight DESC \n",
    "    LIMIT $topOutsideRels\n",
    "} as outsideRels,\n",
    "// Inside Relationships \n",
    "collect {\n",
    "    UNWIND nodes as n\n",
    "    MATCH (n)-[r:RELATED]-(m) \n",
    "    WHERE m IN nodes\n",
    "    RETURN r.description AS descriptionText\n",
    "    ORDER BY r.rank, r.weight DESC \n",
    "    LIMIT $topInsideRels\n",
    "} as insideRels,\n",
    "// Entities description\n",
    "collect {\n",
    "    UNWIND nodes as n\n",
    "    RETURN n.description AS descriptionText\n",
    "} as entities\n",
    "// We don't have covariates or claims here\n",
    "RETURN {Chunks: text_mapping, Reports: report_mapping, \n",
    "       Relationships: outsideRels + insideRels, \n",
    "       Entities: entities} AS text, 1.0 AS score, {} AS metadata\n",
    "\"\"\"\n",
    "\n",
    "embeddings, dimension = load_embedding_model(\"sentence_transformer\")\n",
    "lc_vector = Neo4jVector.from_existing_index(\n",
    "    embeddings,\n",
    "    url=os.environ[\"NEO4J_URI\"],\n",
    "    username=os.environ[\"NEO4J_USERNAME\"],\n",
    "    password=os.environ[\"NEO4J_PASSWORD\"],\n",
    "    index_name=index_name,\n",
    "    retrieval_query=lc_retrieval_query,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "docs = lc_vector.similarity_search_with_score(\n",
    "    \"Major cities of India\",\n",
    "    k=topEntities,\n",
    "    params={\n",
    "        \"topChunks\": topChunks,\n",
    "        \"topCommunities\": topCommunities,\n",
    "        \"topOutsideRels\": topOutsideRels,\n",
    "        \"topInsideRels\": topInsideRels,\n",
    "    },\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Entities:\n",
      "- None\n",
      "- None\n",
      "- None\n",
      "- One of the three biodiversity hotspots in India.\n",
      "- Officially the Republic of India, located in South Asia.\n",
      "- Geographical realm that includes India.\n",
      "- One of the three biodiversity hotspots in India.\n",
      "- Defines the northern frontiers of India.\n",
      "- One of the three biodiversity hotspots in India.\n",
      "- Commonly used name for the Republic of India.\n",
      "Reports:\n",
      "- India, officially the Republic of India, is a country located in South Asia and is part of the Indomalayan Realm. It shares borders with several countries including China, Bhutan, Nepal, Pakistan, Bangladesh, and Myanmar, and is bounded by the Indian Ocean, Arabian Sea, and Bay of Bengal. India is known for its rich biodiversity, featuring hotspots like the Western Ghats, Eastern Himalayas, and Indo-Burma Hotspot, and has a significant forest cover, which has been increasing as reported by the 2013 Forest Survey of India.\n",
      "\n",
      "India has a complex history, with ancient civilizations like the Indus Valley Civilisation and significant cultural contributions such as the Rigveda, which marks the dawn of Hinduism. It is also the birthplace of Buddhism and Jainism. The country has a diverse linguistic heritage, including the diffusion of the Indo-European language Sanskrit.\n",
      "\n",
      "Economically, India is a major global player, ranking as the fifth-largest economy by nominal GDP and third-largest by purchasing power parity (PPP). It has a significant public sector, a large labor force, and is a member of the World Trade Organization. The country has adopted broad economic liberalization since 1991, leading to substantial GDP growth and a robust service sector that makes up more than 50% of its GDP. India also has a high number of billionaires and is considered a welfare state with significant social welfare spending.\n",
      "\n",
      "Politically, India has been a federal republic since 1950, with the Indian National Congress historically dominating its politics until 1977. The Supreme Court of India heads its independent judiciary. The country has a rich legislative history concerning forest administration, with significant acts like the Indian Forest Act of 1865 and the Forest Act of 1878, and contributions from figures like Sir Dietrich Brandis, the Inspector General of Forests from 1864 to 1883.\n",
      "\n",
      "India's geographical and cultural landscape is further enriched by its rivers, such as the Ganges and Sindhu (Indus River), and its proximity to neighboring countries like Sri Lanka and the Maldives. The country is also part of the larger Indomalayan Realm and has historical ties to Africa, from where modern humans arrived on the Indian subcontinent.\n",
      "- India, officially the Republic of India, is a country located in South Asia and is part of the Indomalayan Realm. It shares borders with several countries including China, Bhutan, Nepal, Pakistan, Bangladesh, and Myanmar, and is bounded by the Indian Ocean, Arabian Sea, and Bay of Bengal. India is known for its rich biodiversity, featuring hotspots like the Western Ghats, Eastern Himalayas, and Indo-Burma Hotspot, and has a significant forest cover, which has been increasing as reported by the 2013 Forest Survey of India.\n",
      "\n",
      "India has a complex history, with ancient civilizations like the Indus Valley Civilisation and significant cultural contributions such as the Rigveda, which marks the dawn of Hinduism. It is also the birthplace of Buddhism and Jainism. The country has a diverse linguistic heritage, including the diffusion of the Indo-European language Sanskrit.\n",
      "\n",
      "Economically, India is a major global player, ranking as the fifth-largest economy by nominal GDP and third-largest by purchasing power parity (PPP). It has a significant public sector, a large labor force, and is a member of the World Trade Organization. The country has adopted broad economic liberalization since 1991, leading to substantial GDP growth and a robust service sector that makes up more than 50% of its GDP. India also has a high number of billionaires and is considered a welfare state with significant social welfare spending.\n",
      "\n",
      "Politically, India has been a federal republic since 1950, with the Indian National Congress historically dominating its politics until 1977. The Supreme Court of India heads its independent judiciary. The country has a rich legislative history concerning forest administration, with significant acts like the Indian Forest Act of 1865 and the Forest Act of 1878, and contributions from figures like Sir Dietrich Brandis, the Inspector General of Forests from 1864 to 1883.\n",
      "\n",
      "India's geographical and cultural landscape is further enriched by its rivers, such as the Ganges and Sindhu (Indus River), and its proximity to neighboring countries like Sri Lanka and the Maldives. The country is also part of the larger Indomalayan Realm and has historical ties to Africa, from where modern humans arrived on the Indian subcontinent.\n",
      "- India, officially the Republic of India, is a country located in South Asia and is part of the Indomalayan Realm. It shares borders with several countries including China, Bhutan, Nepal, Pakistan, Bangladesh, and Myanmar, and is bounded by the Indian Ocean, Arabian Sea, and Bay of Bengal. India is known for its rich biodiversity, featuring hotspots like the Western Ghats, Eastern Himalayas, and Indo-Burma Hotspot, and has a significant forest cover, which has been increasing as reported by the 2013 Forest Survey of India.\n",
      "\n",
      "India has a complex history, with ancient civilizations like the Indus Valley Civilisation and significant cultural contributions such as the Rigveda, which marks the dawn of Hinduism. It is also the birthplace of Buddhism and Jainism. The country has a diverse linguistic heritage, including the diffusion of the Indo-European language Sanskrit.\n",
      "\n",
      "Economically, India is a major global player, ranking as the fifth-largest economy by nominal GDP and third-largest by purchasing power parity (PPP). It has a significant public sector, a large labor force, and is a member of the World Trade Organization. The country has adopted broad economic liberalization since 1991, leading to substantial GDP growth and a robust service sector that makes up more than 50% of its GDP. India also has a high number of billionaires and is considered a welfare state with significant social welfare spending.\n",
      "\n",
      "Politically, India has been a federal republic since 1950, with the Indian National Congress historically dominating its politics until 1977. The Supreme Court of India heads its independent judiciary. The country has a rich legislative history concerning forest administration, with significant acts like the Indian Forest Act of 1865 and the Forest Act of 1878, and contributions from figures like Sir Dietrich Brandis, the Inspector General of Forests from 1864 to 1883.\n",
      "\n",
      "India's geographical and cultural landscape is further enriched by its rivers, such as the Ganges and Sindhu (Indus River), and its proximity to neighboring countries like Sri Lanka and the Maldives. The country is also part of the larger Indomalayan Realm and has historical ties to Africa, from where modern humans arrived on the Indian subcontinent.\n",
      "Chunks:\n",
      "- India is one of the most biodiverse regions and is home to a large variety of wildlife. It is one of the 17 megadiverse countries and includes three of the worlds 36 biodiversity hotspots – the Western Ghats, the Eastern Himalayas, and the Indo-Burma hotspot. About 24.6% of the total land area is covered by forests. It has various ecosystems ranging from the high altitude Himalayas, tropical evergreen forests along the Western Ghats, desert in the north-west, coastal plains and mangroves along the peninsular region. India lies within the Indomalayan realm and is home to about 7.6% of mammal, 14.7% of amphibian, 6% of bird, 6.2% of reptilian, and 6.2% of flowering plant species. Human encroachment, deforestation and poaching are significant challenges that threaten the existence of certain fauna and flora. Government of India established a system of national parks and\n",
      "-  threaten the existence of certain fauna and flora. Government of India established a system of national parks and protected areas in 1935, which have been subsequently expanded to nearly 1022 protected areas by 2023. India has enacted the Wildlife Protection Act of 1972 and special projects such as Project Tiger, Project Elephant and Project Dolphin for protection of critical species.   == Fauna ==  India has an estimated 92,873 species of fauna, roughly about 7.5% of the species available worldwide. Insects form the major category with 63423 recorded species. India is home to 423 mammals, 1233 birds, 526 reptiles, 342 amphibians, 3022 fish apart from other species which form 7.6% of mammal, 14.7% of amphibian, 6% of bird, 6.2% of reptilian species worldwide. Many Indian species are descendants of species originating in Gondwana, of which India originally was a part. Peninsular Indias subsequent movement towards\n",
      "-  Gondwana, of which India originally was a part. Peninsular Indias subsequent movement towards, and collision with, the Laurasian landmass set off a mass exchange of species. However, volcanism in the Deccan Traps and climatic change 20 million years ago caused the extinction of many endemic Indian forms. Soon thereafter, mammals entered India from Asia through two zoogeographical passes on either side of the emerging Himalayas. As a result, among Indian species, only 12.6% of mammals and 4.5% of birds are endemic, contrasting with 45.8% of reptiles and 55.8% of amphibians  India is home to several well-known large animals, including the Indian elephant, Indian rhinoceros, and Gaur. India is the only country where the big cats tiger and lion exist in the wild. Members of the cat family include Bengal tiger, Asiatic lion, Indian leopard, snow leopard, and clouded\n",
      "Relationships:\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(docs[0][0].page_content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = \"openai-gpt-4o\"\n",
    "llm, model_name = get_llm(model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "MAP_SYSTEM_PROMPT = \"\"\"\n",
    "---Role---\n",
    "\n",
    "You are a helpful assistant responding to questions about data in the tables provided.\n",
    "\n",
    "\n",
    "---Goal---\n",
    "\n",
    "Generate a response consisting of a list of key points that responds to the user's question, summarizing all relevant information in the input data tables.\n",
    "\n",
    "You should use the data provided in the data tables below as the primary context for generating the response.\n",
    "If you don't know the answer or if the input data tables do not contain sufficient information to provide an answer, just say so. Do not make anything up.\n",
    "\n",
    "Each key point in the response should have the following element:\n",
    "- Description: A comprehensive description of the point.\n",
    "- Importance Score: An integer score between 0-100 that indicates how important the point is in answering the user's question. An 'I don't know' type of response should have a score of 0.\n",
    "\n",
    "The response should be JSON formatted as follows:\n",
    "{{\n",
    "    \"points\": [\n",
    "        {{\"description\": \"Description of point 1 [Data: Reports (report ids)]\", \"score\": score_value}},\n",
    "        {{\"description\": \"Description of point 2 [Data: Reports (report ids)]\", \"score\": score_value}}\n",
    "    ]\n",
    "}}\n",
    "\n",
    "The response shall preserve the original meaning and use of modal verbs such as \"shall\", \"may\" or \"will\".\n",
    "\n",
    "Points supported by data should list the relevant reports as references as follows:\n",
    "\"This is an example sentence supported by data references [Data: Reports (report ids)]\"\n",
    "\n",
    "**Do not list more than 5 record ids in a single reference**. Instead, list the top 5 most relevant record ids and add \"+more\" to indicate that there are more.\n",
    "\n",
    "For example:\n",
    "\"Person X is the owner of Company Y and subject to many allegations of wrongdoing [Data: Reports (2, 7, 64, 46, 34, +more)]. He is also CEO of company X [Data: Reports (1, 3)]\"\n",
    "\n",
    "where 1, 2, 3, 7, 34, 46, and 64 represent the id (not the index) of the relevant data report in the provided tables.\n",
    "\n",
    "Do not include information where the supporting evidence for it is not provided.\n",
    "\n",
    "\n",
    "---Data tables---\n",
    "\n",
    "{context_data}\n",
    "\n",
    "---Goal---\n",
    "\n",
    "Generate a response consisting of a list of key points that responds to the user's question, summarizing all relevant information in the input data tables.\n",
    "\n",
    "You should use the data provided in the data tables below as the primary context for generating the response.\n",
    "If you don't know the answer or if the input data tables do not contain sufficient information to provide an answer, just say so. Do not make anything up.\n",
    "\n",
    "Each key point in the response should have the following element:\n",
    "- Description: A comprehensive description of the point.\n",
    "- Importance Score: An integer score between 0-100 that indicates how important the point is in answering the user's question. An 'I don't know' type of response should have a score of 0.\n",
    "\n",
    "The response shall preserve the original meaning and use of modal verbs such as \"shall\", \"may\" or \"will\".\n",
    "\n",
    "Points supported by data should list the relevant reports as references as follows:\n",
    "\"This is an example sentence supported by data references [Data: Reports (report ids)]\"\n",
    "\n",
    "**Do not list more than 5 record ids in a single reference**. Instead, list the top 5 most relevant record ids and add \"+more\" to indicate that there are more.\n",
    "\n",
    "For example:\n",
    "\"Person X is the owner of Company Y and subject to many allegations of wrongdoing [Data: Reports (2, 7, 64, 46, 34, +more)]. He is also CEO of company X [Data: Reports (1, 3)]\"\n",
    "\n",
    "where 1, 2, 3, 7, 34, 46, and 64 represent the id (not the index) of the relevant data report in the provided tables.\n",
    "\n",
    "Do not include information where the supporting evidence for it is not provided.\n",
    "\n",
    "The response should be JSON formatted as follows:\n",
    "{{\n",
    "    \"points\": [\n",
    "        {{\"description\": \"Description of point 1 [Data: Reports (report ids)]\", \"score\": score_value}},\n",
    "        {{\"description\": \"Description of point 2 [Data: Reports (report ids)]\", \"score\": score_value}}\n",
    "    ]\n",
    "}}\n",
    "\"\"\"\n",
    "\n",
    "map_prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\n",
    "            \"system\",\n",
    "            MAP_SYSTEM_PROMPT,\n",
    "        ),\n",
    "        (\n",
    "            \"human\",\n",
    "            \"{question}\",\n",
    "        ),\n",
    "    ]\n",
    ")\n",
    "\n",
    "map_chain = map_prompt | llm | StrOutputParser()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "REDUCE_SYSTEM_PROMPT = \"\"\"\n",
    "---Role---\n",
    "\n",
    "You are a helpful assistant responding to questions about a dataset by synthesizing perspectives from multiple analysts.\n",
    "\n",
    "\n",
    "---Goal---\n",
    "\n",
    "Generate a response of the target length and format that responds to the user's question, summarize all the reports from multiple analysts who focused on different parts of the dataset.\n",
    "\n",
    "Note that the analysts' reports provided below are ranked in the **descending order of importance**.\n",
    "\n",
    "If you don't know the answer or if the provided reports do not contain sufficient information to provide an answer, just say so. Do not make anything up.\n",
    "\n",
    "The final response should remove all irrelevant information from the analysts' reports and merge the cleaned information into a comprehensive answer that provides explanations of all the key points and implications appropriate for the response length and format.\n",
    "\n",
    "Add sections and commentary to the response as appropriate for the length and format. Style the response in markdown.\n",
    "\n",
    "The response shall preserve the original meaning and use of modal verbs such as \"shall\", \"may\" or \"will\".\n",
    "\n",
    "The response should also preserve all the data references previously included in the analysts' reports, but do not mention the roles of multiple analysts in the analysis process.\n",
    "\n",
    "**Do not list more than 5 record ids in a single reference**. Instead, list the top 5 most relevant record ids and add \"+more\" to indicate that there are more.\n",
    "\n",
    "For example:\n",
    "\n",
    "\"Person X is the owner of Company Y and subject to many allegations of wrongdoing [Data: Reports (2, 7, 34, 46, 64, +more)]. He is also CEO of company X [Data: Reports (1, 3)]\"\n",
    "\n",
    "where 1, 2, 3, 7, 34, 46, and 64 represent the id (not the index) of the relevant data record.\n",
    "\n",
    "Do not include information where the supporting evidence for it is not provided.\n",
    "\n",
    "\n",
    "---Target response length and format---\n",
    "\n",
    "{response_type}\n",
    "\n",
    "\n",
    "---Analyst Reports---\n",
    "\n",
    "{report_data}\n",
    "\n",
    "\n",
    "---Goal---\n",
    "\n",
    "Generate a response of the target length and format that responds to the user's question, summarize all the reports from multiple analysts who focused on different parts of the dataset.\n",
    "\n",
    "Note that the analysts' reports provided below are ranked in the **descending order of importance**.\n",
    "\n",
    "If you don't know the answer or if the provided reports do not contain sufficient information to provide an answer, just say so. Do not make anything up.\n",
    "\n",
    "The final response should remove all irrelevant information from the analysts' reports and merge the cleaned information into a comprehensive answer that provides explanations of all the key points and implications appropriate for the response length and format.\n",
    "\n",
    "The response shall preserve the original meaning and use of modal verbs such as \"shall\", \"may\" or \"will\".\n",
    "\n",
    "The response should also preserve all the data references previously included in the analysts' reports, but do not mention the roles of multiple analysts in the analysis process.\n",
    "\n",
    "**Do not list more than 5 record ids in a single reference**. Instead, list the top 5 most relevant record ids and add \"+more\" to indicate that there are more.\n",
    "\n",
    "For example:\n",
    "\n",
    "\"Person X is the owner of Company Y and subject to many allegations of wrongdoing [Data: Reports (2, 7, 34, 46, 64, +more)]. He is also CEO of company X [Data: Reports (1, 3)]\"\n",
    "\n",
    "where 1, 2, 3, 7, 34, 46, and 64 represent the id (not the index) of the relevant data record.\n",
    "\n",
    "Do not include information where the supporting evidence for it is not provided.\n",
    "\n",
    "\n",
    "---Target response length and format---\n",
    "\n",
    "{response_type}\n",
    "\n",
    "Add sections and commentary to the response as appropriate for the length and format. Style the response in markdown.\n",
    "\"\"\"\n",
    "\n",
    "reduce_prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\n",
    "            \"system\",\n",
    "            REDUCE_SYSTEM_PROMPT,\n",
    "        ),\n",
    "        (\n",
    "            \"human\",\n",
    "            \"{question}\",\n",
    "        ),\n",
    "    ]\n",
    ")\n",
    "reduce_chain = reduce_prompt | llm | StrOutputParser()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "graph = Neo4jGraph(\n",
    "    url=os.environ[\"NEO4J_URI\"],\n",
    "    username=os.environ[\"NEO4J_USERNAME\"],\n",
    "    password=os.environ[\"NEO4J_PASSWORD\"],\n",
    "    refresh_schema=False,\n",
    ")\n",
    "\n",
    "response_type: str = \"multiple paragraphs\"\n",
    "\n",
    "\n",
    "def global_retriever(query: str, level: int, response_type: str = response_type) -> str:\n",
    "    community_data = graph.query(\n",
    "        \"\"\"\n",
    "    MATCH (c:__Community__)\n",
    "    WHERE c.level = $level\n",
    "    RETURN c.full_content AS output\n",
    "    \"\"\",\n",
    "        params={\"level\": level},\n",
    "    )\n",
    "    intermediate_results = []\n",
    "    for community in tqdm(community_data, desc=\"Processing communities\"):\n",
    "        intermediate_response = map_chain.invoke(\n",
    "            {\"question\": query, \"context_data\": community[\"output\"]}\n",
    "        )\n",
    "        intermediate_results.append(intermediate_response)\n",
    "    final_response = reduce_chain.invoke(\n",
    "        {\n",
    "            \"report_data\": intermediate_results,\n",
    "            \"question\": query,\n",
    "            \"response_type\": response_type,\n",
    "        }\n",
    "    )\n",
    "    return final_response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:neo4j.notifications:Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.UnknownPropertyKeyWarning} {category: UNRECOGNIZED} {title: The provided property key is not in the database} {description: One of the property names in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing property name is: full_content)} {position: line: 4, column: 14, offset: 69} for query: '\\n    MATCH (c:__Community__)\\n    WHERE c.level = $level\\n    RETURN c.full_content AS output\\n    '\n",
      "Processing communities: 0it [00:00, ?it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm sorry, but the provided reports do not contain sufficient information to provide an answer to your question about the major cities of India. If you have any other questions or need information on a different topic, please let me know!\n"
     ]
    }
   ],
   "source": [
    "print(global_retriever(\"Major cities of India?\", 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "chatbotenv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}