Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 4:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 32 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Word Frequency in text object
PostPosted: September 26th, 2014, 1:13 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Mack,

Having difficulty getting the second "if" condition to work: eliminates almost every word instead of just the 2 common words tested for. Must be missing something?

Code:
function checkWord(w){

var tmpFound = false;
for (var b=0;b<myWordsArray.length;b++){

   if ((myWordsArray[b].word == "and") || (myWordsArray[b].word == "the")){
         tmpFound = true
}
}

for (var b=0;b<myWordsArray.length;b++){

   if (String.toupper(myWordsArray[b].word) == String.toupper(w)) {
      myWordsArray[b].count++;
      tmpFound = true
      }
}
if (!tmpFound)myWordsArray[b] = new WORDOBJECT(w);

}

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 26th, 2014, 4:22 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Repeat the whole for loop.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 26th, 2014, 4:45 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Sorry Mack: am still doing this incorrectly.

Still not sure what to do differently to 'repeat the whole for loop.'

Tried a number of variations, but still either get almost all words eliminated or common words like "and" still showing up in the list and counted.

Code:
function checkWord(w){

var tmpFound = false;

for (var b=0;b<myWordsArray.length;b++){

   if (String.toupper(myWordsArray[b].word) == String.toupper(w)) {
      myWordsArray[b].count++;
      tmpFound = true
      }
}
for (var b=0;b<myWordsArray.length;b++){

   if ((myWordsArray[b].word) == "and") {
      //myWordsArray[b].count++;
      tmpFound = true
      }
}

if (!tmpFound)myWordsArray[b] = new WORDOBJECT(w);

}


Having been at this now for 2 days, trying every conceivable script combination. So far, setting the tmpFound flag as true still doesn't prevent the WORDOBJECT(w) function from adding, to the listbox, the common word to be filtered out, and counting it. Need to filter it out from the list.

I must still be doing something wrong in the scripting.

Unfortunately, still stuck. Any help getting it to work, appreciated. :oops:

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 28th, 2014, 12:11 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Now you're messing with my brain...

You're supposed to be checking the found word against a list of common words - you're trying to check the list of already found words against the common words which should never be in that list anyway.

The simplest change would look like this:

Code:
  if (w == "and")


Hopefully that makes sense.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 28th, 2014, 1:45 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Mack,

OK, if I use if (w == "and") it works OK, filtering out "and" from the listbox.

However, if I try to check "and" or "the", it only filters out "and". "the" continues to display, with a count number, in the listbox.

Here's the script that is not working to filter out both words:

Code:
function checkWord(w){

var tmpFound = false;

for (var b=0;b<myWordsArray.length;b++){

   if (String.toupper(myWordsArray[b].word) == String.toupper(w)) {
      myWordsArray[b].count++;
      tmpFound = true
      }
}
for (var b=0;b<myWordsArray.length;b++){

   if ((w == "and") || (w == "the"))  {
      //myWordsArray[b].count++;
      tmpFound = true
      }
}

if (!tmpFound)myWordsArray[b] = new WORDOBJECT(w);

}
function WORDOBJECT(w){
this.word = w.tolower();
this.count = 1;
}


Had also tried if ((w == "and") && (w == "the")) which does not filter either "and" or "the".

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 28th, 2014, 2:51 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Words fine.

the and The and THE and tHE are not the same thing. You need to convert everything to the same case before comparing as in the for loop above.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 28th, 2014, 5:47 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Thanks again, Mack.

Once I add String.toupper, it appears that common words used for testing are filtered out.

