compromise
Advanced tools
Comparing version 14.14.0 to 14.14.1
@@ -5,3 +5,3 @@ { | ||
"description": "modest natural language processing", | ||
"version": "14.14.0", | ||
"version": "14.14.1", | ||
"module": "./src/three.js", | ||
@@ -75,4 +75,3 @@ "main": "./src/three.js", | ||
"build": "npm run version && rollup -c --silent", | ||
"watch": "amble ./scratch.js", | ||
"watch:tag": "amble ./tagger.scratch.js", | ||
"watch": "node --watch ./scratch.js", | ||
"pack": "node ./scripts/pack.js", | ||
@@ -121,5 +120,4 @@ "version": "node ./scripts/version.js", | ||
"@rollup/plugin-terser": "0.4.4", | ||
"amble": "1.3.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "9.8.0", | ||
"eslint": "9.12.0", | ||
"eslint-plugin-regexp": "2.6.0", | ||
@@ -131,3 +129,3 @@ "nlp-corpus": "4.4.0", | ||
"tap-dancer": "0.3.4", | ||
"tape": "5.8.1" | ||
"tape": "5.9.0" | ||
}, | ||
@@ -134,0 +132,0 @@ "eslintIgnore": [ |
@@ -1,1 +0,1 @@ | ||
export default '14.14.0' | ||
export default '14.14.1' |
const dollarStub = /\$[0-9a-z]+/g | ||
const fns = {} | ||
const titleCase = function (str) { | ||
return str.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase()) | ||
} | ||
// case logic | ||
const isTitleCase = (str) => /^\p{Lu}[\p{Ll}'’]/u.test(str) || /^\p{Lu}$/u.test(str) | ||
const toTitleCase = (str) => str.replace(/^\p{Ll}/u, x => x.toUpperCase()) | ||
const toLowerCase = (str) => str.replace(/^\p{Lu}/u, x => x.toLowerCase()) | ||
// doc.replace('foo', (m)=>{}) | ||
const replaceByFn = function (main, fn) { | ||
const replaceByFn = function (main, fn, keep) { | ||
main.forEach(m => { | ||
let out = fn(m) | ||
m.replaceWith(out) | ||
m.replaceWith(out, keep) | ||
}) | ||
@@ -38,6 +39,8 @@ return main | ||
if (typeof input === 'function') { | ||
return replaceByFn(main, input) | ||
return replaceByFn(main, input, keep) | ||
} | ||
let terms = main.docs[0] | ||
let isPossessive = keep.possessives && terms[terms.length - 1].tags.has('Possessive') | ||
if (!terms) return main | ||
let isOriginalPossessive = keep.possessives && terms[terms.length - 1].tags.has('Possessive') | ||
let isOriginalTitleCase = keep.case && isTitleCase(terms[0].text) | ||
// support 'foo $0' replacements | ||
@@ -51,2 +54,4 @@ input = subDollarSign(input, main) | ||
let oldTags = (original.docs[0] || []).map(term => Array.from(term.tags)) | ||
let originalPre = original.docs[0][0].pre | ||
let originalPost = original.docs[0][original.docs[0].length - 1].post | ||
// slide this in | ||
@@ -66,3 +71,3 @@ if (typeof input === 'string') { | ||
// keep "John's" | ||
if (isPossessive) { | ||
if (isOriginalPossessive) { | ||
let tmp = main.docs[0] | ||
@@ -76,2 +81,7 @@ let term = tmp[tmp.length - 1] | ||
} | ||
// try to keep some pre-post punctuation | ||
if (originalPre) main.docs[0][0].pre = originalPre | ||
if (originalPost && !main.docs[0][main.docs[0].length - 1].post.trim()) main.docs[0][main.docs[0].length - 1].post = originalPost | ||
// what should we return? | ||
@@ -89,12 +99,11 @@ let m = main.toView(ptrs).compute(['index', 'freeze', 'lexicon']) | ||
} | ||
if (!m.docs[0] || !m.docs[0][0]) return m | ||
// try to co-erce case, too | ||
if (keep.case && m.docs[0] && m.docs[0][0] && m.docs[0][0].index[1] === 0) { | ||
m.docs[0][0].text = titleCase(m.docs[0][0].text) | ||
if (keep.case) { | ||
let transformCase = isOriginalTitleCase ? toTitleCase : toLowerCase | ||
m.docs[0][0].text = transformCase(m.docs[0][0].text) | ||
} | ||
// try to keep some pre-post punctuation | ||
// if (m.terms().length === 1 && main.terms().length === 1) { | ||
// console.log(original.docs) | ||
// } | ||
// console.log(input.docs[0]) | ||
@@ -101,0 +110,0 @@ // let regs = input.docs[0].map(t => { |
@@ -107,3 +107,2 @@ import doAstrix from './steps/astrix.js' | ||
// ok, finally test the term-reg | ||
// console.log(' - ' + state.terms[state.t].text) | ||
let hasMatch = matchTerm(state.terms[state.t], reg, state.start_i + state.t, state.phrase_length) | ||
@@ -117,4 +116,2 @@ if (hasMatch === true) { | ||
} | ||
// console.log('=-=-=-= here -=-=-=-') | ||
//ok who cares, keep going | ||
@@ -121,0 +118,0 @@ if (reg.optional === true) { |
@@ -5,2 +5,11 @@ import type { Document, Pointer, Groups, JsonProps, outMethods, matchOptions, Term, Net, ParsedMatch } from '../misc.d.ts' | ||
export interface ReplaceWithProps { | ||
/** preserve the case of the original, ignoring the case of the replacement */ | ||
case?: boolean | ||
/** preserve whether the original was a possessive */ | ||
possessives?: boolean | ||
/** preserve all of the tags of the original, regardless of the tags of the replacement */ | ||
tags?: boolean | ||
} | ||
declare class View { | ||
@@ -162,3 +171,3 @@ // Utils | ||
/** substitute-in new content */ | ||
replaceWith: (to: string | Function, keep?: object) => View | ||
replaceWith: (to: string | Function, keep?: ReplaceWithProps) => View | ||
@@ -165,0 +174,0 @@ /** remove any duplicate matches */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2577116
11
29065