Topics

Addon to count words #addonrequestreview

Rui Fontes
 

Hello!

Here is and addon made by Oriol Gómez and updated by me.

A special thanks to Jose Manuel Delicado Alcolea by teaching me how to use gitHub and some tips to improve my code...

It can be find in:
ruifontes/wordCount: NVDA addon to count words in a selected text

Here is the readme:

* Authors: Oriol Gómez <ogomez.s92@...> and Rui Fontes <rui.fontes@...>
* Compatibility: NVDA 2017.2 to 2019.1

Use:
This addon announces the number of words of the selected text by pressing NVDA + Control + W.

In any text editor, or in a virtual document, for example in a web browser, PDF, email body, etc., select the desired text using the usual text selection commands and press NVDA Control W.

This command can be modified in the "Input gestures" dialog in the "Word count" section.


Direct download:
https://github.com/ruifontes/wordCount/releases/download/1.2/wordCount-1.2.nvda-addon

Thanks and best regards,

Rui Fontes
NVDA portuguese team
Tiflotecnia, Lda.

James Scholes
 

Many thanks for this work. A few minor observations:

The add-on imports NVDAObjects and winUser, but no functionality from those modules is used. Try to avoid unused imports for code cleanliness.

There's no real need to spread the word count calculation across four lines and three variables. You can just do:

message(_("{wordcount} words").format(wordcount=len(info.text.split())))

Do you plan to add more functionality to this add-on? If not, I wonder if giving it its own category in the Input Gestures dialog is really appropriate. It would probably fit in the Text Review category, especially if you updated the word "announces" to "reports" in the docstring for consistency's sake.

Thanks again.

Regards,

James Scholes
https://twitter.com/JamesScholes

Michal Suchý
 

I would like the character counting feature in this addon. I don't know way, how to count characters fast in some text.

 

Hey Rui,
Thanks for this add-on.
Much appreciated indeed :)

Cheers,
Marcio AKA Starboy
Follow or add me on Facebook

Em 03/04/2019 20:44, Rui Fontes disse:

Hello!

Here is and addon made by Oriol Gómez and updated by me.

A special thanks to Jose Manuel Delicado Alcolea by teaching me how to use gitHub and some tips to improve my code...

It can be find in:
ruifontes/wordCount: NVDA addon to count words in a selected text

Here is the readme:

* Authors: Oriol Gómez <ogomez.s92@...> and Rui Fontes <rui.fontes@...>
* Compatibility: NVDA 2017.2 to 2019.1

Use:
This addon announces the number of words of the selected text by pressing NVDA + Control + W.

In any text editor, or in a virtual document, for example in a web browser, PDF, email body, etc., select the desired text using the usual text selection commands and press NVDA Control W.

This command can be modified in the "Input gestures" dialog in the "Word count" section.


Direct download:
https://github.com/ruifontes/wordCount/releases/download/1.2/wordCount-1.2.nvda-addon

Thanks and best regards,

Rui Fontes
NVDA portuguese team
Tiflotecnia, Lda.


Rui Fontes
 

Hello!

Answering two messages...
James Scholes wrote:
The add-on imports NVDAObjects and winUser, but no functionality from those modules is used.  Try to avoid unused imports for code cleanliness.
Thanks! Corrected.


James Scholes wrote:
There's no real need to spread the word count calculation across four lines and three variables.  You can just do:
message(_("{wordcount} words").format(wordcount=len(info.text.split())))
As a beginner I still don't like this condensed format...


James Scholes wrote:
Do you plan to add more functionality to this add-on?  If not, I wonder if giving it its own category in the Input Gestures dialog is really appropriate.  It would probably fit in the Text Review category, especially if you updated the word "announces" to "reports" in the docstring for consistency's sake.
I do not agree.
1 - "Text review" is ment for review commands related;
2 - The only exception is the announcement of the formatation.

Maybe we should create a new entry "Text edition"?


Michal Suchý wrote:
I would like the character counting feature in this addon. I don't know way, how to count characters fast in some text.
By the way, how is defined that we want to count words in the function?
The function split can take some parameter to set characters, word, lines and so on to be used as unit for the split operation?
I tried to get some hints from speech.py in the announcement of xxx characters selected, but I didn't find any...

Best regards,

Rui Fontes
NVDA portuguese team

Rui Fontes
 

