<commit_before>import { TextEditor, Grammar } from "atom";
import * as path from "path";
import { readFile } from "fs";
import _ from "lodash";
import { promisify } from "util";

const { dialog } = require("electron").remote;

import { fromJS } from "@nteract/commutable";
import type { Notebook, Cell } from "@nteract/commutable";
import store from "./store";
import { getCommentStartString } from "./code-manager";
import { importResult, convertMarkdownToOutput } from "./result";
const readFileP = promisify(readFile);
const linesep = process.platform === "win32" ? "\r\n" : "\n";

/**
 * Determines if the provided uri is a valid file for Hydrogen to import.
 * Then it loads the notebook.
 *
 * @param {String} uri - Uri of the file to open.
 */
export function ipynbOpener(uri: string) {
  if (
    path.extname(uri).toLowerCase() === ".ipynb" &&
    atom.config.get("Hydrogen.importNotebookURI") === true
  ) {
    return _loadNotebook(
      uri,
      atom.config.get("Hydrogen.importNotebookResults")
    );
  }
}

/**
 * Determines if the provided event is trying to open
 * a valid file for Hydrogen to import.
 * Otherwise it will ask the user to chose
 * a valid file for Hydrogen to import.
 * Then it loads the notebook.
 *
 * @param {Event} event - Atom Event from clicking in a treeview.
 */
export function importNotebook(event?: atom$CustomEvent) {
  // Use selected filepath if called from tree-view context menu
  const filenameFromTreeView = _.get(event, "target.dataset.path");

  if (filenameFromTreeView && path.extname(filenameFromTreeView) === ".ipynb") {
    return _loadNotebook(
      filenameFromTreeView,
      atom.config.get("Hydrogen.importNotebookResults")
    );
  }

  dialog.showOpenDialog(
    {
      properties: ["openFile"],
      filters: [
        {
          name: "Notebooks",
          extensions: ["ipynb"],
        },
      ],
    },
    (filenames: Array<string> | null | undefined) => {
      if (!filenames) {
        atom.notifications.addError("No filenames selected");
        return;
      }

      const filename = filenames[0];<commit_msg>Replace atom$CustomEvent with imported CustomEvent<commit_after>import { TextEditor, Grammar, CustomEvent } from "atom";
import * as path from "path";
import { readFile } from "fs";
import _ from "lodash";
import { promisify } from "util";

const { dialog } = require("electron").remote;

import { fromJS } from "@nteract/commutable";
import type { Notebook, Cell } from "@nteract/commutable";
import store from "./store";
import { getCommentStartString } from "./code-manager";
import { importResult, convertMarkdownToOutput } from "./result";
const readFileP = promisify(readFile);
const linesep = process.platform === "win32" ? "\r\n" : "\n";

/**
 * Determines if the provided uri is a valid file for Hydrogen to import.
 * Then it loads the notebook.
 *
 * @param {String} uri - Uri of the file to open.
 */
export function ipynbOpener(uri: string) {
  if (
    path.extname(uri).toLowerCase() === ".ipynb" &&
    atom.config.get("Hydrogen.importNotebookURI") === true
  ) {
    return _loadNotebook(
      uri,
      atom.config.get("Hydrogen.importNotebookResults")
    );
  }
}

/**
 * Determines if the provided event is trying to open
 * a valid file for Hydrogen to import.
 * Otherwise it will ask the user to chose
 * a valid file for Hydrogen to import.
 * Then it loads the notebook.
 *
 * @param {Event} event - Atom Event from clicking in a treeview.
 */
export function importNotebook(event?: CustomEvent) {
  // Use selected filepath if called from tree-view context menu
  const filenameFromTreeView = _.get(event, "target.dataset.path");

  if (filenameFromTreeView && path.extname(filenameFromTreeView) === ".ipynb") {
    return _loadNotebook(
      filenameFromTreeView,
      atom.config.get("Hydrogen.importNotebookResults")
    );
  }

  dialog.showOpenDialog(
    {
      properties: ["openFile"],
      filters: [
        {
          name: "Notebooks",
          extensions: ["ipynb"],
        },
      ],
    },
    (filenames: Array<string> | null | undefined) => {
      if (!filenames) {
        atom.notifications.addError("No filenames selected");
        return;
      }

      const filename = filenames[0];
{'fraction_non_alphanumeric': 0.12844685364129155, 'fraction_numerical': 0.0014140938015555031, 'mean_word_length': 3.278225806451613, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4083041', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1265, 'n_words': 380}