Skip to content

phoneNumbers, json offset request #1144

@priley86

Description

@priley86

hey there again @spencermountain !

This is a small feature request on the phoneNumbers() method exposed.

I'm noting some offset weirdness.

Example that offsets correctly:

const json = nlp('My co-worker's number is +1 212-456-7890.').phoneNumbers(0).json({ offset: true })[0];

console.log(json.offset); 
// offset: { index: 4, start: 25, length: 16 }
 
console.log('My co-worker\'s number is +1 212-456-7890.'.substr(25,16));
// '+1 212-456-7890.'

Example that offsets incorrectly:

const json = nlp('My phone number is (201) 111-2222.').phoneNumbers(0).json({ offset: true })[0];

console.log(json.offset); 
// offset: { index: 4, start: 20, length: 15 }
 
console.log('My phone number is (201) 111-2222.'.substr(20,15));
// '201) 111-2222.'

I would expect the opening ( to have been included in the top level offset to be consistent with the first response. The closing . (period) could also be omitted in both cases, but that seems more of a global issue and unrelated (and i think you've mentioned using other helpers to remove those post-facto).

I would have contributed this change directly, but the fix appears non obvious, so i've added a simple unit test instead that may help indicate the suggested fix.
priley86@5182385

Could this an extension of the toJson method on the phoneNumbers View defined here?
https://github.com/spencermountain/compromise/blob/master/src/3-three/misc/selections/index.js#L39

Sorry, totally unfamiliar here but trying to help 😄

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions