Class: RTM::AR::Topic
- Includes:
- Sugar::Topic::Characteristics, Sugar::Topic::Counterparts, Sugar::Topic::HashAccess, Sugar::Topic::IdentifierDirect, Sugar::Topic::PredefinedAssociations, Topic
- Defined in:
- lib/rtm/activerecord/topic.rb,
lib/rtm/activerecord.rb
Instance Method Summary collapse
-
#==(o) ⇒ Object
class:Topic equality, www.isotopicmaps.org/sam/sam-model/#d0e1029.
- #characteristics(*args) ⇒ Object (also: #children, #characteristics_by)
- #create_name(arg1, arg2 = :nothing, arg3 = :nothing) ⇒ Object (also: #cn, #create_topic_name)
- #create_occurrence(type, value, params = {}) ⇒ Object
- #filter_roles(*args) ⇒ Object
- #id ⇒ Object
Methods included from TraverseAssociations
Methods included from Sugar::Topic::HashAccess
Methods included from Sugar::Topic::IdentifierDirect
Methods included from Sugar::Topic::Counterparts
#counterparts, #counterplayers
Methods included from Sugar::Topic::Characteristics
#external_occurrences, #internal_occurrences
Methods included from Construct
Instance Method Details
#==(o) ⇒ Object
class:Topic equality, www.isotopicmaps.org/sam/sam-model/#d0e1029
This method is all crap. These ActiveRecord Arrays can’t be intersected, so I map the identifiers to their reference which seems long winded. Still I find it better than using their ID in the long.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/rtm/activerecord/topic.rb', line 172 def ==(o) return false unless o return false unless o.respond_to?(:subject_identifiers) return false unless o.respond_to?(:subject_locators) return false unless o.respond_to?(:names) # Two topic items are equal if they have: # * at least one equal string in their [subject identifiers] properties, # -> test if intersection are > 0 my_si = self.subject_identifiers.map{|si| si.reference} ot_si = o.subject_identifiers.map{|si| si.reference} return true if ( my_si & ot_si).size > 0 # * at least one equal string in their [item identifiers] properties, my_ii = self.item_identifiers.map{|ii| ii.reference} ot_ii = o.item_identifiers.map{|ii| ii.reference} return true if (my_ii & ot_ii).size > 0 # * at least one equal string in their [subject locators] properties, my_sl = self.subject_locators.map{|sl| sl.reference} ot_sl = o.subject_locators.map{|sl| sl.reference} return true if (my_sl & ot_sl).size > 0 # * an equal string in the [subject identifiers] property of the one topic item and the [item identifiers] property of the other, or return true if (my_si & ot_ii).size > 0 return true if (my_ii & ot_si).size > 0 # * the same information item in their [reified] properties. return true if self.reified != nil && o.reified != nil && (self.reified == o.reified) # ... otherwise false end |
#characteristics(*args) ⇒ Object Also known as: children, characteristics_by
89 90 91 |
# File 'lib/rtm/activerecord/topic.rb', line 89 def characteristics(*args) names(*args).to_a + occurrences(*args).to_a end |
#create_name(arg1, arg2 = :nothing, arg3 = :nothing) ⇒ Object Also known as: cn, create_topic_name
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rtm/activerecord/topic.rb', line 32 def create_name(arg1,arg2 = :nothing, arg3 = :nothing) if (arg2 == :nothing) && (arg3 == :nothing) #arg1 = value raise "create_name(value): value must be a String" unless arg1.is_a?(String) return create_name_internal(:value => arg1, :type => self.parent._topic_by_locator!(RTM::PSI[:name_type])) end if (arg3 == :nothing) if arg2.is_a?(Array) #arg1 = value, arg2 = scope raise "create_name(value, scope): value must be a String" unless arg1.is_a?(String) arg2.each do |theme| raise "create_name(value, scope): scope must be an Array of Topics/Topic-References" unless (theme.is_a?(String) || theme.is_a?(RTM::Topic) || theme.is_a?(RTM::Locator)) end return arg2.empty? ? create_name_internal(:value => arg1) : create_name_internal(:value => arg1, :scope => self.parent._topic_by_locator!(arg2)) elsif arg2.is_a?(String) #arg1 = type, arg2 = value raise "create_name(type, value): type must be a Topic/Topic-Reference" unless (arg1.is_a?(String) || arg1.is_a?(RTM::Topic) || arg1.is_a?(RTM::Locator)) return create_name_internal(:type => self.parent._topic_by_locator!(arg1), :value => arg2) else raise "create_name(?,?): arguments don't match" end end #arg1 = type, arg2 = value, arg3 = scope raise "create_name(type, value, scope): type must be a Topic/Topic-Reference" unless (arg1.is_a?(String) || arg1.is_a?(RTM::Topic) || arg1.is_a?(RTM::Locator)) raise "create_name(type, value, scope): value must be a String" unless arg2.is_a?(String) raise "create_name(type, value, scope): scope must be an Array" unless arg3.is_a?(Array) arg3.each do |theme| raise "create_name(type, value, scope): scope must be an Array of Topics/Topic-References" unless (theme.is_a?(String) || theme.is_a?(RTM::Topic) || theme.is_a?(RTM::Locator)) end return create_name_internal(:type => self.parent._topic_by_locator!(arg1), :value => arg2, :scope => self.parent._topic_by_locator!(arg3)) end |
#create_occurrence(type, value, params = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rtm/activerecord/topic.rb', line 69 def create_occurrence(type,value,params={}) if params[:scope] if value.is_a?(RTM::Locator) return create_occurrence_internal(topic_map.get!(type),value,topic_map._topic_by_locator!(params[:scope]), :datatype => RTM::PSI[:IRI]) elsif !params[:datatype] return create_occurrence_internal(topic_map.get!(type),value,topic_map._topic_by_locator!(params[:scope])) else # datatype given, no locator return create_occurrence_internal(topic_map.get!(type),value,topic_map.create_locator(params[:datatype]),topic_map._topic_by_locator!(params[:scope])) end else #no scope if value.is_a?(RTM::Locator) return create_occurrence_internal(topic_map.get!(type),value, :datatype => RTM::PSI[:IRI]) elsif !params[:datatype] return create_occurrence_internal(topic_map.get!(type),value, params) else #datatype given, no locator return create_occurrence_internal(topic_map.get!(type),value,topic_map.create_locator(params[:datatype])) end end end |
#filter_roles(*args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rtm/activerecord/topic.rb', line 97 def filter_roles(*args) # puts # puts "topic filter roles:" # puts args.inspect if args.size == 1 a1 = args.shift # if a1 == :any # a1 = nil # end role_type = topic_map.get(a1) return self.roles unless role_type if role_type.respond_to?(:each) query_conditions = (["ttype_id = ?"] * role_type.size).join(" OR ") puts puts "qq:" puts query_conditions puts role_type.map{|rt| rt.id} puts return self.roles.find(:all,:conditions => [query_conditions, role_type.map{|rt| rt.id}]) else return self.roles.find(:all,:conditions => ["ttype_id = ?", role_type.id]) end elsif args.size == 2 role_type = args.shift # if role_type == :any # role_type = nil # end role_type = topic_map.get(role_type) assoc_type = args.shift # if assoc_type == :any # assoc_type = nil # end assoc_type = topic_map.get(assoc_type) if role_type && assoc_type puts "trying to return topic.roles for #{role_type.inspect} and #{assoc_type.inspect}" res = self.roles.find(:all, :conditions => ["roles.ttype_id = ? and associations.ttype_id = ?", role_type.id, assoc_type.id]) puts res.inspect return res elsif assoc_type return self.roles.find(:all, :conditions => ["associations.ttype_id = ?", assoc_type.id]) elsif role_type return self.roles.find(:all,:conditions => ["ttype_id = ?", role_type.id]) else warn("Topic#roles got 2 arguments but doesn't know how to handle (or referenced topics where not found)") end end false end |
#id ⇒ Object
162 163 164 |
# File 'lib/rtm/activerecord/topic.rb', line 162 def id __getobj__.id end |