Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for some switch lock-ins for common terms #1078

Merged
merged 4 commits into from Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})
})