"""Optional evaluation of independent source excerpts; never a production import.""" from __future__ import annotations import argparse,json,time from pathlib import Path from generator import musicxml,parts,production,vocabulary,score,musicxml_writer def main(): p=argparse.ArgumentParser(description=__doc__) p.add_argument('--sources',type=Path,default=Path('tests/evaluation_sources')) p.add_argument('--data-dir',type=Path,default=Path('data')) p.add_argument('--output',type=Path,required=True) args=p.parse_args();args.output.mkdir(parents=True,exist_ok=True) report={'scope':'Four-bar source excerpts, not complete standards; read adjacent provenance. No target solo used.', 'cases':[]} for path in sorted(args.sources.glob('*.xml')): source=production.SourceAnalysis.read(parts.prepare_document(musicxml.load_musicxml(path))) roles={};case={'source':str(path),'canonical_source':source.musical_key,'roles':{}} for role in production.ROLES: start=time.monotonic() try: value=production.generate_role(source,role,args.data_dir) roles[role]=value;case['roles'][role]={'valid':True,'seconds':time.monotonic()-start,'hash':vocabulary.fingerprint(value['document'])} except ValueError as error: case['roles'][role]={'valid':False,'seconds':time.monotonic()-start,'diagnostic':str(error)} print(path.stem,role,case['roles'][role],flush=True) if len(roles)==len(production.ROLES): for part,document in production.assemble(source,roles).items(): score.write_json(args.output/(path.stem+'_'+part+'.json'),document) musicxml_writer.write_musicxml(args.output/(path.stem+'_'+part+'.xml'),document) report['cases'].append(case) (args.output/'report.json').write_text(json.dumps(report,indent=2)) return int(any(not r['valid'] for c in report['cases'] for r in c['roles'].values())) if __name__=='__main__':raise SystemExit(main())