<commit_before>import * as io from '../io/cgd';
import * as pgr from '../pgraphs/periodic';
import * as sym from '../pgraphs/symmetries';
import * as inv from '../pgraphs/invariant';


const fs = require('fs');

Array.prototype.toString = function() {
  return `${this.map(x => x.toString()).join(' ')}`;
};


process.argv.slice(2).forEach(file => {
  const text = fs.readFileSync(file, { encoding: 'utf8' });

  for (const b of io.structures(text)) {
    console.log(b.name);

    const G = b.graph;

    try {
      if (!pgr.isConnected(G))
        console.log(`  Error: net '${b.name}' is not connected`);
      else if (!pgr.isLocallyStable(G))
        console.log(`  Error: net '${b.name}' is not locally stable`);
      else {
        const key = inv.invariant(sym.minimalImage(G));
        timers.start('printing results');
        for (const [head, tail, shift] of key)
          console.log(`  ${head} ${tail} ${shift}`);
        timers.stop('printing results');
      }
    } catch(ex) {
      console.log(ex.stack);
    }

    console.log();
  }
});<commit_msg>scripts/systreKey: tidy up<commit_after>import * as fs from 'fs';

import { structures } from '../io/cgd';
import { isConnected, isLocallyStable } from '../pgraphs/periodic';
import { minimalImage } from '../pgraphs/symmetries';
import { invariant } from '../pgraphs/invariant';


process.argv.slice(2).forEach(file => {
  const text = fs.readFileSync(file, { encoding: 'utf8' });

  for (const { name, graph } of structures(text)) {
    console.log(name);

    try {
      if (!isConnected(graph))
        console.log(`  Error: net '${name}' is not connected`);
      else if (!isLocallyStable(graph))
        console.log(`  Error: net '${name}' is not locally stable`);
      else {
        for (const [head, tail, shift] of invariant(minimalImage(graph)))
          console.log(`  ${head} ${tail} ${shift.join(' ')}`);
      }
    } catch(ex) {
      console.log(ex.stack);
    }

    console.log();
  }
});
{'fraction_non_alphanumeric': 0.1841574167507568, 'fraction_numerical': 0.0020181634712411706, 'mean_word_length': 2.865497076023392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2939887', 'n_tokens_mistral': 666, 'n_tokens_neox': 653, 'n_words': 159}