tmlab / tmql

Automatically exported from code.google.com/p/tmql
1 stars 0 forks source link

Clear Topic Map efficiently #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a topic map with names, variants, occurrences, including reification
2. try to delete everything in an efficient way
3. write a lot of code or fail

What is the expected output? What do you see instead?
a "clear" method on ITopicMap which does all the hard work in the right order

The code in RTM's TopicMap for that may be useful for copying:

    def clear
      # This is supported by some backends (e.g. Ontopia) and should be faster than the procedure below.
      if self.respond_to?(:wrapped) && self.wrapped.respond_to?(:clear)
        self.wrapped.clear
        return
      end

      set_reifier(nil)

      variants.to_a.each do |v|
        v.set_reifier(nil)
        v.remove
      end

      names.to_a.each do |n|
        n.set_reifier(nil)
        n.remove
      end

      occurrences.to_a.each do |o|
        o.set_reifier(nil)
        o.remove
      end

      roles.to_a.each do |r|
        r.set_reifier(nil)
        # Roles should not be removed here! They are removed when the association is removed
        #r.remove
      end

      associations.to_a.each do |a|
        a.set_reifier(nil)
        a.remove
      end

      types.to_a.each do |type|
        type.instances.to_a.each do |instance|
          instance.remove_type(type)
        end
      end

      topics.to_a.each do |t|
        t.remove
      end

    end

Original issue reported on code.google.com by bnjmn...@gmail.com on 27 Jul 2010 at 2:08

GoogleCodeExporter commented 9 years ago
Oups. This was meant for majortom. 
http://code.google.com/p/majortom/issues/detail?id=34

Original comment by bnjmn...@gmail.com on 27 Jul 2010 at 2:23