Refactored and generalized the RDF query parsing code.