Skip to content

Commit

Permalink
progress: basic elevate stimulation functioning
Browse files Browse the repository at this point in the history
* veeery basic.
  • Loading branch information
wraiford committed Jan 16, 2023
1 parent 00f1c28 commit ed2d09c
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 210 deletions.
4 changes: 2 additions & 2 deletions ionic-gib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ionic-gib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ionicgib",
"version": "0.2.724",
"version": "0.2.727",
"author": "William Raiford",
"repository": {
"url": "https://github.com/wraiford/ibgib",
Expand Down
11 changes: 10 additions & 1 deletion ionic-gib/src/app/common/types/robbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,16 @@ export interface RobbotSessionIbGib_V1 extends IbGib_V1<RobbotSessionData_V1, Ro
export type AtomicId =
'hi' | 'welcome' | 'bye' |
'yes' | 'no' |
'learn';
'learn' |
'wtg';
export const AtomicId = {
hi: 'hi' as AtomicId,
welcome: 'welcome' as AtomicId,
bye: 'bye' as AtomicId,
yes: 'yes' as AtomicId,
no: 'no' as AtomicId,
learn: 'learn' as AtomicId,
wtg: 'wtg' as AtomicId,
}

/**
Expand Down Expand Up @@ -520,6 +522,7 @@ export type SemanticId =
'semantic_options' |
'semantic_ready' |
'semantic_stop' |
'semantic_result' |
'semantic_unknown' | 'semantic_default' |
string; // have to do this for inheritance?
export const SemanticId = {
Expand All @@ -540,6 +543,7 @@ export const SemanticId = {
options: 'semantic_options' as SemanticId,
ready: 'semantic_ready' as SemanticId,
stop: 'semantic_stop' as SemanticId,
result: 'semantic_result' as SemanticId,
unknown: 'semantic_unknown' as SemanticId,
default: 'semantic_default' as SemanticId,
};
Expand Down Expand Up @@ -733,6 +737,11 @@ export const DEFAULT_HUMAN_LEX_DATA_ENGLISH_ATOMICS: LexData<RobbotPropsData> =
'learn', 'study', 'review',
]),
],
[AtomicId.wtg]: [
...toLexDatums_Atomics(AtomicId.wtg, [
'wtg', 'nice', 'not bad', 'pretty good', 'good job',
]),
],
}
export const DEFAULT_HUMAN_LEX_DATA_ENGLISH: LexData<RobbotPropsData> = {
...DEFAULT_HUMAN_LEX_DATA_ENGLISH_SEMANTICS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/**
* blank stimulator
*/

import * as h from 'ts-gib/dist/helper';
import { IbGib_V1 } from 'ts-gib/dist/V1';
import { IbGibAddr } from 'ts-gib';

import * as c from '../../../../../common/constants';
import {
StimulateArgs, Stimulation, StimulationScope, StimulationTarget, StimulationType, Stimulator, WordyTextInfo
} from '.././types';
import { getMostSpecialestWords, getTargets, getWords, getWordyTextInfo } from '.././helper';
import { StimulatorBase } from './stimulator-base';
import { LexData, PropsData } from '../../../../../common/helper/lex';
import { SemanticId, toLexDatums_Semantics } from 'src/app/common/types/robbot';
import { getSaferSubstring, pickRandom, replaceCharAt, weAreRunningOnMobileProbably } from '../../../../../common/helper/utils';
import { ContinuableStimulatorBase } from './continuable-base';
import { CommentIbGib_V1 } from 'src/app/common/types/comment';


const logalot = c.GLOBAL_LOG_A_LOT || true;


export type BlankSemanticId =
"semantic_blank" |
SemanticId;
export const BlankSemanticId = {
...SemanticId,
blank: 'semantic_blank' as BlankSemanticId,
}

interface LexPropsData extends PropsData {

}

interface StimulationDetails_Blank {
/**
* Text slice(s) that the user is to blank.
*/
texts?: string[];
/**
* if applicable, 0-based index that depends on stimulationScope.
*
* If the scope is word, then this will indicate the indexes within the string, i.e. found/incidence index.
* If the scope is line, then this wll provide the index(s) of the line.
* If the scope is a paragraph, then this will indicate the paragraph index(s).
*
* @optional
*/
indexes?: number[];
}

export class Stimulator_Blank extends ContinuableStimulatorBase {
protected lc: string = `[${Stimulator_Blank.name}]`;

constructor() {
super();
}

_lexData: LexData<LexPropsData>;
protected async getLexData(): Promise<LexData<PropsData>> {
if (!this._lexData) {
this._lexData = {
[BlankSemanticId.blank]: [
{
texts: [
`# blank`,
`## type the blanked out text`,
``,
`$textWithBlanks`,
],
}
],
}
}
return this._lexData;
}

protected getName(): string { return Stimulator_Blank.name; }
protected getVersion(): string { return "v1"; }
protected getTypes(): StimulationType[] { return [StimulationType.blank]; }

/**
* We don't want to have to type out if we're on mobile.
*/
protected canStimulateImpl(args: StimulateArgs): Promise<boolean> {
// can always blank to some degree
return Promise.resolve(true);
// const { ibGibs, prevStimulations, stimulationType, textInfo, semanticInfo } = args;

// const isFirstStimulation = prevStimulations.length === 0;
// const isMultiline = textInfo.lines?.length > 1;
// const stimulationScope = isFirstStimulation || !isMultiline ?
// StimulationScope.word :
// StimulationScope.line;
// if we're running on mobile, only type single words.
// const onMobile = weAreRunningOnMobileProbably();
// return !onMobile;
}

protected async getStimulationImpl_Fresh({
args,
targets,
}: {
args: StimulateArgs
targets: StimulationTarget[],
}): Promise<Stimulation> {
const lc = `${this.lc}[${this.getStimulationImpl_Fresh.name}]`;
try {
if (logalot) { console.log(`${lc} starting... (I: 973aaf4076124f98b7fc50a3f0f736c3)`); }

let { ibGibs, prevStimulations, textInfo, semanticInfo } = args;

// in accordance with "elevated stimulations", we want to start out
// small and grow bigger as we go. So first blank just single words
// (TF/IDF-ish), and then entire lines.
debugger;

const stimulationScope = StimulationScope.word;

// just concat the incoming ibGib(s). Right now, there is only one ibGib anyway...
let fullText = ibGibs.map(x => x.data?.text).join('\n\n');

// get the more special words (rarer, TF/IDF-ish)
const countToBlank = pickRandom({ x: [3, 7] });
const specialWords = await getMostSpecialestWords({
subsetText: fullText,
globalTextInfo: textInfo,
countToReturn: countToBlank,
});

if (specialWords?.length > countToBlank) { throw new Error(`(UNEXPECTED) specialWords.length (${specialWords.length}) > countToBlank (${countToBlank})? (E: 54d80a4aabdd4b5c8acafb73247a293d)`); }

if (logalot) { console.log(`${lc} specialWords: ${specialWords.join(',')} (I: 932a365e02284e813a9594332838da23)`); }

let textWithBlanks = fullText.concat();
for (let i = 0; i < specialWords.length; i++) {
const specialWord = specialWords[i];
const regExp = new RegExp(`(\\W)${specialWord}(\\W)`, 'g');
debugger;
textWithBlanks = textWithBlanks.replace(regExp, '$1_____$2');
}

// get the blank text from our local lex.
// todo: vary text for blank via property isFirst or something, so we can say "for starters, blank over this..."
const speech = this.lex.get(BlankSemanticId.blank, {
vars: {
textWithBlanks,
}
});

const resStimulation: Stimulation = {
stimulationType: 'blank',
stimulatorName: this.name,
stimulatorVersion: this.version,
actualTimestampUTC: h.getTimestamp(),
targets,
commentText: speech.text,
expectedTexts: specialWords,
stimulationScope,
isComplete: true,
};

return resStimulation;
} catch (error) {
console.error(`${lc} ${error.message}`);
throw error;
} finally {
if (logalot) { console.log(`${lc} complete.`); }
}
}

protected async getStimulationImpl_Continuation({
args,
targets,
mostRecentStimulation,
}: {
args: StimulateArgs
targets: StimulationTarget[],
mostRecentStimulation: Stimulation,
}): Promise<Stimulation> {
const lc = `${this.lc}[${this.getStimulationImpl_Continuation.name}]`;
try {
if (logalot) { console.log(`${lc} starting... (I: 5e24fe61febf43a39754c7a95ba592a7)`); }

return await this.getStimulationImpl_Fresh({ args, targets });
} catch (error) {
console.error(`${lc} ${error.message}`);
throw error;
} finally {
if (logalot) { console.log(`${lc} complete.`); }
}
}
}
Loading

0 comments on commit ed2d09c

Please sign in to comment.