<commit_before><?php
namespace Koklu\Service;

use Doctrine\ODM\MongoDB\DocumentManager;
use Koklu\Model\ItemManager;
use Koklu\Model\Recommender;

class RecommenderService
{
    /** @var ItemManager */
    protected $_itemManager;
    /** @var Recommender */
    protected $_recommender;

    /**
     * @param DocumentManager $documentManager
     */
    public function __construct(DocumentManager $documentManager)
    {
        $this->_itemManager = new ItemManager($documentManager);
        $this->_recommender = new Recommender($documentManager, $this->_itemManager);
    }

    /**
     * @param string|array $itemIds
     * @param string|null  $collection
     * @param int|bool     $limit
     * @return array
     */
    public function recommend($itemIds, $collection = null, $limit = false)
    {
        return $this->_recommender->recommend($itemIds, $collection, $limit);
    }

    /**
     * @param int         $itemId
     * @param array       $data
     * @param string|null $collection
     */
    public function post($itemId, array $data, $collection = null)
    {
        $item = $this->_itemManager->get($itemId, $collection);
        if ($item) {
            $this->delete($item, $collection);
        }

        $item = $this->_itemManager->post($itemId, $data);
        $this->_recommender->onPost($item);
    }

    /**
     * @param string|Item $item
     * @param string|null $collection
     */
    public function delete($item, $collection = null)
    {
        if (is_string($item)) {
            $item = $this->_itemManager->get($item, $collection);
        }
        if ($item) {
            $this->_itemManager->delete($item, $collection);
            $this->_recommender->onDelete($item);
        }
    }
}<commit_msg>simplified delete<commit_after><?php
namespace Koklu\Service;

use Doctrine\ODM\MongoDB\DocumentManager;
use Koklu\Model\ItemManager;
use Koklu\Model\Recommender;

class RecommenderService
{
    /** @var ItemManager */
    protected $_itemManager;
    /** @var Recommender */
    protected $_recommender;

    /**
     * @param DocumentManager $documentManager
     */
    public function __construct(DocumentManager $documentManager)
    {
        $this->_itemManager = new ItemManager($documentManager);
        $this->_recommender = new Recommender($documentManager, $this->_itemManager);
    }

    /**
     * @param string|array $itemIds
     * @param string|null  $collection
     * @param int|bool     $limit
     * @return array
     */
    public function recommend($itemIds, $collection = null, $limit = false)
    {
        return $this->_recommender->recommend($itemIds, $collection, $limit);
    }

    /**
     * @param int         $itemId
     * @param array       $data
     * @param string|null $collection
     */
    public function post($itemId, array $data, $collection = null)
    {
        $this->delete($itemId, $collection);
        $item = $this->_itemManager->post($itemId, $data);
        $this->_recommender->onPost($item);
    }

    /**
     * @param string      $itemId
     * @param string|null $collection
     */
    public function delete($itemId, $collection = null)
    {
        $item = $this->_itemManager->get($itemId, $collection);
        if ($item) {
            $this->_itemManager->delete($item, $collection);
            $this->_recommender->onDelete($item);
        }
    }
}
{'fraction_non_alphanumeric': 0.1408284023668639, 'fraction_numerical': 0.0, 'mean_word_length': 2.5292275574112737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '660208', 'n_tokens_mistral': 1001, 'n_tokens_neox': 983, 'n_words': 200}