<commit_before>/* LanguageTool, a natural language style checker 
 * Copyright (C) 2006 <NAME> (http://www.danielnaber.de)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */
package de.danielnaber.languagetool.dev;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import de.danielnaber.languagetool.JLanguageTool;
import de.danielnaber.languagetool.Language;
import de.danielnaber.languagetool.tools.StringTools;

/**
 * Command line tool to list supported languages and their number of rules.
 * 
 * @author <NAME>
 */
public final class Overview {

  public static void main(String[] args) throws IOException {
    Overview prg = new Overview();
    prg.run();
  }
  
  private Overview() {
    // no constructor
  }
  
  private void run() throws IOException {
    System.out.println("<b>Rules in LanguageTool " + JLanguageTool.VERSION + "</b><br />");
    System.out.println("Date: " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "<br /><br />\n");
    System.out.println("<table>");
    System.out.println("<tr>");
    System.out.println("  <th></th>");
    System.out.println("  <th align=\"right\">XML rules</th>");
    System.out.println("  <th>&nbsp;&nbsp;</th>");
    System.out.println("  <th align=\"right\">Java rules</th>");
    System.out.println("</tr>");
    for (int i = 0; i < Language.LANGUAGES.length; i++) {
      if (Language.LANGUAGES[i] == Language.DEMO) {
        continue;
      }
      Language lang = Language.LANGUAGES[i];
      System.out.print("<tr>");
      System.out.print("<td>" + lang.getName() + "</td>");
      String xmlFile = "/rules" + File.separator + lang.getShortName() + File.separator + "grammar.xml";
      java.net.URL url = this.getClass().getResource(xmlFile);    
      if (url == null) {
        System.out.println("<td align=\"right\">0</td>");
      } else {
        // count XML rules:
        String xmlRules = StringTools.readFile(this.getClass().getResourceAsStream(xmlFile));
        xmlRules = xmlRules.replaceAll("(?s)<!--.*?-->", "");
        xmlRules = xmlRules.replaceAll("(?s)<rules.*?>", "");
        int pos = 0;
        int count = 0;
        while (pos != -1) {
          pos = xmlRules.indexOf("<rule ", pos + 1);          
          if (pos == -1) 
            break;          
          count++;
        }
        pos = 0;
        int countInRulegroup = 0;
        while (pos != -1) {
          pos = xmlRules.indexOf("<rule>", pos + 1);          
          if (pos == -1) 
            break;          
          countInRulegroup++;
        }
        System.out.print("<td align=\"right\">" + (count + countInRulegroup) +<commit_msg>sort languages alphabetically<commit_after>/* LanguageTool, a natural language style checker 
 * Copyright (C) 2006 <NAME> (http://www.danielnaber.de)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */
package de.danielnaber.languagetool.dev;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import de.danielnaber.languagetool.JLanguageTool;
import de.danielnaber.languagetool.Language;
import de.danielnaber.languagetool.tools.StringTools;

/**
 * Command line tool to list supported languages and their number of rules.
 * 
 * @author <NAME>
 */
public final class Overview {

  public static void main(String[] args) throws IOException {
    Overview prg = new Overview();
    prg.run();
  }
  
  private Overview() {
    // no constructor
  }
  
  private void run() throws IOException {
    System.out.println("<b>Rules in LanguageTool " + JLanguageTool.VERSION + "</b><br />");
    System.out.println("Date: " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "<br /><br />\n");
    System.out.println("<table>");
    System.out.println("<tr>");
    System.out.println("  <th></th>");
    System.out.println("  <th align=\"right\">XML rules</th>");
    System.out.println("  <th>&nbsp;&nbsp;</th>");
    System.out.println("  <th align=\"right\">Java rules</th>");
    System.out.println("</tr>");
    List<String> sortedLanguages = new ArrayList<String>();
    for (int i = 0; i < Language.LANGUAGES.length; i++) {
      if (Language.LANGUAGES[i] == Language.DEMO) {
        continue;
      }
      sortedLanguages.add(Language.LANGUAGES[i].getName());
    }
    Collections.sort(sortedLanguages);
    for (String langName : sortedLanguages) {
      Language lang = Language.getLanguageForName(langName);
      System.out.print("<tr>");
      System.out.print("<td>" + lang.getName() + "</td>");
      String xmlFile = "/rules" + File.separator + lang.getShortName() + File.separator + "grammar.xml";
      java.net.URL url = this.getClass().getResource(xmlFile);    
      if (url == null) {
        System.out.println("<td align=\"right\">0</td>");
      } else {
        // count XML rules:
        String xmlRules = StringTools.readFile(this.getClass().getResourceAsStream(xmlFile));
        xmlRules = xmlRules.replaceAll("(?s)<!--.*?-->", "");
        xmlRules = xmlRules.replaceAll("(?s)<rules.*?>", "");
        int pos = 0;
        int count = 0;
        while (pos != -1) {
          pos = xmlRules.indexOf("<rule ", pos + 1);          
          if (pos == -1) 
            break;          
          count++;
        }
        pos = 0;
        int countInRulegroup = 0;
        while (pos != -1) {
          pos = xmlRules.indexOf("<rule>", pos + 1);          
          if (pos == -1) 
            break;          
          countInRulegroup++;
        }
        System.out.print("<td align=\"right\">" + (count + countInRulegroup) +
{'fraction_non_alphanumeric': 0.14622509121526803, 'fraction_numerical': 0.00813920853213584, 'mean_word_length': 2.809192944949225, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 22}, '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': '3022503', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2101, 'n_words': 608}