Fitting Ontologies and Constraints to Relational Structures