semantic_naming 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/semantic_naming/source_class.rb +22 -4
- metadata +1 -1
@@ -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
|
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
|
115
|
+
next if(subkey.is_a?(Symbol))
|
98
116
|
hierarchy[subkey] ||= {}
|
99
117
|
values[subkey] = hierarchy[subkey]
|
100
118
|
values[subkey][:is_child] = true
|