'Calais Configuration', 'description' => 'Configurations for Calais', 'page callback' => 'drupal_get_form', 'page arguments' => array('calais_api_admin_settings'), 'access arguments' => array('administer calais api'), ); $items['admin/settings/calais/calais-api'] = array( 'title' => 'Calais API Settings', 'description' => 'Configurations for Calais API', 'type' => MENU_DEFAULT_LOCAL_TASK, ); // Used for testing/debug $items['admin/settings/calais/test'] = array( 'title' => 'Calais Tester Page', 'description' => 'Calais Test Call', 'page callback' => 'calais_call_test', 'access arguments' => array('administer calais api'), 'type' => MENU_CALLBACK, ); return $items; } /** * Build the admin settings form. */ function calais_api_admin_settings() { $form = array(); $calais_url = array( '!calaisurl' => l(t('Calais Website'), 'http://www.opencalais.com/user/register') ); $form['calais_api_key'] = array( '#type' => 'textfield', '#title' => t('Calais API Key'), '#default_value' => variable_get('calais_api_key', NULL), '#size' => 60, '#description' => t('You need to obtain an API Key from the !calaisurl first', $calais_url), ); $form['calais_api_allow_searching'] = array( '#type' => 'checkbox', '#title' => t('Allow Calais Searching'), '#default_value' => variable_get('calais_api_allow_searching', NULL), '#description' => t('Indicates whether future searches can be performed on the extracted metadata by Calais'), ); $form['calais_api_allow_distribution'] = array( '#type' => 'checkbox', '#title' => t('Allow Calais Distribution'), '#default_value' => variable_get('calais_api_allow_distribution', NULL), '#description' => t('Indicates whether the extracted metadata can be distributed by Calais'), ); $form = system_settings_form($form); return $form; } /** * Analyze the content via Calais. * * @param $content The content to ship off to Calais for analysis * @param $parameters Array of Calais parameters for overriding defaults. * @see http://www.opencalais.com/APIcalls#inputparameters * * @return The analyzed content */ function calais_api_analyze($content, $parameters = array()) { $calais = new Calais($parameters); return $calais->analyze($content); } /** * Analyze the content via the Calais XML interface. * * @param $title The title of the content * @param $body The entire body of the content * @param $date The date of the content (can be created or updated date) * This date is used to base calculations of words like "tomorrow" or "yesterday" * @param $parameters Array of Calais parameters for overriding defaults. * @see http://www.opencalais.com/APIcalls#inputparameters * * @return The analyzed content */ function calais_api_analyze_xml($title, $body, $date, $parameters = array()) { $calais = new Calais($parameters); return $calais->analyzeXML($title, $body, $date); } /** * Takes a CamelCase word and adds spaces to make it Camel Case * * @return an formated string */ function calais_api_make_readable($camel_case) { return preg_replace('/(.*?[a-z]{1})([A-Z]{1}.*?)/', '${1} ${2}', $camel_case); } /** * Declare the Calais namespace to the RDF API module (in case we use it) */ function calais_api_rdf_namespaces() { return array( 'c' => 'http://s.opencalais.com/1/pred/', ); } /** * Get a list of the entities that Calais API defines: * http://opencalais.mashery.com/page/calaissemanticmetadata * * TODO: When Calais updates to have a static list at a URL or via API call, return that instead. * * @return flat array listing of Calais entities */ function calais_api_get_all_entities() { return array( 'Anniversary', 'City', 'Company', 'Continent', 'Country', 'Currency', 'EmailAddress', 'EntertainmentAwardEvent', 'EventsFacts', // Special reserved vocab for Events & Facts 'Facility', 'FaxNumber', 'Holiday', 'IndustryTerm', 'MarketIndex', 'MedicalCondition', 'MedicalTreatment', 'Movie', 'MusicAlbum', 'MusicGroup', 'NaturalDisaster', 'NaturalFeature', 'OperatingSystem', 'Organization', 'Person', 'PhoneNumber', 'Product', 'ProgrammingLanguage', 'ProvinceOrState', 'PublishedMedium', 'RadioProgram', 'RadioStation', 'Region', 'SportsEvent', 'SportsGame', 'SportsLeague', 'Technology', 'TVShow', 'TVStation', 'URL', ); }