Module: RTM::Sugar::Topic::BestName
- Defined in:
- lib/rtm/sugar/topic/best_name.rb
Overview
Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. License: Apache License, Version 2.0
Instance Method Summary collapse
-
#best_name(theme = nil) ⇒ Object
Tries to find the best matching name for a given topic.
Instance Method Details
#best_name(theme = nil) ⇒ Object
Tries to find the best matching name for a given topic.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rtm/sugar/topic/best_name.rb', line 8 def best_name (theme = nil) all_names = self.names # return last part of identifier if no name exist return find_user_friendly_identifier(self) if all_names.empty # collect name with default name type default_names = [] all_names.each do |name| type_of_name = name.getType next if type_of_name.nil? type_identifiers = type_of_name.subject_identifiers.to_a type_identifiers.each do |i| if i.toExternalForm == RTM::PSI[:name_type] then default_names << name break end end end default_names = all_names if default_names.empty? default_names = default_names.select { |name| not name.scope.to_a.index(theme).nil? } if not theme.nil? default_names = all_names if default_names.empty? # get default name with the minimum number of scopes min_scoped_name = default_names.sort_by{|n| n.value}.min {|n1,n2| n1.getScope.size <=> n2.getScope.size} min_scoped_name.value end |