philipperemy / stanford-openie-python

Stanford Open Information Extraction made simple!
ISC License
635 stars 102 forks source link

UnsupportedOperation: fileno #53

Closed leo-smi closed 2 years ago

leo-smi commented 2 years ago

I have installed GraphViz on my windows 10 x64, python 3.10.1

from openie import StanfordOpenIE

# https://stanfordnlp.github.io/CoreNLP/openie.html#api
# Default value of openie.affinity_probability_cap was 1/3.
properties = {
    'openie.affinity_probability_cap': 2 / 3,
}

with StanfordOpenIE(properties=properties) as client:
    text = 'Barack Obama was born in Hawaii. Richard Manning wrote this sentence.'
    print('Text: %s.' % text)
    for triple in client.annotate(text):
        print('|-', triple)

    graph_image = 'graph.png'
    client.generate_graphviz_graph(text, graph_image)
    print('Graph generated: %s.' % graph_image)

    with open('corpus/pg6130.txt', encoding='utf8') as r:
        corpus = r.read().replace('\n', ' ').replace('\r', '')

    triples_corpus = client.annotate(corpus[0:5000])
    print('Corpus: %s [...].' % corpus[0:80])
    print('Found %s triples in the corpus.' % len(triples_corpus))
    for triple in triples_corpus[:3]:
        print('|-', triple)
    print('[...]')

ERROR

Text: Barack Obama was born in Hawaii. Richard Manning wrote this sentence..
Starting server with command: java -Xmx8G -cp C:\Users\leand\.stanfordnlp_resources\stanford-corenlp-4.1.0/* edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 60000 -threads 5 -maxCharLength 100000 -quiet True -serverProperties corenlp_server-7d8b9d63184a4a3b.props -preload openie
|- {'subject': 'Barack Obama', 'relation': 'was', 'object': 'born'}
|- {'subject': 'Barack Obama', 'relation': 'was born in', 'object': 'Hawaii'}
|- {'subject': 'Richard Manning', 'relation': 'wrote', 'object': 'sentence'}
---------------------------------------------------------------------------
UnsupportedOperation                      Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9140/148240852.py in <module>
     14 
     15     graph_image = 'graph.png'
---> 16     client.generate_graphviz_graph(text, graph_image)
     17     print('Graph generated: %s.' % graph_image)
     18 

~\AppData\Local\Programs\Python\Python310\lib\site-packages\openie\openie.py in generate_graphviz_graph(self, text, png_filename)
     93 
     94         command = 'dot -Tpng {} -o {}'.format(out_dot, png_filename)
---> 95         dot_process = Popen(command, stdout=stderr, shell=True)
     96         dot_process.wait()
     97         assert not dot_process.returncode, 'ERROR: Call to dot exited with a non-zero code status.'

~\AppData\Local\Programs\Python\Python310\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
    830         (p2cread, p2cwrite,
    831          c2pread, c2pwrite,
--> 832          errread, errwrite) = self._get_handles(stdin, stdout, stderr)
    833 
    834         # We wrap OS handles *before* launching the child, otherwise a

~\AppData\Local\Programs\Python\Python310\lib\subprocess.py in _get_handles(self, stdin, stdout, stderr)
   1297             else:
   1298                 # Assuming file-like object
-> 1299                 c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
   1300             c2pwrite = self._make_inheritable(c2pwrite)
   1301 

~\AppData\Local\Programs\Python\Python310\lib\site-packages\ipykernel\iostream.py in fileno(self)
    306             return self._original_stdstream_copy
    307         else:
--> 308             raise io.UnsupportedOperation("fileno")
    309 
    310     def _watch_pipe_fd(self):

UnsupportedOperation: fileno
philipperemy commented 2 years ago

@leo-smi Windows is not correctly supported.. Sorry about that

leo-smi commented 2 years ago

@leo-smi Windows is not correctly supported.. Sorry about that

Thanks!