tarjan_tree.rb revision 1b335309140b973b0e98381e8c3b213afde1d963
#Class for using the Tarjan algorithm to remove cycles in the entity trees.
subclasses.each do |s|
if @hashed_entities[parent_id]
@hashed_entities[parent_id] << child_id
else
@hashed_entities[parent_id] = [child_id]
end
end
end
def tsort_each_node(&block)
@hashed_entities.each_key(&block)
end
def tsort_each_child(node, &block)
@hashed_entities[node].each(&block) if @hashed_entities[node]
end
# Get SubClassOf Strings without explicit Thing
def inheritance_sentences ontology
ontology.sentences
.where("text LIKE '%SubClassOf%' AND text NOT LIKE '%Thing%'")
.select do |sentence|
sentence.text.split(' ').size == 4
end
end
end