Module: RTM::Sugar::Topic::BestName
- Defined in:
- rtm/lib/rtm/sugar/topic/best_name.rb,
rtm/spec/rtm/sugar/topic/best_name_spec.rb
Overview
Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. License: Apache License, Version 2.0
Instance Method Summary
-
- (Object) best_name(theme = nil)
Tries to find the best matching name for a given topic.
-
- (Object) shortest_topic_identifier
Returns the shortest most significant identifier in yaml-style.
Instance Method Details
- (Object) best_name(theme = nil)
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 |
# File 'rtm/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 if all_names.empty resulting_names = [] if theme resulting_names = self["- @#{theme.reference}"] if resulting_names.empty? resulting_names = all_names.select{|name| name.scope.include?(theme)} end end # collect name with default name type if resulting_names.empty? resulting_names = self["-"] end # use all names if resulting_names.empty? resulting_names = all_names end # get the name with the smalles scope and smallest value min_scoped_name = resulting_names.sort_by{|name| [name.scope.size, name.value.length, name.value]}.first return min_scoped_name.value end |
- (Object) shortest_topic_identifier
Returns the shortest most significant identifier in yaml-style.
39 40 41 42 43 44 |
# File 'rtm/lib/rtm/sugar/topic/best_name.rb', line 39 def shortest_topic_identifier return self.references(:outputstyle => :yaml, :resolve_qnames => :true, :resolve_base_iri => :true, :sort_by_length => :true). first unless references.empty? raise("Runtime Exception: Topic has no identifiers.") end |