Skip to content

Instantly share code, notes, and snippets.

@dustalov
Last active April 22, 2019 12:44
Show Gist options
  • Save dustalov/3900780 to your computer and use it in GitHub Desktop.
Save dustalov/3900780 to your computer and use it in GitHub Desktop.
Tesuçk Invocation Script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
import argparse
import httplib, urllib
from urlparse import urlparse
parser = argparse.ArgumentParser(description='Invoke Tesuçk.')
parser.add_argument('-o', '--output', required=True,
help='Output file name')
parser.add_argument('-i', '--input', required=True,
help='Input file name')
parser.add_argument('-l', '--language', required=True, default='ru',
help='Preferred language (ru, en)')
parser.add_argument('-a', '--approach', default='textrank',
help='Preferred approach (degext, textrank)')
parser.add_argument('-w', '--window', type=int, default=2,
help='Specify the words window')
parser.add_argument('-e', '--endpoint',
default='http://tesuck.eveel.ru/extract.graphml',
help='Endpoint URI')
args = parser.parse_args()
with open(args.input, 'r') as input:
text = input.read()
url = urlparse(args.endpoint)
params = urllib.urlencode({
'text': text,
'language': args.language,
'approach': args.approach,
'window': args.window
})
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/plain'
}
conn = httplib.HTTPConnection(url.netloc)
conn.request('POST', url.path, params, headers)
response = conn.getresponse()
data = response.read()
with open(args.output, 'w') as output:
output.write(data)
conn.close()
#!/usr/bin/env ruby
# encoding: utf-8
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
require 'optparse'
options = {
endpoint: 'http://tesuck.eveel.ru/extract.graphml',
approach: 'textrank',
language: 'ru',
window: '2'
}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
opts.on '-o', '--output FILE', 'Output file name' do |o|
o and options[:output] = o
end
opts.on '-i', '--input FILE', 'Input file name' do |i|
i and options[:input] = i
end
opts.on '-a', '--approach [TYPE]', %w(degext textrank),
'Preferred approach (degext, textrank)' do |a|
a and options[:approach] = a
end
opts.on '-l', '--language [LANG]', %w(ru en),
'Preferred language (ru, en)' do |l|
l and options[:language] = l
end
opts.on '-w', '--window [N]', 'Specify the words window' do |w|
options[:window] = w if w.to_i > 0
end
opts.on '-e', '--endpoint [URI]', 'Endpoint URI' do |e|
e and options[:endpoint] = e
end
opts.on_tail '-h', '--help', 'Display this help and exit' do
puts opts
exit
end
end
optparse.parse!
require 'cgi'
require 'uri'
require 'net/http'
unless options[:input] && options[:output] && options[:endpoint]
puts optparse
exit 1
end
rep = Net::HTTP.post_form(URI(options[:endpoint]),
'text' => File.read(options[:input]),
'approach' => options[:approach],
'language' => options[:language],
'window' => options[:window])
case rep
when Net::HTTPSuccess then
File.open(options[:output], 'w') { |f| f.write(rep.body) }
else
raise '%d: %s' % [rep.code, rep.message]
end
@SerzhNS
Copy link

SerzhNS commented Sep 15, 2017

На простом примере из 2-х предложений код на .rb дает ошибку:
C:/Ruby24-x64/lib/ruby/2.4.0/net/protocol.rb:176:in rbuf_fill': Net::ReadTimeout (Net::ReadTimeout) from invoke.rb:65:in

'.
Лечится?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment