# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 class Java::DeTopicmapslabMajortomCore::TopicImpl def read_only? return false unless (self.is_a?(Java::DeTopicmapslabMajortomDatabaseReadonly::JdbcReadOnlyTopic) || self.is_a?(Java::DeTopicmapslabMajortomInmemoryStoreRevisionReadonly::InMemoryReadOnlyTopic)) end def best_label(theme = nil) theme = self.parent.get(theme) unless theme.is_a?(RTM::Topic) label = theme ? getBestLabel(theme) : getBestLabel if label.empty? label = self.reference(:outputstyle => :blank) end return label end def add_supertype(identifier) self.addSupertype(topic_map.get!(identifier)) end def add_subtype(identifier) topic_map.get!(identifier).addSupertype(self) end def supertypes result_types = new_s_t = direct_supertypes until new_s_t.empty? new_s_t = new_s_t.map{|s| s.direct_supertypes}.flatten.uniq new_s_t = new_s_t.reject{|s| result_types.include?(s)} result_types = result_types + new_s_t end result_types #return getSupertypes.to_a end alias :transitive_supertypes :supertypes def characteristics(type=:any) _characteristics = names.to_a + occurrences.to_a return _characteristics if type == :any _type = topic_map.get(type) return [] unless _type #_characteristics.select{|c| c.type == _topic} _characteristics.select{|c| c.type.supertypes.include?(_type)} end # Returns all Associations in which this Topic # is a player. # # A filter-hash may be used to filter # for the type of the Role this Topic plays (:rtype), # for the Association type (:atype), # for the type of another role (:otype) as well as # for the player of this other role (:oplayer). # Each value of this filter-hash may be a topic reference. # # The result may be empty. # # :call-seq: # associations_played -> Array of Associations # associations_played({:rtype => identifier}) -> Array of Associations # associations_played({:atype => identifier}) -> Array of Associations # associations_played({:otype => identifier}) -> Array of Associations # associations_played({:otype => identifier, :oplayer => identifier}) -> Array of Associations # associations_played({:rtype => identifier, :atype => identifier}) -> Array of Associations # associations_played({:rtype => identifier, :atype => identifier, :otype => identifier}) -> Array of Associations # associations_played({:rtype => identifier, :atype => identifier, :otype => identifier, :oplayer => identifier}) -> Array of Associations # def associations_played(filter = {}) topic_map.cached self, :associations_played, filter do raise("associations_played(filter): filter must be a Hash") unless filter.is_a?(Hash) default_hash = {:rtype => :any, :atype => :any, :otype => :any, :oplayer => :any} filter = default_hash.merge(filter) # get all roles played roles = self.roles_played(filter[:rtype], filter[:atype]) filter.delete(:rtype) filter.delete(:atype) #filter for the other roles types and players if there are other roles roles = roles.reject do |role| if role.parent.roles.size == 1 #association size if (filter[:otype] != :any) || filter[:player] != :any end else role.counterparts(filter).empty? end end # return parent associations roles.map{|role| role.parent}.uniq end end # remove_supertype end