Last active
September 27, 2018 00:28
-
-
Save wildjcrt/e81eae05f169d9984add4b361f6104f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
keys_h=Hash.new(0) | |
keys_d=Hash.new(0) | |
values_h=Hash.new(0) | |
values_d=Hash.new(0) | |
counter=0 | |
Dir['*'].each do |filename| | |
next if filename.match(/\.json/).nil? | |
next unless filename.sub(/\.json/, '').match(/\=|stem-words|index|lenToRegex|ch-mapping|stem-ch-mapping|lenToRegex|precomputed/).nil? | |
json = JSON.parse(File.read(filename)) | |
json['h'].each do |value_h| | |
value_h.keys.each do |element| | |
keys_h[element] += 1 | |
values_h[value_h[element].class.to_s] += 1 | |
end | |
value_h['d'].each do |value_d| | |
counter += 1 | |
value_d.keys.each do |element| | |
keys_d[element] += 1 | |
values_d[value_d[element].class.to_s] += 1 | |
end | |
end | |
end | |
end | |
puts keys_h.inspect # => {"d"=>87} | |
puts values_h.inspect # => {"Array"=>87} | |
puts counter # => 100 | |
puts keys_d.inspect # => {"s"=>56, "f"=>100, "type"=>11, "e"=>18} | |
puts values_d.inspect # => {"Array"=>74, "String"=>111} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
keys=Hash.new(0) | |
values=Hash.new(0) | |
Dir['*'].each do |filename| | |
next if filename.match(/\.json/).nil? | |
next unless filename.sub(/\.json/, '').match(/\=|stem-words|index|lenToRegex|ch-mapping|stem-ch-mapping|lenToRegex|precomputed/).nil? | |
json = JSON.parse(File.read(filename)) | |
array = json.flatten | |
array.each_with_index do |element, i| | |
if i.even? | |
keys[element] += 1 | |
else | |
values["#{element.class.to_s}#{i}"] += 1 | |
end | |
end | |
end | |
puts keys.inspect # => {"h"=>39449, "t"=>39449, "stem"=>33099, "tag"=>4182} | |
puts values.inspect # => {"Array1"=>39449, "String3"=>39449, "String5"=>33420, "String7"=>3861} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
潘世光、博利亞阿法字典
amis-json-spec-check.rb
amis-json-spec-check-deeper.rb