
    g=i                        d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d	Z G d
 de      ZddZ G d d      Z G d deee      Z G d de      Z G d de      Zd Zy)    N)ListTuple)_java_optionsconfig_javafind_jar_iterjava)ParserI)DependencyGraph)TaggerI)
TokenizerI)Treez&https://stanfordnlp.github.io/CoreNLP/c                       e Zd ZdZy)CoreNLPServerErrorz/Exceptions associated with the Core NLP server.N)__name__
__module____qualname____doc__     G/var/www/openai/venv/lib/python3.12/site-packages/nltk/parse/corenlp.pyr   r      s    9r   r   c                     t        j                   t         j                  t         j                        }|j                  d| f       |j	                         d   }|j                          |S )N    )socketAF_INETSOCK_STREAMbindgetsocknameclose)portsockps      r   try_portr#      sM    ==););<DIIr4j1AJJLHr   c                   B    e Zd ZdZdZ	 	 	 	 	 	 d	dZd
dZd Zd Zd Z	y)CoreNLPServerz0stanford-corenlp-(\d+)\.(\d+)\.(\d+)-models\.jarz)stanford-corenlp-(\d+)\.(\d+)\.(\d+)\.jarNc                     |ddg}t        t         j                  |ddt        |d            }t	        | fd      }|	 t        d	      }n't        |       |j                  d
t        |      g       d|  _	        t	        t         j                  |ddt        |d       fd      }	| _        ||	f _        | _        |xs dg _        y # t        $ r) t               }|j                  d
t        |      g       Y w xY w)Nz-preloadz(tokenize,ssplit,pos,lemma,parse,depparse)CORENLPr   T)env_vars
searchpathurlverboseis_regexc                 D    t        j                  j                  |       S N)rematch_JAR
model_nameselfs    r   <lambda>z(CoreNLPServer.__init__.<locals>.<lambda>E   s    J8Wr   )keyi(#  z-portzhttp://localhost:)CORENLP_MODELSc                 D    t        j                  j                  |       S r.   )r/   r0   _MODEL_JAR_PATTERNr2   s    r   r5   z(CoreNLPServer.__init__.<locals>.<lambda>]   s    288D,C,CZ#Pr   z-mx2g)listr   r1   _stanford_urlmaxr#   OSErrorextendstrr*   r9   r+   
_classpathcorenlp_optionsjava_options)
r4   path_to_jarpath_to_models_jarr+   rB   rA   r    jarsstanford_jar	model_jars
   `         r   __init__zCoreNLPServer.__init__,   s    ")+UVO		%!

 4%WX<=~
 TN""GSY#78&tf-''",! Q
	 &	1.(5WI7  =z&&T';<=s   C /DDc                    ddl }dg}| j                  r|j                  | j                         dj                  t              }t        | j                  | j                         	 t        || j                  d||      | _
        t        || j                         | j                  j                         }|G| j                  j                         \  }}t        |dj                  |j                  d	                  t!        d
      D ]F  }		 |j#                  |j$                  j'                  | j(                  d            }
|
j*                  sF n t        d      t!        d      D ]F  }		 |j#                  |j$                  j'                  | j(                  d            }
|
j*                  sF y t        d      # t        || j                         w xY w# |j,                  j.                  $ r t1        j2                  d       Y w xY w# |j,                  j.                  $ r t1        j2                  d       Y w xY w)zStarts the CoreNLP server

        :param stdout, stderr: Specifies where CoreNLP output is redirected. Valid values are 'devnull', 'stdout', 'pipe'
        r   Nz/edu.stanford.nlp.pipeline.StanfordCoreNLPServer )optionsr+   F)	classpathblockingstdoutstderrz-Could not start the server. The error was: {}ascii   liver   z Could not connect to the server.<   readyzThe server is not ready.)requestsrA   r>   joinr   r   rB   r+   r   r@   popenpollcommunicater   formatdecoderangegetcompaturljoinr*   ok
exceptionsConnectionErrortimesleep)r4   rN   rO   rU   cmddefault_options
returncode_
stderrdatairesponses              r   startzCoreNLPServer.startg   s   
 	@AJJt++, ((=1D--t||D
	G//DJ F ZZ__&
! JJ224MAz$$$*F:+<+<W+E$F  rA#<<(?(?&(QR ;;  %%GHHrA#<<(?(?'(RS ;;  %%?@@A F &&66 

1 &&66 

1s0   &F= 5G-5H=G.H
	H
.H>=H>c                 l    | j                   j                          | j                   j                          y r.   )rW   	terminatewaitr4   s    r   stopzCoreNLPServer.stop   s     



r   c                 &    | j                          | S r.   )rl   rp   s    r   	__enter__zCoreNLPServer.__enter__   s    

r   c                 $    | j                          y)NF)rq   )r4   exc_typeexc_valexc_tbs       r   __exit__zCoreNLPServer.__exit__   s    		r   )NNFNNN)devnullry   )
r   r   r   r9   r1   rH   rl   rq   rs   rx   r   r   r   r%   r%   (   s=    L7D 96v:Ax
r   r%   c                   z    e Zd ZdZ	 	 	 	 ddZd ZddZddZ	 ddZd Z	dd	Z
d
 Zdedeeeef      fdZd Zy)GenericCoreNLPParserz Interface to the CoreNLP Parser.Nc                     dd l }|| _        || _        |dvrt        d      || _        || _        |j                         | _        y )Nr   )posnerNz+tagtype must be either 'pos', 'ner' or None)rU   r*   encoding
ValueErrortagtypestrict_jsonSessionsession)r4   r*   r   r   r   rU   s         r   rH   zGenericCoreNLPParser.__init__   sI     	 ..JKK&'')r   c                 @    d |D        } | j                   |g|i |S )a  Parse multiple sentences.

        Takes multiple sentences as a list where each sentence is a list of
        words. Each sentence will be automatically tagged with this
        CoreNLPParser instance's tagger.

        If a whitespace exists inside a token, then the token will be treated as
        several tokens.

        :param sentences: Input sentences to parse
        :type sentences: list(list(str))
        :rtype: iter(iter(Tree))
        c              3   >   K   | ]  }d j                  |        ywrJ   NrV   .0wordss     r   	<genexpr>z3GenericCoreNLPParser.parse_sents.<locals>.<genexpr>        <)SXXe_)   )raw_parse_sents)r4   	sentencesargskwargss       r   parse_sentsz GenericCoreNLPParser.parse_sents   s+     =)<	#t##I????r   c                 x    ddi}|j                  |xs i        t         | j                  |gg|d|i|      S )a  Parse a sentence.

        Takes a sentence as a string; before parsing, it will be automatically
        tokenized and tagged by the CoreNLP Parser.

        :param sentence: Input sentence to parse
        :type sentence: str
        :rtype: iter(Tree)
        ztokenize.whitespacefalse
properties)updatenextr   )r4   sentencer   r   r   default_propertiess         r   	raw_parsezGenericCoreNLPParser.raw_parse   s\     4W=!!*"23 D  
<@'9DJ
 	
r   c                    ddj                  | j                        d}|j                  |xs i        | j                  j	                  | j
                  dt        j                  |      i|j                  | j                        dd| j                   i|      }|j                          |j                  | j                  	      S )
Njsonz,tokenize,pos,lemma,ssplit,{parser_annotator})parser_annotator)outputFormat
annotatorsr   zContent-Typeztext/plain; charset=)paramsdataheaderstimeout)strict)rZ   r   r   r   postr*   r   dumpsencoder   raise_for_statusr   )r4   r   r   r   r   rk   s         r   api_callzGenericCoreNLPParser.api_call   s    "HOO!%!6!6 P 
 	!!*"23<<$$HH $**-?"@AT]]+#';DMM?%KL % 
 	!!#}}D$4$4}55r   c              /      K   ddi}|j                  |xs i        	 | j                  dj                  |      |      }|d   D ]!  }| j                  |      }	t	        |	g       # yw)a  Parse multiple sentences.

        Takes multiple sentences as a list of strings. Each sentence will be
        automatically tokenized and tagged.

        :param sentences: Input sentences to parse.
        :type sentences: list(str)
        :rtype: iter(iter(Tree))

        zssplit.eolonlytrue
r   r   N)r   r   rV   	make_treeiter)
r4   r   r+   r   r   r   r   parsed_dataparsed_senttrees
             r   r   z$GenericCoreNLPParser.raw_parse_sents  sv      f

 	!!*"23		 mmDIIi$8EWmX&{3K>>+.Dv, 4s   A'A)c              /   r   K    | j                   |g|i |}|d   D ]  }| j                  |        yw)a  Parse a piece of text.

        The text might contain several sentences which will be split by CoreNLP.

        :param str text: text to be split.
        :returns: an iterable of syntactic structures.  # TODO: should it be an iterable of iterables?

        r   N)r   r   )r4   textr   r   r   parses         r   
parse_textzGenericCoreNLPParser.parse_text&  s@      $dmmD:4:6: -E..'' .s   57c              #      K   ddi}|j                  |xs i        | j                  ||      }|d   D ]  }|d   D ]  }|d   xs |d      yw)	a  Tokenize a string of text.

        Skip these tests if CoreNLP is likely not ready.
        >>> from nltk.test.setup_fixt import check_jar
        >>> check_jar(CoreNLPServer._JAR, env_vars=("CORENLP",), is_regex=True)

        The CoreNLP server can be started using the following notation, although
        we recommend the `with CoreNLPServer() as server:` context manager notation
        to ensure that the server is always stopped.
        >>> server = CoreNLPServer()
        >>> server.start()
        >>> parser = CoreNLPParser(url=server.url)

        >>> text = 'Good muffins cost $3.88\nin New York.  Please buy me\ntwo of them.\nThanks.'
        >>> list(parser.tokenize(text))
        ['Good', 'muffins', 'cost', '$', '3.88', 'in', 'New', 'York', '.', 'Please', 'buy', 'me', 'two', 'of', 'them', '.', 'Thanks', '.']

        >>> s = "The colour of the wall is blue."
        >>> list(
        ...     parser.tokenize(
        ...         'The colour of the wall is blue.',
        ...             properties={'tokenize.options': 'americanize=true'},
        ...     )
        ... )
        ['The', 'colour', 'of', 'the', 'wall', 'is', 'blue', '.']
        >>> server.stop()

        r   ztokenize,ssplitr   r   tokensoriginalTextwordN)r   r   )r4   r   r   r   resultr   tokens          r   tokenizezGenericCoreNLPParser.tokenize4  sl     : +,=>!!*"23t0BC{+H!(+N+<uV}< , ,s   AAc                 b    d |D        }| j                  |      D cg c]  }|d   	 c}S c c}w )a  
        Tag multiple sentences.

        Takes multiple sentences as a list where each sentence is a list of
        tokens.

        :param sentences: Input sentences to tag
        :type sentences: list(list(str))
        :rtype: list(list(tuple(str, str))
        c              3   >   K   | ]  }d j                  |        ywr   r   r   s     r   r   z1GenericCoreNLPParser.tag_sents.<locals>.<genexpr>g  r   r   r   )raw_tag_sents)r4   r   s     r   	tag_sentszGenericCoreNLPParser.tag_sents[  s7     =)<	.2.@.@.KL.K	!.KLLLs   ,r   returnc                 ,    | j                  |g      d   S )ay  
        Tag a list of tokens.

        :rtype: list(tuple(str, str))

        Skip these tests if CoreNLP is likely not ready.
        >>> from nltk.test.setup_fixt import check_jar
        >>> check_jar(CoreNLPServer._JAR, env_vars=("CORENLP",), is_regex=True)

        The CoreNLP server can be started using the following notation, although
        we recommend the `with CoreNLPServer() as server:` context manager notation
        to ensure that the server is always stopped.
        >>> server = CoreNLPServer()
        >>> server.start()
        >>> parser = CoreNLPParser(url=server.url, tagtype='ner')
        >>> tokens = 'Rami Eid is studying at Stony Brook University in NY'.split()
        >>> parser.tag(tokens)  # doctest: +NORMALIZE_WHITESPACE
        [('Rami', 'PERSON'), ('Eid', 'PERSON'), ('is', 'O'), ('studying', 'O'), ('at', 'O'), ('Stony', 'ORGANIZATION'),
        ('Brook', 'ORGANIZATION'), ('University', 'ORGANIZATION'), ('in', 'O'), ('NY', 'STATE_OR_PROVINCE')]

        >>> parser = CoreNLPParser(url=server.url, tagtype='pos')
        >>> tokens = "What is the airspeed of an unladen swallow ?".split()
        >>> parser.tag(tokens)  # doctest: +NORMALIZE_WHITESPACE
        [('What', 'WP'), ('is', 'VBZ'), ('the', 'DT'),
        ('airspeed', 'NN'), ('of', 'IN'), ('an', 'DT'),
        ('unladen', 'JJ'), ('swallow', 'VB'), ('?', '.')]
        >>> server.stop()
        r   )r   )r4   r   s     r   tagzGenericCoreNLPParser.tagj  s    : ~~xj)!,,r   c              #   "  K   ddd}| j                   dv sJ |dxx   | j                   z  cc<   |D ]O  }| j                  ||      }|d   D cg c]'  }|d   D cg c]  }|d	   || j                      f c}) c}} Q y
c c}w c c}}w w)z
        Tag multiple sentences.

        Takes multiple sentences as a list where each sentence is a string.

        :param sentences: Input sentences to tag
        :type sentences: list(str)
        :rtype: list(list(list(tuple(str, str)))
        r   ztokenize,ssplit,)zssplit.isOneSentencer   )r}   r~   r   r   r   r   r   N)r   r   )r4   r   r   r   tagged_datatagged_sentencer   s          r   r   z"GenericCoreNLPParser.raw_tag_sents  s      %+,
 ||~---<(DLL8(!H--=O-PK (3;'?
 (@O "1!:!: 6]E$,,$78!: (@  "s*   ABB	B6B	;	BB		B)zhttp://localhost:9000utf8NTr.   )NrS   )FN)r   r   r   r   rH   r   r   r   r   r   r   r   r?   r   r   r   r   r   r   r   r{   r{      si    * $*(@$
&6. 48!F(%=NM-C -DsCx$9 ->r   r{   c                       e Zd ZdZdZdZd Zy)CoreNLPParseru  
    Skip these tests if CoreNLP is likely not ready.
    >>> from nltk.test.setup_fixt import check_jar
    >>> check_jar(CoreNLPServer._JAR, env_vars=("CORENLP",), is_regex=True)

    The recommended usage of `CoreNLPParser` is using the context manager notation:
    >>> with CoreNLPServer() as server:
    ...     parser = CoreNLPParser(url=server.url)
    ...     next(
    ...         parser.raw_parse('The quick brown fox jumps over the lazy dog.')
    ...     ).pretty_print()  # doctest: +NORMALIZE_WHITESPACE
                            ROOT
                            |
                            S
            _______________|__________________________
            |                         VP               |
            |                _________|___             |
            |               |             PP           |
            |               |     ________|___         |
            NP              |    |            NP       |
        ____|__________     |    |     _______|____    |
        DT   JJ    JJ   NN  VBZ   IN   DT      JJ   NN  .
        |    |     |    |    |    |    |       |    |   |
        The quick brown fox jumps over the     lazy dog  .

    Alternatively, the server can be started using the following notation.
    Note that `CoreNLPServer` does not need to be used if the CoreNLP server is started
    outside of Python.
    >>> server = CoreNLPServer()
    >>> server.start()
    >>> parser = CoreNLPParser(url=server.url)

    >>> (parse_fox, ), (parse_wolf, ) = parser.raw_parse_sents(
    ...     [
    ...         'The quick brown fox jumps over the lazy dog.',
    ...         'The quick grey wolf jumps over the lazy fox.',
    ...     ]
    ... )

    >>> parse_fox.pretty_print()  # doctest: +NORMALIZE_WHITESPACE
                         ROOT
                          |
                          S
           _______________|__________________________
          |                         VP               |
          |                _________|___             |
          |               |             PP           |
          |               |     ________|___         |
          NP              |    |            NP       |
      ____|__________     |    |     _______|____    |
     DT   JJ    JJ   NN  VBZ   IN   DT      JJ   NN  .
     |    |     |    |    |    |    |       |    |   |
    The quick brown fox jumps over the     lazy dog  .

    >>> parse_wolf.pretty_print()  # doctest: +NORMALIZE_WHITESPACE
                         ROOT
                          |
                          S
           _______________|__________________________
          |                         VP               |
          |                _________|___             |
          |               |             PP           |
          |               |     ________|___         |
          NP              |    |            NP       |
      ____|_________      |    |     _______|____    |
     DT   JJ   JJ   NN   VBZ   IN   DT      JJ   NN  .
     |    |    |    |     |    |    |       |    |   |
    The quick grey wolf jumps over the     lazy fox  .

    >>> (parse_dog, ), (parse_friends, ) = parser.parse_sents(
    ...     [
    ...         "I 'm a dog".split(),
    ...         "This is my friends ' cat ( the tabby )".split(),
    ...     ]
    ... )

    >>> parse_dog.pretty_print()  # doctest: +NORMALIZE_WHITESPACE
            ROOT
             |
             S
      _______|____
     |            VP
     |    ________|___
     NP  |            NP
     |   |         ___|___
    PRP VBP       DT      NN
     |   |        |       |
     I   'm       a      dog

    >>> parse_friends.pretty_print()  # doctest: +NORMALIZE_WHITESPACE
         ROOT
          |
          S
      ____|___________
     |                VP
     |     ___________|_____________
     |    |                         NP
     |    |                  _______|________________________
     |    |                 NP           |        |          |
     |    |            _____|_______     |        |          |
     NP   |           NP            |    |        NP         |
     |    |     ______|_________    |    |     ___|____      |
     DT  VBZ  PRP$   NNS       POS  NN -LRB-  DT       NN  -RRB-
     |    |    |      |         |   |    |    |        |     |
    This  is   my  friends      '  cat -LRB- the     tabby -RRB-

    >>> parse_john, parse_mary, = parser.parse_text(
    ...     'John loves Mary. Mary walks.'
    ... )

    >>> parse_john.pretty_print()  # doctest: +NORMALIZE_WHITESPACE
          ROOT
           |
           S
      _____|_____________
     |          VP       |
     |      ____|___     |
     NP    |        NP   |
     |     |        |    |
    NNP   VBZ      NNP   .
     |     |        |    |
    John loves     Mary  .

    >>> parse_mary.pretty_print()  # doctest: +NORMALIZE_WHITESPACE
          ROOT
           |
           S
      _____|____
     NP    VP   |
     |     |    |
    NNP   VBZ   .
     |     |    |
    Mary walks  .

    Special cases

    >>> next(
    ...     parser.raw_parse(
    ...         'NASIRIYA, Iraq—Iraqi doctors who treated former prisoner of war '
    ...         'Jessica Lynch have angrily dismissed claims made in her biography '
    ...         'that she was raped by her Iraqi captors.'
    ...     )
    ... ).height()
    14

    >>> next(
    ...     parser.raw_parse(
    ...         "The broader Standard & Poor's 500 Index <.SPX> was 0.46 points lower, or "
    ...         '0.05 percent, at 997.02.'
    ...     )
    ... ).height()
    11

    >>> server.stop()
    pennr   c                 2    t        j                  |d         S )Nr   )r   
fromstringr4   r   s     r   r   zCoreNLPParser.make_treeF  s    vg//r   Nr   r   r   r   _OUTPUT_FORMATr   r   r   r   r   r   r     s    Zx N0r   r   c                       e Zd ZdZdZdZd Zy)CoreNLPDependencyParsera  Dependency parser.

    Skip these tests if CoreNLP is likely not ready.
    >>> from nltk.test.setup_fixt import check_jar
    >>> check_jar(CoreNLPServer._JAR, env_vars=("CORENLP",), is_regex=True)

    The recommended usage of `CoreNLPParser` is using the context manager notation:
    >>> with CoreNLPServer() as server:
    ...     dep_parser = CoreNLPDependencyParser(url=server.url)
    ...     parse, = dep_parser.raw_parse(
    ...         'The quick brown fox jumps over the lazy dog.'
    ...     )
    ...     print(parse.to_conll(4))  # doctest: +NORMALIZE_WHITESPACE
    The        DT      4       det
    quick      JJ      4       amod
    brown      JJ      4       amod
    fox        NN      5       nsubj
    jumps      VBZ     0       ROOT
    over       IN      9       case
    the        DT      9       det
    lazy       JJ      9       amod
    dog        NN      5       obl
    .  .       5       punct

    Alternatively, the server can be started using the following notation.
    Note that `CoreNLPServer` does not need to be used if the CoreNLP server is started
    outside of Python.
    >>> server = CoreNLPServer()
    >>> server.start()
    >>> dep_parser = CoreNLPDependencyParser(url=server.url)
    >>> parse, = dep_parser.raw_parse('The quick brown fox jumps over the lazy dog.')
    >>> print(parse.tree())  # doctest: +NORMALIZE_WHITESPACE
    (jumps (fox The quick brown) (dog over the lazy) .)

    >>> for governor, dep, dependent in parse.triples():
    ...     print(governor, dep, dependent)  # doctest: +NORMALIZE_WHITESPACE
    ('jumps', 'VBZ') nsubj ('fox', 'NN')
    ('fox', 'NN') det ('The', 'DT')
    ('fox', 'NN') amod ('quick', 'JJ')
    ('fox', 'NN') amod ('brown', 'JJ')
    ('jumps', 'VBZ') obl ('dog', 'NN')
    ('dog', 'NN') case ('over', 'IN')
    ('dog', 'NN') det ('the', 'DT')
    ('dog', 'NN') amod ('lazy', 'JJ')
    ('jumps', 'VBZ') punct ('.', '.')

    >>> (parse_fox, ), (parse_dog, ) = dep_parser.raw_parse_sents(
    ...     [
    ...         'The quick brown fox jumps over the lazy dog.',
    ...         'The quick grey wolf jumps over the lazy fox.',
    ...     ]
    ... )
    >>> print(parse_fox.to_conll(4))  # doctest: +NORMALIZE_WHITESPACE
    The        DT      4       det
    quick      JJ      4       amod
    brown      JJ      4       amod
    fox        NN      5       nsubj
    jumps      VBZ     0       ROOT
    over       IN      9       case
    the        DT      9       det
    lazy       JJ      9       amod
    dog        NN      5       obl
    .  .       5       punct

    >>> print(parse_dog.to_conll(4))  # doctest: +NORMALIZE_WHITESPACE
    The        DT      4       det
    quick      JJ      4       amod
    grey       JJ      4       amod
    wolf       NN      5       nsubj
    jumps      VBZ     0       ROOT
    over       IN      9       case
    the        DT      9       det
    lazy       JJ      9       amod
    fox        NN      5       obl
    .  .       5       punct

    >>> (parse_dog, ), (parse_friends, ) = dep_parser.parse_sents(
    ...     [
    ...         "I 'm a dog".split(),
    ...         "This is my friends ' cat ( the tabby )".split(),
    ...     ]
    ... )
    >>> print(parse_dog.to_conll(4))  # doctest: +NORMALIZE_WHITESPACE
    I   PRP     4       nsubj
    'm  VBP     4       cop
    a   DT      4       det
    dog NN      0       ROOT

    >>> print(parse_friends.to_conll(4))  # doctest: +NORMALIZE_WHITESPACE
    This       DT      6       nsubj
    is VBZ     6       cop
    my PRP$    4       nmod:poss
    friends    NNS     6       nmod:poss
    '  POS     4       case
    cat        NN      0       ROOT
    (  -LRB-   9       punct
    the        DT      9       det
    tabby      NN      6       dep
    )  -RRB-   9       punct

    >>> parse_john, parse_mary, = dep_parser.parse_text(
    ...     'John loves Mary. Mary walks.'
    ... )

    >>> print(parse_john.to_conll(4))  # doctest: +NORMALIZE_WHITESPACE
    John       NNP     2       nsubj
    loves      VBZ     0       ROOT
    Mary       NNP     2       obj
    .  .       2       punct

    >>> print(parse_mary.to_conll(4))  # doctest: +NORMALIZE_WHITESPACE
    Mary        NNP     2       nsubj
    walks       VBZ     0       ROOT
    .   .       2       punct

    Special cases

    Non-breaking space inside of a token.

    >>> len(
    ...     next(
    ...         dep_parser.raw_parse(
    ...             'Anhalt said children typically treat a 20-ounce soda bottle as one '
    ...             'serving, while it actually contains 2 1/2 servings.'
    ...         )
    ...     ).nodes
    ... )
    23

    Phone  numbers.

    >>> len(
    ...     next(
    ...         dep_parser.raw_parse('This is not going to crash: 01 111 555.')
    ...     ).nodes
    ... )
    10

    >>> print(
    ...     next(
    ...         dep_parser.raw_parse('The underscore _ should not simply disappear.')
    ...     ).to_conll(4)
    ... )  # doctest: +NORMALIZE_WHITESPACE
    The        DT      2       det
    underscore NN      7       nsubj
    _  NFP     7       punct
    should     MD      7       aux
    not        RB      7       advmod
    simply     RB      7       advmod
    disappear  VB      0       ROOT
    .  .       7       punct

    >>> print(
    ...     next(
    ...         dep_parser.raw_parse(
    ...             'for all of its insights into the dream world of teen life , and its electronic expression through '
    ...             'cyber culture , the film gives no quarter to anyone seeking to pull a cohesive story out of its 2 '
    ...             '1/2-hour running time .'
    ...         )
    ...     ).to_conll(4)
    ... )  # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
    for        IN      2       case
    all        DT      24      obl
    of IN      5       case
    its        PRP$    5       nmod:poss
    insights   NNS     2       nmod
    into       IN      9       case
    the        DT      9       det
    dream      NN      9       compound
    world      NN      5       nmod
    of IN      12      case
    teen       NN      12      compound
    ...

    >>> server.stop()
    	conll2007depparsec                 N    t        d t        t        |            D        d      S )Nc              3   D   K   | ]  }d j                  |dd         yw)rJ   r   Nr   )r   n_itemss     r   r   z4CoreNLPDependencyParser.make_tree.<locals>.<genexpr>  s'      8G %8s    rJ   )cell_separator)r
   sorted	transformr   s     r   r   z!CoreNLPDependencyParser.make_tree  s+    %i&78 
 	
r   Nr   r   r   r   r   r   J  s    ob !N!
r   r   c              #      K   | d   D ]<  }|d   }| d   |dz
     }|d|d   |d   |d   |d   dt        |d	         |d
   ddf > y w)NbasicDependencies	dependentr   r   rh   r   lemmar}   governordep)r?   )r   
dependencydependent_indexr   s       r   r   r   	  s     23
$[1"?Q#67
 &M'N%L%L
:&'u
 	
 4s   AA)r   ) r   osr/   r   rc   typingr   r   nltk.internalsr   r   r   r   nltk.parse.apir	   nltk.parse.dependencygraphr
   nltk.tag.apir   nltk.tokenize.apir   	nltk.treer   r;   EnvironmentErrorr   r#   r%   r{   r   r   r   r   r   r   <module>r      s     	 	    J J " 6   ( 8:) :F FRr7J rja0( a0H|
2 |
~
r   