A characterization of classical and semiclassical orthogonal polynomials from their dual polynomials