? 726088-1_placemaker.patch
? 726088-2_placemaker.patch
? placemaker.patch
Index: ExtractorSimplePieParser.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/extractor/ExtractorSimplePieParser.inc,v
retrieving revision 1.1
diff -u -p -r1.1 ExtractorSimplePieParser.inc
--- ExtractorSimplePieParser.inc	4 Dec 2009 15:01:46 -0000	1.1
+++ ExtractorSimplePieParser.inc	26 Feb 2010 17:39:33 -0000
@@ -29,14 +29,30 @@ class ExtractorSimplePieParser extends F
    */
   public function getSourceElement($item, $element_key) {
     if ($element_key == 'extracted_terms') {
-      return extractor_extract($item['title'] .' '. $item['description']);
+      return extractor_extract($item['title'] .' '. $item['description'], $this->config);
     }
     elseif ($element_key == 'extracted_tids') {
-      $terms = extractor_extract($item['title'] .' '. $item['description']);
+      $terms = extractor_extract($item['title'] .' '. $item['description'], $this->config);
       return array_keys($terms);
     }
     else {
       return parent::getSourceElement($item, $element_key);
     }
   }
-}
+  /**
+    * Config Form Defaults
+    */
+  public function configDefaults() {
+    return array(
+      'extractors' => 'simple_extractor',
+      'language' => 'en-US',
+      'placemaker_key' => '',
+      );
+  }
+  /**
+    * Config Form
+    */
+  public function configForm(&$form_state) {
+    return extractor_form($this->config);
+  }
+}
\ No newline at end of file
Index: ExtractorSyndicationParser.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/extractor/ExtractorSyndicationParser.inc,v
retrieving revision 1.1
diff -u -p -r1.1 ExtractorSyndicationParser.inc
--- ExtractorSyndicationParser.inc	4 Dec 2009 15:01:46 -0000	1.1
+++ ExtractorSyndicationParser.inc	26 Feb 2010 17:39:33 -0000
@@ -29,14 +29,30 @@ class ExtractorSyndicationParser extends
    */
   public function getSourceElement($item, $element_key) {
     if ($element_key == 'extracted_terms') {
-      return extractor_extract($item['title'] .' '. $item['description']);
+      return extractor_extract($item['title'] .' '. $item['description'], $this->config);
     }
     elseif ($element_key == 'extracted_tids') {
-      $terms = extractor_extract($item['title'] .' '. $item['description']);
+      $terms = extractor_extract($item['title'] .' '. $item['description'], $this->config);
       return array_keys($terms);
     }
     else {
       return parent::getSourceElement($item, $element_key);
     }
   }
-}
+  /**
+    * Config Form Defaults
+    */
+  public function configDefaults() {
+    return array(
+      'extractors' => 'simple_extractor',
+      'language' => 'en-US',
+      'placemaker_key' => '',
+      );
+  }
+  /**
+    * Config Form
+    */
+  public function configForm(&$form_state) {
+    return extractor_form($this->config);
+  }
+}
\ No newline at end of file
Index: extractor.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/extractor/extractor.info,v
retrieving revision 1.1
diff -u -p -r1.1 extractor.info
--- extractor.info	4 Dec 2009 15:01:46 -0000	1.1
+++ extractor.info	26 Feb 2010 17:39:33 -0000
@@ -2,4 +2,10 @@
 name = Extractor
 description = "API for extracting terms from text"
 dependencies[] = taxonomy