Hello!

It seems nobody read the last question, so here it is again...



Às 15:28 de 04/04/2019, Rui Fontes escreveu:

Hello!
Michal Suchý wrote:
I would like the character counting feature in this addon. I don't know way, how to count characters fast in some text.
By the way, how is defined that we want to count words in the function?
The function split can take some parameter to set characters, word, lines and so on to be used as unit for the split operation?
I tried to get some hints from speech.py in the announcement of xxx characters selected, but I didn't find any...
Best regards,
Rui Fontes
NVDA portuguese team

James Scholes
 

I don't understand the question. Are you asking for help with Python's string split method? Or asking how something in NVDA works.

Regards,

James Scholes
https://twitter.com/JamesScholes

Rui Fontes
 

If possible, both!

But, more specifically, in my code were it is defined to split in words?
And in the case of the NVDA message, "xxx characters copied", where is set to split in characters...

I'm trying to find that in NVDA sources, but not yet find...

Rui Fontes


Às 19:23 de 04/04/2019, James Scholes escreveu:

I don't understand the question.  Are you asking for help with Python's string split method?  Or asking how something in NVDA works.
Regards,
James Scholes
https://twitter.com/JamesScholes

James Scholes
 

If you want to tell Python to split a string based on a different seperator, just provide the seperator as an argument to the split method. Example using a comma:

'value1,value2,value3'.split(',')

But if you're wanting to obtain the number of characters in a string to provide a character count, just call len on the string:

len('hello world')

If that's not what you're asking, please let me know. I don't know where the code is defined in NVDA to speak the "X characters selected" message, although I'm not sure it would help you here. Again, if I've misunderstood, please just say.

Regards,

James Scholes
https://twitter.com/JamesScholes

Rui Fontes
 

Hello!

James Scholes wrote:
If you want to tell Python to split a string based on a different seperator, just provide the seperator as an argument to the split method.  Example using a comma:
'value1,value2,value3'.split(',')
Regarding the addon, we have:
words = info.text.split()

and it splits the text in words...
If I want to split in sentences or lines, how to do it?


James Scholes wrote:
But if you're wanting to obtain the number of characters in a string to provide a character count, just call len on the string:
Thanks! I was being stupid! Wanting to split the text in characters... Smile!

Best regards,

Rui Fontes

Larry Wang
 

Hi, there is a _getLineCount method  for textInfo.

If you want to split by sentence. A regular expression may be requried. You can see examples in symbols.dict.

On 2019/4/5 7:46, Rui Fontes wrote:
Hello!

James Scholes wrote:
If you want to tell Python to split a string based on a different seperator, just provide the seperator as an argument to the split method.  Example using a comma:

'value1,value2,value3'.split(',')
Regarding the addon, we have:
            words = info.text.split()

and it splits the text in words...
If I want to split in sentences or lines, how to do it?


James Scholes wrote:
But if you're wanting to obtain the number of characters in a string to provide a character count, just call len on the string:
Thanks! I was being stupid! Wanting to split the text in characters... Smile!

Best regards,

Rui Fontes


Rui Fontes
 

Hello!

Version 1.3 ready to review!

New in this version:
Added characters counting;
Code enhancements.

Available in:
https://github.com/ruifontes/wordCount/releases/download/1.3/wordCount-1.3.nvda-addon

Best regards,

Rui Fontes
NVDA portuguese team
Tiflotecnia, Lda.


Às 00:46 de 05/04/2019, Rui Fontes escreveu:

Hello!
James Scholes wrote:
If you want to tell Python to split a string based on a different seperator, just provide the seperator as an argument to the split method.  Example using a comma:

'value1,value2,value3'.split(',')
Regarding the addon, we have:
            words = info.text.split()
and it splits the text in words...
If I want to split in sentences or lines, how to do it?
James Scholes wrote:
But if you're wanting to obtain the number of characters in a string to provide a character count, just call len on the string:
Thanks! I was being stupid! Wanting to split the text in characters... Smile!
Best regards,
Rui Fontes

Noelia Ruiz
 

Hi Larry and all, then, if _getLineCount is private, I think it would be better to use:

info = blah.makeTextInfo(textInfos.POSITION_SELECTION), WHERE OBJECT CAN BE THE FOCUS, NAVIGATOR OR SOMETHING.
Then:
c = info.unitCount(textInfos.UNIT_LINE)
Or whatever.

