/** * Automatically extracts and replaces the category, keywords and entities * for a data object. * * @param DataObject $object */ public function alchemise(DataObject $object) { if (!$object->hasExtension('Alchemisable')) { throw new Exception('The object must have the Alchemisable extension.'); } $text = $object->getContentForAlchemy(); if (strlen($text) < $this->charLimit) { return; } $alchemyInfo = $object->AlchemyMetadata->getValues(); if (!$alchemyInfo) { $alchemyInfo = array(); } $cat = $this->getCategoryFor($text); $keywords = $this->getKeywordsFor($text); $entities = $this->getEntitiesFor($text); $alchemyInfo['Category'] = $cat; $alchemyInfo['Keywords'] = $keywords; $alchemyInfo['Entities'] = $entities; $object->AlchemyMetadata = $alchemyInfo; // foreach (Alchemisable::entity_fields() as $field => $name) { // $name = substr($field, 3); // // if (array_key_exists($name, $entities)) { // $object->$field = $entities[$name]; // } else { // $object->$field = array(); // } // } }