Skip to content

Commit

Permalink
Run composer cs:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
st3iny committed Oct 17, 2024
1 parent 0581ac4 commit 5305b56
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NewCompositeExtractor extends CompositeExtractor {
private SubjectExtractor $subjectExtractor;

public function __construct(VanillaCompositeExtractor $ex1,
SubjectExtractor $ex2) {
SubjectExtractor $ex2) {
parent::__construct([$ex1, $ex2]);
$this->subjectExtractor = $ex2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Datasets\Unlabeled;
use Rubix\ML\Transformers\MinMaxNormalizer;
use Rubix\ML\Transformers\MultibyteTextNormalizer;
use Rubix\ML\Transformers\PrincipalComponentAnalysis;
use Rubix\ML\Transformers\TfIdfTransformer;
use Rubix\ML\Transformers\TSNE;
use Rubix\ML\Transformers\MultibyteTextNormalizer;
use Rubix\ML\Transformers\Transformer;
use Rubix\ML\Transformers\WordCountVectorizer;
use RuntimeException;
Expand Down Expand Up @@ -78,7 +77,7 @@ public function prepare(Account $account, array $incomingMailboxes, array $outgo
->apply(new MultibyteTextNormalizer())
->apply($this->wordCountVectorizer)
->apply($this->tfidf)
;//->apply($this->dimensionalReductionTransformer);
;//->apply($this->dimensionalReductionTransformer);

$this->limitFeatureSize();
}
Expand All @@ -89,7 +88,7 @@ public function prepare(Account $account, array $incomingMailboxes, array $outgo
public function extract(Message $message): array {
$sender = $message->getFrom()->first();
if ($sender === null) {
throw new RuntimeException("This should not happen");
throw new RuntimeException('This should not happen');
}

// Build training data set
Expand All @@ -99,7 +98,7 @@ public function extract(Message $message): array {
->apply(new MultibyteTextNormalizer())
->apply($this->wordCountVectorizer)
->apply($this->tfidf)
;//->apply($this->dimensionalReductionTransformer);
;//->apply($this->dimensionalReductionTransformer);

// Use zeroed vector if no features could be extracted
if ($trainDataSet->numFeatures() === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

class VanillaCompositeExtractor extends CompositeExtractor {
public function __construct(ImportantMessagesExtractor $ex1,
ReadMessagesExtractor $ex2,
RepliedMessagesExtractor $ex3,
SentMessagesExtractor $ex4) {
ReadMessagesExtractor $ex2,
RepliedMessagesExtractor $ex3,
SentMessagesExtractor $ex4) {
parent::__construct([
$ex1,
$ex2,
Expand Down
10 changes: 3 additions & 7 deletions lib/Service/Classification/ImportanceClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\Service\Classification\FeatureExtraction\IExtractor;
use OCA\Mail\Service\Classification\FeatureExtraction\NewCompositeExtractor;
use OCA\Mail\Service\Classification\FeatureExtraction\SubjectExtractor;
use OCA\Mail\Service\Classification\FeatureExtraction\VanillaCompositeExtractor;
use OCA\Mail\Support\PerformanceLogger;
use OCA\Mail\Support\PerformanceLoggerTask;
Expand All @@ -34,13 +33,10 @@
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Datasets\Unlabeled;
use Rubix\ML\Estimator;
use Rubix\ML\Kernels\Distance\Manhattan;
use Rubix\ML\Kernels\Distance\Jaccard;
use Rubix\ML\Learner;
use Rubix\ML\Persistable;
use Rubix\ML\Transformers\TfIdfTransformer;
use Rubix\ML\Transformers\Transformer;
use Rubix\ML\Transformers\WordCountVectorizer;
use RuntimeException;
use function array_column;
use function array_combine;
Expand Down Expand Up @@ -333,7 +329,7 @@ public function trainWithCustomDataSet(
/** @var Learner&Estimator&Persistable $persistedEstimator */
$persistedEstimator = $estimator();
$this->trainClassifier($persistedEstimator, $dataSet);
$perf->step("train classifier with full data set");
$perf->step('train classifier with full data set');

// Extract persisted transformers of the subject extractor.
// Is a bit hacky but a full abstraction would be overkill.
Expand Down Expand Up @@ -437,8 +433,8 @@ private function getFeaturesAndImportance(Account $account,
* @throws ServiceException
*/
public function classifyImportance(Account $account,
array $messages,
LoggerInterface $logger): array {
array $messages,
LoggerInterface $logger): array {
$pipeline = null;
try {
$pipeline = $this->persistenceService->loadLatest($account);
Expand Down
19 changes: 10 additions & 9 deletions lib/Service/Classification/PersistenceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function __construct(ClassifierMapper $mapper,
* @throws ServiceException
*/
public function persist(Classifier $classifier,
Learner $estimator,
array $transformers): void {
Learner $estimator,
array $transformers): void {
/*
* First we have to insert the row to get the unique ID, but disable
* it until the model is persisted as well. Otherwise another process
Expand Down Expand Up @@ -147,7 +147,7 @@ public function persist(Classifier $classifier,
$file = $folder->newFile((string)$classifier->getId());
$file->putContent($serializedClassifier);
$this->logger->debug('Serialized classifier written to app data');
} catch (NotPermittedException | NotFoundException $e) {
} catch (NotPermittedException|NotFoundException $e) {
throw new ServiceException('Could not create classifiers directory: ' . $e->getMessage(), 0, $e);
}

Expand All @@ -171,14 +171,14 @@ public function persist(Classifier $classifier,
$serializedTransformer = file_get_contents($tmpPath);
$this->logger->debug('Serialized transformer written to tmp file (' . strlen($serializedTransformer) . 'B');
} catch (RuntimeException $e) {
throw new ServiceException("Could not serialize transformer: " . $e->getMessage(), 0, $e);
throw new ServiceException('Could not serialize transformer: ' . $e->getMessage(), 0, $e);
}

try {
$file = $folder->newFile("{$classifier->getId()}_t$transformerIndex");
$file->putContent($serializedTransformer);
$this->logger->debug("Serialized transformer $transformerIndex written to app data");
} catch (NotPermittedException | NotFoundException $e) {
} catch (NotPermittedException|NotFoundException $e) {
throw new ServiceException(
"Failed to persist transformer $transformerIndex: " . $e->getMessage(),
0,
Expand Down Expand Up @@ -275,7 +275,7 @@ public function load(Classifier $classifier): ClassifierPipeline {

try {
$serializedTransformer = $transformerFile->getContent();
} catch (NotFoundException | NotPermittedException $e) {
} catch (NotFoundException|NotPermittedException $e) {
$this->logger->debug("Could not load content for transformer file $i with classifier id $id: " . $e->getMessage());
throw new ServiceException("Could not load content for transformer file $i with classifier id $id: " . $e->getMessage(), 0, $e);
}
Expand Down Expand Up @@ -350,6 +350,7 @@ private function deleteModel(int $id): void {
'exception' => $e,
]);
}
}

/**
* Load and instantiate extractor based on a classifier's app version.
Expand All @@ -362,7 +363,7 @@ private function deleteModel(int $id): void {
* @throws ServiceException
*/
private function loadExtractor(Classifier $classifier,
ClassifierPipeline $pipeline): IExtractor {
ClassifierPipeline $pipeline): IExtractor {
$appVersion = $this->parseAppVersion($classifier->getAppVersion());
if ($appVersion[0] >= 3 && $appVersion[1] >= 2) {
return $this->loadExtractorV2($pipeline->getTransformers());
Expand Down Expand Up @@ -390,11 +391,11 @@ private function loadExtractorV1(): VanillaCompositeExtractor {
private function loadExtractorV2(array $transformers): NewCompositeExtractor {
$wordCountVectorizer = $transformers[0];
if (!($wordCountVectorizer instanceof WordCountVectorizer)) {
throw new ServiceException("Failed to load persisted transformer: Expected " . WordCountVectorizer::class . ", got" . $wordCountVectorizer::class);
throw new ServiceException('Failed to load persisted transformer: Expected ' . WordCountVectorizer::class . ', got' . $wordCountVectorizer::class);
}
$tfidfTransformer = $transformers[1];
if (!($tfidfTransformer instanceof TfIdfTransformer)) {
throw new ServiceException("Failed to load persisted transformer: Expected " . TfIdfTransformer::class . ", got" . $tfidfTransformer::class);
throw new ServiceException('Failed to load persisted transformer: Expected ' . TfIdfTransformer::class . ', got' . $tfidfTransformer::class);
}

$subjectExtractor = new SubjectExtractor();
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Sync/ImapToDbSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ private function runPartialSync(
try {
$importantTag = $this->tagMapper->getTagByImapLabel(Tag::LABEL_IMPORTANT, $account->getUserId());
} catch (DoesNotExistException $e) {
$this->logger->error('Could not find important tag for ' . $account->getUserId(). ' ' . $e->getMessage(), [
$this->logger->error('Could not find important tag for ' . $account->getUserId() . ' ' . $e->getMessage(), [
'exception' => $e,
]);
}
Expand Down

0 comments on commit 5305b56

Please sign in to comment.