English Word Association Game Revisit Tutorial

English Word Association Game Revisit Tutorial

English Word Association Game Revisit Tutorial

One step forward, and steps back is how we’d describe progress, onto the PHP Word Association web application game of Language Word Association Game Tutorial

  • the step forward being the replacing of obsolete Yahoo YQL Thesaurus sources of information with that of the newly introduced Free Thesaurus source, thanks … making the game not show error messages any more and …
  • the steps back relate to our Word Association game being locked into “English modus operandi” only

We add coding to make this happen, just in case Yahoo YQL is ever resurrected, and for “coding posterity purposes”, by introducing a new PHP variable called $theone as featuring in changed PHP code snippets below …

New variables
<?php

$theone=0;
$rdonly="";

?>
Read from thesaurus data source
<?php

$pageContent = "";
if ((
$theone % 2) == 0) {
$pageContent = @file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20thesaurus%20where%20key%3D%225r3uguAhHMoAQJIlShGL%22%20and%20word%3D%22".urlencode($selname)."%22%20and%20language%3D%22" . $language . "%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
}
if (
$theone == 1 && $pageContent != '') { $theone=2; } else if ($pageContent == '') { $theone=1; }
if (
$theone == 1) {
$pageContent = @file_get_contents("ht
tp://www.freethesaurus.com/".urlencode($selname)); //."%22%20and%20language%3D%22" . $language . "%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
$rdonly=" disabled";
if (strpos($pageContent, '<div class="TCont">') === false) {
header('Location: ./word_association.php');
exit;
}
}


?>
Process thesaurus data
<?php

if ($theone == 1) {
$mylist = explode('<div class="TCont">', $pageContent);
if (sizeof($mylist) > 1) {
$pageContent=explode('</div>', $mylist[1])[0];
//file_put_contents('xzz.xzz', $pageContent);
}
$mylist = explode('</h4>', $pageContent);
if (sizeof($mylist) > 1) {
$pageContent=$mylist[0] . '</h4>' . explode('</ul>', $mylist[1])[0] . '</ul>';
$mylist = explode('</h4>', $pageContent);
}
} else {

$mylist = explode('"synonyms":"', $pageContent);
}

if (sizeof($mylist) > 1 || $persist == "n") {
for ($i=1; $i<sizeof($mylist); $i++) {
if ($theone == 1) {
$myline = explode('</ul>', $mylist[$i]);
$mywords = explode("</li>", $myline[0]);
} else {

$myline = explode('"', $mylist[$i]);
$mywords = explode("|", $myline[0]);
}
for ($ii=0; $ii<sizeof($mywords); $ii++) {
if ($theone == 1) {
$selname = "";
//echo "yes" . $ii . " ... " . explode('>', explode('</a>', $mywords[$ii])[0])[(-1 + sizeof(explode('>', explode('</a>', $mywords[$ii])[0])))];
//exit;
$tra=trim(explode('>', explode('</a>', $mywords[$ii])[0])[(-1 + sizeof(explode('>', explode('</a>', $mywords[$ii])[0])))]);
if ($tra != '') {
$rest = str_replace("</select>", "<option value=\"" . $tra . "\">" . $tra . "</option></select>", $rest);
}
} else {

$preword = explode(" (", $mywords[$ii]);
$proposed = str_replace(" (umgangssprachlich)", "", str_replace(" (antonym)", "", str_replace(" (related term)", "", str_replace(" (similar term)", "", $mywords[$ii]))));
$huhs = explode(" (", $proposed);
if (sizeof($huhs) > 1) $proposed = $huhs[0];
if (substr(($proposed . " "), 0, 1) == "(") {
$huhs = explode(") ", $proposed);
if (sizeof($huhs) > 1) $proposed = str_replace($huhs[0] . ") ", "", $proposed);
}
if (strlen(str_replace(" -> " . $proposed . " -> ", "", " -> " . $myp . " -> ")) == strlen(" -> " . $myp . " -> ") && strlen(str_replace(">" . $proposed . "<", "", ">" . $rest . "<")) == strlen(">" . $rest . "<")) {
if (strpos($mywords[$ii], " (antonym)") !== false) {
$selname = "";
$rest = str_replace("</select>", "<option value=\"" . $proposed . "\">" . $proposed . "</option></select>", $rest);
//echo "<tr><td style='background-color:white;'></td><td style='background-color:white;'><a style='text-decoration:none;' target=_blank title='" . str_replace(" (antonym)", "", $mywords[$ii]) . "' href='" . $dprefix . str_replace(" (antonym)", "", $preword[0]) . "'>" . str_replace(" (antonym)", "", $mywords[$ii]) . "</a></td></tr>";
} else {
$selname = "";
$rest = str_replace("</select>", "<option value=\"" . $proposed . "\">" . $proposed . "</option></select>", $rest);
//echo "<tr><td style='background-color:white;'><a style='text-decoration:none;' target=_blank title='" . str_replace(" (antonym)", "", $mywords[$ii]) . "' href='" . $dprefix . str_replace(" (antonym)", "", $preword[0]) . "'>" . str_replace(" (antonym)", "", $mywords[$ii]) . "</a></td><td style='background-color:white;'></td></tr>";
}
}
}
}
}
}

?>

… and so, we’d recommend you (re-)try the changed word_association.php English Word Association Game.


Previous relevant Language Word Association Game Tutorial is shown below.

Language Word Association Game Tutorial

Language Word Association Game Tutorial

Yesterday we created English Word Association Game Primer Tutorial as shown below, to show a draft English only version of a Word Association game good for ESL purposes.

Today we build on that functionality by allowing Word Associations in French or German or Spanish or Italian (the other languages offered with altervista thesaurus web service database with Yahoo YQL), in addition, as long as the user supplies the first “seed” word for these languages. Everything about the English functionality stays as is … keeping backward compatibility, as you’d see by clicking the picture of the tutorial below, where you play the English (only) Word Association Game, as we had it yesterday.

With yesterday’s yesterday’s Yahoo YQL Web Service JSON Thesaurus Tutorial, using Yahoo Web Services called YQL, as shown below, building on previous ones here at this blog, we effectively signed off on the final (supplementing recent PHP/CSS Sentence Auxiliary Verb Game Tutorial showing CSS #[elementID]:before { content: [prefixContent]; } and #[elementID]:after { content: [suffixContent]; } functionality presented on the day before yesterday) impediment to writing an English Word Association game a teacher of ESL could use for the teaching of vocabulary for an advanced student learning English as their second language (or maybe their first?!). The YQL name is the way it is because it simplified the API aspects of its functionality for the developer to concentrate on SQL, and I’m really supportive of this concept. You don’t have to output in JSON, as other data forms like XML are acceptable. Let’s see what Wikipedia says about YQL below.

Yahoo! Query Language (YQL) is an SQL-like query language created by Yahoo! as part of their Developer Network. YQL is designed to retrieve and manipulate data from APIs through a single Web interface, thus allowing mashups that enable developers to create their own applications.[1]

Initially launched in October 2008 with access to Yahoo APIs,[2] February 2009 saw the addition of open data tables from third parties such as Google Reader, the Guardian, and The New York Times.[3] Some of these APIs still require an API key to access them. On April 29th of 2009, Yahoo introduced the capability to execute the tables of data built through YQL using JavaScript run on the company’s servers for free.[3]

So this tutorial builds on the logic of the thesaurus tutorial of yesterday to use a YQL web service into data emanating from its links to the altervista thesaurus web service database with Yahoo YQL website … thanks. For the altervista thesaurus database usage it is best to request a key for your web service queries. You fill in a word (or two, or three) of interest to search for like-minded words.

And what is a thesaurus? Recap on yesterday, perhaps, by reading what Wikipedia says here but, basically, it can be thought of as a repository of a language’s list of words of a similar meaning to the word of your interest. It is a great tool for people learning a language foreign to them, especially regarding their vocabulary.

With word association, as you might imagine, a thesaurus comes in handy for the words associated with the original word and its chosen followers, but if we want a feature to be, in English execution runs, that we can supply that first English word programmatically, we need functionality like for PHP/Javascript Words Within Words Game Tutorial to get that initial English “seed” word chosen from a dictionary. For the French or German or Spanish or Italian parts of the functionality the user supplies this first “seed” word, and then the thesaurus kicks in in a programmatical way from then on, as for the English functionality.

Here is a link to some downloadable PHP programming source code which you may want to rename to word_association.php (and then there is a PHP live run).

How we got there … word_association.php


Previous relevant English Word Association Game Primer Tutorial is shown below.

English Word Association Game Primer Tutorial

English Word Association Game Primer Tutorial

With yesterday’s Yahoo YQL Web Service JSON Thesaurus Tutorial, using Yahoo Web Services called YQL, as shown below, building on previous ones here at this blog, we effectively signed off on the final (supplementing recent PHP/CSS Sentence Auxiliary Verb Game Tutorial showing CSS #[elementID]:before { content: [prefixContent]; } and #[elementID]:after { content: [suffixContent]; } functionality presented on the day before yesterday) impediment to writing an English Word Association game a teacher of ESL could use for the teaching of vocabulary for an advanced student learning English as their second language (or maybe their first?!). The YQL name is the way it is because it simplified the API aspects of its functionality for the developer to concentrate on SQL, and I’m really supportive of this concept. You don’t have to output in JSON, as other data forms like XML are acceptable. Let’s see what Wikipedia says about YQL below.

Yahoo! Query Language (YQL) is an SQL-like query language created by Yahoo! as part of their Developer Network. YQL is designed to retrieve and manipulate data from APIs through a single Web interface, thus allowing mashups that enable developers to create their own applications.[1]

Initially launched in October 2008 with access to Yahoo APIs,[2] February 2009 saw the addition of open data tables from third parties such as Google Reader, the Guardian, and The New York Times.[3] Some of these APIs still require an API key to access them. On April 29th of 2009, Yahoo introduced the capability to execute the tables of data built through YQL using JavaScript run on the company’s servers for free.[3]

So this tutorial builds on the logic of the thesaurus tutorial of yesterday to use a YQL web service into data emanating from its links to the altervista thesaurus web service database with Yahoo YQL website … thanks. For the altervista thesaurus database usage it is best to request a key for your web service queries. You fill in a word (or two, or three) of interest to search for like-minded words.

And what is a thesaurus? Recap on yesterday, perhaps, by reading what Wikipedia says here but, basically, it can be thought of as a repository of a language’s list of words of a similar meaning to the word of your interest. It is a great tool for people learning a language foreign to them, especially regarding their vocabulary.

With word association, as you might imagine, a thesaurus comes in handy for the words associated with the original word and its chosen followers, but we need functionality like for PHP/Javascript Words Within Words Game Tutorial to get that initial “seed” word chosen from a dictionary.

Here is a link to some downloadable PHP programming source code which you may want to rename to word_association.php (and then there is a PHP live run).

Did you know?

Again we use PHP and we hope this is not frustrating those readers who have no PHP installed? It is easy to install PHP web server language (and Apache web server with MySql database) locally for Windows or Mac and would recommend, respectively, EasyPHP Windows Framework for PHP/MySql Tutorial and MAMP Mac Framework for PHP/MySql Tutorial for (install) advice here.


Previous relevant Yahoo YQL Web Service JSON Thesaurus Tutorial is shown below.

Yahoo YQL Web Service JSON Thesaurus Tutorial

Yahoo YQL Web Service JSON Thesaurus Tutorial

Here is a tutorial that might be re-introducing you to the Yahoo Web Services called YQL, building on previous ones here at this blog. The name is the way it is because it simplified the API aspects of its functionality for the developer to concentrate on SQL, and I’m really supportive of this concept. You don’t have to output in JSON, as other data forms like XML are acceptable. Let’s see what Wikipedia says about YQL below.

Yahoo! Query Language (YQL) is an SQL-like query language created by Yahoo! as part of their Developer Network. YQL is designed to retrieve and manipulate data from APIs through a single Web interface, thus allowing mashups that enable developers to create their own applications.[1]

Initially launched in October 2008 with access to Yahoo APIs,[2] February 2009 saw the addition of open data tables from third parties such as Google Reader, the Guardian, and The New York Times.[3] Some of these APIs still require an API key to access them. On April 29th of 2009, Yahoo introduced the capability to execute the tables of data built through YQL using JavaScript run on the company’s servers for free.[3]

So this tutorial uses a YQL web service into the data emanating from its links to the altervista thesaurus web service database with Yahoo YQL website … thanks. For the altervista thesaurus database usage it is best to request a key for your web service queries. You fill in a word (or two, or three) of interest to search for like-minded words.

And what is a thesaurus? Read what Wikipedia says here but, basically, it can be thought of as a repository of a language’s list of words of a similar meaning to the word of your interest. It is a great tool for people learning a language foreign to them, especially regarding their vocabulary.

The two big PHP functions of use (as distinct from an Ajax approach, requiring no PHP … read on) for this are:

  • file_get_contents
  • json_decode … when there is a data structure of any complexity, this function is highly recommended, but for today’s tutorial we do not use it, and take the opportunity to show you a solution using Ajax that requires no PHP … link to some downloadable Ajax inspired HTML programming source code which you may want to rename to Ajax_yql_thesaurus.html which changes from the HTML supervising PHP approach as per Ajax_yql_thesaurus.html (and then there is an Ajax live run)

Good links for information regarding this tutorial (thanks) are:

Another tool you should have in your armoury for jobs like this is the online JSON validator here. A generic JSON approach to issues could be:

  1. Type the URL you were given into a web browser address bar and have a look at it
  2. Type the URL you were given into http://jsonlint.com/ and have it validated
  3. Understand in your own mind what would be different about 1. to make it suitable
  4. Incorporate findings of 3. into massaging of data between file_get_contents and json_decode

Here is a link to some downloadable HTML programming source code which you may want to rename to yql_thesaurus.html which calls some downloadable PHP programming source code which you may want to rename to yql_thesaurus.php (and then there is a PHP live run).

We thank the following free online dictionaries …

Stay tuned for an interesting blog posting tomorrow which combines the new thesaurus functionality of today’s contribution, along with the functionality “smarts” of yesterday’s PHP/CSS Sentence Auxiliary Verb Game Tutorial.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Games, Tutorials and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *