Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2018
    New York
    Thanked 0 Times in 0 Posts

    How to access TokensAnnotation, TextAnnotation, NamedEntityTagAnnotation via Python a

    Hi, I'm hoping to get specific answers, since I can't find this in any existing Stanford Python wrapper or the documentation.

    I'm converting some Java to Python without any code documentation or much access to the original developer. I am NOT a Java coder.

    I have the Java StanfordCoreNLPServer running in the background (OSX)
    I have the Python module StanfordCoreNLP
    And I am able to do things like annotate with the code...

    class StanfordNLP:
    def __init__(self, host='http://localhost', port=9000):
        self.nlp = StanfordCoreNLP(host, port=port, timeout=30000)
        self.props = { 'annotators': 'tokenize,ssplit,pos,lemma,ner,parse,depparse,dcoref,relation',
                       'pipelineLanguage': 'de',
                       'outputFormat': 'json'
    def annotate(self, sentence):
        return json.loads(self.nlp.annotate(sentence, properties=self.props))
    but I have these Java lines in the code...

    for (CoreMap sentence : sentences) {
            // traversing the words in the current sentence
            // a CoreLabel is a CoreMap with additional token-specific methods
            for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
                // this is the text of the token
                String word = token.get(TextAnnotation.class);
                // this is the NER label of the token
                String ne = token.get(NamedEntityTagAnnotation.class);
                output += word + "/" + ne + " ";
    ...and I don't know how to access those features of the Stanford NLP library via Python and the StanfordCoreNLP.

    If this segment can be entirely replaced using Python NLTK, that would be fine as well.

    Last edited by vinyl-junkie; Jul 19th, 2018 at 07:09 AM. Reason: advertising/self-promotional link removed

  2. #2
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Behind the Wall
    Thanked 602 Times in 595 Posts
    Note: Java != JavaScript, like Austria != Australia
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  3. #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,715 Times in 2,689 Posts
    This is the Javascript forum - not Java (quite different from Javascript) nor Python. Ask a mod to move this thread to a more appropriate forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  4. #4
    Super Moderator vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Thanked 50 Times in 50 Posts
    Quote Originally Posted by Philip M View Post
    Ask a mod to move this thread to a more appropriate forum.
    Thread moved.
    Music Around The World - Collecting tips, trade and want lists, album reviews, & more


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts