Skip to content

Commit

Permalink
Added tooltip to manual word seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMockler committed Aug 15, 2024
1 parent f28ca85 commit 249b358
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 68 deletions.
80 changes: 31 additions & 49 deletions ngapp/src/app/core/services/dr-story.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,6 @@ export class DigitalReaderStoryService {
let outputType = '';
let form:string = tagsArr.shift();

/*
+Part particle
+Ad adverbial, e.g. go holc ‘ badly’
+Nm numeral, e.g. a haon ‘one’
+Comp comparative degree, e.g. níos fearr ‘better’
+Pat patronym, e.g. Ó Beirn, Ní Bheirn, Uí Bheirn
+Voc vocative particle, e.g. a Mháire ‘Mary!’
+Deg degree particle, e.g. a géire a labhair sé
'how sharply he spoke'
+Cp copular particle
*/

if (form === 'Rel') {
outputType += ', rel.';
form = tagsArr.shift();
Expand Down Expand Up @@ -476,18 +463,13 @@ export class DigitalReaderStoryService {
}

parseGrammarTags(tags:string) {
if (tags === '') return '?';
if (tags === '') return {class: '?', attrs: ''};

let tagsArr = tags.split(' ');
let isGuess = false;
let isProperNoun = false;
let isSubstantive = false;
let outputString = '';
/*let parsedTags:any = {
gender: null,
number: null,
category: null,
};*/
let outputClass = '';

let wordClass = tagsArr.shift();
if (wordClass === 'Guess') {
Expand All @@ -499,7 +481,7 @@ export class DigitalReaderStoryService {
wordClass = tagsArr.shift();
}
if (wordClass === 'Subst') {
outputString += 'Substantive ';
//outputClass += 'Substantive ';
isSubstantive = true;
wordClass = tagsArr.shift();
}
Expand All @@ -509,11 +491,12 @@ export class DigitalReaderStoryService {
if (wordClass === 'Noun') {

if (isProperNoun)
outputString += 'Proper ';

outputString += 'Noun';
outputClass += 'Proper ';

// maybe refactor to reduce the number of brackets
if (isSubstantive)
outputClass += 'Noun-like';
else
outputClass += 'Noun';

if (!isSubstantive) {
attributes += this.parseGender(tagsArr);
Expand All @@ -539,7 +522,7 @@ export class DigitalReaderStoryService {

} else if (wordClass === 'Part') {

outputString += 'Particle';
outputClass += 'Particle';
attributes += this.parseParticleType(tagsArr);
if (tagsArr.length > 0)attributes += this.parseNeg(tagsArr);
if (tagsArr.length > 0) attributes += this.parseParticleRelativity(tagsArr);
Expand All @@ -550,14 +533,12 @@ export class DigitalReaderStoryService {
tagsArr.unshift(pronominalOrTense);
attributes += this.parseNeg(tagsArr);
attributes += this.parseTense(tagsArr);
//outputString += this.parseParticleRelativity(tagsArr);
}
//outputString += this.parseTense(tagsArr);
}

} else if (wordClass === 'Adj') {

outputString += 'Adjective';
outputClass += 'Adjective';

attributes += this.parseAdjForm(tagsArr);

Expand All @@ -567,7 +548,7 @@ export class DigitalReaderStoryService {

} else if (wordClass === 'Verb') {

outputString += wordClass;
outputClass += wordClass;
attributes += this.parseVerbTransitivity(tagsArr);
this.removeExtraVerbInfo(tagsArr);
attributes += this.parseVerbType(tagsArr);
Expand All @@ -577,12 +558,12 @@ export class DigitalReaderStoryService {

} else if (wordClass === 'Adv') {

outputString += 'Adverb';
outputClass += 'Adverb';
attributes += this.parseAdverbType(tagsArr);

}else if (wordClass === 'Pron') {

outputString += 'Pronoun';
outputClass += 'Pronoun';
attributes += this.parsePronounType(tagsArr);
attributes += this.parsePerson(tagsArr);
attributes += this.parseNumber(tagsArr);
Expand All @@ -591,14 +572,14 @@ export class DigitalReaderStoryService {

} else if (wordClass === 'Verbal') {

outputString += wordClass;
outputClass += wordClass;
attributes += this.parseVerbalType(tagsArr);
attributes += this.parseVerbTransitivity(tagsArr);
if (tagsArr.length>0) attributes += this.parseMutation(tagsArr);

} else if (wordClass === 'Det') {

outputString += 'Determiner';
outputClass += 'Determiner';

attributes += this.parseDeterminerType(tagsArr);
if (tagsArr.length > 0) attributes += this.parsePerson(tagsArr);
Expand All @@ -608,71 +589,72 @@ export class DigitalReaderStoryService {

} else if (wordClass === 'Num') {

outputString += 'Number';
outputClass += 'Number';

attributes += this.parseNumberType(tagsArr);
if (tagsArr.length > 0) attributes += this.parseMutation(tagsArr);

} else if (wordClass === 'Prep') {

outputString += 'Preposition';
outputClass += 'Preposition';
attributes += this.parseMutation(tagsArr);
if (tagsArr.length > 0) attributes += this.parseNumber(tagsArr);

} else if (wordClass === 'Punct') {

outputString += 'Punctuation';
outputClass += 'Punctuation';
tagsArr = []; // extra punctuation information is not necessary

} else if (wordClass === 'Cop') {

outputString += 'Copula';
outputClass += 'Copula';
attributes += this.parseTense(tagsArr);
if (tagsArr.length > 0) attributes += this.parseClauseType(tagsArr);
if (tagsArr.length > 0) this.removeExtraVerbInfo(tagsArr);
if (tagsArr.length > 0) attributes += this.parseAdverbType(tagsArr);

} else if (wordClass === 'Conj') {
outputString += 'Conjunction';
outputClass += 'Conjunction';

attributes += this.parseClauseType(tagsArr);
if (tagsArr.length > 0) attributes += this.parseTense(tagsArr);

} else if (wordClass === 'Art') {

outputString += 'Article';
outputClass += 'Article';
attributes += this.parseCase(tagsArr);
attributes += this.parseNumber(tagsArr);
attributes += this.parseMutation(tagsArr); // definite
if (tagsArr.length>0) attributes += this.parseGender(tagsArr);

} else if (wordClass === 'Itj') {

outputString += 'Interjection';
outputClass += 'Interjection';

}else if (wordClass === 'Foreign') {

outputString += wordClass;
outputClass += wordClass;

}

// failsafe so as not to lose any info
if (tagsArr) {
if (outputString == '') {
outputString += wordClass;
if (attributes == '') {
attributes += wordClass;
}
for (let i=0; i<tagsArr.length; i++) {
const tag = tagsArr[i];
if (i!=0 || outputString !== '') outputString += ', '
outputString += tag;
if (i!=0 || attributes !== '') attributes += ', '
attributes += tag;
}
}

if (attributes!='') outputString += ' (' + attributes.slice(2,attributes.length) + ')';
if (attributes!='') attributes = '(' + attributes.slice(2,attributes.length) + ')';

if (isGuess) outputString += ' ?';
if (isGuess) attributes += ' ?';

return outputString;
//return outputClass + ' ' + attributes;
return {class: outputClass, attrs: attributes};
}

saveDRStory(title: string, /*dialects: Array<string>*/collections: Array<string>, thumbnail:string, story: Object, isPublic: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {
content: (reference) => {
const lemma = reference.getAttribute('lemma');
const tags:string = reference.getAttribute('tags');
const parsedTags = this.drStoryService.parseGrammarTags(tags);
return `<div class="tooltipContent"><div><p>Base word: ${lemma}</p><p>test: ${tags}</p><p>Info: ${parsedTags}</p></div></div>`;
const parsedTags:any = this.drStoryService.parseGrammarTags(tags);
//return `<div class="tooltipContent"><div><p>Base word: ${lemma}</p><p>test: ${tags}</p><p>Info: ${parsedTags}</p></div></div>`;
return `<div class="tooltipContent"><div><p>Base form: ${lemma}</p><p>${parsedTags.class} <i>${parsedTags.attrs}</i></p></div></div>`;
},
delay: [200, 50], // delay before it shows/hides
interactive: true,
Expand Down Expand Up @@ -462,6 +463,7 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {

this.clickTimeoutRef = setTimeout( async () => {
const audioObjPromise = this.synthRequest(this.currentWord.textContent, this.speaker);
this.currentWord?.dispatchEvent(new Event('mouseenter'));
this.clickTimeoutRef = setTimeout( async () => {
const audioObj = await audioObjPromise;
if (!this.audioPlaying) // auto-played audio is a lower priority than other audio
Expand All @@ -484,7 +486,12 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {
console.log(this.currentWord)
this.playStory();
}
} else if (event.code==='ArrowRight') {
} if (['ArrowRight', 'ArrowLeft', 'Enter'].includes(event.code)) {

// should also call this event when another word gets hovered
this.currentWord?.dispatchEvent(new Event('blur'));

if (event.code==='ArrowRight') {

this.pause();
if (!event.ctrlKey) {
Expand Down Expand Up @@ -590,22 +597,6 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {
}

}
/*if (this.currentSentence) {
//let parentSentence:Element | null = this.checkForSegmentParent(this.currentWord.parentElement);
let nextSentence:Element | null = this.checkForNextSiblingSeg(this.currentSentence, 'sentence');
if (!nextSentence)
nextSentence = this.checkForNextSentence(this.currentSentence);
if (nextSentence) {
this.currentSentence = nextSentence;
const firstWordChild = this.currentSentence?.querySelector('.word');
this.updateCurrentWord(firstWordChild);
this.playWordOnSeekStop();
}
}*/
}
} else if (event.code==='Enter') {
if (this.currentWord) {
Expand All @@ -619,6 +610,7 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {
}
}
}
}
}
}

Expand Down

0 comments on commit 249b358

Please sign in to comment.