-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modernizing the codebase for use with PHP namespaces and Composer
- Loading branch information
Curtis Farnham
committed
Jan 24, 2014
1 parent
045eaf0
commit da67ab7
Showing
18 changed files
with
118 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the RNCryptor package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
require __DIR__.'/lib/PHPInsight/Autoloader.php'; | ||
|
||
PHPInsight\Autoloader::register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "jwhennessey/phpinsight", | ||
"type": "library", | ||
"description": "Sentiment analysis tool for PHP", | ||
"keywords": ["sentiment", "insight", "phpinsight"], | ||
"homepage": "https://github.com/JWHennessey/phpInsight", | ||
"license": "GPLv3 or later", | ||
"authors": [ | ||
{ | ||
"name": "James Hennessey" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0", | ||
}, | ||
"autoload": { | ||
"psr-0": {"PHPInsight": "lib/"} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
if (PHP_SAPI != 'cli') { | ||
echo "<pre>"; | ||
} | ||
|
||
$strings = array( | ||
1 => 'Weather today is rubbish', | ||
2 => 'This cake looks amazing', | ||
3 => 'His skills are mediocre', | ||
4 => 'He is very talented', | ||
5 => 'She is seemingly very agressive', | ||
6 => 'Marie was enthusiastic about the upcoming trip. Her brother was also passionate about her leaving - he would finally have the house for himself.', | ||
7 => 'To be or not to be?', | ||
); | ||
|
||
require_once __DIR__ . '/../autoload.php'; | ||
$sentiment = new \PHPInsight\Sentiment(); | ||
|
||
foreach ($strings as $string) { | ||
|
||
// calculations: | ||
$scores = $sentiment->score($string); | ||
$class = $sentiment->categorise($string); | ||
|
||
// output: | ||
echo "String: $string\n"; | ||
echo "Dominant: $class, scores: "; | ||
print_r($scores); | ||
echo "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace PHPInsight; | ||
|
||
class Autoloader | ||
{ | ||
private $directory; | ||
private $prefix; | ||
private $prefixLength; | ||
|
||
/** | ||
* @param string $baseDirectory Base directory where the source files are located. | ||
*/ | ||
public function __construct($baseDirectory = __DIR__) | ||
{ | ||
$this->directory = $baseDirectory; | ||
$this->prefix = __NAMESPACE__ . '\\'; | ||
$this->prefixLength = strlen($this->prefix); | ||
} | ||
|
||
/** | ||
* Registers the autoloader class with the PHP SPL autoloader. | ||
* | ||
* @param bool $prepend Prepend the autoloader on the stack instead of appending it. | ||
*/ | ||
public static function register($prepend = false) | ||
{ | ||
spl_autoload_register(array(new self, 'autoload'), true, $prepend); | ||
} | ||
|
||
/** | ||
* Loads a class from a file using its fully qualified name. | ||
* | ||
* @param string $className Fully qualified name of a class. | ||
*/ | ||
public function autoload($className) | ||
{ | ||
if (0 === strpos($className, $this->prefix)) { | ||
$parts = explode('\\', substr($className, $this->prefixLength)); | ||
$filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php'; | ||
|
||
if (is_file($filepath)) { | ||
require($filepath); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
data/data.ign.php → lib/PHPInsight/data/data.ign.php
100755 → 100644
File renamed without changes.
0
data/data.neg.php → lib/PHPInsight/data/data.neg.php
100755 → 100644
File renamed without changes.
0
data/data.neu.php → lib/PHPInsight/data/data.neu.php
100755 → 100644
File renamed without changes.
0
data/data.pos.php → lib/PHPInsight/data/data.pos.php
100755 → 100644
File renamed without changes.
0
data/data.prefix.php → lib/PHPInsight/data/data.prefix.php
100755 → 100644
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
require __DIR__ . '/PHPInsight/Autoloader.php'; | ||
PHPInsight_Autoloader::register(); |