jackkoo

26 Jan 2015

My project was to find words that are good friends with other words.
This is what I did.

1. Youtube query a word
2. return with descriptions
3. find and rank most common words in the description.

Some searches that was interesting is that the most common word while searching “Sexy” was “Pranks”. For the word “Interaction, we see poetic words such as thought, learning, moments and eyes”.

History returns with words such as “times, interesting, humble, science”. However it is also fun to see that BREAKFAST was a good friend of history.

I think think I’d like to display these information as individual searches, although some charts such as “narcsist” words (words who return themselves highly) may be fun. I also thought about a “One sided relationships chart” that would display words that return a certain word that doesn’t return itself.

IMG_004522

Here are some sample results:

“History”

56 = the
55 = full
53 = times
53 = interesting
50 = set
48 = with
47 = genghis
46 = franklin
45 = humble
43 = science
42 = breakfast
41 = created
40 = nova
40 = discovery
39 = everything
39 = loewen
38 = of
38 = republic
37 = this
36 = an
35 = about\
33 = quarter
32 = population
32 = extraordinary
31 = from
27 = video
27 = watching
27 = lies
27 = american
27 = critically

“Sexy”

25 = pranks
25 = wronghaving
24 = ass
23 = oppaibreast
22 = for
21 = killer
21 = 2014
20 = 2015
19 = breast
19 = check
19 = basketball
18 = twitter
17 = with
16 = ball
16 = and
16 = comparisons
16 = upton
16 = ???
16 = shirt
16 = ?
14 = seduction
14 = getting
14 = gems
14 = ?
14 = it
14 = originality
12 = new

And last but not least here is my code:

// BFF's (Words)

import com.temboo.core.*;
import com.temboo.Library.YouTube.Search.*;
import java.util.Collections;
// Create a session using your Temboo account application details
TembooSession session = new TembooSession("asveron", "myFirstApp", "abf52e76ec6b4e0f84c076b531180b3a");

void setup()
{
 
 // Run the ListSearchResults Choreo function
 String allFreinds = findAllFreinds("cartoon");
 
 String[] freindCandidatesArray = allFreinds.split(" ", -1);
 ArrayList<String> freindCandidates = new ArrayList<String>();
 
 for (int i = 0; i < freindCandidatesArray.length; i++)
 {
 freindCandidates.add(freindCandidatesArray[i]);
 }
 
 ArrayList<Score> closeFreinds = new ArrayList<Score>();
 
 // Find close freinds
 for (int i = 0; i < freindCandidates.size(); i++)
 {
 String currentString = freindCandidates.get(i);
 boolean foundFreind = false;
 
 for (int j = 0; j < closeFreinds.size(); j++)
 {
 String closeFreind = freindCandidates.get(j);
 
 if (currentString.equals(closeFreind))
 {
 foundFreind = true;
 Score s = closeFreinds.get(j);
 s.score += 1;
 }
 }
 
 if (foundFreind != true)
 {
 closeFreinds.add(new Score(0, currentString));
 }
 }
 
 // Sort the data
 Collections.sort(closeFreinds, Collections.reverseOrder());
 
 // Print the data
 for (int i = 0; i < closeFreinds.size(); i++)
 {
 Score s = closeFreinds.get(i);
 int score = s.score;
 String word= s.name;
 println(score + " = " + word);
 }
 
 frameRate(1);
}

void draw()
{
 
}


String findAllFreinds(String searchWord)
{
 // Create the Choreo object using your Temboo session
 ListSearchResults listSearchResultsChoreo = new ListSearchResults(session);

 // Set inputs
 listSearchResultsChoreo.setFields("items/snippet/description");
 listSearchResultsChoreo.setQuery(searchWord);
 listSearchResultsChoreo.setMaxResults("50");
 
 // Run the Choreo and store the results
 ListSearchResultsResultSet listSearchResultsResults = listSearchResultsChoreo.run();
 
 // Get description from Temboo query
 String descriptions = listSearchResultsResults.getResponse();
 
 // Change result to list of words
 String result = descriptionsToFreinds(descriptions);
 
 // Return the list of works, aka the freinds
 return result;
}

String descriptionsToFreinds(String descriptions)
{
 ArrayList<String> removeStrings = new ArrayList<String>();
 
 removeStrings.add("[");
 removeStrings.add("]");
 removeStrings.add("{");
 removeStrings.add("}");
 removeStrings.add("(");
 removeStrings.add(")");
 removeStrings.add(":");
 removeStrings.add(",");
 removeStrings.add(".");
 removeStrings.add("/");
 removeStrings.add("\"");
 removeStrings.add("?");
 removeStrings.add("-");
 
 removeStrings.add("items");
 removeStrings.add("snippet");
 removeStrings.add("description");
 
 // remove json stuff & symbols
 for (int i = 0; i < removeStrings.size(); i++)
 {
 descriptions = descriptions.replace(removeStrings.get(i), "");
 }
 
 // Remove extra spaces, first space, last space, change everything to lower case
 descriptions = descriptions.replaceAll("\\s+", " ");
 descriptions = descriptions.substring(1);
 descriptions = descriptions.substring(0, descriptions.length()-1);
 descriptions = descriptions.toLowerCase();
 
 // Now we have freinds
 return descriptions;
}