Skip to content

Commit

Permalink
fix runtime error #965
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 16, 2022
1 parent a1f5dd0 commit 5fadede
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 7 additions & 2 deletions scratch.js
Expand Up @@ -38,8 +38,13 @@ import nlp from './src/three.js'
// matches.forEach((m) => doc.remove(m))
// console.log(doc.text())

let doc = nlp("he said I am a boy")
console.log(doc.verbs().json().map(obj => obj.verb.grammar))

const doc = nlp("people's").debug()
doc.nouns().toSingular()

// let doc = nlp("he said I am a boy")
// console.log(doc.sentences().json())

// [ { form: 'simple-present', tense: 'PresentTense', copula: true } ]

// let doc = nlp(`Remove me 1. A some text. B some text. C some text`)
Expand Down
6 changes: 5 additions & 1 deletion src/1-one/change/api/insert.js
Expand Up @@ -28,7 +28,7 @@ const getTerms = function (input, world) {
}
//allow a view object
if (typeof input === 'object' && input.isView) {
return input.clone().docs[0] //assume one sentence
return input.clone().docs[0] || [] //assume one sentence
}
//allow an array of terms, too
if (isArray(input)) {
Expand All @@ -49,6 +49,10 @@ const insert = function (input, view, prepend) {
// add-in the words
let home = document[n]
let terms = getTerms(input, world)
// are we inserting nothing?
if (terms.length === 0) {
return
}
terms = addIds(terms)
if (prepend) {
expand(view.update([ptr]).firstTerm())
Expand Down
9 changes: 5 additions & 4 deletions src/3-three/nouns/api/parse.js
Expand Up @@ -5,11 +5,12 @@ const getRoot = function (m) {
let tmp = m.clone()
tmp = tmp.match('#Noun+')
tmp = tmp.remove('(#Adjective|#Preposition|#Determiner|#Value)')
// team's captain
// if (tmp.has('#Possessive .? #Noun')) {
tmp = tmp.not('#Possessive')
// }
return tmp.first()
tmp = tmp.first()
if (!tmp.found) {
// return m
}
return tmp
}

const parseNoun = function (m) {
Expand Down
5 changes: 3 additions & 2 deletions tests/three/nouns/toSingular.test.js
Expand Up @@ -112,11 +112,12 @@ test('toSingular:', function (t) {
t.end()
})



test('toSingular - longer:', function (t) {
let arr = [
[`my fingers looked green afterwards`, `my finger looked green afterwards`],
[`other person`, 'other person'],
[`other people`, 'other person'],
[`other people's kids`, 'other person\'s kid'],
]
arr.forEach(function (a) {
let doc = nlp(a[0])
Expand Down

0 comments on commit 5fadede

Please sign in to comment.