The TInvar package provides a set of tools for canonicalization of expressions involving the Riemann tensor.
To run this package you will need to install xAct.
After installing xAct and the package you load it using
<< xAct`TInvar`
You can find examples in the documentation for the RiemannSimplify
function.