-core = 6.x
\ No newline at end of file
+core = 6.x
+; Information added by drupal.org packaging script on 2009-12-04
+version = "6.x-1.0-alpha1"
+core = "6.x"
+project = "extractor"
+datestamp = "1259940075"
+
Index: extractor.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/extractor/extractor.module,v
retrieving revision 1.1
diff -u -p -r1.1 extractor.module
--- extractor.module	4 Dec 2009 15:01:46 -0000	1.1
+++ extractor.module	26 Feb 2010 17:39:33 -0000
@@ -78,11 +78,10 @@ function extractor_settings_form() {
 /**
  * Main API function.
  *
- * @todo: make pluggable.
  */
-function extractor_extract($text) {
-  extractor_include('extractor_simple');
-  return extractor_simple_extract($text);
+function extractor_extract($text, $config) {
+  extractor_include($config['extractors']);
+  return call_user_func_array($config['extractors'].'_extract', array($text, $config));
 }
 
 /**
@@ -94,4 +93,31 @@ function extractor_include($name) {
     include drupal_get_path('module', 'extractor') .'/libraries/'. $name .'.inc';
     $included[$name] = TRUE;
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Choose an Extractor.
+ */
+function extractor_form($config) {  
+  $form['extractors'] = array(
+    '#title' => t('Use extractor engines'),
+    '#type' => 'radios',
+    '#default_value' => $config['extractors'],
+    '#options' => array(
+      'simple_extractor' => t('Simple Extractor'), 
+      'placemaker' => t('Yahoo Placemaker')
+    ),
+  ); 
+  $form['placemaker_key'] = array(
+    '#title' => t('Yahoo API Key'),
+    '#type' => 'textfield',
+    '#default_value' => $config['placemaker_key'],
+  );
+  $form['language'] = array(
+    '#title' => t('Language'),
+    '#description' => t('Use specified language (RFC 4646) for place name recognition return of place names'),
+    '#type' => 'textfield',
+    '#default_value' => $config['language'],
+  ); 
+  return $form;
+}
Index: libraries/placemaker.inc
===================================================================
RCS file: libraries/placemaker.inc
diff -N libraries/placemaker.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libraries/placemaker.inc	26 Feb 2010 17:39:33 -0000
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * Tags a single item.
+ */
+function placemaker_extract($text, $config) { 
+  // TODO: ALLOW PER EXTRACTOR VOCABS?
+  $vid = variable_get('extractor_simple_vid', 1);
+  $term = _placemaker_send_text($text, $vid, $config); 
+  $tags = array();
+  if ($term) {
+    $tags[$term['tid']] = $term;
+  }
+  return $tags;
+}
+
+
+/**
+ * Sends items to Placemaker API.
+ */
+function _placemaker_send_text($text, $vid, $config) {
+  // Make placemaker request
+  $apiendpoint = 'http://wherein.yahooapis.com/v1/document';
+  $inputType = 'text/html';
+  
+  $outputType = 'xml';
+  $post = 'appid='.$config['placemaker_key'].'&documentContent='.$text.'&documentType='.$inputType.'&inputLanguage='.$config['language'].'&outputType='.$outputType.'&autoDisambiguate=true';
+  $ch = curl_init($apiendpoint);
+  
+  curl_setopt($ch, CURLOPT_POST, 1);
+  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
+  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
+  $results = curl_exec($ch);
+  curl_close($ch);
+  
+  // Parse results of placemaker request
+  $xml = simplexml_load_string($results);
+  $item['vid'] = $vid;
+  $item['name'] = (string)$xml->document->placeDetails->place->name;
+  $item['external_id'] = (string)$xml->document->placeDetails->place->woeId;
+  $item['lat'] = (string)$xml->document->placeDetails->place->centroid->latitude;
+  $item['lon'] = (string)$xml->document->placeDetails->place->centroid->longitude;
+  $item['description'] = NULL;
+      
+  if ($item['name']) {    
+    $tags = _placemaker_tag_text($item, $config);
+  } 
+  
+  return $tags;
+} 
+ 
+function _placemaker_tag_text($item, $config) {
+  //Check to see if the term already exists
+  $result = db_query('SELECT tid, external_id FROM {term_geo} WHERE external_id = "%s"', $item['external_id']);
+  if ($term = db_fetch_object($result)) {
+    $item['tid'] = $term->tid;
+    $item['name'] = $term->name;   
+    return $item;
+  }
+  //Otherwise create new term and add geotaxonomy info
+  else {    
+    // Separate call to Yahoo GeoPlanet API to return placename in language of choice if not US English
+    if ($config['language'] != 'en_US') {
+      $apiendpoint = 'http://where.yahooapis.com/v1/place/'.$item['external_id'].'?appid='.$config['placemaker_key'].'&lang='.$config['language'].'&select=short';
+      $ch = curl_init($apiendpoint);       
+      $headers = array('Accept: application/xml');
+      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
+      $results = curl_exec($ch);
+      curl_close($ch);
+      $xml = simplexml_load_string($results);
+      $item['name'] = (string)$xml->name;
+    }
+    taxonomy_save_term($item);
+    return $item;
+  }
+}
\ No newline at end of file