What do you think?

Thanks

El 05/04/2019 a las 1:55, Larry Wang escribió:
Hi, there is a _getLineCount method  for textInfo.
If you want to split by sentence. A regular expression may be requried. You can see examples in symbols.dict.
On 2019/4/5 7:46, Rui Fontes wrote:
Hello!

James Scholes wrote:
If you want to tell Python to split a string based on a different seperator, just provide the seperator as an argument to the split method.  Example using a comma:

'value1,value2,value3'.split(',')
Regarding the addon, we have:
            words = info.text.split()

and it splits the text in words...
If I want to split in sentences or lines, how to do it?


James Scholes wrote:
But if you're wanting to obtain the number of characters in a string to provide a character count, just call len on the string:
Thanks! I was being stupid! Wanting to split the text in characters... Smile!

Best regards,

Rui Fontes



James Scholes
 

This is a long email, hope it helps.

Rui Fontes wrote:
Regarding the addon, we have:
            words = info.text.split()
and it splits the text in words...
No, it splits the text by whitespace. As a naive algorithm for counting words, it works okay. But it's still important to understand that Python is not explicitly splitting your text into words. It's splitting it based on sequences of whitespace characters like space, tab, etc.

Manually count the words in this sentence:

"I...I'm not sure. He looked like a well-dressed businessman to me."

The text contains 13 words... or does it? If someone is counting hyphenated words as a single unit, it only contains 12. You have no way of knowing what a user's preference is in this area, because it probably differs by word. Some words are hyphenated, but obviously constitute a single unit. For example, add-on. Others are only hyphenated for grammatical reasons, such as "well-dressed" in the above text. For me, add-on is 1 word, well-dressed is 2.

Putting that aside, let's try splitting it:

# code start
len("I...I'm not sure. He looked like a well-dressed businessman to me.".split())
# code end

The above returns 11. Why? Because "I" and "I'm" are connected by 3 dots, which is grammatically correct but 3 dots don't constitute whitespace. Similarly, if you do consider hyphenated words to be separate entities for counting purposes, Python won't because the hyphen is not a whitespace character.

For what it's worth, Microsoft Word also thinks there are 11 words in this sentence. NVDA thinks there are 14 if you navigate using control+right arrow through it, because it counts the "I'" and "m" in the word "I'm" as 2 separate words. That's obviously wrong, but the point here is that there probably is no perfect way to do this. Now onto sentences...

If I want to split in sentences or lines, how to do it?
You've already received advice regarding counting the lines in a textinfo, but counting sentences is a whole different issue and much more complex. Here's an example:

"The U.S. mail service operates a Customer Support line, available Monday to Saturday from 9 A.M. to 5.30 P.M. (EDT). Please call this line and ask to speak to Mr. Martins in the Claims department, or directly dial him on 1-800-123-8777 (ext. 5903)."

This text contains 2 sentences. How might you determine that in code? If I'd given you a piece of text without edge cases, you might think of splitting it by a separator consisting of a dot and a space. Which gives us an answer of 7 sentences, and doesn't take sentences which end with question or exclamation marks into account.

Another list member mentioned checking NVDA's symbols processing dictionaries, which contain a number of sentence ending-related regular expressions. But keep in mind that these are not used for purposes of reporting and counting. They're used to determine how certain parts of text are spoken. In my testing, using them to count sentences results in less accurate results than the naive split-based method above.

The Sentence Nav add-on, found here:

https://addons.nvda-project.org/addons/sentenceNav.en.html

counts 3 sentences in the text above, and thus is the most accurate so far. But being more accurate doesn't change the fact that 3 is still the wrong number. If you download that add-on and consult the code, as well as its preferences dialog, you'll note that in this case, it's only more accurate because:

1. It has a preconfigured, static list of prefixes that should not be considered as sentence endings when they have a dot placed after them, e.g. Mr, Mrs.
2. It doesn't count A.M. and P.M. as sentence endings because they're not followed by an uppercase letter, which would suggest that a new sentence has not started.

This approach is good, but still breaks when it encounters the word "ext.", short for "extension", because:

1. It's not in the list of prefixes.
2. It's followed by a number, which is not an uppercase letter but is also a completely valid way to start a new sentence.

