xkeyboard-config/tests/ruby find_fragments.rb, NONE, 1.1 find_match.rb, 1.4, 1.5 utils.rb, NONE, 1.1 xkbparser.rb, 1.3, 1.4

"Sergey V. Oudaltsov" <xlibs-commit-u7BhqnqprCWvj1b/[email protected]>
Newsgroups gmane.comp.freedesktop.xlibs.cvs
Message-ID <[email protected]>
Committed by: svu

Update of /cvs/xkeyboard-config/xkeyboard-config/tests/ruby
In directory kemper:/tmp/cvs-serv28464

Modified Files:
	find_match.rb xkbparser.rb 
Added Files:
	find_fragments.rb utils.rb 
Log Message:
more playing with inet processing

--- NEW FILE: find_fragments.rb ---
#!/usr/bin/ruby
#
# $Id: find_fragments.rb,v 1.1 2007/03/04 11:50:28 svu Exp $
# The script finds the fragments
#

require "xkbparser.rb"

baseDir = "../.."

symbolsDir = "#{baseDir}/symbols"
#symbolsDir = "."

parser = Parser.new

allSyms = parser.parse("#{symbolsDir}/inet")

everything = allSyms.merge

everything.filter(1)

#numCombinations = 1

#puts "everything:"

#everything.find_all do | symName, keycodes |
#puts "#{symName}, #{keycodes.length} mappings -> "
#  keycodes.find_all do | keycode, counter |
#    puts "  #{keycode} -> #{counter} occurences"
#  end
#  numCombinations *= (keycodes.length + 1)
#end

#puts "Total mappings: #{everything.length}/#{everything.full_length()}, #{numCombinations} combinations"
#

numCombinations = 0
allSyms.find_all do | symsName, symbols |
 puts "n: #{symsName}"

 # Counting only symbols which used more than once
 numDupSymbols = symbols.keys.inject(0) do | rv, keycode |
   c = everything.cardinality(keycode, symbols[keycode])
   puts "#{keycode} -> #{symbols[keycode]}, #{c}"
   (c > 0) ? rv : rv + 1
 end

 numCombinations += (1 << numDupSymbols)
 puts "l: #{symbols.length} d: #{numDupSymbols} c: #{numCombinations}"
end

puts "numCombinations: #{numCombinations}"

Index: find_match.rb
===================================================================
RCS file: /cvs/xkeyboard-config/xkeyboard-config/tests/ruby/find_match.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- find_match.rb	26 Oct 2006 23:53:18 -0000	1.4
+++ find_match.rb	4 Mar 2007 11:50:28 -0000	1.5
@@ -1,3 +1,4 @@
+#!/usr/bin/ruby
 #
 # $Id$
 # The script finds best matching xkb_symbols in symbols/in
@@ -8,11 +9,14 @@
 
 require "xkbparser.rb"
 
-basedir = "../.."
+baseDir = "../.."
+
+symbolsDir = "#{baseDir}/symbols"
+#symbolsDir = "."
 
 parser = Parser.new
 
-allSyms = parser.parse("#{basedir}/symbols/inet")
+allSyms = parser.parse("#{symbolsDir}/inet")
 
 newSyms = parser.parse(ARGV[0])
 limit = ARGV[1].to_i

--- NEW FILE: utils.rb ---
#
# $Id: utils.rb,v 1.1 2007/03/04 11:50:28 svu Exp $
#
# Commont classes
#

#
# The hash containing non-unique mappings
# It can have a->b and a->c together
# Also, for every mapping it counts the number of times this mapping was set
#
class NonuniqueCountingHash < Hash

  alias get_original []
  alias put_original []=

  def []=(key, value)
    own = self.get_original(key)
    hash = get_original(key)
    if hash.nil?
      put_original(key, hash = Hash.new)
    end
    if hash.has_key?(value)
      hash[value] += 1
    else
      hash[value] = 1
    end
  end
  
  #
  # Number of all mappings (a->b and a->c counted as 2 mappings)
  #
  def full_length()
    values.inject(0) do | rv, hash |
      rv + hash.length
    end
  end

  def cardinality(key1, key2)
    if has_key?(key1) 
      hash = get_original(key1)
      if hash.has_key?(key2)
        hash[key2]
      else
        0
      end
    else
      0
    end
  end

  def filter(limit)
    find_all do | key, hash |
      hash.find_all do | key1, counter |
        if (counter <= limit)
          hash.delete(key1)
        end
      end
      if hash.empty? 
        delete(key)
      end
    end
  end
end

Index: xkbparser.rb
===================================================================
RCS file: /cvs/xkeyboard-config/xkeyboard-config/tests/ruby/xkbparser.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- xkbparser.rb	26 Oct 2006 23:53:18 -0000	1.3
+++ xkbparser.rb	4 Mar 2007 11:50:28 -0000	1.4
@@ -6,6 +6,8 @@
 # complex XKB format
 #
 
+require "utils.rb"
+
 class Symbols < Hash
 
   #
@@ -68,6 +70,11 @@
     end
   end
 
+  # Size of all keys
+  def length()
+    keys().length()
+  end
+
   #
   # Size - takes into account overlapping key definitions
   #
@@ -138,6 +145,16 @@
     matching
   end
 
+  def merge()
+    everything = NonuniqueCountingHash.new
+    find_all do | symsName, syms |
+      syms.find_all do | symName, keycode |
+        everything[symName] = keycode
+      end
+    end
+    everything
+  end
+
 end
 
 class Parser
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.