Skip to content

Commit

Permalink
fix clauses issues
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Jan 23, 2024
1 parent e5fd879 commit 90a388a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
8 changes: 3 additions & 5 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import nlp from './src/three.js'

// let doc = nlp('one two three four five. one three four')
// doc.before('three four').debug()

let m = nlp("i said, 'did you have to do that' and then left, like nothing happened (which it didn't).")
.clauses()
.debug()
console.log(m.eq(1).text())
let doc = nlp(`...and my butt smells, and i like to kiss my own butt`)
doc.match('@hasEllipses').debug()
// let m = doc.clauses() //.debug()

let arr = [
// 'I left the window open for fresh air.',
Expand Down
4 changes: 2 additions & 2 deletions src/1-one/match/methods/termMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const hasDash = / [-–—]{1,3} /
/** search the term's 'post' punctuation */
const hasPost = (term, punct) => term.post.indexOf(punct) !== -1
/** search the term's 'pre' punctuation */
const hasPre = (term, punct) => term.pre.indexOf(punct) !== -1
// const hasPre = (term, punct) => term.pre.indexOf(punct) !== -1

const methods = {
/** does it have a quotation symbol? */
Expand All @@ -25,7 +25,7 @@ const methods = {
/** does it end with a question mark? */
hasQuestionMark: term => hasPost(term, '?') || hasPost(term, '¿'),
/** is there a ... at the end? */
hasEllipses: term => hasPost(term, '..') || hasPost(term, '…') || hasPre(term, '..') || hasPre(term, '…'),
hasEllipses: term => hasPost(term, '..') || hasPost(term, '…'),
/** is there a semicolon after term word? */
hasSemicolon: term => hasPost(term, ';'),
/** is there a colon after term word? */
Expand Down
17 changes: 10 additions & 7 deletions src/3-three/chunker/api/clauses.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const byComma = function (doc) {
if (m.growRight('. .').wordCount() === 1) {
return false
}
let more = m.grow(".") // grow by 1 word in either direction
let more = m.grow('.') // grow by 1 word in either direction
more = more.ifNo('@hasComma @hasComma') //fun, cool...
more = more.ifNo('@hasComma (and|or) .') //cool, and fun
more = more.ifNo('(#City && @hasComma) #Country') //'toronto, canada'
Expand Down Expand Up @@ -70,13 +70,18 @@ const clauses = function (n) {
found = found.splitBefore('as (though|if)')
found = found.splitBefore('(til|until)')

// it is cool but it is ..
let m = found.match('#Verb .* [but] .* #Verb', 0)
if (m.found) {
found = found.splitBefore(m)
}
// it is cool and it is ..
// let conjunctions = found.if('#Copula #Adjective #Conjunction (#Pronoun|#Determiner) #Verb').match('#Conjunction')
// found = found.splitBefore(conjunctions)

// // if it is this then that
// let condition = found.if('if .{2,9} then .').match('then')
// found = found.splitBefore(condition)
// if it is this then that
let condition = found.if('if .{2,9} then .').match('then')
found = found.splitBefore(condition)

// // misc clause partitions
// found = found.splitBefore('as well as .')
Expand All @@ -87,14 +92,12 @@ const clauses = function (n) {
// found = found.splitAfter('@hasSemicolon')
// found = found.splitAfter('@hasDash')

// //
// //
// found = found.splitBefore('which (were|are|will)')

// // he said [...]
// found = found.splitAfter('#Noun (said|say|says)')



// passive voice verb - '.. which was robbed is empty'
// let passive = found.match('#Noun (which|that) (was|is) #Adverb? #PastTense #Adverb?')
// if (passive.found) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'tape'
import nlp from '../three/_lib.js'
import nlp from './_lib.js'
const here = '[three/clause] '

test('clauses-parentheses:', function (t) {
Expand Down

0 comments on commit 90a388a

Please sign in to comment.