Skip to content

Commit

Permalink
add #85 & #91
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpetro committed Mar 26, 2023
1 parent 8af7399 commit b515553
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
38 changes: 36 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const DEFAULT_SETTINGS = {
show_full_path: false,
expanded_view: true,
group_nearest_by_file: false,
language: "en",
log_render: false,
log_render_files: false,
skip_sections: false,
Expand All @@ -23,6 +24,15 @@ const MAX_EMBED_STRING_LENGTH = 25000;

const VERSION = "1.2.8";

// language specific self-referential pronouns
const SELF_REFERENTIAL_PRONOUNS = {
"en": ["my", "I", "me", "mine", "our", "ours", "us", "we"],
"es": ["mi", "yo", "mí", "tú"],
"fr": ["mon", "ma", "mes", "moi", "nous", "notre", "nos", "notres"],
"de": ["mein", "meine", "meinen", "meiner", "meines", "mir", "uns", "unser", "unseren", "unserer", "unseres"],
"it": ["mio", "mia", "miei", "mie", "noi", "nostro", "nostri", "nostra", "nostre"],
};

This comment has been minimized.

Copy link
@pinuke

pinuke Mar 26, 2023

Contributor

@brianpetro can we split this up into its own json file? This would allow the end-user to add custom languages via JSON like so:

const SELF_REFERENTIAL_PRONOUNS = require( "./languages.json" )

languages.json:

{
  "en": ["my", "I", "me", "mine", "our", "ours", "us", "we"],
  "es": ["mi", "yo", "", ""],
  "fr": ["mon", "ma", "mes", "moi", "nous", "notre", "nos", "notres"],
  "de": ["mein", "meine", "meinen", "meiner", "meines", "mir", "uns", "unser", "unseren", "unserer", "unseres"],
  "it": ["mio", "mia", "miei", "mie", "noi", "nostro", "nostri", "nostra", "nostre"],
}

Another approach would be to split the language file into localization files, and include them on a loop:

const SELF_REFERENTIAL_PRONOUNS = {}
// loop through the languages directory inside the plugin for .json files
require("fs")
  .readdirSync( __dirname + "/languages" )
  .forEach( file => {
    // require the .json files and assign their properties to the SELF_REFERENTIAL_PRONOUNS object
    Object.assign(
      SELF_REFERENTIAL_PRONOUNS,
      require( `${ __dirname }/languages/${ file }` )
    )
  });

We can set a languages/default.json file, like so:

{
  "en": ["my", "I", "me", "mine", "our", "ours", "us", "we"],
  "es": ["mi", "yo", "", ""],
  "fr": ["mon", "ma", "mes", "moi", "nous", "notre", "nos", "notres"],
  "de": ["mein", "meine", "meinen", "meiner", "meines", "mir", "uns", "unser", "unseren", "unserer", "unseres"],
}

Then add support for italian in languages/it.json, like so:

{
  "it": ["mio", "mia", "miei", "mie", "noi", "nostro", "nostri", "nostra", "nostre"]
}

This comment has been minimized.

Copy link
@pinuke

pinuke Mar 26, 2023

Contributor

An example as to why this would be needed is that you can't be expected to know the self-referential pronouns for the 170+ languages that exist in the world.

A current example would be your spanish pronouns. For some reason you included tu (which means you) and not nosotros and nuestra(feminine)/nuestro(masculine) (which is we and our respectively)

This comment has been minimized.

Copy link
@pinuke

pinuke Mar 26, 2023

Contributor

The latter solution is currently proposed with #95

class SmartConnectionsPlugin extends Obsidian.Plugin {
// constructor
constructor() {
Expand All @@ -46,6 +56,7 @@ class SmartConnectionsPlugin extends Obsidian.Plugin {
this.render_log.tokens_saved_by_cache = 0;
this.retry_notice_timeout = null;
this.save_timeout = null;
this.self_ref_kw_regex = null;
}

async loadSettings() {
Expand Down Expand Up @@ -84,6 +95,8 @@ class SmartConnectionsPlugin extends Obsidian.Plugin {
return path.trim();
});
}
// load self_ref_kw_regex
this.self_ref_kw_regex = new RegExp(`\\b(${SELF_REFERENTIAL_PRONOUNS[this.settings.language].join("|")})\\b`, "gi");
// load failed files
await this.load_failed_files();
}
Expand Down Expand Up @@ -2377,6 +2390,24 @@ class SmartConnectionsSettingsTab extends Obsidian.PluginSettingTab {
});
dropdown.setValue(this.plugin.settings.smart_chat_model);
});
// language
new Obsidian.Setting(containerEl).setName("Default Language").setDesc("Default language to use for Smart Chat. Changes which self-referential pronouns will trigger lookup of your notes.").addDropdown((dropdown) => {
// get Object keys from SELF_REFERENTIAL_PRONOUNS
const languages = Object.keys(SELF_REFERENTIAL_PRONOUNS);
for(let i = 0; i < languages.length; i++) {
dropdown.addOption(languages[i], languages[i]);
}
dropdown.onChange(async (value) => {
this.plugin.settings.language = value;
await this.plugin.saveSettings();
self_ref_pronouns_list.setText(this.get_self_ref_list());
});
dropdown.setValue(this.plugin.settings.language);
});
// list current self-referential pronouns
const self_ref_pronouns_list = containerEl.createEl("span", {
text: this.get_self_ref_list()
});
containerEl.createEl("h2", {
text: "Exclusions"
});
Expand Down Expand Up @@ -2496,6 +2527,10 @@ class SmartConnectionsSettingsTab extends Obsidian.PluginSettingTab {
}));

}
get_self_ref_list() {
return "Current: " + SELF_REFERENTIAL_PRONOUNS[this.plugin.settings.language].join(", ");
}

draw_failed_files_list(failed_list) {
failed_list.empty();
if(this.plugin.settings.failed_files.length > 0) {
Expand Down Expand Up @@ -2795,8 +2830,7 @@ class SmartConnectionsChatView extends Obsidian.ItemView {
}

contains_self_referential_keywords(user_input) {
const kw_regex = /\b(my|I|me|mine|our|ours|us|we)\b/gi;
const matches = user_input.match(kw_regex);
const matches = user_input.match(this.plugin.self_ref_kw_regex);
if(matches) return true;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Smart Connections",
"author": "Brian Petro",
"description": "Find links to similar notes using artificial intelligence from OpenAI.",
"version": "1.4.6",
"version": "1.4.7",
"minAppVersion": "1.1.0",
"authorUrl": "https://wfhbrian.com",
"isDesktopOnly": true
Expand Down
2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@

.sc-chat-form {
display: flex;
padding: 0 10px 1rem;
padding: 0 10px 1rem 0;
width: 100%;
max-height: 50%;
}
Expand Down

0 comments on commit b515553

Please sign in to comment.