EdgeExpressDB

 view release on metacpan or  search on metacpan

lib/EEDB/Metadata.pm  view on Meta::CPAN

    if($keyword =~ /\.$/) { chop($keyword); } 
    
    #capitalization test
    my $tkey = $keyword;
    if(!($tkey =~ /\d/) and ($tkey =~ s/^([A-Z])/lc($1)/e) and ($tkey eq lc($keyword))) {
      #printf("'%s' is capitalized\n", $keyword);
      $keyword = lc($keyword);
    }

    next if($keyword eq 'the');
    next if($keyword eq 'and');
    next if($keyword eq 'or');
    next if($keyword eq 'with');

    #printf("   '%s'\n", $keyword);
    $valid_keywords->add_tag_symbol("keyword", $keyword);
    
    #sub-keyword tests
    my @sub_keywords = split /[\-\/]/, $keyword;
    if(scalar(@sub_keywords)>1) {
      foreach my $keyw (@sub_keywords) {
        next unless($keyw);
        next unless(length($keyw) > 2);
        $valid_keywords->add_tag_symbol("keyword", $keyw);
      }
    }
  }
  $valid_keywords->remove_duplicates;
  return $valid_keywords;
}


#################################################
#
# DBObject override methods
#
#################################################

sub store {
  my $self = shift;
  my $db   = shift;
  
  unless($db) { return undef; }
  #if($self->check_exists_db($db)) { return $self; }
  
  my $dbc = $db->get_connection;  
  my $sql = "INSERT INTO metadata (data_type, data) VALUES(?,?)";
  my $sth = $dbc->prepare($sql);
  $sth->execute($self->type, $self->data);
  my $dbID = $dbc->last_insert_id(undef, undef, qw(metadata metadata_id));
  $sth->finish;
  if($dbID) {
    $self->primary_id($dbID);
    $self->database($db);
    return $self;
  } else {
    return undef;
  }
}

sub update {
  #use with extreme caution!!!! I should not even include it
  my $self = shift;
  my $sql = "UPDATE metadata set data_type=?, data=? where metadata_id=?";
  $self->database->execute_sql($sql, $self->type, $self->data, $self->id);
}

sub check_exists_db {
  my $self = shift;
  my $db   = shift;
  
  return undef unless($db);
  my $dbc = $db->get_connection;  

  #first do check if it is already in the database
  my $sth = $dbc->prepare("SELECT metadata_id FROM metadata where data_type=? and data=?");
  $sth->execute($self->type, $self->data);
  my ($dbID) = $sth->fetchrow_array();
  $sth->finish;
  if($dbID) {
    $self->primary_id($dbID);
    $self->database($db);
    return $self;
  } else {
    return undef;
  }
}


sub store_link_to_feature { 
  my $self = shift;
  my $feature = shift;
  
  unless($feature->database) {
    printf("ERROR:: %s has no database to link Metadata\n", $feature->simple_display_desc);
    die();
  }
  $feature->database->execute_sql(
      "INSERT ignore INTO feature_2_metadata (feature_id, metadata_id) VALUES(?,?)",
      $feature->id, $self->id);
}

sub unlink_from_feature { 
  my $self = shift;
  my $feature = shift;
  
  unless($feature->database) {
    printf("ERROR:: %s has no database to link Metadata\n", $feature->simple_display_desc);
    die();
  }
  $feature->database->execute_sql(
      "DELETE from feature_2_metadata where feature_id=? and metadata_id=?",
      $feature->id, $self->id);
}


sub store_link_to_feature_link { 
  my $self = shift;
  my $edge = shift;
  
  unless($edge->database) {



( run in 1.002 second using v1.01-cache-2.11-cpan-39bf76dae61 )