You could say that in the text above, any algorithm could take into account that the text "ext. 5903" is in parentheses, and thus is obviously not the end of a sentence. But that's yet another corner case to add, and language is complex so you'll never think of all of them. Even if you do, you'll then have to think of them all over again in every language on the planet.

Regards,

James Scholes
https://twitter.com/JamesScholes

Rui Fontes
 

Hello James!

Thanks by your attention and time to this issue!

If we want a 100% successfull method to count words, we need to consult some language cientist of each language in our planet!
As that is not possible, we stay with this approach...

Vut, trying to count also lines, sentences and paragraphs, I found the following:

lines = info.unitCount(textInfos.UNIT_LINE)
Firstly, it returns always the mumber of all lines in the text and not the mumber of lines in the selection...

Secondly, it gaves an error in Gecko_ia2_TextInfo because it don't have such attribute...
The same happens for sentences and paragraphs... Any special reason?

In short, I keep it only for characters and words...

Hoping some reviewer to review it...

Best regards,

Rui Fontes



Às 18:23 de 05/04/2019, James Scholes escreveu:

This is a long email, hope it helps.
Rui Fontes wrote:
Regarding the addon, we have:
             words = info.text.split()

and it splits the text in words...
No, it splits the text by whitespace.  As a naive algorithm for counting words, it works okay.  But it's still important to understand that Python is not explicitly splitting your text into words.  It's splitting it based on sequences of whitespace characters like space, tab, etc.
Manually count the words in this sentence:
"I...I'm not sure.  He looked like a well-dressed businessman to me."
The text contains 13 words... or does it?  If someone is counting hyphenated words as a single unit, it only contains 12.  You have no way of knowing what a user's preference is in this area, because it probably differs by word.  Some words are hyphenated, but obviously constitute a single unit.  For example, add-on.  Others are only hyphenated for grammatical reasons, such as "well-dressed" in the above text.  For me, add-on is 1 word, well-dressed is 2.
Putting that aside, let's try splitting it:
# code start
len("I...I'm not sure.  He looked like a well-dressed businessman to me.".split())
# code end
The above returns 11.  Why?  Because "I" and "I'm" are connected by 3 dots, which is grammatically correct but 3 dots don't constitute whitespace.  Similarly, if you do consider hyphenated words to be separate entities for counting purposes, Python won't because the hyphen is not a whitespace character.
For what it's worth, Microsoft Word also thinks there are 11 words in this sentence.  NVDA thinks there are 14 if you navigate using control+right arrow through it, because it counts the "I'" and "m" in the word "I'm" as 2 separate words.  That's obviously wrong, but the point here is that there probably is no perfect way to do this.  Now onto sentences...

If I want to split in sentences or lines, how to do it?
You've already received advice regarding counting the lines in a textinfo, but counting sentences is a whole different issue and much more complex.  Here's an example:
"The U.S. mail service operates a Customer Support line, available Monday to Saturday from 9 A.M. to 5.30 P.M. (EDT).  Please call this line and ask to speak to Mr. Martins in the Claims department, or directly dial him on 1-800-123-8777 (ext. 5903)."
This text contains 2 sentences.  How might you determine that in code? If I'd given you a piece of text without edge cases, you might think of splitting it by a separator consisting of a dot and a space.  Which gives us an answer of 7 sentences, and doesn't take sentences which end with question or exclamation marks into account.
Another list member mentioned checking NVDA's symbols processing dictionaries, which contain a number of sentence ending-related regular expressions.  But keep in mind that these are not used for purposes of reporting and counting.  They're used to determine how certain parts of text are spoken.  In my testing, using them to count sentences results in less accurate results than the naive split-based method above.
The Sentence Nav add-on, found here:
https://addons.nvda-project.org/addons/sentenceNav.en.html
counts 3 sentences in the text above, and thus is the most accurate so far.  But being more accurate doesn't change the fact that 3 is still the wrong number.  If you download that add-on and consult the code, as well as its preferences dialog, you'll note that in this case, it's only more accurate because:
1. It has a preconfigured, static list of prefixes that should not be considered as sentence endings when they have a dot placed after them, e.g. Mr, Mrs.
2. It doesn't count A.M. and P.M. as sentence endings because they're not followed by an uppercase letter, which would suggest that a new sentence has not started.
This approach is good, but still breaks when it encounters the word "ext.", short for "extension", because:
1. It's not in the list of prefixes.
2. It's followed by a number, which is not an uppercase letter but is also a completely valid way to start a new sentence.
You could say that in the text above, any algorithm could take into account that the text "ext. 5903" is in parentheses, and thus is obviously not the end of a sentence.  But that's yet another corner case to add, and language is complex so you'll never think of all of them. Even if you do, you'll then have to think of them all over again in every language on the planet.
Regards,
James Scholes
https://twitter.com/JamesScholes

