| Class | N::SourceClass |
| In: |
lib/semantic_naming/source_class.rb
|
| Parent: | URI |
This is the type of URI that represents a class of sources. The methods that browse the ontology hierarchy depend on ActiveRDF for accessing the RDF store. If ActiveRDF is not present, these will return nitl.
Get all the existing types from the RDF store
# File lib/semantic_naming/source_class.rb, line 36
36: def self.rdf_types
37: return nil unless(URI.active_rdf?)
38: qry = Query.new(SourceClass).distinct.select(:s)
39: qry.where(:s, RDF.type, RDFS.Class)
40: qry.execute
41: end
Return a subclass hierarchy. This is quicker than going through the hierarchy step by step. It will look at all subclass (not superclass!) relationships and return a nested, tree-like structure build of hashes. Each key in the hash will be the class object, and the values are hashes with the child elements, and so on
E.g. : { type1 => { subtype_a => {}, subtype_b => { xtype => {}} }, type_2 => {}}
# File lib/semantic_naming/source_class.rb, line 50
50: def self.subclass_hierarchy
51: return nil unless(URI.active_rdf?)
52: types = rdf_types
53: qry = Query.new(SourceClass).distinct.select(:class, :subclass)
54: qry.where(:class, RDF.type, RDFS.Class)
55: qry.where(:subclass, RDFS.subClassOf, :class)
56: subtype_list = qry.execute
57:
58: build_hierarchy_from(subtype_list, rdf_types)
59: end
This works like the subclass_hierarchy method, with the exception that
# File lib/semantic_naming/source_class.rb, line 67
67: def self.used_subclass_hierarchy
68: all_types_qry = Query.new(SourceClass).distinct.select(:type)
69: all_types_qry.where(:element, RDF.type, :type)
70: all_types = all_types_qry.execute
71:
72: qry = Query.new(SourceClass).distinct.select(:class, :subclass)
73: qry.where(:subclass, RDFS.subClassOf, :class)
74: subtype_list = qry.execute
75:
76: all_types_hash = {}
77: all_types.each { |type| all_types_hash[type] = true }
78:
79: # TODO: Not very efficient, but then we don't expect many types
80: all_type_list = (all_types + subtype_list.collect { |el| el.last }).uniq
81:
82: hierarchy = build_hierarchy_from(subtype_list, all_type_list)
83:
84: purge_hierarchy!(hierarchy, all_types_hash)
85:
86: hierarchy
87: end
Get the instances of this type. return_type will be the class used to create the objects that are returned.
# File lib/semantic_naming/source_class.rb, line 28
28: def instances(return_type)
29: return nil unless(active_rdf? && is_iri?)
30: qry = Query.new(SourceClass).distinct.select(:s)
31: qry.where(:s, RDF.type, self)
32: qry.execute
33: end
Get the subtypes of this type
# File lib/semantic_naming/source_class.rb, line 18
18: def subtypes
19: return nil unless(active_rdf? && is_iri?)
20: qry = Query.new(SourceClass).distinct.select(:s)
21: qry.where(:s, RDFS.subClassOf, self)
22: qry.where(:s, RDF.type, RDFS.Class)
23: qry.execute
24: end
Get the supertype of this class
# File lib/semantic_naming/source_class.rb, line 9
9: def supertypes
10: return nil unless(active_rdf? && is_iri?)
11: qry = Query.new(SourceClass).distinct.select(:o)
12: qry.where(self, RDFS.subClassOf, :o)
13: qry.where(:o, RDF.type, RDFS.Class)
14: qry.execute
15: end