In the past ten years, graph theory has been widely employed in the study of natural and technological phenomena. The representation of the relationships among the units of a network allow for a quantitative analysis of its overall structure, beyond what can be understood by considering only a few units. Here we discuss the application of graph theory to psychiatric diagnosis of psychoses and dementias. The aim is to quantify the flow of thoughts of psychiatric patients, as expressed by verbal reports of dream or waking events. This flow of thoughts is hard to measure but is at the roots of psychiatry as well as psychoanalysis. To this end, speech graphs were initially designed with nodes representing lexemes and edges representing the temporal sequence between consecutive words, leading to directed multigraphs. In a subsequent study, individual words were considered as nodes and their temporal sequence as edges; this simplification allowed for the automatization of the process, effected by the free software Speech Graphs. Using this approach, one can calculate local and global attributes that characterize the network structure, such as the total number of nodes and edges, the number of nodes present in the largest connected and the largest strongly connected components, measures of recurrence such as loops of 1, 2, and 3 nodes, parallel and repeated edges, and global measures such as the average degree, density, diameter, average shortest path, and clustering coefficient. Using these network attributes we were able to automatically sort schizophrenia and bipolar patients undergoing psychosis, and also to separate these psychotic patients from subjects without psychosis, with more than 90% sensitivity and specificity. In addition to the use of the method for strictly clinical purposes, we found that differences in the content of the verbal reports correspond to structural differences at the graph level. When reporting a dream, healthy subjects without psychosis and psychotic subjects with bipolar disorder produced more complex graphs than when reporting waking activities of the previous day; this difference was not observed in psychotic subjects with schizophrenia, which produced equally poor reports irrespective of the content. As a consequence, graphs of dream reports were more efficient for the differential diagnosis of psychosis than graphs of daily reports. Based on these results we can conclude that graphs from dream reports are more informative about mental states, echoing the psychoanalytic notion that dreams are a privileged window into thought.