Converting into pattern-based schemas: a formal approach