Skip to content

Instantly share code, notes, and snippets.

@takehiko
Created January 31, 2019 14:37
Show Gist options
  • Select an option

  • Save takehiko/4b7e862e91a1e05a3ce7fe8843b9b163 to your computer and use it in GitHub Desktop.

Select an option

Save takehiko/4b7e862e91a1e05a3ce7fe8843b9b163 to your computer and use it in GitHub Desktop.
"Junjo" detector (designed for Order-of-Multiplication Dispute)
#!/usr/bin/env ruby
# junjo-detector.rb : 「かけ算の順序」(表記ゆれを含む)を見つける
# by takehikom
# ruby junjo-detector.rb
# ruby junjo-detector.rb file ...
# ruby junjo-detector.rb directory
def find_junjo(io, filename = nil)
r = /((かけ算)|(掛け?算)|(乗法))(の(式の)?)?順[序番]?/
prefix = (filename.nil? ? "" : (filename + ": "))
io.each_line do |line|
if r =~ line
line2 = line.gsub(r) { "《" + $& + "》" }
print prefix + line2
end
end
end
if __FILE__ == $0
if ARGV.empty?
find_junjo(DATA)
elsif test(?d, ARGV.first)
Dir.glob(ARGV.first + "/**/*") do |filename|
next if !test(?f, filename)
open(filename) do |f_in|
find_junjo(f_in, filename)
end
end
else
find_junjo(ARGF)
end
end
__END__
動作確認用
かけ算の順序 かけ算の順番 かけ算の順は?
掛け算の順序問題 掛け算の順番問題
掛算 掛算順序 掛算の順序 掛算の順番 掛け算の順が異なっている
かけ算の式の順番 かけ算の式の順序
乗法の順序 被乗数と乗数の順序 乗法の順番 乗法式順
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment