Download & Extend

Enable Semantic Proxy for Feeds Module

Project:OpenCalais
Version:6.x-3.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

This is a big mess right now but it's a start. It works at identtyfying the Feed Importer ID and we really need to get at the content type in the node processor???

Anyway, thought I would post some of my hacks here to see if it stirs any interest.

Changes to calais.admin.inc

/**
* Configuration for Semantic Proxy integration. This will
*/
function _calais_build_semanticproxy_config(&$form, $node_type) {
 
  $spfields = array('' => "Don't process with SemanticProxy");
  $docfields = array('' => "Don't store document text");

  // If this content type is a FeedAPI feed item
  if(module_exists('feedapi_node')) {
    $feed_types = feedapi_get_types();
    foreach($feed_types as $type => $name) {
      $settings = feedapi_get_settings($type);
      if($settings['processors']['feedapi_node']['content_type'] == $node_type->type) {
        $spfields['calais_feedapi_node'] = t('Feed Item Original URL');
      }
    }
  }
 
  // If this content type is a Feeds feed item
  // THIS RESULTS IN ATTACHING SP TO ANY CONTENT TYPE ATTACHED TO AN IMPORTER
  // NOT WHAT WE WANT???
  if (module_exists('feeds') && ($importer_id = feeds_get_importer_id($node_type->type))) {
    $spfields['calais_feeds_node'] = t('Feed Item Original URL');
  } 
...

Changes to calais.module

/**
* Use SemanticProxy to process this Node.
*
* @param $node The node to process
* @return The Calais keywords for this node.
*/
function calais_process_with_semanticproxy(&$node) {
  $key = drupal_strtolower($node->type);
  $spfield = variable_get("calais_semanticproxy_field_{$key}", '');
 
  if(!empty($spfield)) {
    // FeedAPI
    if($spfield == 'calais_feedapi_node') {
      // On insert, $node->feedapi_node is available
      if(isset($node->feedapi_node)) {
        $url = $node->feedapi_node->feed_item->options->original_url;
      }
      else { // On update, we need to pull the URL from the DB. Should always be the same. #feedapifail
        $url = db_result(db_query('SELECT fi.url FROM {feedapi_node_item} fi WHERE fi.nid = %d', $node->nid));
      }
    }
    // Feeds
   // I GET AN ERROR THAT COMPLAINS ABOUT THIS BEING AN INVALID URL FOR SP. Not surprising.
    if($spfield == 'calais_feeds_node') {
      // On insert, $node->feeds_node_item is available
      if(isset($node->feeds_node_item)) {
        $url = $node->feeds_node_item->url;
      }
      else { // On update, we need to pull the URL from the DB. Should always be the same. #feedapifail
        $url = db_result(db_query('SELECT fi.url FROM {feeds_node_item} fi WHERE fi.nid = %d', $node->nid));
      }
    }
  ...

Comments

#1

Sorry the previous post was so confusing. The issue in general is that Feeds introduces some new concepts like Importers and Sources. Took me awhile to get past the semantics and figure out where the relevant info was stored. Really all this patch is doing is checking to see if Feeds is installed, and if it is then we enable Semantic Proxy for the content types that are used as feed items. I have tested it on a Google News feed on my sandbox http://173.165.43.49/~metanomy/

On this last run I got a SP processing error. It seems some of the items did not get processed by SP, but I expect this is an API issue with the service since I have deleted all feed items and re-imported about four times now and I only got the error once.

The interesting part is, since Feeds allows you to import from things like CSV files, as long as the Importer has the Processor set to store info in a node you should be able to set SP to run on any CCK field in that node type that holds a URL. Have not tested it but can confirm that a custom Importer I created for CSV's does show in the content type SP fields in Calais admin as it should.

The patch was created on OS X running diff for the entire opencalais folder. The patch touches two files, so if I need to break it out into two patches let me know.

R,
C

AttachmentSize
847870.patch 3.01 KB

#2

I will be interested in version 7.x
Thanks
EGA