setName('thesaurus:find:concepts') ->setDescription('Infer concepts using thesaurus') ->addArgument( 'term', InputArgument::REQUIRED, 'Reverse search a term to infer concepts' ) ->addArgument( 'context', InputArgument::OPTIONAL, 'Restrict search to a specific term context' ) ->addOption( 'locale', null, InputOption::VALUE_REQUIRED, 'Specify input locale' ) ->addOption( 'strict', null, InputOption::VALUE_NONE, 'Strict mode (enforce term context matching)' ) ->addOption( 'broad', null, InputOption::VALUE_NONE, 'Keep broad concepts (discards narrower concepts)' ) ->addOption( 'raw', null, InputOption::VALUE_NONE, 'Only output raw concepts' ) ; } protected function doExecute(InputInterface $input, OutputInterface $output) { $term = $input->getArgument('term'); $context = $input->getArgument('context'); $raw = $input->getOption('raw'); if (!$raw) { $message = sprintf('Finding linked concepts: %s', $term); if ($context) { $message .= sprintf(' (with context %s)', $context); } $output->writeln($message); $output->writeln(str_repeat('-', 20)); } $thesaurus = $this->container['thesaurus']; $term = new Term($term, $context); $locale = $input->getOption('locale'); $strict = $input->getOption('strict'); $concepts = $thesaurus->findConcepts($term, $locale, null, $strict); if ($input->getOption('broad')) { $concepts = Concept::pruneNarrowConcepts($concepts); } if (count($concepts)) { $output->writeln($concepts); } elseif (!$raw) { $output->writeln('No concept found'); } } }