#!/usr/bin/ruby def pythonify(rubysource, namespace) private_scope = false python_class = nil comment = nil namespace_wrapper_generated = false cls = <', ':').gsub(/RDF::URI\.new\(([^)]+)\)/, uri_wrapper).gsub('true', 'True').gsub('false', 'False').gsub(/(\w+)\.select ?\{ ?\|(\w+)\| ?(.*[^ ]) ?\}/, 'filter(lambda \2: \3, \1)').gsub(/(\w)\?\(/, '\1(').gsub('has_parent(', 'cls.has_parent(') transduction.gsub!("Namespace('", "Namespace('#{namespace}") if private_scope transduction.gsub!('__', 'cls.__') unless line.strip.start_with?('@@') end cls << "#{transduction.gsub(/^( +)/, '\1\1')}\n" if transduction } cls end unless @loaded_externally then namespace = nil if ARGV.length == 1 then namespace = ARGV[0] end puts pythonify(STDIN, namespace) end