Exemplo n.º 1
0
  private static function getController(RestResponse $response, $path_array) {
    // Check versions of the api.
    if ('v1' != $path_array[0]) {
      die(RestUtils::sendResponse(501));
    }
    try {
      if ('tag' == $path_array[1]) {
        include './tagger/Tagger.php';
        $tagger = Tagger::getTagger();
        if ($response->getRequestVars('url')) {
          $text = file_get_contents($response->getRequestVars('url'));
        } else if ($response->getRequestVars('text')) {
          $text = $response->getRequestVars('text');
        } else {
          RestUtils::sendResponse(500, 'Missing argument: text or url');
        }
        
        $configuration = $tagger->getConfiguration();

        if (empty($configuration['vocab_names'])) {
          RestUtils::sendResponse(500, 'No configured vocabs');
        }

        return $tagger->tagText(
            $text,
            $configuration['vocab_names'],
            $response->getRequestVars('disambiguate') ? true : false,
            $response->getRequestVars('uris') ? true : false,
            $response->getRequestVars('unmatched') ? true : false,
            $response->getRequestVars('markup') ? true : false,
            $response->getRequestVars('nl2br') ? true : false
          );
      }
    }
    catch (Exception $e) {
      die(RestUtils::sendResponse(400));
    }
    die(RestUtils::sendResponse(404));
  }