Noelia Ruiz
 

Hello, I let James to provide more feedback, just answering in case I caused you some confussion with the unitCount method. Since it doesn't work fot selection, just for the object on which the textInfo is based, other possibility is ising the getTextInChunks method, since it accepts unit constants like UNIT_LINE (this is tested in Python console selecting text in notepad):
i=focus.makeTextInfo("selection")
l=sum(1 for t in i.getTextInChunks("line"))

Also see
https://bytes.com/topic/python/answers/490774-count-items-generator

Cheers

El 05/04/2019 a las 21:27, Rui Fontes escribió:
Hello James!
Thanks by your attention and time to this issue!
If we want a 100% successfull method to count words, we need to consult some language cientist of each language in our planet!
As that is not possible, we stay with this approach...
Vut, trying to count also lines, sentences and paragraphs, I found the following:
            lines = info.unitCount(textInfos.UNIT_LINE)
Firstly, it returns always the mumber of all lines in the text and not the mumber of lines in the selection...
Secondly, it gaves an error in Gecko_ia2_TextInfo because it don't have such attribute...
The same happens for sentences and paragraphs... Any special reason?
In short, I keep it only for characters and words...
Hoping some reviewer to review it...
Best regards,
Rui Fontes
Às 18:23 de 05/04/2019, James Scholes escreveu:
This is a long email, hope it helps.

Rui Fontes wrote:
Regarding the addon, we have:
             words = info.text.split()

and it splits the text in words...
No, it splits the text by whitespace.  As a naive algorithm for counting words, it works okay.  But it's still important to understand that Python is not explicitly splitting your text into words.  It's splitting it based on sequences of whitespace characters like space, tab, etc.

Manually count the words in this sentence:

"I...I'm not sure.  He looked like a well-dressed businessman to me."

The text contains 13 words... or does it?  If someone is counting hyphenated words as a single unit, it only contains 12.  You have no way of knowing what a user's preference is in this area, because it probably differs by word.  Some words are hyphenated, but obviously constitute a single unit.  For example, add-on.  Others are only hyphenated for grammatical reasons, such as "well-dressed" in the above text.  For me, add-on is 1 word, well-dressed is 2.

Putting that aside, let's try splitting it:

# code start
len("I...I'm not sure.  He looked like a well-dressed businessman to me.".split())
# code end

The above returns 11.  Why?  Because "I" and "I'm" are connected by 3 dots, which is grammatically correct but 3 dots don't constitute whitespace.  Similarly, if you do consider hyphenated words to be separate entities for counting purposes, Python won't because the hyphen is not a whitespace character.

For what it's worth, Microsoft Word also thinks there are 11 words in this sentence.  NVDA thinks there are 14 if you navigate using control+right arrow through it, because it counts the "I'" and "m" in the word "I'm" as 2 separate words.  That's obviously wrong, but the point here is that there probably is no perfect way to do this.  Now onto sentences...

If I want to split in sentences or lines, how to do it?
You've already received advice regarding counting the lines in a textinfo, but counting sentences is a whole different issue and much more complex.  Here's an example:

"The U.S. mail service operates a Customer Support line, available Monday to Saturday from 9 A.M. to 5.30 P.M. (EDT).  Please call this line and ask to speak to Mr. Martins in the Claims department, or directly dial him on 1-800-123-8777 (ext. 5903)."

This text contains 2 sentences.  How might you determine that in code? If I'd given you a piece of text without edge cases, you might think of splitting it by a separator consisting of a dot and a space.  Which gives us an answer of 7 sentences, and doesn't take sentences which end with question or exclamation marks into account.

Another list member mentioned checking NVDA's symbols processing dictionaries, which contain a number of sentence ending-related regular expressions.  But keep in mind that these are not used for purposes of reporting and counting.  They're used to determine how certain parts of text are spoken.  In my testing, using them to count sentences results in less accurate results than the naive split-based method above.

