A converter from polynomial optimization problems of either commuting or noncommuting variables to sparse SDP input formats