# Words per sentence

**URL:** <https://community.glideapps.com/t/words-per-sentence/37896>\
**Category:** Ask for Help\
**Created:** [January 30, 2022, 8:48pm UTC](https://community.glideapps.com/t/words-per-sentence/37896 "2022-01-30T20:48:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![got10thumbs](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/got10thumbs/32/36638_2.png) [@got10thumbs](https://community.glideapps.com/u/got10thumbs)\
**Post date:** [January 30, 2022, 8:48pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/1 "2022-01-30T20:48:52Z")

</div>

I want to count the numbers of words in successive sentences of a paragraph. If one cell contains the whole paragraph, it’s easy to split it into sentences, making a cell with multiple values, each value being one sentence. Then I’m stuck. A roll-up column will count the number of sentences, but what I want is the number of words per sentence. Can Glide do that or do I have to write a bit of code?

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [January 30, 2022, 8:55pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/2 "2022-01-30T20:55:53Z")

</div>

Couple ways to do this.  
First way:

1. Split text column \> separated by space
2. Rollup column of split text text column to count words

Second way:  
Use the word count plug-in column.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [January 31, 2022, 12:13am UTC](https://community.glideapps.com/t/words-per-sentence/37896/3 "2022-01-31T00:13:07Z")

</div>

How do you want the data to be presented? Let’s say I have a paragraph like this.

“My sentence one. Sentence two. Three”

Then should it return “3, 2, 1” for you?

---

<div class="post-metadata">

**Author:** ![got10thumbs](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/got10thumbs/32/36638_2.png) [@got10thumbs](https://community.glideapps.com/u/got10thumbs)\
**Post date:** [January 31, 2022, 7:08am UTC](https://community.glideapps.com/t/words-per-sentence/37896/4 "2022-01-31T07:08:00Z")

</div>

Yes, that’s exactly right.

(Even better if it returned separate rows:  
3  
2  
1  
– but I suspect that’s impossible)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 31, 2022, 7:24am UTC](https://community.glideapps.com/t/words-per-sentence/37896/5 "2022-01-31T07:24:35Z")

</div>

> [@got10thumbs](#):
>
> but I suspect that’s impossible

It’s not, but it could get really messy and ugly.

What’s your use case? ie. What are you going to do with these numbers?

---

<div class="post-metadata">

**Author:** ![got10thumbs](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/got10thumbs/32/36638_2.png) [@got10thumbs](https://community.glideapps.com/u/got10thumbs)\
**Post date:** [January 31, 2022, 9:01am UTC](https://community.glideapps.com/t/words-per-sentence/37896/6 "2022-01-31T09:01:14Z")

</div>

I tried that. What you suggest will count the words in a column, but not the words per sentence.

If I split the text by full stop (period) to get sentences, the roll-up counts the number of sentences but not the number of words.

I think I need two split-texts, one for sentences and then one for words.

---

<div class="post-metadata">

**Author:** ![got10thumbs](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/got10thumbs/32/36638_2.png) [@got10thumbs](https://community.glideapps.com/u/got10thumbs)\
**Post date:** [January 31, 2022, 9:05am UTC](https://community.glideapps.com/t/words-per-sentence/37896/7 "2022-01-31T09:05:53Z")

</div>

I wanted to demonstrate one of the characteristic differences between writers, the statistical distribution of number of words per sentence. Some writers have all sentences much the same length, some use a wide variety of lengths. I know it 's not what Glide was really meant for, but it’s the sort of thing that end-user programmers might be doing – developing simple text analysis tools; and I’m interested in seeing where Glide’s limits are.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 31, 2022, 9:27am UTC](https://community.glideapps.com/t/words-per-sentence/37896/8 "2022-01-31T09:27:26Z")

</div>

Okay, I get it.  
So, for example, you may want to plot these on a scatter chart?  
Roughly how much text at a time would you want to analyse? I would imagine it would be significantly more than just a few paragraphs? A whole paper, or a whole book?  
Would you do it for a single author at a time, or would you want to do it simultaneously for a whole group of authors, so that you could do side by side comparisons?

I’m asking all these questions because I find these types of challenges intriguing. I love pushing the limits of Glide and finding new ways to solve problems. That said, as you point out - Glide is probably not the best tool for this sort of exercise. But that doesn’t mean it can’t be done.

Oh, the other thing I wanted to point out is that using merely the presence of a period to denote the end of a sentence may not be that reliable. What about sentences that end with a question mark, like this one? Or sentences that end with an exclamation! Or those that have a writing style… like this? (was that one sentence, four sentences, or zero?) I’m sure you get my point, but that’s just a side issue 🙂

---

<div class="post-metadata">

**Author:** ![got10thumbs](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/got10thumbs/32/36638_2.png) [@got10thumbs](https://community.glideapps.com/u/got10thumbs)\
**Post date:** [January 31, 2022, 9:40am UTC](https://community.glideapps.com/t/words-per-sentence/37896/9 "2022-01-31T09:40:29Z")

</div>

Amount of text: A couple of pages would be enough: I’m after a demo, not a professional’s tool. But that’s a good question. How well does Glide scale?

Defining ‘sentence’: excellent point. There’s no way afaik to split text by ‘period _or_ question mark _or_ exclamation mark’. Hmmm …

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 31, 2022, 9:46am UTC](https://community.glideapps.com/t/words-per-sentence/37896/10 "2022-01-31T09:46:20Z")

</div>

> [@got10thumbs](#):
>
> Defining ‘sentence’: excellent point. There’s no way afaik to split text by ‘period _or_ question mark _or_ exclamation mark’.

There is… Glide now (indirectly) supports regular expressions which will take care of this part.

I have a few ideas bubbling around inside my head. I’ll have a play around with this a bit later and may come back to you with a suggestion.

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [January 31, 2022, 1:58pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/11 "2022-01-31T13:58:04Z")

</div>

How many paragraphs max?

---

<div class="post-metadata">

**Author:** ![got10thumbs](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/got10thumbs/32/36638_2.png) [@got10thumbs](https://community.glideapps.com/u/got10thumbs)\
**Post date:** [January 31, 2022, 2:23pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/12 "2022-01-31T14:23:16Z")

</div>

Shall we say 10?

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [January 31, 2022, 2:27pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/13 "2022-01-31T14:27:29Z")

</div>

![CleanShot 2022-01-31 at 09.27.19@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/e/7e0a8ed10d47bba67f05fddbabd4829cbf5e0cd8.png)

I see @Darren_Murphy replying…wondering if he’s thinking the same thing I’m thinking…

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 31, 2022, 2:29pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/14 "2022-01-31T14:29:14Z")

</div>

hmm… ill wait too lol, GS that would be few minutes to solve

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 31, 2022, 2:31pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/15 "2022-01-31T14:31:15Z")

</div>

So I’ve been having a bit of a play with this.

My initial thought was that the [Extract Multiple Matching Text](https://www.glideapps.com/plugins/regex-matchmany) plugin column would handle the first part of this. But it turns out that it doesn’t.

So I ended up writing a bit of javascript to do the initial parsing of the paragraph…

 ![Screen Shot 2022-01-31 at 10.24.55 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/9/b93daf8d516d51da31e5748593f79d24f4824fbf.png)

```auto
if (!p1) { return undefined; }
var sentences = p1.split(/[.?!]\s+/);
  var arr = [];
  sentences.forEach(function (sentence) {
    var words = sentence.split(/\s+/);
    arr.push(words.length);
  })
  return arr.join(',');

```

The above will give you a comma separated list, representing the number of words in each sentence of the paragraph.

My thought from there is that it could be transposed into a series of rows, and from there you could do various rollups to get average, median, etc. But that’s where I’ve got a bit stuck. I’m able to transpose the data okay, but the rollup column doesn’t seem to play nicely with it.

I’ll come back to this a bit later and see if I can figure it out. In the meantime, perhaps somebody else will jump in with an alternative solution.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 31, 2022, 2:33pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/16 "2022-01-31T14:33:39Z")

</div>

and that’s what codes are for… 😉 btw @Darren_Murphy I did find a solution for not running scripts On Change when add, delete a row, or column… lol pretty easy

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 31, 2022, 2:42pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/17 "2022-01-31T14:42:17Z")

</div>

> [@Robert\_Petitto](#):
>
> wondering if he’s thinking the same thing I’m thinking

Probably not, haha 😂  
But I am curious to see what you come up with.

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [January 31, 2022, 2:46pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/18 "2022-01-31T14:46:35Z")

</div>

No code option:

> **[Count Sentences · Glide - 31 January 2022](https://www.loom.com/share/3fcf44137ab64be2ab6ef656f2254fd0)**

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 31, 2022, 2:52pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/19 "2022-01-31T14:52:37Z")

</div>

I wish you could do video tutorials for my Apps … @Robert_Petitto  
You are the best of the best in that field… no doubts… and very good in many others fields… but your video tutorials … even made just to make it… are impressive

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 31, 2022, 3:00pm UTC](https://community.glideapps.com/t/words-per-sentence/37896/20 "2022-01-31T15:00:55Z")

</div>

hehe, that’s more or less the approach I thought you’d take.

Only problem is this:

> [@Darren\_Murphy](#):
>
> Oh, the other thing I wanted to point out is that using merely the presence of a period to denote the end of a sentence may not be that reliable. What about sentences that end with a question mark, like this one? Or sentences that end with an exclamation! Or those that have a writing style… like this? (was that one sentence, four sentences, or zero?) I’m sure you get my point, but that’s just a side issue

That’s why I ended up resorting to code, to deal with that. I initially thought that one of the plugins would help overcome that, but it seems not.

[Next page](https://community.glideapps.com/t/words-per-sentence/37896.md?page=2)