The Sentence Nav add-on, found here:

https://addons.nvda-project.org/addons/sentenceNav.en.html

counts 3 sentences in the text above, and thus is the most accurate so far.  But being more accurate doesn't change the fact that 3 is still the wrong number.  If you download that add-on and consult the code, as well as its preferences dialog, you'll note that in this case, it's only more accurate because:

1. It has a preconfigured, static list of prefixes that should not be considered as sentence endings when they have a dot placed after them, e.g. Mr, Mrs.
2. It doesn't count A.M. and P.M. as sentence endings because they're not followed by an uppercase letter, which would suggest that a new sentence has not started.

This approach is good, but still breaks when it encounters the word "ext.", short for "extension", because:

1. It's not in the list of prefixes.
2. It's followed by a number, which is not an uppercase letter but is also a completely valid way to start a new sentence.

You could say that in the text above, any algorithm could take into account that the text "ext. 5903" is in parentheses, and thus is obviously not the end of a sentence.  But that's yet another corner case to add, and language is complex so you'll never think of all of them. Even if you do, you'll then have to think of them all over again in every language on the planet.

Regards,

James Scholes
https://twitter.com/JamesScholes



Locutor Antonio Cezar
 

It's working perfectly here, dear Rui ... Thank you.



Please, sign our petition in the link below, share with your friends, and collaborate with us! In favor of Functional Braille on Android!

https://secure.avaaz.org/en/petition/Google_Inc_Talkback_Development_Team_Google_Disability_Support_Team_PRECISAMOS_DO_BRAILLE_NO_ANDROID_TAMBEM/

Rui Fontes escreveu:

Hello!

Version 1.3 ready to review!

New in this version:
Added characters counting;
Code enhancements.

Available in:
https://github.com/ruifontes/wordCount/releases/download/1.3/wordCount-1.3.nvda-addon

Best regards,

Rui Fontes
NVDA portuguese team
Tiflotecnia, Lda.


Às 00:46 de 05/04/2019, Rui Fontes escreveu:
Hello!

James Scholes wrote:
If you want to tell Python to split a string based on a different seperator, just provide the seperator as an argument to the split method.  Example using a comma:

'value1,value2,value3'.split(',')

Regarding the addon, we have:
             words = info.text.split()

and it splits the text in words...
If I want to split in sentences or lines, how to do it?


James Scholes wrote:
But if you're wanting to obtain the number of characters in a string to provide a character count, just call len on the string:
Thanks! I was being stupid! Wanting to split the text in characters... Smile!

Best regards,

Rui Fontes




Locutor Antonio Cezar
 

I just forgot to say that it would be nice if NVDA itself spoke the amount of characters of a selected text in any situation, because currently NVDA only verbalizes the amount of characters of a selected text when that amount is equal to or greater than 512 characters ... Thank you.



Please, sign our petition in the link below, share with your friends, and collaborate with us! In favor of Functional Braille on Android!

https://secure.avaaz.org/en/petition/Google_Inc_Talkback_Development_Team_Google_Disability_Support_Team_PRECISAMOS_DO_BRAILLE_NO_ANDROID_TAMBEM/

Locutor Antonio Cezar via Groups.Io escreveu:

It's working perfectly here, dear Rui ... Thank you.



Please, sign our petition in the link below, share with your friends, and collaborate with us! In favor of Functional Braille on Android!

https://secure.avaaz.org/en/petition/Google_Inc_Talkback_Development_Team_Google_Disability_Support_Team_PRECISAMOS_DO_BRAILLE_NO_ANDROID_TAMBEM/

Rui Fontes escreveu:
Hello!

Version 1.3 ready to review!

New in this version:
Added characters counting;
Code enhancements.

Available in:
https://github.com/ruifontes/wordCount/releases/download/1.3/wordCount-1.3.nvda-addon

Best regards,

Rui Fontes
NVDA portuguese team
Tiflotecnia, Lda.


Às 00:46 de 05/04/2019, Rui Fontes escreveu:
Hello!

James Scholes wrote:
If you want to tell Python to split a string based on a different seperator, just provide the seperator as an argument to the split method.  Example using a comma:

'value1,value2,value3'.split(',')

Regarding the addon, we have:
             words = info.text.split()

