<NME> README.md
<BEF> # PHP Classifier

[![Build Status](https://travis-ci.org/camspiers/statistical-classifier.png?branch=master)](https://travis-ci.org/camspiers/statistical-classifier)
[![Latest Stable Version](https://poser.pugx.org/camspiers/statistical-classifier/v/stable.png)](https://packagist.org/packages/camspiers/statistical-classifier)

PHP Classifier uses [semantic versioning](http://semver.org/), it is currently at major version 0, so the public API should not be considered stable.

# What is it?

PHP Classifier is a text classification library with a focus on reuse, customizability and performance.
Classifiers can be used for many purposes, but are particularly useful in detecting spam.

## Features

* Complement Naive Bayes Classifier
* SVM (libsvm) Classifier
* Highly customizable (easily modify or build your own classifier)
* Command-line interface via separate library (phar archive)
* Multiple **data import types** to get your data into the classifier (Directory of files, Database queries, Json, Serialized arrays)
* Multiple types of **model caching**
* Compatible with HipHop VM

# Installation

```bash
$ composer require camspiers/statistical-classifier
```

## SVM Support

For SVM Support both libsvm and php-svm are required. For installation intructions refer to [php-svm](https://github.com/ianbarber/php-svm).

# Usage

## Non-cached Naive Bayes

```php
use Camspiers\StatisticalClassifier\Classifier\ComplementNaiveBayes;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray();
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
```bash
$ composer create-project camspiers/statistical-classifier .
$ ln -s $PWD/bin/classifier /usr/local/bin/classifier
``

## SVM Support


## Non-cached SVM

```php
use Camspiers\StatisticalClassifier\Classifier\SVM;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray()
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
$source->addDocument('ham', 'Some ham document');
$source->addDocument('ham', 'Another ham document');

$classifier = new SVM($source);
$classifier->is('ham', 'Some ham document'); // bool(true)
$classifier->classify('Some ham document'); // string "ham"
```

# Caching models

Caching models requires [maximebf/CacheCache](https://github.com/maximebf/CacheCache) which can be installed via packagist. Additional caching systems can be easily integrated.

## Cached Naive Bayes

```php
use Camspiers\StatisticalClassifier\Classifier\ComplementNaiveBayes;
use Camspiers\StatisticalClassifier\Model\CachedModel;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray();
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
$source->addDocument('ham', 'Some ham document');
$source->addDocument('ham', 'Another ham document');

$model = new CachedModel(
	'mycachename',
	new CacheCache\Cache(
		new CacheCache\Backends\File(
			array(
				'dir' => __DIR__
			)
		)
	)
);

$classifier = new ComplementNaiveBayes($source, $model);
$classifier->is('ham', 'Some ham document'); // bool(true)
$classifier->classify('Some ham document'); // string "ham"
```

## Cached SVM

```php
use Camspiers\StatisticalClassifier\Classifier\SVM;
use Camspiers\StatisticalClassifier\Model\SVMCachedModel;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray();
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
$source->addDocument('ham', 'Some ham document');
$source->addDocument('ham', 'Another ham document');

$model = new Model\SVMCachedModel(
	__DIR__ . '/model.svm',
	new CacheCache\Cache(
		new CacheCache\Backends\File(
			array(
				'dir' => __DIR__
			)
		)
	)
);

$classifier = new SVM($source, $model);
$classifier->is('ham', 'Some ham document'); // bool(true)
$classifier->classify('Some ham document'); // string "ham"
```

# Unit testing

    statistical-classifier/ $ composer install --dev
    statistical-classifier/ $ phpunit

<MSG> MINOR: Error in readme syntac 

<DFF> @@ -44,7 +44,7 @@ $ composer requre camspiers/statistical-classifier:~0.4
 ```bash
 $ composer create-project camspiers/statistical-classifier .
 $ ln -s $PWD/bin/classifier /usr/local/bin/classifier
-``
+```
 
 ## SVM Support
 

{'commit': 'diff --git a/README.md b/README.md\nindex 3583b99..5167e97 100644\n--- a/README.md\n+++ b/README.md\n@@ -44,7 +44,7 @@ $ composer requre camspiers/statistical-classifier:~0.4\n ```bash\n $ composer create-project camspiers/statistical-classifier .\n $ ln -s $PWD/bin/classifier /usr/local/bin/classifier\n-``\n+```\n \n ## SVM Support\n \n', 'commit_subject': 'MINOR: Error in readme syntac\u2028', 'repo_name': 'camspiers/statistical-classifier', 'committer': {'name': 'Cam Spiers', 'email': 'd96ec68f3ee228db786dde6d30502bb5d9a30328@gmail.com', 'time_sec': '1365337599', 'tz_offset': '720', 'date': {'seconds': '1365337599'}}, 'commit_tree': 'e0dde1cd28fa4451fa5230cd98871d4ea3edc9bc', 'commit_message': 'MINOR: Error in readme syntac\u2028\n', 'language_name': 'PHP', 'license': 'mit', 'hunks': '@@ -44,7 +44,7 @@ $ composer requre camspiers/statistical-classifier:~0.4\n ```bash\n $ composer create-project camspiers/statistical-classifier .\n $ ln -s $PWD/bin/classifier /usr/local/bin/classifier\n-``\n+```\n \n ## SVM Support\n \n', 'addition_count': 1, 'deletion_count': 1, 'src_file': 'a/README.md', 'tgt_file': 'b/README.md', 'file_extension': '.md', 'before_file': '# PHP Classifier\n\n[![Build Status](https://travis-ci.org/camspiers/statistical-classifier.png?branch=master)](https://travis-ci.org/camspiers/statistical-classifier)\n[![Latest Stable Version](https://poser.pugx.org/camspiers/statistical-classifier/v/stable.png)](https://packagist.org/packages/camspiers/statistical-classifier)\n\nPHP Classifier uses [semantic versioning](http://semver.org/), it is currently at major version 0, so the public API should not be considered stable.\n\n# What is it?\n\nPHP Classifier is a text classification library with a focus on reuse, customizability and performance.\nClassifiers can be used for many purposes, but are particularly useful in detecting spam.\n\n## Features\n\n* Complement Naive Bayes Classifier\n* SVM (libsvm) Classifier\n* Highly customizable (easily modify or build your own classifier)\n* Command-line interface via separate library (phar archive)\n* Multiple **data import types** to get your data into the classifier (Directory of files, Database queries, Json, Serialized arrays)\n* Multiple types of **model caching**\n* Compatible with HipHop VM\n\n# Installation\n\n```bash\n$ composer require camspiers/statistical-classifier\n```\n\n## SVM Support\n\nFor SVM Support both libsvm and php-svm are required. For installation intructions refer to [php-svm](https://github.com/ianbarber/php-svm).\n\n# Usage\n\n## Non-cached Naive Bayes\n\n```php\nuse Camspiers\\StatisticalClassifier\\Classifier\\ComplementNaiveBayes;\nuse Camspiers\\StatisticalClassifier\\DataSource\\DataArray;\n\n$source = new DataArray();\n$source->addDocument(\'spam\', \'Some spam document\');\n$source->addDocument(\'spam\', \'Another spam document\');\n```bash\n$ composer create-project camspiers/statistical-classifier .\n$ ln -s $PWD/bin/classifier /usr/local/bin/classifier\n``\n\n## SVM Support\n\n\n## Non-cached SVM\n\n```php\nuse Camspiers\\StatisticalClassifier\\Classifier\\SVM;\nuse Camspiers\\StatisticalClassifier\\DataSource\\DataArray;\n\n$source = new DataArray()\n$source->addDocument(\'spam\', \'Some spam document\');\n$source->addDocument(\'spam\', \'Another spam document\');\n$source->addDocument(\'ham\', \'Some ham document\');\n$source->addDocument(\'ham\', \'Another ham document\');\n\n$classifier = new SVM($source);\n$classifier->is(\'ham\', \'Some ham document\'); // bool(true)\n$classifier->classify(\'Some ham document\'); // string "ham"\n```\n\n# Caching models\n\nCaching models requires [maximebf/CacheCache](https://github.com/maximebf/CacheCache) which can be installed via packagist. Additional caching systems can be easily integrated.\n\n## Cached Naive Bayes\n\n```php\nuse Camspiers\\StatisticalClassifier\\Classifier\\ComplementNaiveBayes;\nuse Camspiers\\StatisticalClassifier\\Model\\CachedModel;\nuse Camspiers\\StatisticalClassifier\\DataSource\\DataArray;\n\n$source = new DataArray();\n$source->addDocument(\'spam\', \'Some spam document\');\n$source->addDocument(\'spam\', \'Another spam document\');\n$source->addDocument(\'ham\', \'Some ham document\');\n$source->addDocument(\'ham\', \'Another ham document\');\n\n$model = new CachedModel(\n\t\'mycachename\',\n\tnew CacheCache\\Cache(\n\t\tnew CacheCache\\Backends\\File(\n\t\t\tarray(\n\t\t\t\t\'dir\' => __DIR__\n\t\t\t)\n\t\t)\n\t)\n);\n\n$classifier = new ComplementNaiveBayes($source, $model);\n$classifier->is(\'ham\', \'Some ham document\'); // bool(true)\n$classifier->classify(\'Some ham document\'); // string "ham"\n```\n\n## Cached SVM\n\n```php\nuse Camspiers\\StatisticalClassifier\\Classifier\\SVM;\nuse Camspiers\\StatisticalClassifier\\Model\\SVMCachedModel;\nuse Camspiers\\StatisticalClassifier\\DataSource\\DataArray;\n\n$source = new DataArray();\n$source->addDocument(\'spam\', \'Some spam document\');\n$source->addDocument(\'spam\', \'Another spam document\');\n$source->addDocument(\'ham\', \'Some ham document\');\n$source->addDocument(\'ham\', \'Another ham document\');\n\n$model = new Model\\SVMCachedModel(\n\t__DIR__ . \'/model.svm\',\n\tnew CacheCache\\Cache(\n\t\tnew CacheCache\\Backends\\File(\n\t\t\tarray(\n\t\t\t\t\'dir\' => __DIR__\n\t\t\t)\n\t\t)\n\t)\n);\n\n$classifier = new SVM($source, $model);\n$classifier->is(\'ham\', \'Some ham document\'); // bool(true)\n$classifier->classify(\'Some ham document\'); // string "ham"\n```\n\n# Unit testing\n\n    statistical-classifier/ $ composer install --dev\n    statistical-classifier/ $ phpunit\n', 'message': 'MINOR: Error in readme syntac\u2028\n', 'author_name': 'Cam Spiers', 'lang': 'md'}