<commit_before>;; Copyright (c) <NAME>. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file LICENSE at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.

;; This file has been written by <NAME>, with modifications by DB

(ns conexp.contrib.gui.editors.contexts
  (:use conexp.base
        conexp.fca.contexts
        conexp.fca.lattices
        conexp.io
        conexp.layouts
        [conexp.layouts.base :only (lattice)]
        conexp.contrib.draw.lattices
        conexp.contrib.gui.util
        conexp.contrib.gui.editors.context-editor.context-editor
        conexp.contrib.gui.plugins.base)
  (:use [clojure.string :only (replace)
                        :rename {replace replace-str}])
  (:import [java.io File]))

(ns-doc
 "Provides context-editor, a plugin for contexts for the standard GUI
  of conexp-clj.")

;;; The Plugin

(declare load-context-editor unload-context-editor)

(define-plugin context-editor
  "Context editor plugin."
  :load-hook   #(load-context-editor %),
  :unload-hook #(unload-context-editor %))

;;; The Actions

(defn- load-context-and-go
  "Loads context with given loader and adds a new tab with a context-editor."
  [frame loader]
  (when-let [^File file (choose-open-file frame)]
    (let [path (.getPath file),
          thing (loader path)]
      (add-tab frame
               (make-context-editor thing)
               (str "Context " path)))))

(defn- clone-context-and-go
  "Loads context with given loader and adds a new tab with a context-editor."
  [frame]
  (add-tab frame
    (clone-context-view-from-panel (current-tab frame))
    (str (current-tab-title frame) "*")))

(defn- random-context-and-go
  "Creates a random context and adds a new tab with a context-editor."
  [frame]
  (let [thing (rand-context #{"a" "b" "c" "d" "e" "f"} #{1 2 3 4 5 6} 0.4)]
    (add-tab frame
             (make-context-editor thing)
             "Context")))

(defn- second-op-context-and-go
  "Show the current second operand context in a new tab."
  [frame]
  (let [thing (get-current-second-operand-context)]
    (add-tab frame
             (make-context-editor thing)
             "Context")))

(defn- save-context-and-go
  "Saves context with given writer."
  [frame writer]
  (when-let [thing (get-context-from-panel (current-tab frame))]
    (when-let [^File file (choose-save-file frame)]
      (let [path (.getPath file)]
        (writer thing path)))))

(defn- show-lattice-and-go
  "Shows concept lattice of current tab."
  [frame]
  (let [thing (get-context-from-panel (current-tab frame))]
    (add-tab frame
             (make-lattice-editor frame
                                  (standard-layout (concept-lattice thing)))
             "Concept-Lattice")))

;;; The Hooks

(defvar- context-menu
  {:name "Context",
   :content [{:name "Load Context",
              :handler #(load-context-and-go % read-context)},
             {:name "Random Context",
              :handler random-context-and-go},
             {:name "Second Operand Context",<commit_msg>Add possibility to create new context in GUI directly<commit_after>;; Copyright (c) <NAME>. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file LICENSE at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.

;; This file has been written by <NAME>, with modifications by DB

(ns conexp.contrib.gui.editors.contexts
  (:use conexp.base
        conexp.fca.contexts
        conexp.fca.lattices
        conexp.io
        conexp.layouts
        [conexp.layouts.base :only (lattice)]
        conexp.contrib.draw.lattices
        conexp.contrib.gui.util
        conexp.contrib.gui.editors.context-editor.context-editor
        conexp.contrib.gui.plugins.base)
  (:use [clojure.string :only (replace)
                        :rename {replace replace-str}])
  (:import [java.io File]))

(ns-doc
 "Provides context-editor, a plugin for contexts for the standard GUI
  of conexp-clj.")

;;; The Plugin

(declare load-context-editor unload-context-editor)

(define-plugin context-editor
  "Context editor plugin."
  :load-hook   #(load-context-editor %),
  :unload-hook #(unload-context-editor %))

;;; The Actions

(defn- load-context-and-go
  "Loads context with given loader and adds a new tab with a context-editor."
  [frame]
  (when-let [^File file (choose-open-file frame)]
    (let [path (.getPath file),
          thing (read-context path)]
      (add-tab frame
               (make-context-editor thing)
               (str "Context " path)))))

(defn- clone-context-and-go
  "Loads context with given loader and adds a new tab with a context-editor."
  [frame]
  (add-tab frame
    (clone-context-view-from-panel (current-tab frame))
    (str (current-tab-title frame) "*")))

(defn- context-and-go
  "Opens given context in a new context editor tab."
  [frame context]
  (add-tab frame
           (make-context-editor context)
           "Context"))

(defn- second-op-context-and-go
  "Show the current second operand context in a new tab."
  [frame]
  (let [thing (get-current-second-operand-context)]
    (add-tab frame
             (make-context-editor thing)
             "Context")))

(defn- save-context-and-go
  "Saves context with given writer."
  [frame writer]
  (when-let [thing (get-context-from-panel (current-tab frame))]
    (when-let [^File file (choose-save-file frame)]
      (let [path (.getPath file)]
        (writer thing path)))))

(defn- show-lattice-and-go
  "Shows concept lattice of current tab."
  [frame]
  (let [thing (get-context-from-panel (current-tab frame))]
    (add-tab frame
             (make-lattice-editor frame
                                  (standard-layout (concept-lattice thing)))
             "Concept-Lattice")))

;;; The Hooks

(defvar- context-menu
  {:name "Context",
   :content [{:name "New Context",
              :handler #(context-and-go % (make-context (set-of-range 10)
                                                        (set-of-range 10)
                                                        #{}))},
             {:name "Load Context",
              :handler load-context-and-go},
             {:name "Random Context",
              :handler #(context-and-go % (rand-context 5 5 0.4))},
             {:name "Second Operand Context",
{'fraction_non_alphanumeric': 0.12677707753187747, 'fraction_numerical': 0.003517514289901803, 'mean_word_length': 2.4780835881753314, 'pattern_counts': {'":': 0, '<': 7, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2968937', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2067, 'n_words': 643}