Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output gets generated to stdout #81

Closed
yyellin opened this issue May 7, 2019 · 4 comments
Closed

output gets generated to stdout #81

yyellin opened this issue May 7, 2019 · 4 comments

Comments

@yyellin
Copy link

yyellin commented May 7, 2019

During initialization of stanfordnlp.Pipeline() output gets generated to stdout - this makes it difficult to integrate within command line utilities that too send their output to stdout.
So for example, assuming a python script 'process_text' I would like for it to accept input from stdin, and sent output to stdout, so that I can run something like:
grep "something" input_file | process_text
Currently this won't work.

@dlazesz
Copy link

dlazesz commented Jul 4, 2019

Very sophisticated workaround:

import os
import sys
my_stdout = sys.stdout  # Save STDOUT
sys.stdout = open(os.devnull, 'w', encoding='UTF-8')  # Overload STDOUT to /dev/null


import stanfordnlp

nlp = stanfordnlp.Pipeline(processors='tokenize,mwt,pos,lemma,depparse', lang='en', models_dir='.')  # Shut up!
doc = nlp('Your text here!')
sys.stdout = my_stdout  # Restore STDOUT
for i, sentence in enumerate(doc.sentences):
    print(f"Sentence {i}:")
    sentence.print_tokens()

Should be done internally with some config switch.

@qipeng
Copy link
Collaborator

qipeng commented Jul 28, 2019

Good catch! This is definitely an area of improvement for us. Will add this to our TODO list for future releases.

@qipeng
Copy link
Collaborator

qipeng commented Mar 17, 2020

Now all logging has been moved to Python's logging package and controlled at the Pipeline level, part of the new v1.0.0 release: https://github.com/stanfordnlp/stanza/releases/tag/v1.0.0

Closing now!

@qipeng qipeng closed this as completed Mar 17, 2020
@vegai
Copy link

vegai commented Apr 27, 2020

You should probably not define a global logger in __init__.py because that seems to overwrite whatever loggers are defined by an application when it runs import stanza

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

No branches or pull requests

4 participants