<commit_before><?php
/**
 * This file belongs to semtools project
 *
 * @copyright 2014 <NAME>
 * @license   The MIT License (MIT) <http://choosealicense.com/licenses/mit/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code or visit the link above.
 */
namespace nv\semtools\Classifiers\uClassify;

use nv\semtools;

/**
 * uClassify Response
 *
 * Encapsulates uClassify response specifics
 *
 * @package nv\semtools\Classifiers\uClassify
 * @author <NAME> <<EMAIL>>
 */
class UclassifyResponse extends semtools\Common\ApiResponseAbstract
{
    // @todo Encapsulate response data: parse XML
}<commit_msg>Implement classification retrieval as array.<commit_after><?php
/**
 * This file belongs to semtools project
 *
 * @copyright 2014 <NAME>
 * @license   The MIT License (MIT) <http://choosealicense.com/licenses/mit/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code or visit the link above.
 */
namespace nv\semtools\Classifiers\uClassify;

use nv\semtools;

/**
 * uClassify Response
 *
 * Encapsulates uClassify response specifics
 *
 * @package nv\semtools\Classifiers\uClassify
 * @author <NAME> <<EMAIL>>
 */
class UclassifyResponse extends semtools\Common\ApiResponseAbstract
{
    /**
     * Get classification data as PHP array
     *
     * @return array
     * @throws \nv\semtools\Exception\ServiceReaderException
     */
    public function getClassification()
    {
        $xml = simplexml_load_string($this->response);
        $result = array();

        if ($xml instanceof \SimpleXMLElement) {
            if ((string) $xml->status->attributes()->success == 'true') {
                foreach ($xml->readCalls->classify as $classify) {
                    foreach ($classify->classification->class as $class) {
                        $result[strtolower($class->attributes()->className)] = (float) $class->attributes()->p;
                    }
                }
                return $result;
            }
            throw new semtools\Exception\ServiceReaderException($xml->status->attributes()->statusCode);
        }
        throw new semtools\Exception\ServiceReaderException('Failed parsing XML response.');
    }
}
{'fraction_non_alphanumeric': 0.11337966985230234, 'fraction_numerical': 0.0034752389226759338, 'mean_word_length': 3.0052173913043476, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3825684', 'n_tokens_mistral': 627, 'n_tokens_neox': 607, 'n_words': 175}