semantic_naming 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -69,17 +69,35 @@ module N
69
69
  all_types_qry.where(:element, RDF.type, :type)
70
70
  all_types = all_types_qry.execute
71
71
 
72
+ all_types_hash = {}
73
+ all_types.each { |type| all_types_hash[type] = true }
74
+
72
75
  qry = Query.new(SourceClass).distinct.select(:class, :subclass)
73
- qry.where(:element, RDF.type, :class)
74
- qry.where(:other, RDF.type, :subclass)
75
76
  qry.where(:subclass, RDFS.subClassOf, :class)
76
77
  subtype_list = qry.execute
77
78
 
78
- build_hierarchy_from(subtype_list, all_types)
79
+ hierarchy = build_hierarchy_from(subtype_list)
80
+ purge_hierarchy!(hierarchy, all_types_hash)
81
+
82
+ hierarchy
79
83
  end
80
84
 
81
85
  private
82
86
 
87
+ # Purge the elements from the hierarchy that don't have any "used"
88
+ # children. Returns true if some "used" elements were found in
89
+ # the hierarchy
90
+ def self.purge_hierarchy!(elements, used_elements)
91
+ used = false
92
+ elements.each do |element, children|
93
+ used_children = purge_hierarchy!(children, used_elements)
94
+ used_element = used_children || used_elements[element]
95
+ elements.delete(element) unless(used_element)
96
+ used ||= used_element
97
+ end
98
+ used
99
+ end
100
+
83
101
  # If all_types is given, it must be a true superset of all
84
102
  # types in the query result
85
103
  def self.build_hierarchy_from(query_result, all_types = nil)
@@ -94,7 +112,7 @@ module N
94
112
  # Now we link up the subclass relations
95
113
  hierarchy.each do |key, values|
96
114
  values.each_key do |subkey|
97
- next if(subkey == :is_child)
115
+ next if(subkey.is_a?(Symbol))
98
116
  hierarchy[subkey] ||= {}
99
117
  values[subkey] = hierarchy[subkey]
100
118
  values[subkey][:is_child] = true
metadata CHANGED
@@ -5,7 +5,7 @@ homepage: http://talia.discovery-project.eu/
5
5
  executables: []
6
6
 
7
7
  version: !ruby/object:Gem::Version
8
- version: 2.0.2
8
+ version: 2.0.3
9
9
  post_install_message:
10
10
  date: 2009-11-04 23:00:00 +00:00
11
11
  files: