Skip to content

Commit

Permalink
Merge pull request #1078 from ryancasburn-KAI/also-fix
Browse files Browse the repository at this point in the history
Fix for some switch lock-ins for common terms
  • Loading branch information
spencermountain committed Jan 16, 2024
2 parents 4265424 + a26630d commit 2b2693c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
15 changes: 8 additions & 7 deletions src/2-two/preTagger/compute/tagger/3rd-pass/06-switches.js
Expand Up @@ -13,7 +13,7 @@ const checkWord = (term, obj) => {
found = obj[str]
}
if (found && env.DEBUG_TAGS) {
console.log(`\n \x1b[2m\x1b[3m ↓ - '${str}' \x1b[0m`)//eslint-disable-line
console.log(`\n \x1b[2m\x1b[3m ↓ - '${str}' \x1b[0m`) //eslint-disable-line
}
return found
}
Expand All @@ -30,7 +30,7 @@ const checkTag = (term, obj = {}, tagSet) => {
})
let found = tags.find(tag => obj[tag])
if (found && env.DEBUG_TAGS) {
console.log(` \x1b[2m\x1b[3m ↓ - '${term.normal || term.implicit}' (#${found}) \x1b[0m`)//eslint-disable-line
console.log(` \x1b[2m\x1b[3m ↓ - '${term.normal || term.implicit}' (#${found}) \x1b[0m`) //eslint-disable-line
}
found = obj[found]
return found
Expand All @@ -40,13 +40,14 @@ const pickTag = function (terms, i, clues, model) {
if (!clues) {
return null
}
const beforeIndex = terms[i - 1]?.text !== 'also' ? i - 1 : Math.max(0, i - 2)
const tagSet = model.one.tagSet
// look -> right word, first
let tag = checkWord(terms[i + 1], clues.afterWords)
// look <- left word, second
tag = tag || checkWord(terms[i - 1], clues.beforeWords)
// look <- left tag
tag = tag || checkTag(terms[i - 1], clues.beforeTags, tagSet)
tag = tag || checkWord(terms[beforeIndex], clues.beforeWords)
// look <- left tag
tag = tag || checkTag(terms[beforeIndex], clues.beforeTags, tagSet)
// look -> right tag
tag = tag || checkTag(terms[i + 1], clues.afterTags, tagSet)
// console.log(clues)
Expand Down Expand Up @@ -82,8 +83,8 @@ const doSwitches = function (terms, i, world) {
// add plural/singular etc.
fillTags(terms, i, model)
} else if (env.DEBUG_TAGS) {
console.log(`\n -> X - '${str}' : (${form}) `)//eslint-disable-line
console.log(`\n -> X - '${str}' : (${form}) `) //eslint-disable-line
}
}
}
export default doSwitches
export default doSwitches
2 changes: 1 addition & 1 deletion src/2-two/preTagger/model/clues/_adj.js
Expand Up @@ -61,6 +61,6 @@ export default {
also: jj, //insulting too
or: jj, //insulting or
enough: jj, //cool enough
about: jj, //cool about
//about: jj, //cool about
},
}
43 changes: 22 additions & 21 deletions src/2-two/preTagger/model/clues/adj-past.js
Expand Up @@ -17,22 +17,22 @@ const adjPast = {
Pronoun: past, //hooked me
Determiner: past, //hooked the
Adverb: past, //cooked perfectly
Comparative: past,//closed higher
Date: past,// alleged thursday
Gerund: past,//left dancing
Comparative: past, //closed higher
Date: past, // alleged thursday
Gerund: past, //left dancing
},
beforeWords: {
be: past,//be hooked vs be embarrassed
who: past,//who lost
get: 'Adjective',//get charged
be: past, //be hooked vs be embarrassed
who: past, //who lost
get: 'Adjective', //get charged
had: past,
has: past,
have: past,
been: past,
it: past,//it intoxicated him
as: past,//as requested
for: 'Adjective',//for discounted items
more: 'Adjective',//more broken promises
it: past, //it intoxicated him
as: past, //as requested
for: 'Adjective', //for discounted items
more: 'Adjective', //more broken promises
},
afterWords: {
by: past, //damaged by
Expand All @@ -49,16 +49,17 @@ const adjPast = {
as: past, //known as
on: past, //focused on
at: past, //recorded at
between: past,//settled between
to: past,//dedicated to
into: past,//pumped into
us: past,//charged us
them: past,//charged us
his: past,//shared his
her: past,//
their: past,//
our: past,//
me: past,//
between: past, //settled between
to: past, //dedicated to
into: past, //pumped into
us: past, //charged us
them: past, //charged us
his: past, //shared his
her: past, //
their: past, //
our: past, //
me: past, //
about: 'Adjective',
},
}

Expand All @@ -67,4 +68,4 @@ export default {
afterTags: Object.assign({}, adj.afterTags, adjPast.afterTags),
beforeWords: Object.assign({}, adj.beforeWords, adjPast.beforeWords),
afterWords: Object.assign({}, adj.afterWords, adjPast.afterWords),
}
}
17 changes: 15 additions & 2 deletions tests/two/variables/past-adj.test.js
Expand Up @@ -3,7 +3,6 @@ import nlp from '../_lib.js'
const here = '[two/past-adj] '

let arr = [

// == adjectives ==
[`'cool'`, '#Adjective'],
['great', '#Adjective'],
Expand Down Expand Up @@ -156,6 +155,20 @@ let arr = [
// ['it was fixed', '#Noun #Copula #PastTense'],
['it will be boxed', '#Noun #Verb #Verb #PastTense'],
// ['i am gutted', '#Noun #PastTense #Adjective'],
// [
// 'She felt abandoned about the sudden change in plans',
// '#Pronoun #PastTense #Adjective #Preposition #Determiner #Adjective #Noun #Preoposition #Noun',
// ],
[
'The puzzled detective was bewildered about the abandoned clues.',
'#Determiner #Adjective #Noun #Copula #Adjective #Preposition #Determiner #Adjective #Noun',
],
[
"He was amazed about the abandoned building's mysterious past.",
'#Pronoun #Copula #Adjective #Preposition #Determiner #Adjective #Possessive #Adjective #Noun',
],
['He also developed software.', '#Pronoun #Adverb #Verb #Noun'],
['Cheese is also aged', '#Noun #Copula #Adverb #Adjective'],
]
test('match:', function (t) {
arr.forEach(function (a) {
Expand All @@ -167,4 +180,4 @@ test('match:', function (t) {
t.equal(m.text(), doc.text(), here + msg)
})
t.end()
})
})

0 comments on commit 2b2693c

Please sign in to comment.