-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuclassify.php
More file actions
150 lines (126 loc) · 4.02 KB
/
uclassify.php
File metadata and controls
150 lines (126 loc) · 4.02 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* A PHP5 uClassify URL API Wrapper Class
*
* Encapsulates the uClassify URL API
* see http://uclassify.com/UrlApiDocumentation.aspx
*
* Requires a uClassify read key which you can get from uClassify.com
*
* @author Mark Thompson <mark@smithandthompson.net>
*
**/
class uClassify {
// private properties
private $baseUrl = 'http://uclassify.com/browse/';
private $provider = "uClassify";
private $readkey = '***YOUR_READ_KEY***';
private $removeHTML = 1;
private $encoding = 'json';
private $version = '1.01';
private $classifier = "topics"; // default to topics command
private $classifier_whitelist = array( 'topics'=>'uClassify',
'society topics'=>'uClassify',
'home topics'=>'uClassify',
'art topics'=>'uClassify',
'game topics'=>'uClassify',
'health topics'=>'uClassify',
'computer topics'=>'uClassify',
'business topics'=>'uClassify',
'recreation topics'=>'uClassify',
'sport topics'=>'uClassify',
'science topics'=>'uClassify',
'text language'=>'uClassify',
'sentiment'=>'uClassify',
'ageanalyzer'=>'uClassify',
'genderanalyzer_v5'=>'uClassify',
'classics'=>'uClassify',
'mood'=>'prfekt',
'tonality'=>'prfekt',
'myers briggs judging function'=>'prfekt',
'myers briggs lifestyle'=>'prfekt',
'myers briggs attitude'=>'prfekt',
'myers briggs perceiving function'=>'prfekt');
// Class methods
public function __construct() {
//echo 'The class "', __CLASS__, '" was initiated!<br />';
}
public function __destruct() {
//echo 'The class "', __CLASS__, '" was destroyed.<br />';
}
public function __toString() {
return implode(', ', get_object_vars($this));
}
// Property accessors
// set removeHTML
public function setRemoveHTML($trueOrFalse) {
if($trueOrFalse){
$this->removeHTML = 1;
} else {
$this->removeHTML = 0;
}
return $this->removeHTML;
}
// get removeHTML
public function getRemoveHTML() {
return $this->removeHTML;
}
// set encoding
public function setEncoding($newEncoding) {
if($newEncoding == 'xml' || $newEncoding == 'json'){
$this->removeHTML = $newEncoding;
return 0;
} else {
return -1;
}
}
// get encoding
public function getEncoding() {
return $this->Encoding;
}
//set the classifier
public function setClassifier($c){
if(array_key_exists(strtolower($c),$this->classifier_whitelist)){
$this->classifier = $c;
$this->provider = $this->classifier_whitelist[$c];
return 0;
} else {
return -1;
}
}
// get the current classifier
public function getClassifier(){
return $this->classifier;
}
// classify a URL & return the scored classification
public function classifyUrl($url) {
// assemble the query string
$qs = $this->baseUrl.$this->provider."/".str_replace(' ','%20',$this->classifier).'/ClassifyUrl/?readkey='.urlencode($this->readkey).
'&url='.urlencode($url).'&removeHtml='.$this->removeHTML.'&output='.$this->encoding."&version=".$this->version;
// instantiate cUrl
$curl = curl_init($qs);
// set options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
// execute, close & return result
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
// classify some text & return the scored classification
public function classifyText($txt) {
// assemble the query string
$qs = $this->baseUrl.$this->provider."/".ucwords($this->classifier).'/ClassifyText/?readkey='.urlencode($this->readkey).
'&text='.urlencode($url).'&removeHtml='.$this->removeHTML.'&output='.$this->encoding."&version=".$this->version;
// instantiate cUrl
$curl = curl_init($qs);
// set options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
// execute, close & return result
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
}
?>