<commit_before>package org.basex;

import static org.basex.core.Text.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.basex.core.BaseXException;
import org.basex.core.Main;
import org.basex.core.MainProp;
import org.basex.core.Prop;
import org.basex.core.cmd.Check;
import org.basex.core.cmd.Set;
import org.basex.core.cmd.XQuery;
import org.basex.io.IO;
import org.basex.io.in.TextInput;
import org.basex.io.out.PrintOutput;
import org.basex.server.LocalSession;
import org.basex.server.Session;
import org.basex.util.Args;
import org.basex.util.Util;
import org.basex.util.list.StringList;

/**
 * This is the starter class for the stand-alone console mode.
 * It executes all commands locally.
 *
 * @author BaseX Team 2005-11, BSD License
 * @author <NAME>
 */
public class BaseX extends Main {
  /** User name. */
  protected String user;
  /** Password. */
  protected String pass;

  /** Flag for writing properties to disk. */
  private boolean writeProps;
  /** Operations to be executed. */
  private StringList ops;

  /**
   * Main method, launching the standalone mode.
   * Command-line arguments are listed with the {@code -h} argument.
   * @param args command-line arguments
   */
  public static void main(final String... args) {
    try {
      new BaseX(args);
    } catch(final IOException ex) {
      Util.errln(ex);
      System.exit(1);
    }
  }

  /**
   * Constructor.
   * @param args command-line arguments
   * @throws IOException I/O exception
   */
  public BaseX(final String... args) throws IOException {
    super(args);

    // create session to show optional login request
    session();

    try {
      // open initial document or database
      for(int i = 0; i < ops.size(); i += 2) {
        final String key = ops.get(i);
        final String val = ops.get(i + 1);
        if(key.equals("c")) {
          // run database command
          execute(val);
        } else if(key.equals("f")) {
          // query file
          final IO io = IO.get(val);
          if(!io.exists()) throw new BaseXException(INFOERROR + FILEWHICH, val);
          final String query = TextInput.content(io).toString().trim();
          execute(new Set(Prop.QUERYPATH, io.path()), false);
          execute(new XQuery(query), verbose);
        } else if(key.equals("i")) {
          // set context
          execute(new Check(val), verbose);
        } else if(key.equals("q")) {
          // run query
          execute(new XQuery(val), verbose);
        }<commit_msg>[FIX] API, GH276: don't create DB on disk if input is main-memory-based<commit_after>package org.basex;

import static org.basex.core.Text.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.basex.core.BaseXException;
import org.basex.core.Main;
import org.basex.core.MainProp;
import org.basex.core.Prop;
import org.basex.core.cmd.Check;
import org.basex.core.cmd.Set;
import org.basex.core.cmd.XQuery;
import org.basex.io.IO;
import org.basex.io.IOContent;
import org.basex.io.in.TextInput;
import org.basex.io.out.PrintOutput;
import org.basex.server.LocalSession;
import org.basex.server.Session;
import org.basex.util.Args;
import org.basex.util.Util;
import org.basex.util.list.StringList;

/**
 * This is the starter class for the stand-alone console mode.
 * It executes all commands locally.
 *
 * @author BaseX Team 2005-11, BSD License
 * @author <NAME>
 */
public class BaseX extends Main {
  /** User name. */
  protected String user;
  /** Password. */
  protected String pass;

  /** Flag for writing properties to disk. */
  private boolean writeProps;
  /** Operations to be executed. */
  private StringList ops;

  /**
   * Main method, launching the standalone mode.
   * Command-line arguments are listed with the {@code -h} argument.
   * @param args command-line arguments
   */
  public static void main(final String... args) {
    try {
      new BaseX(args);
    } catch(final IOException ex) {
      Util.errln(ex);
      System.exit(1);
    }
  }

  /**
   * Constructor.
   * @param args command-line arguments
   * @throws IOException I/O exception
   */
  public BaseX(final String... args) throws IOException {
    super(args);

    // create session to show optional login request
    session();

    try {
      // open initial document or database
      for(int i = 0; i < ops.size(); i += 2) {
        final String key = ops.get(i);
        final String val = ops.get(i + 1);
        if(key.equals("c")) {
          // run database command
          execute(val);
        } else if(key.equals("f")) {
          // query file
          final IO io = IO.get(val);
          if(!io.exists()) throw new BaseXException(INFOERROR + FILEWHICH, val);
          final String query = TextInput.content(io).toString().trim();
          execute(new Set(Prop.QUERYPATH, io.path()), false);
          execute(new XQuery(query), verbose);
        } else if(key.equals("i")) {
          // create main memory database if input is XML snippet
          final boolean mem = IO.get(val) instanceof IOContent;
          execute(new Set(Prop.MAINMEM, mem), false);
          execute(new Check(val), verbose);
          execute(new Set(Prop.MAINMEM, false), false);
        } else if(key.equals("q")) {
          // run query
          execute(new XQuery(val), verbose);
        }
{'fraction_non_alphanumeric': 0.12972972972972974, 'fraction_numerical': 0.004287045666356011, 'mean_word_length': 2.645380434782609, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5812408', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1626, 'n_words': 468}