Skip to content

Instantly share code, notes, and snippets.

@v21
Created August 31, 2018 10:33
Show Gist options
  • Save v21/51fd62450dfe07bd06548e3512186571 to your computer and use it in GitHub Desktop.
Save v21/51fd62450dfe07bd06548e3512186571 to your computer and use it in GitHub Desktop.
oulipo word tool
<html>
<head>
<style type="text/css">
.match {
font-weight: bold;
font-size: 125%;
}
.nomatch {
color:#aaa;
}
.match a, .nomatch a {
color: #000;
text-decoration: none;
}
p {
margin: 2px;
}
html, body {
font-family: monospace;
}
h1 {
column-span: all;
}
.results {
column-gap: 4em;
column-width: 300px;
column-fill: auto;
min-height: 100%;
height: auto;
}
</style>
</head>
<body>
<?php
function printSection($result, $section)
{
foreach ($result as $result_section) {
if ($result_section["relationshipType"] === $section) {
echo "<h2>".$section."s</h2>";
foreach ($result_section["words"] as $word) {
if (strpos($word, "e") === false) {
echo("<p class=\"match\"><a href=\"/oulipo/". $word. "\">". $word. "</a></p>");
}
else {
echo("<p class=\"nomatch\"><a href=\"/oulipo/". $word. "\">". $word. "</a></p>");
}
}
}
}
}
$ch = curl_init( "https://api.wordnik.com/v4/word.json/". $_GET["word"] ."/relatedWords?useCanonical=false&limitPerRelationshipType=50&api_key=API KEY GOES HERE");
// Configuring curl options
$options = array(
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_RETURNTRANSFER => true
);
// Setting curl options
curl_setopt_array( $ch, $options );
// Getting results
$json = curl_exec($ch); // Getting jSON result string
$result = json_decode($json, true);
echo "<div class=\"results\">";
echo "<h1>".$_GET["word"]."</h1>";
//print_r( $result);
printSection($result, "equivalent");
printSection($result, "synonym");
printSection($result, "variant");
printSection($result, "hypernym");
printSection($result, "hyponym");
printSection($result, "verb-form");
printSection($result, "etymologically-related-term");
printSection($result, "same-context");
printSection($result, "rhyme");
printSection($result, "antonym");
echo "</div>";
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment