Complex noiseless dynamical systems can be represented in a compressed manner by unstable periodic orbits. It is unknown, however, how to use this technique to obtain a suitable notion of similarity among them, how to extend such an approach to more general complex networks, and how to apply such a method in the important case of noisy systems. Our approach provides a solution to these questions. For a proof-of-concept, we consider Drosophila's precopulatory courtship, where our method reveals the existence of a complex grammar (similar to those found in complex physical systems and in language), leading to the conclusion that the observed grammar is very unlikely the product of chance. Complex noiseless dynamical systems can be represented in a compressed manner by unstable periodic orbits. It is unknown, however, how to use this technique to obtain a suitable notion of similarity among them, how to extend such an approach to more general complex networks, and how to apply such a method in the important case of noisy systems. Our approach provides a solution to these questions. For a proof-of-concept, we consider Drosophila's precopulatory courtship, where our method reveals the existence of a complex grammar (similar to those found in complex physical systems and in language), leading to the conclusion that the observed grammar is very unlikely the product of chance. Complex networks are usually described in terms of abstract network structures, where a node often comes equipped with a rule characterizing its local activity, or by using Markov random walks models. For their understanding, however, intermediate scales may play a distinguished role. This is the case if measures characterizing the network as a whole are too crude for providing the desired insights and if the local node dynamics do not provide an overview of the network. We formulate here in precise mathematical terms such as intermediate, mesoscopic, description of the network, based on periodic orbits as the mesoscopic observables. From these observables, we develop a method for measuring the similarity of graphs, a challenge of great importance that seems not to have been solved in the generality put forward here. An obvious typical application of our approach would be, e.g., the characterization of behavior, with robotics motion planning or the characterization of animal courtship behavior as prominent examples. Animal courtship, which we chose as the real-world testing case of our approach, is a puzzling phenomenon. Its function and purpose have largely remained unexplained, not least because of the generally large and complex underlying network structure and the lack of methods able to deal with such situations. The driving biological questions that we wish to answer here are: Could it be that during courtship, nontrivial information about a prospective mate is conveyed? And if so, how is this information organized and what purpose could it serve? The proposed approach provides partial answers to these questions. We verify that Dro...