compromise icon indicating copy to clipboard operation
compromise copied to clipboard

Feature request: parse doublet, triplet, etc. as numbers with compromise-numbers

Open schneiderfelipe opened this issue 3 years ago • 5 comments

This could be very useful in a lot of contexts, especially in science texts.

schneiderfelipe avatar May 24 '21 04:05 schneiderfelipe

Hey @schneiderfelipe i may need an example to understand the feature request. Doublets mean a lot of things1 Cheers

spencermountain avatar May 24 '21 11:05 spencermountain

Hi @spencermountain I had spectroscopy in mind, but there might be other fields using this nomenclature as well. An example:

In spectroscopy and quantum chemistry, the multiplicity of an energy level is defined as 2S+1, where S is the total spin angular momentum.[1][2][3] States with multiplicity 1, 2, 3, 4, 5 are respectively called singlets, doublets, triplets, quartets and quintets.[2] The multiplicity is also equal to the number of unpaired electrons plus one.[4]

Emphasis mine. From here.

schneiderfelipe avatar May 24 '21 11:05 schneiderfelipe

hey @schneiderfelipe you could support this by adding a regex to a match command, as specified here

doc.match('/[1-9]S\+[1-9]/').tag('#Doublet') //  finds '2S+1'

then you can do something like:

let found = doc.match('the spin of Boron is [#Doublet]', 0)

although this example may be obscure, I'd love to support basic chemistry nomenclature, through a cool regex or something. If you wanted to work on a chemistry-plugin, I'd be happy to collaborate cheers

spencermountain avatar May 29 '21 20:05 spencermountain

hey @schneiderfelipe you could support this by adding a regex to a match command, as specified here

doc.match('/[1-9]S\+[1-9]/').tag('#Doublet') //  finds '2S+1'

then you can do something like:

let found = doc.match('the spin of Boron is [#Doublet]', 0)

@spencermountain Nice! A question: does this parse mathematical expressions? (I.e., does "3" matches "2S + 1"? Is there a way to match the "S" of "3" if I know it should be "2S + 1"?)

although this example may be obscure, I'd love to support basic chemistry nomenclature, through a cool regex or something. If you wanted to work on a chemistry-plugin, I'd be happy to collaborate

That's awesome, I'm interested. I'll start something and let you know.

schneiderfelipe avatar May 31 '21 14:05 schneiderfelipe

hey, yep you can play with the regex to have it perform as you'd like see here for example.

parsing mathematical expressions is something I've shied-away from, but I know some libraries have had some success. Things get tricky pretty-fast.

if you have more examples for parsing multiplicity, I'm happy to help. I was thinking chemical formulae like CH4S2 would be fun to parse because there's a limited number of elements, and combinations. cheers

spencermountain avatar Jun 02 '21 14:06 spencermountain