mirror of
https://github.com/vaccarini-lorenzo/MagicCalendar.git
synced 2026-07-22 08:40:30 +00:00
beta feature
This commit is contained in:
parent
f188010ad0
commit
bfe5531ed2
4 changed files with 85 additions and 25 deletions
|
|
@ -108,6 +108,26 @@ class NlpController {
|
|||
const selectedDate = dates[0];
|
||||
const selectedDateIndex = caseInsensitiveText.indexOf(selectedDate.value);
|
||||
|
||||
if (this._setting.customSymbol != "" ){
|
||||
const customEvent = this.getCustomEvent(sentence);
|
||||
if (customEvent){
|
||||
const cleanDates = this.cleanJunkDates(dates);
|
||||
const dateRange = this.parseDates(cleanDates);
|
||||
if (!dateRange) return;
|
||||
sentence.injectSemanticFields(dateRange.start, dateRange.end, customEvent.value)
|
||||
matchedEvent = eventController.semanticCheck(sentence);
|
||||
// Matched semantic check;
|
||||
if (matchedEvent) return null;
|
||||
const selection = this.getSelectionArray(sentence.value, cleanDates, customEvent);
|
||||
const event = eventController.createNewEvent(sentence);
|
||||
|
||||
return {
|
||||
selection,
|
||||
event
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find purpose in text
|
||||
// e.g. "to discuss finances"
|
||||
const purpose = this.filterPurpose(caseInsensitiveText, mainCustomEntities, tokens);
|
||||
|
|
@ -391,8 +411,8 @@ class NlpController {
|
|||
return selectedProperName;
|
||||
}
|
||||
|
||||
private getSelectionArray(text: string, dates: {value, index, type}[], selectedEventNoun: {value, index, type}, backwardsAdjAttributes: {value, index, type}[],
|
||||
forwardAdjAttributes: {value, index, type}[], selectedProperName: {value, index, type}, purpose: {value, index, type}): {value, index, type}[] {
|
||||
private getSelectionArray(text: string, dates: {value, index, type}[], selectedEventNoun: {value, index, type}, backwardsAdjAttributes?: {value, index, type}[],
|
||||
forwardAdjAttributes?: {value, index, type}[], selectedProperName?: {value, index, type}, purpose?: {value, index, type}): {value, index, type}[] {
|
||||
const selection = []
|
||||
|
||||
dates.forEach(date => {
|
||||
|
|
@ -400,19 +420,19 @@ class NlpController {
|
|||
selection.push({value: date.value, index: dateIndex, type: date.type});
|
||||
})
|
||||
|
||||
if (selectedEventNoun!= null) selection.push(selectedEventNoun);
|
||||
if (selectedProperName!= null) selection.push(selectedProperName);
|
||||
if (backwardsAdjAttributes != null){
|
||||
if (selectedEventNoun) selection.push(selectedEventNoun);
|
||||
if (selectedProperName) selection.push(selectedProperName);
|
||||
if (backwardsAdjAttributes){
|
||||
backwardsAdjAttributes.forEach(backwardsAdjAttribute => {
|
||||
selection.push(backwardsAdjAttribute);
|
||||
})
|
||||
}
|
||||
if (forwardAdjAttributes != null){
|
||||
if (forwardAdjAttributes){
|
||||
forwardAdjAttributes.forEach(forwardAdjAttribute => {
|
||||
selection.push(forwardAdjAttribute);
|
||||
})
|
||||
}
|
||||
if (purpose != null) selection.push(purpose);
|
||||
if (purpose) selection.push(purpose);
|
||||
|
||||
// Order by index (builder.add needs to be called with increasing values)
|
||||
return selection.sort((a, b) => a.index - b.index);
|
||||
|
|
@ -467,6 +487,24 @@ class NlpController {
|
|||
if(!this._setting.bannedPatterns) return false;
|
||||
return this._setting.bannedPatterns.some(bannedPattern => sentence.value.indexOf(bannedPattern) > -1);
|
||||
}
|
||||
|
||||
private getCustomEvent(sentence: Sentence) {
|
||||
const chars = sentence.value.split("");
|
||||
let startIndex;
|
||||
let endIndex;
|
||||
chars.forEach((char, index) => {
|
||||
if (char != this._setting.customSymbol) return;
|
||||
if (!startIndex) startIndex = index;
|
||||
else endIndex = index;
|
||||
})
|
||||
if (!startIndex || !endIndex) return;
|
||||
return {
|
||||
value: sentence.value.slice(startIndex + 1, endIndex),
|
||||
index: startIndex,
|
||||
type: "customEvent"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const nplController = new NlpController();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {App, PluginSettingTab, Setting, TextAreaComponent, TextComponent} from "
|
|||
import MagicCalendar from "./main";
|
||||
import moment, {tz} from "moment-timezone";
|
||||
import {CalendarProvider} from "../model/cloudCalendar/calendarProvider";
|
||||
import {BannedListHTML} from "./bannedListHTML";
|
||||
import {settingListHTML} from "./settingListHTML";
|
||||
|
||||
export interface SettingInterface {
|
||||
tz: string;
|
||||
|
|
@ -11,6 +11,7 @@ export interface SettingInterface {
|
|||
iv: string;
|
||||
calendarProvider: CalendarProvider;
|
||||
bannedPatterns: string[];
|
||||
customSymbol: string;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: Partial<SettingInterface> = {
|
||||
|
|
@ -19,6 +20,8 @@ export const DEFAULT_SETTINGS: Partial<SettingInterface> = {
|
|||
key: "none",
|
||||
iv: "none",
|
||||
calendarProvider: CalendarProvider.NOT_SELECTED,
|
||||
bannedPatterns: [],
|
||||
customSymbol: ""
|
||||
};
|
||||
|
||||
export class AppSetting extends PluginSettingTab {
|
||||
|
|
@ -28,7 +31,9 @@ export class AppSetting extends PluginSettingTab {
|
|||
key: string;
|
||||
iv: string;
|
||||
bannedPatternText: TextComponent;
|
||||
bannedListHTML: BannedListHTML;
|
||||
bannedListHTML: settingListHTML;
|
||||
customPatternText: TextComponent;
|
||||
customSymbolHTML: settingListHTML;
|
||||
|
||||
|
||||
constructor(app: App, plugin: MagicCalendar) {
|
||||
|
|
@ -77,8 +82,6 @@ export class AppSetting extends PluginSettingTab {
|
|||
})
|
||||
})
|
||||
|
||||
containerEl.createEl("h3", {text: "Advanced"});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Encryption key")
|
||||
.addText(key => {
|
||||
|
|
@ -99,6 +102,17 @@ export class AppSetting extends PluginSettingTab {
|
|||
})
|
||||
})
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Custom symbol")
|
||||
.addText(async text => {
|
||||
text.setPlaceholder("N/A")
|
||||
text.setValue(this.plugin.settings.customSymbol)
|
||||
text.onChange(async value => {
|
||||
this.plugin.settings.customSymbol = value;
|
||||
await this.plugin.updateSettings();
|
||||
})
|
||||
})
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Ban pattern")
|
||||
.addText(text => {
|
||||
|
|
@ -114,7 +128,7 @@ export class AppSetting extends PluginSettingTab {
|
|||
})
|
||||
})
|
||||
|
||||
this.bannedListHTML = new BannedListHTML(containerEl, this.updateBannedPatterns.bind(this), this.plugin.settings.bannedPatterns)
|
||||
this.bannedListHTML = new settingListHTML(containerEl, this.updateBannedPatterns.bind(this), this.plugin.settings.bannedPatterns)
|
||||
this.bannedListHTML
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,43 +2,46 @@ import {Setting} from "obsidian";
|
|||
import {Misc} from "../misc/misc";
|
||||
import {Media} from "../misc/media";
|
||||
|
||||
export class BannedListHTML extends Setting {
|
||||
export class settingListHTML extends Setting {
|
||||
containerEl: HTMLElement;
|
||||
bannedPatterns: string[];
|
||||
elements: string[];
|
||||
listContainer: HTMLElement;
|
||||
maxLength?: number;
|
||||
deleteCallback: (pattern: string) => void;
|
||||
|
||||
constructor(containerEl: HTMLElement, deleteCallback :(pattern: string) => void, bannedPatterns: string[]) {
|
||||
constructor(containerEl: HTMLElement, deleteCallback :(pattern: string) => void, elements: string[], maxLength?: number) {
|
||||
super(containerEl);
|
||||
this.containerEl = containerEl;
|
||||
this.bannedPatterns = bannedPatterns;
|
||||
this.elements = elements;
|
||||
this.deleteCallback = deleteCallback;
|
||||
this.listContainer = this.containerEl.createEl("div", { cls: "magicCalendarSettingListContainer" });
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
build(){
|
||||
this.listContainer.empty();
|
||||
|
||||
this.bannedPatterns.forEach(bannedPattern => {
|
||||
this.createListElement(bannedPattern)
|
||||
if (!this.elements) return;
|
||||
this.elements.forEach(element => {
|
||||
this.createListElement(element)
|
||||
});
|
||||
}
|
||||
|
||||
createListElement(bannedPattern: string){
|
||||
createListElement(element: string){
|
||||
const listItem = this.listContainer.createEl("div", { cls: "magicCalendarSettingListItem" });
|
||||
const itemText = listItem.createEl("span", { cls: "magicCalendarSettingListText" });
|
||||
itemText.setText(bannedPattern);
|
||||
itemText.setText(element);
|
||||
const trashIcon = listItem.createEl("img", { cls: "magicCalendarSettingListDeleteIcon" });
|
||||
trashIcon.setAttribute("src", Media.getBase64DeleteIcon());
|
||||
trashIcon.onClickEvent(click => {
|
||||
this.bannedPatterns.remove(bannedPattern);
|
||||
this.elements.remove(element);
|
||||
this.build();
|
||||
this.deleteCallback(bannedPattern);
|
||||
this.deleteCallback(element);
|
||||
})
|
||||
}
|
||||
|
||||
append(bannedPattern: string) {
|
||||
this.bannedPatterns.push(bannedPattern);
|
||||
if (this.maxLength && this.elements.length >= this.maxLength) this.elements.pop();
|
||||
this.elements.unshift(bannedPattern);
|
||||
this.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -89,6 +89,9 @@
|
|||
border-radius: 5px;
|
||||
float: right; /* This aligns the container to the right */
|
||||
border: none; /* This removes the border */
|
||||
width: 100%;
|
||||
display: block;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.magicCalendarSettingListContainer::-webkit-scrollbar {
|
||||
|
|
@ -107,7 +110,9 @@
|
|||
}
|
||||
|
||||
.magicCalendarSettingListText {
|
||||
flex-grow: 1;
|
||||
text-align: right;
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.magicCalendarSettingListDeleteIcon {
|
||||
|
|
|
|||
Loading…
Reference in a new issue