kailash001 Posted December 18, 2010 Share Posted December 18, 2010 Hello guys, i need some help in assigning a score to a word according to its occurrence in a group of sentences. [code=php:0] $words="Hello, how are you?"; $sentences="Hello! I am fine. How about you? You look good."; [/code] now i'm trying to assign a score to each word in $words e.g Hello=1, how=1, are=0, you=2. Link to comment https://forums.phpfreaks.com/topic/222042-help-needed-to-tag-words-with-score/ Share on other sites More sharing options...
denno020 Posted December 18, 2010 Share Posted December 18, 2010 I'm not sure exactly how to do this, but I would approach it this way. You would have to parse the string, and break up each of the individual words. Then you would need to compare each individual word to a db of words that you have. When a match is found, then pull the score for that word.. Might be an easier way, but I'm not sure? Denno Link to comment https://forums.phpfreaks.com/topic/222042-help-needed-to-tag-words-with-score/#findComment-1148923 Share on other sites More sharing options...
kailash001 Posted December 18, 2010 Author Share Posted December 18, 2010 I'm not sure exactly how to do this, but I would approach it this way. You would have to parse the string, and break up each of the individual words. Then you would need to compare each individual word to a db of words that you have. When a match is found, then pull the score for that word.. Might be an easier way, but I'm not sure? Denno ok so i made some modifications <?php $words="Hello how are you"; $word_array = explode(" ", $words); $paragraph="Hello! I am fine. How about you? You look good."; $sencetences = strtok($paragraph, ".!?"); ?> now i have all the words in an array and the sentences are separated. i don't want to compare the words from DB but check its occurrence in the paragraph then assign the score to it. the score is in fact the number of times it is repeated in the paragraph. Link to comment https://forums.phpfreaks.com/topic/222042-help-needed-to-tag-words-with-score/#findComment-1148930 Share on other sites More sharing options...
denno020 Posted December 18, 2010 Share Posted December 18, 2010 Wouldn't you explode the paragraph into another array, and then you could compare the arrays, iterating through them looking for matches.. Link to comment https://forums.phpfreaks.com/topic/222042-help-needed-to-tag-words-with-score/#findComment-1148937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.