#1 (permalink)  
Old 11-14-2008, 01:51 AM
Registered User
 
Join Date: Jul 2004
Posts: 249
matching phrases

I spent a good number of hours of trying to figure out on how to skip the smallest words except when it's part of a common phrase between the two strings. This is what I have so far:
Code:
function getPhrases(){
    var searchChapWords=document.getElementsByName('search_chap_words'); //grabs from the 1st column
    var searchChapWords2=document.getElementsByName('search_chap_words2'); //grabs from the 2nd column
    document.getElementById('keyword0').innerHTML = "";
    document.getElementById('keyword1').innerHTML = "";
       
    var myOldString = "";
    var myOldString2 = "";
    for(i=0;i<searchChapWords.length;i++){
        myOldString += searchChapWords[i].innerHTML + " "; //joins 1st column in one string
    }
    for(i=0;i<searchChapWords2.length;i++){
        myOldString2 += searchChapWords2[i].innerHTML + " "; //joins 2nd column in one string
    }
    var myNewString = myOldString.replace(/[\:\;\?\.\,\(\)\']/gi, "");//to eliminate the punctuations
    var myNewString2 = myOldString2.replace(/[\:\;\?\.\,\(\)\']/gi, "");//to eliminate the punctuations
   
    var mySplitString = myNewString.split(" ");
    var mySplitString2 = myNewString2.split(" ");
   
    // Our common phrase goes here.
    var common_phrase = "";
    var phraseCollection =  new Array();
    // Now go through a double-loop and match each common word.
    //for(k=0; k<15; k++){
        k=0;
        phraseCollection[k] = "";
        for(var i=0; i < mySplitString.length; i++){ //length of 1st array
            if(i!=0){
                //common_phrase += " ";
                phraseCollection[k] += " ";
            }
            for(var j=0; j < mySplitString2.length; j++){ //picks a word and runs through 2nd array
                if(mySplitString[i] == mySplitString2[j]){ //when match found
                    phraseCollection[k] += mySplitString[i]; //records word
                    /*
                    //common_phrase += mySplitString[i];
                    //common_phrase += " ";
                    if(j!=mySplitString2.length-1){
                        phraseCollection[k] += " ";
                        //common_phrase += " ";
                    }
                    */
                    // Move it forward to the next word in the phrase1.
                    i++; // goes to the next word
                }else{
                    k++;//skips to the next array element
                    i++;// goes to the next word
                }
            }
            /*
            if(i!=mySplitString.length-1){
                phraseCollection[k] += ",,";
                //common_phrase += ",,";
            }
            */
        }
    //}
    for(k=0; k<phraseCollection.length; k++){
        common_phrase += phraseCollection[k] + ",,";
    }
    // Clean up the extra space at the end.
    common_phrase = common_phrase.substr(0, common_phrase.length-1);
    document.getElementById('keyword0').innerHTML=common_phrase;
 
}
What I thought of doing is to create an array of phraseCollection and whatever is a good find, a match, would be part of this array. But I'm getting undefined as an answer.
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio

  #2 (permalink)  
Old 11-14-2008, 01:55 AM
Registered User
 
Join Date: Jul 2004
Posts: 249
This is the example, 1st column of span tags (name="search_chap_words") I'm working with.
Code:
<div id="notForForum" style="border: thin dashed ; position: absolute; left: -30px; display: block; margin-left: 2em; overflow-y: scroll; overflow-x: hidden; height: 300px; width: 300px; padding-right: 5px;">
	 <span style="padding: 5px; background-color: rgb(235, 255, 255); font-weight: bold; width: 300px; display: block;">2 Chronicles 16
</span><br><span id="regular[]" style="padding: 5px; font-weight: bold;">1</span>
<span name="search_chap_words" id="14_16_1" style="">In the six and thirtieth year of the reign of Asa Baasha king of Israel came up against Judah, and built Ramah, to the intent that he might let none go out or come in to Asa king of Judah.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">2</span>
<span name="search_chap_words" id="14_16_2" style="">Then Asa brought out silver and gold out of the treasures of the house of the LORD and of the king's house, and sent to Benhadad king of Syria, that dwelt at Damascus, saying,
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">3</span>
<span name="search_chap_words" id="14_16_3" style="">There is a league between me and thee, as there was between my father and thy father: behold, I have sent thee silver and gold; go, break thy league with Baasha king of Israel, that he may depart from me.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">4</span>

<span name="search_chap_words" id="14_16_4" style="">And Benhadad hearkened unto king Asa, and sent the captains of his armies against the cities of Israel; and they smote Ijon, and Dan, and Abelmaim, and all the store cities of Naphtali.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">5</span>
<span name="search_chap_words" id="14_16_5" style="">And it came to pass, when Baasha heard it, that he left off building of Ramah, and let his work cease.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">6</span>
<span name="search_chap_words" id="14_16_6" style="">Then Asa the king took all Judah; and they carried away the stones of Ramah, and the timber thereof, wherewith Baasha was building; and he built therewith Geba and Mizpah.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">7</span>
<span name="search_chap_words" id="14_16_7" style="">And at that time Hanani the seer came to Asa king of Judah, and said unto him, Because thou hast relied on the king of Syria, and not relied on the LORD thy God, therefore is the host of the king of Syria escaped out of thine hand.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">8</span>
<span name="search_chap_words" id="14_16_8" style="">Were not the Ethiopians and the Lubims a huge host, with very many chariots and horsemen? yet, because thou didst rely on the LORD, he delivered them into thine hand.

</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">9</span>
<span name="search_chap_words" id="14_16_9" style="">For the eyes of the LORD run to and fro throughout the whole earth, to show himself strong in the behalf of them whose heart is perfect toward him. Herein thou hast done foolishly: therefore from henceforth thou shalt have wars.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">10</span>
<span name="search_chap_words" id="14_16_10" style="">Then Asa was wroth with the seer, and put him in a prison house; for he was in a rage with him because of this thing. And Asa oppressed some of the people the same time.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">11</span>
<span name="search_chap_words" id="14_16_11" style="">And, behold, the acts of Asa, first and last, lo, they are written in the book of the kings of Judah and Israel.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">12</span>
<span name="search_chap_words" id="14_16_12" style="">And Asa in the thirty and ninth year of his reign was diseased in his feet, until his disease was exceeding great: yet in his disease he sought not to the LORD, but to the physicians.
</span><br>

<span id="regular[]" style="padding: 5px; font-weight: bold;">13</span>
<span name="search_chap_words" id="14_16_13" style="">And Asa slept with his fathers, and died in the one and fortieth year of his reign.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">14</span>
<span name="search_chap_words" id="14_16_14" style="">And they buried him in his own sepulchres, which he had made for himself in the city of David, and laid him in the bed which was filled with sweet odorous and divers kinds of spices prepared by the apothecaries' art: and they made a very great burning for him.
</span><br>
</div>
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
  #3 (permalink)  
Old 11-14-2008, 02:00 AM
Registered User
 
Join Date: Jul 2004
Posts: 249
name="search_chap_words2" is the 2nd column. The JavaScript function grabs the words in the first column and searches in this column:
Code:
<div id="notForForum2" style="border: thin dashed ; position: absolute; left: -30px; display: block; margin-left: 2em; overflow-y: scroll; overflow-x: hidden; height: 300px; width: 300px; padding-right: 5px;">
	 <span style="padding: 5px; background-color: rgb(235, 255, 255); font-weight: bold; width: 300px; display: block;">Zechariah 4
</span><br><span id="regular[]" style="padding: 5px; font-weight: bold;">1</span>
<span name="search_chap_words2" id="38_4_1" style="">And the angel that talked with me came again, and waked me, as a man that is wakened out of his sleep.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">2</span>
<span name="search_chap_words2" id="38_4_2" style="">And said unto me, What seest thou? And I said, I have looked, and behold a candlestick all of gold, with a bowl upon the top of it, and his seven lamps thereon, and seven pipes to the seven lamps, which are upon the top thereof:
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">3</span>
<span name="search_chap_words2" id="38_4_3" style="">And two olive trees by it, one upon the right side of the bowl, and the other upon the left side thereof.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">4</span>

<span name="search_chap_words2" id="38_4_4" style="">So I answered and spake to the angel that talked with me, saying, What are these, my lord?
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">5</span>
<span name="search_chap_words2" id="38_4_5" style="">Then the angel that talked with me answered and said unto me, Knowest thou not what these be? And I said, No, my lord.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">6</span>
<span name="search_chap_words2" id="38_4_6" style="">Then he answered and spake unto me, saying, This is the word of the LORD unto Zerubbabel, saying, Not by might, nor by power, but by my spirit, saith the LORD of hosts.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">7</span>
<span name="search_chap_words2" id="38_4_7" style="">Who art thou, O great mountain? before Zerubbabel thou shalt become a plain: and he shall bring forth the headstone thereof with shoutings, crying, Grace, grace unto it.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">8</span>
<span name="search_chap_words2" id="38_4_8" style="">Moreover the word of the LORD came unto me, saying,

</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">9</span>
<span name="search_chap_words2" id="38_4_9" style="">The hands of Zerubbabel have laid the foundation of this house; his hands shall also finish it; and thou shalt know that the LORD of hosts hath sent me unto you.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">10</span>
<span name="search_chap_words2" id="38_4_10" style="">For who hath despised the day of small things? for they shall rejoice, and shall see the plummet in the hand of Zerubbabel with those seven; they are the eyes of the LORD, which run to and fro through the whole earth.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">11</span>
<span name="search_chap_words2" id="38_4_11" style="">Then answered I, and said unto him, What are these two olive trees upon the right side of the candlestick and upon the left side thereof?
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">12</span>
<span name="search_chap_words2" id="38_4_12" style="">And I answered again, and said unto him, What be these two olive branches which through the two golden pipes empty the golden oil out of themselves?
</span><br>

<span id="regular[]" style="padding: 5px; font-weight: bold;">13</span>
<span name="search_chap_words2" id="38_4_13" style="">And he answered me and said, Knowest thou not what these be? And I said, No, my lord.
</span><br>
<span id="regular[]" style="padding: 5px; font-weight: bold;">14</span>
<span name="search_chap_words2" id="38_4_14" style="">Then said he, These are the two anointed ones, that stand by the LORD of the whole earth.
</span><br>
</div>
I want to grab all the name="search_chap_words" join them together then break it down to words and search it into name="search_chap_words2".

The problem comes afterward. If the search found only small words like a or the it would be insignificant. But if the a or the the is accompanied with other words in common then it should be included.

What I had in mind is to create another array which would include all the phrases the search has found.

Instead of //common_phrase I have the array phraseCollection[k]. But this method gives error. Is there way to make phraseCollection[k] work in the for loop?
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
  #4 (permalink)  
Old 11-14-2008, 06:35 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,533
Is there a reason you're doing all of this in javascript rather than using PHP or some other, more powerful, server-side script?

I'm not sure how effectively you're going to be able to accomplish this with JS; and unfortunately, I just don't know enough JS to be able to debug that much code at once.
__________________
I hate Internet Explorer! Anyone with me?
  #5 (permalink)  
Old 11-15-2008, 02:55 AM
Registered User
 
Join Date: Jul 2004
Posts: 249
Quote:
Originally Posted by curtiss View Post
Is there a reason you're doing all of this in javascript rather than using PHP or some other, more powerful, server-side script?

I'm not sure how effectively you're going to be able to accomplish this with JS; and unfortunately, I just don't know enough JS to be able to debug that much code at once.
I started with this idea because of the AJAX get method in the specific tag. I thought the best way to start was play with the url string.
I was trying to figure this out. Up until the for loop I got to find the similar words within the two columns as mentioned above.

But I want to find out phrases (a sequence of words) in common between the two columns.

Whichever word is common is added to the phraseCollection array. But that's where logic stops. I can't think of how to get this further.

Do you think php is better for this?
Code:
// JavaScript Document
function getPhrases(){
	var searchChapWords=document.getElementsByName('search_chap_words'); //grabs from the 1st column
	var searchChapWords2=document.getElementsByName('search_chap_words2'); //grabs from the 2nd column
	document.getElementById('keyword0').innerHTML = "";
	document.getElementById('keyword1').innerHTML = "";
	
	var myOldString = "";
	var myOldString2 = "";
	for(i=0;i<searchChapWords.length;i++){
		myOldString += searchChapWords[i].innerHTML + " "; //joins 1st column in one string
	}
	for(i=0;i<searchChapWords2.length;i++){
		myOldString2 += searchChapWords2[i].innerHTML + " "; //joins 2nd column in one string
	}
	var myNewString = myOldString.replace(/[\:\;\?\.\,\(\)\']/gi, "");//to eliminate the punctuations
	var myNewString2 = myOldString2.replace(/[\:\;\?\.\,\(\)\']/gi, "");//to eliminate the punctuations
	
	var mySplitString = myNewString.split(" ");
	var mySplitString2 = myNewString2.split(" ");
	
	// Our common phrase goes here.
	var common_phrase = "";
	var phraseCollection =  new Array();
	// Now go through a double-loop and match each common word.
	k=0;
	phraseCollection[k] = "";
	for(var i=0; i < mySplitString.length; i++){ //length of 1st array
		if(i!=0){
			//common_phrase += " ";
			phraseCollection[k] += "";
		}
		for(var j=0; j < mySplitString2.length; j++){ //picks a word and runs through 2nd array
			if(mySplitString[i] == mySplitString2[j]){ //when match found
				phraseCollection[k] += mySplitString[i]+" "; //records word
				// Move it forward to the next word in the phrase1.
				i++; // goes to the next word
			}
		}
		k++;//skips to the next array element
		phraseCollection[k]="";
	}
	function sortNumber(a,b){
		return a - b;
	}
	var sortByLength = new Array();
	
	for(m=0; m<sortByLength.length; m++){
		sortByLength[m] = phraseCollection[m].length;

	}	
	for(k=0; k<phraseCollection.length; k++){
		if(phraseCollection[k].length> document.getElementById("number_words").value){
			common_phrase += phraseCollection[k] + ",,";
		}		
	}
	// Clean up the extra space at the end.
	common_phrase = common_phrase.substr(0, common_phrase.length-1);
	document.getElementById('keyword0').innerHTML=common_phrase;
}
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
  #6 (permalink)  
Old 11-15-2008, 08:07 AM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,533
I'm not sure I understand completely what you are trying to do.

Are you trying to build the "phrase collection" dynamically, or are you coming up with a collection of common phrases yourself, and then planning to compare them against the items the user searches?
__________________
I hate Internet Explorer! Anyone with me?
  #7 (permalink)  
Old 11-15-2008, 10:29 PM
Registered User
 
Join Date: Jul 2004
Posts: 249
I want to find common phrases between two texts. But here's an example of the result I'm getting:
For the eyes of the LORD run to and fro taken from 9 For the eyes of the LORD run to and fro throughout the whole earth, to show himself strong in the behalf of them whose heart is perfect toward him. Herein thou hast done foolishly: therefore from henceforth thou shalt have wars. from the first column. The second column has 10 For who hath despised the day of small things? for they shall rejoice, and shall see the plummet in the hand of Zerubbabel with those seven; they are the eyes of the LORD, which run to and fro through the whole earth. . The two columns have words in common such as for except these two phrases don't match with the for in it.
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio

Last edited by gilgalbiblewhee; 11-16-2008 at 04:33 PM..
  #8 (permalink)  
Old 11-25-2008, 12:16 AM
Registered User
 
Join Date: Jul 2004
Posts: 249
Ok How can I allow words to be recorded:
wordCollection[k] = mySplitString[i]; //records word

only once?

I was thinking that I could do it this way:
Code:
/*
				for(m=0; m<wordCollection.length; m++){

					if(wordCollection[k]==wordCollection[m]){
						i++;
					}else{
*/
Using the same array picking each array word and running it within itself to see if there are anymore of this word. If it's not found then it would record. But it didn't work.
Code:
// JavaScript Document
function getPhrases(){
	var searchChapWords=document.getElementsByName('search_chap_words'); //grabs from the 1st column
	var searchChapWords2=document.getElementsByName('search_chap_words2'); //grabs from the 2nd column
	document.getElementById('keyword0').innerHTML = "";
	document.getElementById('keyword1').innerHTML = "";
	
	var myOldString = "";
	var myOldString2 = "";
	for(i=0;i<searchChapWords.length;i++){
		myOldString += searchChapWords[i].innerHTML + " "; //joins 1st column in one string
	}
	for(i=0;i<searchChapWords2.length;i++){
		myOldString2 += searchChapWords2[i].innerHTML + " "; //joins 2nd column in one string
	}
	var myNewString = myOldString.toLowerCase().replace(/[\:\;\?\.\,\(\)\']/gi, "");//to eliminate the punctuations
	var myNewString2 = myOldString2.toLowerCase().replace(/[\:\;\?\.\,\(\)\']/gi, "");//to eliminate the punctuations
	
	var mySplitString = myNewString.split(" ");
	var mySplitString2 = myNewString2.split(" ");
	
	// Our common phrase goes here.
	var common_phrase = "";
	var wordCollection =  new Array();
	// Now go through a double-loop and match each common word.
	k=0;

	for(var i=0; i < mySplitString.length; i++){ //length of 1st array

		for(var j=0; j < mySplitString2.length; j++){ //picks a word and runs through 2nd array

			if(mySplitString[i] == mySplitString2[j]){ //when match found
/*
				for(m=0; m<wordCollection.length; m++){

					if(wordCollection[k]==wordCollection[m]){
						i++;
					}else{
*/
						wordCollection[k] = mySplitString[i]; //records word
						k++;//skips to the next array element
						// Move it forward to the next word in the phrase1.

						i++; // goes to the next word

					}

/*				}


			}*/

		}


	}
	
	for(k=0; k<wordCollection.length; k++){
//		if(wordCollection[k].length> document.getElementById("number_words").value){
			common_phrase += wordCollection[k] + ",,\n";
//		}		
	}
	// Clean up the extra space at the end.
	common_phrase = common_phrase.substr(0, common_phrase.length-1);
	document.getElementById('keyword0').innerHTML=common_phrase;
}
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
  #9 (permalink)  
Old 11-25-2008, 06:02 AM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,533
First of all, to answer your first question, I think you are looking for a "fulltext match". Try reading that part of the MySQL manual and see if that helps at all.

For your latest question, don't worry about which words are being recorded. In fact, I wouldn't even loop through the words.

Instead, I would just use explode(' ',$keywords) to split all of the keywords into an array (everywhere there's a space, a new array item will be created). Then, use array_unique to eliminate words that showed up more than once.

Finally, write a very simple function that just checks the strlen of the input variable. If it's long enough, return true. If it's not, return false. Then, use array_filter to call that function on your array of keywords.
__________________
I hate Internet Explorer! Anyone with me?
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SEO Future? Cleo8 SEO - Search Engine Optimization 19 04-08-2009 11:38 AM


All times are GMT -5. The time now is 01:31 PM.

 
Clicky Web Analytics
CloudContacts
Loop11
Page.ly


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.1 PL1
© 1997-2009 HTMLCenter