-
Notifications
You must be signed in to change notification settings - Fork 4
/
TwemoteDict.php
62 lines (58 loc) · 1.35 KB
/
TwemoteDict.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @package Twemote
* @copyright Hackersquad (Refer README for details)
* @description Generates the dictionary meaning of a particular word.
*/
class TwemoteDict {
public $outputstring;
public $p;
public function __construct()
{
$this->outputstring ="";
}
public function input($params)
{
$this->p = $params[0];
}
public function output()
{
return $this->lookup($this->p);
}
public function lookup($params)
{
require("Wordnik.php");
$api_key = "d1aa3e2004ffb04eb15050fa244069def43fb2b4b282e6da3";
$wordnik = Wordnik::instance($api_key);
$wordstring = $params;
$definitions = $wordnik->getDefinitions($wordstring);
$this->outputstring = $wordstring.":\n";
if (empty($definitions))
{
$this->outputstring = "Not Found";
return ;
}
else
{
foreach($definitions as $definition) {
if (isset($definition->text)) {
$this->outputstring = $this->outputstring.$definition->text." ; ";
}
}
}
$this->outputstring = $this->outputstring."\r\n"."Usage : ";
$examples = $wordnik->getExamples($wordstring);
if (empty($examples))
{
}
else
{
$example = $examples[0];
if (isset($example->display)) {
$this->outputstring = $this->outputstring."\n".$example->display;
}
}
return $this->outputstring;
}
}
?>