and it splits the text in words...
If I want to split in sentences or lines, how to do it?


James Scholes wrote:
But if you're wanting to obtain the number of characters in a string to provide a character count, just call len on the string:
Thanks! I was being stupid! Wanting to split the text in characters... Smile!

Best regards,

Rui Fontes




derek riemer
 

Has this been uploaded yet?


On Thu, Apr 4, 2019 at 8:28 AM Rui Fontes <rui.fontes@...> wrote:
Hello!

Answering two messages...
James Scholes wrote:
> The add-on imports NVDAObjects and winUser, but no functionality from
> those modules is used.  Try to avoid unused imports for code cleanliness.

Thanks! Corrected.


James Scholes wrote:
> There's no real need to spread the word count calculation across four
> lines and three variables.  You can just do:
>
> message(_("{wordcount} words").format(wordcount=len(info.text.split())))

As a beginner I still don't like this condensed format...


James Scholes wrote:
> Do you plan to add more functionality to this add-on?  If not, I wonder
> if giving it its own category in the Input Gestures dialog is really
> appropriate.  It would probably fit in the Text Review category,
> especially if you updated the word "announces" to "reports" in the
> docstring for consistency's sake.

I do not agree.
1 - "Text review" is ment for review commands related;
2 - The only exception is the announcement of the formatation.

Maybe we should create a new entry "Text edition"?


Michal Suchý wrote:
> I would like the character counting feature in this addon. I don't know way, how to count characters fast in some text.

By the way, how is defined that we want to count words in the function?
The function split can take some parameter to set characters, word,
lines and so on to be used as unit for the split operation?
I tried to get some hints from speech.py in the announcement of xxx
characters selected, but I didn't find any...

Best regards,

Rui Fontes
NVDA portuguese team






--
Derek Riemer
Improving the world one byte at a time!        ⠠⠊⠍⠏⠗⠕⠧⠬ ⠮ ⠸⠺ ⠐⠕ ⠃⠽⠞⠑ ⠁⠞ ⠁ ⠐⠞⠖
•    Accessibility enthusiast.
•    Proud user of the NVDA screen reader.
•    Open source enthusiast.
•    Skier.

•    Personal website: https://derekriemer.com




derek riemer
 

_get_count is almost certainly an autoproperty method. _get_count magically allows foo.count to work, because of the way NVDAObjects are defined.


On Fri, Apr 5, 2019 at 12:36 AM Noelia Ruiz <nrm1977@...> wrote:
Hi Larry and all, then, if _getLineCount is private, I think it would be
better to use:

info = blah.makeTextInfo(textInfos.POSITION_SELECTION), WHERE OBJECT CAN
BE THE FOCUS, NAVIGATOR OR SOMETHING.
Then:
c = info.unitCount(textInfos.UNIT_LINE)
Or whatever.

What do you think?

Thanks



El 05/04/2019 a las 1:55, Larry Wang escribió:
> Hi, there is a _getLineCount method  for textInfo.
>
> If you want to split by sentence. A regular expression may be requried.
> You can see examples in symbols.dict.
>
> On 2019/4/5 7:46, Rui Fontes wrote:
>> Hello!
>>
>> James Scholes wrote:
>>> If you want to tell Python to split a string based on a different
>>> seperator, just provide the seperator as an argument to the split
>>> method.  Example using a comma:
>>>
>>> 'value1,value2,value3'.split(',')
>>
>> Regarding the addon, we have:
>>             words = info.text.split()
>>
>> and it splits the text in words...
>> If I want to split in sentences or lines, how to do it?
>>
>>
>> James Scholes wrote:
>>> But if you're wanting to obtain the number of characters in a string
>>> to provide a character count, just call len on the string:
>> Thanks! I was being stupid! Wanting to split the text in characters...
>> Smile!
>>
>> Best regards,
>>
>> Rui Fontes
>>
>>
>>
>>
>
>
>





--
Derek Riemer
Improving the world one byte at a time!        ⠠⠊⠍⠏⠗⠕⠧⠬ ⠮ ⠸⠺ ⠐⠕ ⠃⠽⠞⠑ ⠁⠞ ⠁ ⠐⠞⠖
•    Accessibility enthusiast.
•    Proud user of the NVDA screen reader.
•    Open source enthusiast.
•    Skier.

•    Personal website: https://derekriemer.com