charlesLoder / havarotjs

A Typescript package for getting syllabic data about Hebrew text with niqqud.
https://www.npmjs.com/package/havarotjs
MIT License
12 stars 4 forks source link

Meteg preceding shureq causes incorrect structure #118

Closed charlesLoder closed 1 year ago

charlesLoder commented 1 year ago

See example:

const str = "רֽוּחַ׃";
const text = new Text(str);
text.syllables.forEach((s) => {
  const [a, b, c] = [...s.structure()];
  console.log({
    onset: a,
    nucleus: b,
    coda: c
  });
});
// { onset: 'ר', nucleus: '', coda: 'ֽוּ' }
// { onset: '', nucleus: 'ַ', coda: 'ח׃' }

This is caused by this line:

// (add to the coda everything else from the first cluster - e.g. out of order characters)
for (; i < heClusters[0].chars.length; i++) {
  coda += heClusters[0].chars[i].text;
}

B/c the meteg gets added to the coda, the next section:

// (add to the nucleus add any shureq or mater - if we haven't already added anything to the coda)
let clusters_processed = 1;
if (coda.length === 0 && heClusters.length > 1 && (heClusters[1].isShureq || heClusters[1].isMater)) {
  nucleus += heClusters[1].text;
  clusters_processed++;
}

evaluates to false because there is coda.length