A 25-year-old man has been sentenced to six years in prison for setting a fire that destroyed two Somerville restaurants.