Commit a949d045 authored by Koichi Yasuoka's avatar Koichi Yasuoka
Browse files

bug fix for python2.7

parent 195601da
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
#! /usr/bin/python -i
# "UDPipe2UD.py" by Koichi Yasuoka, June 27, 2019.
# "UDPipe2UD.py" by Koichi Yasuoka, July 2, 2019.

class UDPipeEntry:
  def __init__(self,result):
@@ -54,13 +54,14 @@ class UDPipe2UD:
    self.parseURL="http://lindat.mff.cuni.cz/services/udpipe/api/process?model="+lang+"&"+option
  def __call__(self,sentence):
    import json
    s=sentence if type(sentence) is str else sentence.encode("utf-8")
    try:
      import urllib.request,urllib.parse
      with urllib.request.urlopen(self.parseURL+"&data="+urllib.parse.quote(sentence)) as r:
      with urllib.request.urlopen(self.parseURL+"&data="+urllib.parse.quote(s)) as r:
        q=r.read()
    except:
      import urllib,urllib2
      r=urllib2.urlopen(self.parseURL+"&data="+urllib.quote(sentence))
      r=urllib2.urlopen(self.parseURL+"&data="+urllib.quote(s))
      q=r.read().decode("utf-8")
    return UDPipeEntry(json.loads(q)["result"])