IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

39 rindas
1.5KB

  1. class Data(object):
  2. def __init__(self):
  3. self.node_types = []
  4. self.relation_types = []
  5. def add_node_type(self, name):
  6. self.node_types.append(name)
  7. def add_relation(self, node_type_row, node_type_column, adjacency_matrix, name):
  8. n = len(self.node_types)
  9. if node_type_row >= n or node_type_column >= n:
  10. raise ValueError('Node type index out of bounds, add node type first')
  11. self.relation_types.append((node_type_row, node_type_column, adjacency_matrix, name))
  12. def __repr__(self):
  13. n = len(self.node_types)
  14. if n == 0:
  15. return 'Empty GNN Data'
  16. s = ''
  17. s += 'GNN Data with:\n'
  18. s += '- ' + str(n) + ' node type(s):\n'
  19. for nt in self.node_types:
  20. s += ' - ' + nt + '\n'
  21. if len(self.relation_types) == 0:
  22. s += '- No relation types\n'
  23. return s.strip()
  24. s += '- ' + str(len(self.relation_types)) + ' relation type(s):\n'
  25. for i in range(n):
  26. for j in range(n):
  27. rels = list(filter(lambda a: a[0] == i and a[1] == j, self.relation_types))
  28. if len(rels) == 0:
  29. continue
  30. # dir = '<->' if i == j else '->'
  31. dir = '--'
  32. s += ' - ' + self.node_types[i] + ' ' + dir + ' ' + self.node_types[j] + ':\n'
  33. for r in rels:
  34. s += ' - ' + r[3] + '\n'
  35. return s.strip()