Reasoning about Graphs with Application to Temporal and Spatial Reasoning