API¶
Datastructures¶
Defines a vertex/node with a given label and incoming and outgoing edges.
Source code in src/collaboration_detection/datastructures/graph_collection.py
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 | |
graph
property
¶
The graph of the vertex
label
property
writable
¶
The label property.
label_id
property
¶
The id of the label
preceding_vertices
property
¶
Return all preceding vertices (from incoming edges).
:return: All preceding vertices (from incoming edges)
proceeding_vertices
property
¶
Return all proceeding vertices (from outgoing edges).
:return: All proceeding vertices (from outgoing edges)
vertex_id
property
¶
The id of the vertex
__eq__(other)
¶
Two vertices are equal if the vertex_id is equal. The metadata values are not compared.
:param other: Vertex :return: True if both vertices are equal
Source code in src/collaboration_detection/datastructures/graph_collection.py
__init__(graph, vertex_id, label, vertex_type=None, metadata=None, **kwargs)
¶
Creates a new vertex inside the graph.
:param graph: The graph where the vertex is a member :param vertex_id: The unique id of the vertex inside the graph :param label: The label of the vertex as string :param vertex_type: The v_type of the vertex :param metadata: Optional metadata for the vertex
Source code in src/collaboration_detection/datastructures/graph_collection.py
add_edge(other_vertex, directed=True, edge_metadata=None)
¶
Add an outgoing edge to this vertex. The other vertex must be present in the same graph.
:param other_vertex: The other vertex :param directed: Defines if the edge is directed or not :param edge_metadata: The optional metadata for the edge :return: this vertex
Source code in src/collaboration_detection/datastructures/graph_collection.py
as_str_rep(variant)
¶
To string representation: The id of the vertex is printed, as well as the label_id as integer and the type id of the vertex (No metadata are saved)
'v id label type'
e.g.: 'v 1 3 5' :return: A string representation of the vertex
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_edge(other)
¶
Get an outgoing edge to the other Vertex, return None if there is no edge
:param other: The other Vertex :return: An edge or None if there is no edge
Source code in src/collaboration_detection/datastructures/graph_collection.py
has_edge(other)
¶
Check if there is an outgoing edge to the other Vertex
:param other: The other Vertex :return: True if there is an edge, else False
Source code in src/collaboration_detection/datastructures/graph_collection.py
An edge represents a directed arc between two vertices.
Source code in src/collaboration_detection/datastructures/graph_collection.py
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 | |
as_edge_rep
property
¶
Save as edge representation. (No metadata are saved)
:return: A tuple of the source vertex label and the sink vertex label, and the type
from_vertex
property
¶
The source vertex of this edge
graph
property
¶
The graph of the edge
to_vertex
property
¶
The sink vertex of this edge
__eq__(other)
¶
The other edge is only equal, if the source vertex and the sink vertex are equal. The metadata values are not compared.
:param other: the other edge :return: True if both edges are equal
Source code in src/collaboration_detection/datastructures/graph_collection.py
__init__(graph, from_vertex, to_vertex, metadata=None, **kwargs)
¶
Creates a new directed edge between two vertices.
:param graph: The graph, where the edge is a member :param from_vertex: The source vertex :param to_vertex: The sink vertex :param metadata: Optional metadata about the edge
Source code in src/collaboration_detection/datastructures/graph_collection.py
as_str_rep(variant='gspan')
¶
The str representation of the edge where the ids of the vertices are used. (No metadata are saved)
'e source sink type'
e.g.:
'e 1 2 1'
:return: A string representation of the edge
Source code in src/collaboration_detection/datastructures/graph_collection.py
Source code in src/collaboration_detection/datastructures/graph_collection.py
zip_images(path, format='svg')
¶
Exports the graphs of a GraphCollection cluster to a zip file (images of the graphs).
:param path: The base path where the zip file will be saved. :param format: The format of the images, Default: svg
Source code in src/collaboration_detection/datastructures/graph_collection.py
A graph represents a set of vertices and a set of edges which connects the vertices.
Source code in src/collaboration_detection/datastructures/graph_collection.py
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 | |
as_adjacency_matrix
property
¶
Create an adjacency matrix of this graph as Pandas DataFrame.
:return: the adjacency matrix of the graph as Pandas DataFrame
as_edge_rep
property
¶
Returns a dict of the graph with all edges. The keys are tuples of strings (the two connected vertices) The vertices are defined by their label (string). The value is the type of the edge. (No metadata are saved)
e.g.
{('A','B'):2,('B','C'):1}
:return: The edge representation of a graph
as_edge_tuple
property
¶
Returns a dict of the graph with all edges. The keys are tuples of strings (the two connected vertices) The vertices are defined by their label (string). The value is the type of the edge. e.g.
{('A','B'):2,('B','C'):1}
:return: The edge representation of a graph
as_graph_map
property
¶
Converts the graph into a graph map. (No metadata are saved) :return: A Graph Map
as_networkx_digraph
property
¶
Converts the graph into a python networkx graph object :return: DiGraph object of this graph
__eq__(other)
¶
A graph is equal to another graph if the other graph hase the same edges and vertices. The metadata are not compared.
:param other: The other graph :return: True if the graphs are equal
Source code in src/collaboration_detection/datastructures/graph_collection.py
__init__(graph_collection, graph_id, cluster_id=None, metadata=None, **kwargs)
¶
Creates a new graph. Each graph is part of a graph collection (which contains information about the label mapping)
:param graph_collection: The Graph Collection :param graph_id: The id of the graph :param cluster_id: The id of the cluster the graph belongs to :param metadata: Optional metadata for the graph
Source code in src/collaboration_detection/datastructures/graph_collection.py
__len__()
¶
The len of a graph is equal to len(graph.vertices)
:return: The len of the graph
add_edge(from_vertex, to_vertex, directed=True, edge_metadata=None)
¶
Add a new edge in this graph. Both vertices must be part of this graph.
:param from_vertex: The source vertex :param to_vertex: The sink vertex :param directed: if False, the edge is created twice. In the second edge the source and sink vertex are swapped. :param edge_metadata: Optional metadata for the edge
Source code in src/collaboration_detection/datastructures/graph_collection.py
as_str_rep(variant='gspan')
¶
Returns a string of the graph with all vertices and edges. (No metadata are saved)
- t # graph_id
- v vertex_id vertex_label_id (vertex_type_id)
- v vertex_id vertex_label_id (vertex_type_id)
- ...
- e vertex_source_id vertex_sink_id edge_type
- e vertex_source_id vertex_sink_id edge_type
- ...
:return: The string representation of the graph
Source code in src/collaboration_detection/datastructures/graph_collection.py
copy_into(graph_collection, additional_metadata=None)
¶
Copy this graph into a graph_collection
:param graph_collection: The other graph collection :return: The new graph on the other graph_collection
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_edges_by_metadata(**kwargs)
¶
Get all edges with the given metadata attributes
:param kwargs: The attribute key, value pair the edge metadata must satisfy :return: The dict of edges matching the provided metadata (id: Vertex)
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_vertex(label, *, force_create=False, vertex_id=None, vertex_type=None, metadata=None)
¶
Get the vertex with the given label. If the vertex does not exist, it will be created.
:param label: The label of the requested vertex :param force_create: Force create a new vertex, even if there is a vertex with the same label :param vertex_id: If provided, the vertex with this id is returned if exising, else created with this id. If the force create is True, and no vertex_id is provided, a new vertex id will be created. :param vertex_type: The optional vertex type of the vertex :param metadata: The optional metadata added to the vertex if the vertex is created. This parameter will be ignored if the vertex already exists. :return: The vertex with the given label
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_vertex_by_id(vertex_id)
¶
Get the vertex with the given vertex_id. If the vertex does not exist, the function will return None.
:param vertex_id: The label of the requested vertex :return: The vertex with the given vertex_id or None, if the vertex does not exist.
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_vertices_by_metadata(**kwargs)
¶
Get all vertices with the given metadata attributes
:param kwargs: The attribute key, value pair the vertex metadata must satisfy :return: The dict of vertices matching the provided metadata (id: Vertex)
Source code in src/collaboration_detection/datastructures/graph_collection.py
is_subgraph_of(other)
¶
Check if the current graph is a subgraph of the other graph. A graph is a subgraph, only if all its vertices are in the other graph and all its edges are also in the other graph.
:param other: The other graph (the super graph) :return: True if the current graph is a subgraph of the other graph.
Source code in src/collaboration_detection/datastructures/graph_collection.py
to_dot_digraph(path=None, rankdir='TB')
¶
Create a digraph object of the graph.
:param path: if filled with a path to a file name (.png/.svg) the digraph is saved to the given path :param rankdir: the rank direction of the graph, "TB" or "LR" :return: a digraph
Source code in src/collaboration_detection/datastructures/graph_collection.py
A GraphCollection represents a collection of graphs. It holds these graphs in a list, where each graph has a unique ID. It further contains a shared mapping for the labels.
Source code in src/collaboration_detection/datastructures/graph_collection.py
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 | |
collection_id
property
¶
Get the collection id of this collection
__init__(*, label_list=None, collection_id=None)
¶
Creates a new GraphCollection.
:param label_list: The label_list as list or path to a pickel file containing the label_list, optional, can be created on the fly by building the graph_collection :param collection_id: An id for this collection, if None, a new unique id one will be created
Source code in src/collaboration_detection/datastructures/graph_collection.py
as_edge_rep()
¶
Creates an edge representation of the graphs. So the output of this function is a list of graphs. Each graph is represented as a dict. Each Edge is represented as a tuple of two strings, which are the both connected vertices. The value represents the type of the edge.
[{('A','B'):2,('B','C'):1},{('A','C'):1,('C','B'): 1},...]
:return: a list of dicts (graphs as edge representation)
Source code in src/collaboration_detection/datastructures/graph_collection.py
as_networkx_digraphs()
¶
Creates a list of networkx.DiGraph objects.
:return: A list of networkx.DiGraph objects of the graphs
Source code in src/collaboration_detection/datastructures/graph_collection.py
as_str_rep(variant='gspan')
¶
Creates the string representation of the graph collection. Important: The labels are printed as integer values (the id of the label) The variant can be 'gspan' or 'subdue'.
- t # graph_id
- v vertex_id vertex_attributes_id
- v vertex_id vertex_attributes_id
- ...
- e vertex_source_id vertex_sink_id edge_type
- e vertex_source_id vertex_sink_id edge_type
- ...
- t # graph_id
- ...
:return: The string representation of the graphs
Source code in src/collaboration_detection/datastructures/graph_collection.py
as_str_rep_lines(variant='gspan')
¶
Creates the string representation of the graph collection. Important: The labels are printed as integer values (the id of the label) The variant can be 'gspan' or 'subdue'.
:return: a list of strings (the string representation of the graphs)
Source code in src/collaboration_detection/datastructures/graph_collection.py
clean(label_list=None)
¶
Clean the graph collection. Optional initialize the label mapping with the given label_list. The label_list should contain strings of the labels.
:param label_list: The list of labels. Or path to the pickle file.
Source code in src/collaboration_detection/datastructures/graph_collection.py
export(path)
¶
Saves the graph collection as pickle file.
:file: the path of the file
filter(vertex_count_min=None, vertex_count_max=None, edge_count_min=None, edge_count_max=None, vertex_label_in=None, vertex_label_is=None, cluster_id=None, expected_metadata=None, filter_func=None)
¶
Creates an iterator for this graph collection. It iterates over all graphs and applies the given filter.
:param vertex_count_min: The graph should contain at least x vertices :param vertex_count_max: The graph should contain at maximum x vertices :param edge_count_min: The graph should contain at least x edges :param edge_count_max: The graph should contain at maximum x edges :param vertex_label_in: The graph should contain a vertex with a label matches a part of this value :param vertex_label_is: The graph should contain a vertex with a label matches this value :param cluster_id: The graph should be part of the given cluster_id :param expected_metadata: The graph should have the values of the specified expected_metadata :param filter_func: A filter function that gets a graph and should return true or false :return: Iterator over the graphs
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_label(label_id)
¶
Get the label for the given label id
:param label_id: the id of the label :return: the label as string or None if the id is not present
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_label_type(label_id)
¶
Get the label type for the given label id
:param label_id: the id of the label :return: the label type as string or None if the id or none if label type is None for the label id is not present
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_label_type_by_label(label)
¶
Get the label type for the given label
:param label: the label as string :return: the label type as string or None if the id or none if label type is None for the label id is not present
Source code in src/collaboration_detection/datastructures/graph_collection.py
get_set_label_id(label, label_type=None)
¶
Get the id of the given label. If the label is not present, it is created for this graph_collection.
:param label: the label as string :return: the id of the label
Source code in src/collaboration_detection/datastructures/graph_collection.py
init_label_mapping(label_list=None, format='pickle')
¶
Init the label mapping with the given list of label tuples. The index of the label is the id of the label mapping. The param label_list can be a path to a pickle file which was created with 'save_label_mapping'.
:param label_list: The list of labels. Or path to the pickle file or text file. :param format: The format of the file (pickle or text), if label_list is the path to the file.
Source code in src/collaboration_detection/datastructures/graph_collection.py
load(path)
staticmethod
¶
Loads the graph collection from a pickle file
:file: the path of the file
Source code in src/collaboration_detection/datastructures/graph_collection.py
load_graph_from_heuristic_net(heu_net, ignore_type=True, graph_metadata=None)
¶
Loads a graph from a heuristic net.
:param heu_net: The heuristic net :param ignore_type: Ignores the edge type (sets to 1) :param graph_metadata: Additional graph metadata :return: the created graph
Source code in src/collaboration_detection/datastructures/graph_collection.py
load_graphs_from_edge_rep(graph_edge_rep, ignore_type=True)
¶
Loads the graph collection from an edge representation.
e.g. [{('A','B'):2,('B','C'):1},{('A','C'):1,('C','B'): 1},...]
:param graph_edge_rep: The edge representation object :param ignore_type: Ignores the edge type (sets to 1) :return: the created graph
Source code in src/collaboration_detection/datastructures/graph_collection.py
load_graphs_from_str_rep(graph_str_rep, graph_metadata=None, variant='gspan')
¶
Loads the graph collection from a string representation. Important: The label_mapping must be initialized before starting the import! The labels are not stored in the string representation!
e.g.
- t # graph_id
- v vertex_id vertex_attributes_id
- v vertex_id vertex_attributes_id
- ...
- e vertex_source_id vertex_sink_id edge_type
- e vertex_source_id vertex_sink_id edge_type
- ...
- t # graph_id
:param graph_str_rep: The string representation :param graph_metadata: Additional graph metadata :return: the created graph
Source code in src/collaboration_detection/datastructures/graph_collection.py
load_graphs_from_str_rep_file(file, graph_metadata=None, variant='gspan')
¶
Loads the graph collection from a string representation file. Important: The label_mapping must be initialized before starting the import.
e.g.
- t # graph_id
- v vertex_id vertex_attributes_id
- v vertex_id vertex_attributes_id
- ...
- e vertex_source_id vertex_sink_id edge_type
- e vertex_source_id vertex_sink_id edge_type
- ...
- t # graph_id
- ...
:param file: The file of the string representation
Source code in src/collaboration_detection/datastructures/graph_collection.py
load_subdue_results_from_file(file, graph_metadata=None)
¶
Loads the graph collection from a subdue results file. The result file is a human-readable report.
Source code in src/collaboration_detection/datastructures/graph_collection.py
new_graph(*, graph_id=None, cluster_id=None, metadata=None, **kwargs)
¶
Creates a new graph in this graph collection. The graph gets a new unique id.
:param graph_id: An id for the graph :param cluster_id: An id for the cluster the graph belongs to :param metadata: Optional additional metadata as dict. :return: a new Graph object
Source code in src/collaboration_detection/datastructures/graph_collection.py
save_label_mapping(file_path, format='pickle')
¶
Save the label mapping in a pickle file
:param file_path: the file_path of the output :param format: "pickle" if pickle should be used, "text" plain if a text file should be used
Source code in src/collaboration_detection/datastructures/graph_collection.py
save_str_rep(file, variant='gspan')
¶
Saves the graph collection as string representation as file. The variant can be 'gspan' or 'subdue'.
:param file: The path or the file object
Source code in src/collaboration_detection/datastructures/graph_collection.py
tar_images(path, format='svg')
¶
Exports the graphs of a GraphCollection to a tar file (images of the graphs).
:param path: The base path where the tar file will be saved. :param format: The format of the images, Default: svg
Source code in src/collaboration_detection/datastructures/graph_collection.py
zip_images(path, format='svg')
¶
Exports the graphs of a GraphCollection to a zip file (images of the graphs).
:param path: The base path where the zip file will be saved. :param format: The format of the images, Default: svg
Source code in src/collaboration_detection/datastructures/graph_collection.py
Neo4j¶
Bases: BaseRepository
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
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 | |
close()
¶
delete_graph_collection(graph_collection)
¶
Delete the graph collection in the repository. Delete all nodes of this graph collection.
:param graph_collection: The Graph Collection
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
download_graph_collection(collection_id, graph_id=None, cluster_id=None)
¶
Download the Graph Collection with the given ID
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
drop_all()
¶
get_collections()
¶
Get all collections (overview, not data) of the repository
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
get_number_of_clusters(collection_id)
¶
Get the number of clusters of this graph collection
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
get_number_of_graphs(collection_id, cluster_id=None)
¶
Get the size of a graph collection, optional filtered by the cluster_id for the size of the cluster
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
set_cluster_attributes(graph_collection, cluster_id)
¶
Saves the attributes for the given cluster
:param graph_collection: The Graph Collection :param cluster_id: Optional: The Cluster Id, if the attributes of a single cluster should be saved
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
set_clusters(graph_collection, cluster_id=None)
¶
Save all cluster information for the given graph_collection
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
set_graph_metadata(graph_collection, graph_id)
¶
Saves the metadata for the given graph (or all graphs)
:param graph_collection: The Graph Collection :param graph_id: Optional: The Graph Id, if the metadata of a single graph should be saved
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
upload_graph_collection(graph_collection)
¶
Upload the graph collection Attention: The existing graph collection will be deleted beforehand.
:param graph_collection: The Graph Collection
Source code in src/collaboration_detection/datastructures/neo4jstorage/repository.py
Graph Mining¶
Bases: ABC
Create graphs from event logs. The input events logs are processed and converted using a custom event log converter. Furthermore, this class can be used to create for each original trace individual graphs.
Source code in src/collaboration_detection/graph_mining/graph_miner.py
converter
property
¶
Get the current event log converter of this graph miner.
__init__(converter=None, **kwargs)
¶
Creates a new Graph Miner
:param converter: The converter for the preprocessing of the event log :param kwargs: Additional parameter for the graph mining algorithm.
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graph(event_log, graph_collection=None)
¶
This function first converts the event log into a new event log and creates then a new graph. If the converter returns multiple sublogs, multiple graphs are created. The resulting graph(s) is/are stored inside the GraphCollection.
:param event_log: The event log :param graph_collection: A graph collection. If no graph collection is provided a new GraphCollection is created. :return: The GraphCollection with the minded graph(s)
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graphs_for_traces(event_log)
¶
This function first converts each trace into a new EventLog and creates then creates for each of them a new graph. The resulting graphs are stored inside the GraphCollection.
:param event_log: The event log :return: The GraphCollection with the minded graphs
Source code in src/collaboration_detection/graph_mining/graph_miner.py
iter_graphs_for_traces(event_log)
¶
Iter all traces, convert them into a new EventLog and yield a graph for each of these traces.
:param event_log: The event log
Source code in src/collaboration_detection/graph_mining/graph_miner.py
Bases: GraphMiner
A simple graph mining algorithm that takes an event log and converts it into a Directly Follow Graph (DFG). No additional kwargs are required.
Source code in src/collaboration_detection/graph_mining/dfg_graph_miner.py
converter
property
¶
Get the current event log converter of this graph miner.
__init__(converter=None, **kwargs)
¶
Creates a new Graph Miner
:param converter: The converter for the preprocessing of the event log :param kwargs: Additional parameter for the graph mining algorithm.
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graph(event_log, graph_collection=None)
¶
This function first converts the event log into a new event log and creates then a new graph. If the converter returns multiple sublogs, multiple graphs are created. The resulting graph(s) is/are stored inside the GraphCollection.
:param event_log: The event log :param graph_collection: A graph collection. If no graph collection is provided a new GraphCollection is created. :return: The GraphCollection with the minded graph(s)
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graphs_for_traces(event_log)
¶
This function first converts each trace into a new EventLog and creates then creates for each of them a new graph. The resulting graphs are stored inside the GraphCollection.
:param event_log: The event log :return: The GraphCollection with the minded graphs
Source code in src/collaboration_detection/graph_mining/graph_miner.py
iter_graphs_for_traces(event_log)
¶
Iter all traces, convert them into a new EventLog and yield a graph for each of these traces.
:param event_log: The event log
Source code in src/collaboration_detection/graph_mining/graph_miner.py
Bases: GraphMiner
Discovers a heuristics net.
The following kwargs parameters can be provided
- dependency_threshold: Dependency threshold (default: 0.5)
- and_threshold: AND threshold (default: 0.65)
- loop_two_threshold: Loop two threshold (default: 0.5)
Source code in src/collaboration_detection/graph_mining/heuristic_graph_miner.py
converter
property
¶
Get the current event log converter of this graph miner.
__init__(converter=None, **kwargs)
¶
Creates a new Graph Miner
:param converter: The converter for the preprocessing of the event log :param kwargs: Additional parameter for the graph mining algorithm.
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graph(event_log, graph_collection=None)
¶
This function first converts the event log into a new event log and creates then a new graph. If the converter returns multiple sublogs, multiple graphs are created. The resulting graph(s) is/are stored inside the GraphCollection.
:param event_log: The event log :param graph_collection: A graph collection. If no graph collection is provided a new GraphCollection is created. :return: The GraphCollection with the minded graph(s)
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graphs_for_traces(event_log)
¶
This function first converts each trace into a new EventLog and creates then creates for each of them a new graph. The resulting graphs are stored inside the GraphCollection.
:param event_log: The event log :return: The GraphCollection with the minded graphs
Source code in src/collaboration_detection/graph_mining/graph_miner.py
iter_graphs_for_traces(event_log)
¶
Iter all traces, convert them into a new EventLog and yield a graph for each of these traces.
:param event_log: The event log
Source code in src/collaboration_detection/graph_mining/graph_miner.py
Bases: GraphMiner
This algorithm discovers a collaboration instance graph.
The following kwargs parameters can be provided
- activity_classifier: List of additional attributes for the concept name of the activity nodes. default: []
- relation_attributes: List of attribute names, which are used as object nodes that are connected to the activities. default = []
- activity_delimiter: Delimiter of the activity classifier attributes. default = " -- "
- create_object_nodes: If true, create the object nodes; if false, just simulate the object nodes and only create the activty nodes; default: True
- override_labels_of_relation_attributes: If true, the labels of the object nodes are overridden with the object type (e.g. org:resource, spm:sdid, ..); If a set is provided, only the attributes defined in this sets are used to override the object node labeles with its value. Default: False
- use_object_type_in_label: Create the label of the object nodes with the object type as part of label
Source code in src/collaboration_detection/graph_mining/collaboration_instance_graph_miner.py
converter
property
¶
Get the current event log converter of this graph miner.
__init__(converter=None, **kwargs)
¶
Creates a new Graph Miner
:param converter: The converter for the preprocessing of the event log :param kwargs: Additional parameter for the graph mining algorithm.
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graph(event_log, graph_collection=None)
¶
This function first converts the event log into a new event log and creates then a new graph. If the converter returns multiple sublogs, multiple graphs are created. The resulting graph(s) is/are stored inside the GraphCollection.
:param event_log: The event log :param graph_collection: A graph collection. If no graph collection is provided a new GraphCollection is created. :return: The GraphCollection with the minded graph(s)
Source code in src/collaboration_detection/graph_mining/graph_miner.py
get_graphs_for_traces(event_log)
¶
This function first converts each trace into a new EventLog and creates then creates for each of them a new graph. The resulting graphs are stored inside the GraphCollection.
:param event_log: The event log :return: The GraphCollection with the minded graphs
Source code in src/collaboration_detection/graph_mining/graph_miner.py
iter_graphs_for_traces(event_log)
¶
Iter all traces, convert them into a new EventLog and yield a graph for each of these traces.
:param event_log: The event log
Source code in src/collaboration_detection/graph_mining/graph_miner.py
Preprocessing Converters¶
Bases: ABC
Transform an event log into a new event log where the traces and/or events (and/or their attributes) are preprocessed / converted based on the concrete implementation of the converter.
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
convert_event(event)
abstractmethod
¶
Converts an event into a new event.
:param event: The input event :return: The converted event
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
convert_event_log(event_log)
abstractmethod
¶
Converts an event log into one or more new event log(s).
:param event_log: The input event log :return: The converted event log(s)
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
convert_trace(trace)
abstractmethod
¶
Converts a trace into one (OR MORE) new trace(s).
:param trace: The input trace :return: The converted trace or a list of traces
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
is_sub_log_converter()
abstractmethod
¶
Does the converter returns multiple sub-logs?
:return: True if convert_event_log returns multiple (sub-)logs
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: EventLogConverter
The DefaultEventLogConverter converts all traces and events as they are (no modifications). Can be used as base class for inheritance.
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: DefaultEventLogConverter
The ActivityJoinerConverter converts the concept:name of all events
by joining the attributes provided by activity_classifier. All other attributes are untouched.
Source code in src/collaboration_detection/preprocessing/event_log_converter/activity_joiner_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: DefaultEventLogConverter
The trace split converter convert a trace from the event log into a new trace with modified case IDs.
The new case IDs are created by appending a unique identifier to the original case ID for each trace.
The unique identifier is created by concatenating the values (the category codes) for the attributes specified
in the split_attributes list. If the split_attributes list is empty, the case IDs are not modified.
Source code in src/collaboration_detection/preprocessing/event_log_converter/trace_split_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: EventLogConverter
The CombinedConverter combines multiple event log converters into a single converter.
The convert_event_log, convert_trace, and convert_event
methods apply the corresponding method of each converter in the given order to the input data.
Source code in src/collaboration_detection/preprocessing/event_log_converter/combined_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: TraceSplitConverter
Convert an event log into a list of sublogs. The split_attributes list is used to split each existing trace into
multiple subtraces which are then are used to create the sublogs.
Each sublog contains a group of related (sub)traces, where the trace are considered as related if their events have
overlapping timestamps and share common values for the attributes specified in the similarity_attributes list.
The timedelta parameter defines how many seconds two events of two traces can be apart from each other.
Source code in src/collaboration_detection/preprocessing/event_log_converter/sublog_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: DefaultEventLogConverter
This converter adds a new pseudo-event at the beginning and end of the trace,
depending on the values of the add_pseudo_start_event and add_pseudo_end_event variables.
The timestamp of the events is based on the first/last event -/+ one second.
The new events are created using the attributes_start_event and attributes_end_event dictionaries
and are added to the trace.
Source code in src/collaboration_detection/preprocessing/event_log_converter/add_pseudo_event_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: DefaultEventLogConverter
Merges all traces of the event log into a single trace by setting the CASE_CONCEPT_NAME to the value
provided by the function case_id_provider or by a fixed value defined by new_case_id.
Source code in src/collaboration_detection/preprocessing/event_log_converter/trace_merger_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Bases: DefaultEventLogConverter
The AddCountAttributeInTraceConverter adds count-based attributes to specified columns in a trace DataFrame.
The parameter columns_with_value_prefix (Dict[str, str]) defines a dictionary specifying columns and their
corresponding value prefixes. The value prefixes will be used to create a new attribute for each unique value
in the specified columns.
The parameter column_prefix defines a prefix that will be added to the newly created columns.
Source code in src/collaboration_detection/preprocessing/event_log_converter/add_count_attribute_in_traces_converter.py
iter_converted_traces(event_log)
¶
Iterates over an event log and yields all converted traces.
:param event_log: The input event log
Source code in src/collaboration_detection/preprocessing/event_log_converter/event_log_converter.py
Frequent Subgraph Mining¶
execute_gspan(data, result=None, sup=10, min_node=3, max_node=10, remove_data_graphs=True, variant=GSpanVariant.GSPAN_JAVA_PARSEMIS)
¶
Executes the gspan algorithm using either a Java or Rust implementation.
The implementation binary or jar file should be provided in the bin folder.
Download the Java gspan jar from:
GitHub gSpan.Java <https://github.com/joleaf/gSpan.Java/tree/master/target>_
GitHub parsemis <https://github.com/timtadh/parsemis>_ (supports directed edges) (preffed version)
and GitHub parsemis wrapper (jar file) <https://github.com/tomkdickinson/parsemis_wrapper/blob/master/parsemis/parsemis.jar>_
The data parameter must be provided. The output is stored in the Graph Collection.
:param data: File path (str) of the graph data set / or GraphCollection :param result: File path of the result file :param sup: Minimum support :param min_node: Minimum number of nodes for each sub-graph :param max_node: Maximum number of nodes for each sub-graph :param remove_data_graphs: Only relevant, if type(data)==GraphCollection: Remove all other graphs before adding the sub graphs :param variant: Define the GSpanVariant (java or rust implementation) :param ignore_directed: Define if gspan should ignore the direction of edges
Source code in src/collaboration_detection/subgraph_mining/gspan/gspan_wrapper.py
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 | |
execute_subdue(data, result=None, min_node=3, max_node=10, iterations=0, nsubs=3, beam=10, limit=10, remove_data_graphs=True)
¶
Executes the subdue algorithm using a standard C implementation. The subdue module must be downloaded and built. The data parameter must be provided. The output is stored in the Graph Collection.
:param data: File path (str) of the graph data set / or GraphCollection :param result: File path of the result file :param min_node: Minimum number of nodes for each sub-graph :param max_node: Maximum number of nodes for each sub-graph :param iterations: Number of iterations :param nsubs: Number of substructures that should be found :param beam: Beam width for the search :param limit: Limit on the number of substructures :param remove_data_graphs: Only relevant, if type(data)==GraphCollection: Remove all other graphs before adding the sub graphs
Source code in src/collaboration_detection/subgraph_mining/subdue/subdue_wrapper.py
Graph Set Clustering¶
Source code in src/collaboration_detection/clustering/clustering.py
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 | |
execute(graph_collection, algorithm, distance_metric, number_of_clusters=None, cluster_division_selector_metric=None, cluster_representative_seeder=None, cluster_dissimilarity=None, cluster_centroid_selector=None)
staticmethod
¶
This function is the entry point into the clustering package.
:param graph_collection: the graph collection to get the graphs from. The resulting clusters are updated inplace. :param algorithm: the clustering_tests algorithm to use for clustering_tests :param distance_metric: the distance metric to calculate the distances between the graphs :param number_of_clusters: the number of clusters as stopping criterion for the hierarchical algorithm :param cluster_division_selector_metric: the selector for the cluster to divided for the hierarchical algorithm :param cluster_representative_seeder: the seed selector for the split clusters of the hierarchical algorithm :param cluster_dissimilarity: the dissimilarity measure for the dissimilar cluster centroid selector for density and partitioning algorithm :param cluster_centroid_selector: the selected cluster centroid selector for the partitioning algorithm :return: Resulting clusters
Source code in src/collaboration_detection/clustering/clustering.py
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 | |