Code:
if (String.toupper(w) == String.toupper("and") || String.toupper(w) == String.toupper("the") || String.toupper(w) == String.toupper("for") || String.toupper(w) == String.toupper("her")){


It looks like if I use a larger number of common words to filter, it may slow down noticeably. A dictionary of these (or other terms) would probably be too slow to check/filter out.

Is there a way to improve speed if a large number of common (or other) words are checked for filtering out?

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 28th, 2014, 11:28 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
You can start by typing "AND" not String.toupper("and"). You could also do the same with the w but this would need to be read into a new variable and then compared. IE:

Code:
var uw = String.toupper(w);

if (uw == "AND")


Also, your FOR loop is redundant - my suggestion used an array of common words rather than a long string of IFs.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 29th, 2014, 1:14 am 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Did some more research on English "common" words also known as "stop" words. The widely used list (http://norm.al/2009/04/14/list-of-english-stop-words/ is 319 words long.

So definitely need a faster way to script the filtering, have it hopefully run faster.

Followed your first suggestion to use "AND" etc. for my tests. Much easier to write.

As to another suggestion: if a new array was created for the (319) common words (all added as upper case), not too sure how to set up the comparison? Maybe something like (pseudocode):

Code:
function checkWord(w){
var tmpFound = false;
for (var b=0;b<myWordsArray.length;b++){
   if (String.toupper(myWordsArray[b].word) == String.toupper(w)) {
      myWordsArray[b].count++;
      tmpFound = true
      }
}
for (var b=0;b<myWordsArray.length;b++){
for (m = 0;m<commonwordarray.length;m++){
if  (String.toupper(w) == commonwordarray[m].word{
tmpFound = true
}// plus a few more closing brackets


No doubt the above is a mess of contradictions and poor syntax. But maybe something like that, minus the mess and poor syntax?
Hmmm... Should have this sorted by 2018 give or take. :D

Unrelated: as a longtime Conan Doyle fan (years ago read every Sherlock Holmes ever written), I think I finally recognized that quote under your signature? Took me a while, eh?

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 29th, 2014, 8:32 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Don't think you'll need to wait that long.

The code is almost perfect but in that second group you only need the commonwordarray FOR loop.

Yes, it's elementary :-) Though I'm a fan of the modern moving picture versions. Both the Cumberbatch BBC series and Downing Jr / McAdam's films and am looking forward to Elementary if it ever makes it to UK TV.

Mack

P.S camelCase makes names easier to read as in "commonWordArray"

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 29th, 2014, 12:49 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Gave it a try, seems to work to filter out 3 test words: "and", "the", "of":

Code:
commonwordarray = new Array();
commonwordarray[0] = "and"
commonwordarray[1] = "the"
commonwordarray[2] = "of"
//set up the commonwordarray

function checkWord(w){

var tmpFound = false;

for (var b=0;b<myWordsArray.length;b++){

   if (String.toupper(myWordsArray[b].word) == String.toupper(w)) {
      myWordsArray[b].count++;
      tmpFound = true
      }
}
for (m = 0;m<commonwordarray.length;m++){
if  (String.toupper(w) == String.toupper(commonwordarray[m])){
tmpFound = true
}
}

if (!tmpFound)myWordsArray[b] = new WORDOBJECT(w);

}
function WORDOBJECT(w){
this.word = w.tolower();
this.count = 1;
}


Any easier way to create a 391 word array?

Watch Elementary (http://www.imdb.com/title/tt2191671/?ref_=ttfc_fc_tt) every week. Hope it makes it over. Jonny Lee Miller does a very credible and quirky Holmes; occasionally Rhys Ifans joins the cast and does an edgy Mycroft. Wonderful.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 29th, 2014, 1:18 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
You can do it when you create the array:

Code:
myArray = new Array("AND","BUT","IF","HOW")


Modern JS is even easier but it doesn't work for OpusScript though you can use it with the Opus JS object in a HTML5 project (literal notation)

Code:
myArray = ["AND","BUT","IF","HOW"]


Alternatively, you could have a text file of words and just read them into the array.


Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Word Frequency in text object
PostPosted: September 29th, 2014, 1:47 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Quote:
Alternatively, you could have a text file of words and just read them into the array.


Got this to work.

Thanks, again.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: October 1st, 2014, 12:35 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Am now trying to figure out how to clear the list box, if the user needs to replace and count text in the text box.

The text box can be cleared by using:

Code:
myWords = "";


The listbox can be cleared by using:

Code:
T10.SetSelection(0,-1);//T10 is the listbox
T10.ReplaceSelection("");


But, even if the listbox is cleared, when any new text is processed and sent as a list to that now emptied listbox, the old removed text re-displays first, followed by the newly processed text.

Any suggestions appreciated.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Word Frequency in text object
PostPosted: October 2nd, 2014, 1:37 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Probably need to initial the arrays as well.

Code:
array = new Array()


Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group