code: public static GrammarRules series2SequiturRules(double[] timeseries, int saxWindowSize,
        int saxPAASize, int saxAlphabetSize, NumerosityReductionStrategy numerosityReductionStrategy,
        double normalizationThreshold) throws Exception, IOException {
  
      LOGGER.debug("Discretizing time series...");
  
      SAXRecords saxFrequencyData = sp.ts2saxViaWindow(timeseries, saxWindowSize, saxPAASize,
          normalA.getCuts(saxAlphabetSize), numerosityReductionStrategy, normalizationThreshold);
  
      LOGGER.debug("Inferring the grammar...");
  
      // this is a string we are about to feed into Sequitur
      //
      String saxDisplayString = saxFrequencyData.getSAXString(" ");
  
      // reset the Sequitur data structures
      SAXRule.numRules = new AtomicInteger(0);
      SAXRule.theRules.clear();
      SAXSymbol.theDigrams.clear();
  
      // bootstrap the grammar
      SAXRule grammar = new SAXRule();
      SAXRule.arrRuleRecords = new ArrayList<GrammarRuleRecord>();
  
      // digest the string via the tokenizer and build the grammar
      StringTokenizer st = new StringTokenizer(saxDisplayString, " ");
      int currentPosition = 0;
      while (st.hasMoreTokens()) {
        grammar.last().insertAfter(new SAXTerminal(st.nextToken(), currentPosition));
        grammar.last().p.check();
        currentPosition++;
      }
  
      // bw.close();
      LOGGER.debug("Collecting the grammar rules statistics and expanding the rules...");
      GrammarRules rules = grammar.toGrammarRulesData();
  
      LOGGER.debug("Mapping expanded rules to time-series intervals...");
      SequiturFactory.updateRuleIntervals(rules, saxFrequencyData, true, timeseries, saxWindowSize,
          saxPAASize);
  
      return rules;
  
    }
docs: Takes a time series and returns a grammar.
  
  @param timeseries the input time series.
  @param saxWindowSize the sliding window size.
  @param saxPAASize the PAA num.
  @param saxAlphabetSize the SAX alphabet size.
  @param numerosityReductionStrategy the SAX Numerosity Reduction strategy.
  @param normalizationThreshold the SAX normalization threshod.
  @return the set of rules, i.e. the grammar.
  @throws Exception if error occurs.
  @throws IOException if error occurs.