tarjan_tree.rb revision 5ef489668196d4db3b698ac9eb538649d79a1a45
1516N/A#Class for using the Tarjan algorithm to remove cycles in the entity trees. 565N/A @hashed_entities[parent] = [child] 926N/A def tsort_each_node(&block) 3158N/A @hashed_entities.each_key(&block) 2026N/A def tsort_each_child(node, &block) 3094N/A @hashed_entities[node].each(&block) if @hashed_entities[node] 926N/A # Get SubClassOf Strings without explicit Thing 926N/A def inheritance_sentences ontology 2339N/A .where("text LIKE '%SubClassOf%' AND text NOT LIKE '%Thing%'") 926N/A sentence.text.split(' ').size == 4 565N/A def create_tree ontology 1540N/A groups = self.strongly_connected_components 1540N/A groups.each do |entity_group| 1540N/A entities = Entity.where(id: entity_group) 1968N/A name = determine_group_name(entities) 1540N/A EntityGroup.create!(ontology: ontology, entities: entities, name: name) 2034N/A @hashed_entities.each do |parent, children| 2034N/A parent_group = Entity.find(parent).entity_group 565N/A children.each do |child| 2339N/A child_group = Entity.find(child).entity_group 2339N/A unless parent_group == child_group 2339N/A EEdge.find_or_create_by_parent_id_and_child_id(parent_group.id, child_group.id) 2524N/A def determine_group_name entities 2524N/A entities.each_with_index do |entity, i|