Community detection for networks with unipartite and bipartite structure