Package biana :: Package BianaObjects :: Module ExternalEntityAttribute'
[hide private]
[frames] | no frames]

Source Code for Module biana.BianaObjects.ExternalEntityAttribute'

  1  """ 
  2      BIANA: Biologic Interactions and Network Analysis 
  3      Copyright (C) 2009  Javier Garcia-Garcia, Emre Guney, Baldo Oliva 
  4   
  5      This program is free software: you can redistribute it and/or modify 
  6      it under the terms of the GNU General Public License as published by 
  7      the Free Software Foundation, either version 3 of the License, or 
  8      (at your option) any later version. 
  9   
 10      This program is distributed in the hope that it will be useful, 
 11      but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13      GNU General Public License for more details. 
 14   
 15      You should have received a copy of the GNU General Public License 
 16      along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18  """ 
 19   
 20  import sets 
 21  import sys 
 22  import re # for checking given value's integrity 
 23   
 24   
 25  ATTRIBUTE_IDENTIFIER_TO_OBJECT = {} 
 26   
 27   
28 -class ExternalEntityAttribute(object):
29 """ 30 Class that represents an external entity attribute 31 """ 32 33 34
35 - def __init__(self, attribute_identifier, value, type=None, version=None, additional_fields={}):
36 37 # Check for a correct value 38 self.value = value 39 self.type = type 40 self.version = version 41 self.additional_fields = additional_fields 42 self.attribute_identifier = attribute_identifier
43 44
45 - def get_field(self, field_name):
46 47 if( field_name == "value" ): 48 return self.value 49 elif( field_name == "type" ): 50 return self.type 51 elif( field_name == "version" ): 52 return self.version 53 else: 54 return self.additional_fields[field_name]
55 56
57 - def __str__(self):
58 59 temp1 = ["value: %s" %self.value] 60 if( self.type is not None ): 61 temp1.append("type: %s" %self.type) 62 if( self.version is not None ): 63 temp1.append("version: " %self.version) 64 temp2 = [ ("%s: %s") %(x,self.additional_fields[x]) for x in self.additional_fields ] 65 66 return "Attribute %s. %s %s" %(self.attribute_identifier,"\t".join(temp1),"\t".join(temp2))
67
68 - def __repr__(self):
69 return self.__str__()
70 71 72
73 - def __eq__(self, other):
74 """Other can be either string of dictionary however comparison below is generic enough""" 75 return str(self.value).lower() == str(other.value).lower()
76 77 78 79
80 - def isFullTextSearchable(attribute_identifier, biana_database):
81 82 # Possible bug: it is only applyed for general attributes. If a specific attribute has to have a keyword index, this won't work 83 return attribute_identifier.lower() in biana_database.VALID_EXTERNAL_ENTITY_DESCRIPTIVE_SEARCHABLE_ATTRIBUTE_TYPES_SET
84 85 isFullTextSearchable = staticmethod(isFullTextSearchable) 86 87 88 89
90 - def isNumericAttribute(attribute_identifier, biana_database):
91 return attribute_identifier.lower() in biana_database.VALID_EXTERNAL_ENTITY_NUMERIC_ATTRIBUTE_TYPES_SET
92 93 isNumericAttribute = staticmethod(isNumericAttribute) 94 95
96 - def isSpecialAttribute(attribute_identifier, biana_database):
97 return attribute_identifier.lower() in biana_database.VALID_EXTERNAL_ENTITY_SPECIAL_ATTRIBUTE_TYPES_SET
98 99 isSpecialAttribute = staticmethod(isSpecialAttribute) 100 101
102 - def isValidAttribute(attribute_identifier, biana_database):
103 104 return attribute_identifier.lower() in biana_database.VALID_EXTERNAL_ENTITY_ATTRIBUTE_TYPES_DICT
105 106 isValidAttribute = staticmethod(isValidAttribute) 107 108 109
110 - def isIdentifierType(attribute_identifier, biana_database):
111 112 113 return attribute_identifier.lower() in biana_database.VALID_EXTERNAL_ENTITY_IDENTIFIER_ATTRIBUTE_TYPES_SET or attribute_identifier.lower() in biana_database.VALID_EXTERNAL_ENTITY_VERSIONABLE_IDENTIFIER_ATTRIBUTE_TYPES_SET
114 115 isIdentifierType = staticmethod(isIdentifierType) 116 117 118
119 - def isVersionableIdentifier(attribute_identifier, biana_database):
120 121 return attribute_identifier.lower() in biana_database.VALID_EXTERNAL_ENTITY_VERSIONABLE_IDENTIFIER_ATTRIBUTE_TYPES_SET
122 123 isVersionableIdentifier = staticmethod(isVersionableIdentifier)
124