GithubHelp home page GithubHelp logo

Parsing API about spacy HOT 12 CLOSED

explosion avatar explosion commented on May 3, 2024
Parsing API

from spacy.

Comments (12)

honnibal avatar honnibal commented on May 3, 2024

Okay, thanks. This part was a little bit hasty. I wanted to polish things a bit more before release, but am travelling soon so bit the bullet and decided to put it in people's hands.

I think it's clear that there needs to be some sort of child node iterator, possibly for left and right subtrees, as well as a way to get the left and right arity of the node.

I think the positive/negative indexing I did here is bad, too. It just needs to be a sequence, -1 should always be "from the end".

How do you feel about these names?

n_left
n_right
lefts
rights
siblings

One trick could be that siblings iterates in alternating left/right order. If you need the left or right siblings, you can do token.head.lefts or token.head.rights. If you only need the two nearest leftmost, you can do siblings[0:4:2]

from spacy.

simonhughes22 avatar simonhughes22 commented on May 3, 2024

That sounds reasonable. I think the main thing is to have a reliable way of iterating through the children and getting the parent. The rest is helpful. As child() is somewhat unreliable, I have to use the head property to get the full tree presently.

Simon Hughes | Chief Data Scientist | Dice Data Science Team | Dice Holdings, Inc.
Dice | eFinancialCareers | ClearanceJobs | Rigzone | HealthCallings | Targeted Job Fairs
M: 515.371.4258

From: honnibal <[email protected]mailto:[email protected]>
Reply-To: honnibal/spaCy <[email protected]mailto:[email protected]>
Date: Wednesday, January 28, 2015 at 10:37 PM
To: honnibal/spaCy <[email protected]mailto:[email protected]>
Cc: Simon Hughes <[email protected]mailto:[email protected]>
Subject: Re: [spaCy] Parsing API (#14)

Okay, thanks. This part was a little bit hasty. I wanted to polish things a bit more before release, but am travelling soon so bit the bullet and decided to put it in people's hands.

I think it's clear that there needs to be some sort of child node iterator, possibly for left and right subtrees, as well as a way to get the left and right arity of the node.

I think the positive/negative indexing I did here is bad, too. It just needs to be a sequence, -1 should always be "from the end".

How do you feel about these names?

n_left
n_right
lefts
rights
siblings

One trick could be that siblings iterates in alternating left/right order. If you need the left or right siblings, you can do token.head.lefts or token.head.rights. If you only need the two nearest leftmost, you can do siblings[0:4:2]


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-71968256.

from spacy.

honnibal avatar honnibal commented on May 3, 2024

Yes, I'll add tests that verify:

for token in tokens:
    for child in token.children:
        child.head == token

from spacy.

honnibal avatar honnibal commented on May 3, 2024

Leaving this issue open until I test and document this feature properly, but I think I've got this covered now.

from spacy.

simonhughes22 avatar simonhughes22 commented on May 3, 2024

Note that the test above won't uncover the bug I found. The bug I found was that some nodes had missing children. However, all nodes correctly had their heads. For now I'm using it by reconstructing the tree from the head relation as that seems to work.

from spacy.

yang avatar yang commented on May 3, 2024

@honnibal In the meantime, would you mind providing an example of how to traverse the parse tree (using the current API), e.g. to print the full tree? Thanks!

from spacy.

honnibal avatar honnibal commented on May 3, 2024

I've updated the tests here: https://github.com/honnibal/spaCy/blob/master/tests/test_parse_navigate.py

This also gives an example of how to traverse the parse tree for now, until I have time to write the documentation.

from spacy.

honnibal avatar honnibal commented on May 3, 2024

Documentation now contains some information about navigating the parse trees. I'll write a tutorial for this in the future as well.

from spacy.

simonedu avatar simonedu commented on May 3, 2024

I am interesting in knowing how to traverse the parse tree. The link to the tests and the example suggested above is broken.

Thank you very much.

from spacy.

rgregory1963 avatar rgregory1963 commented on May 3, 2024

@simonedu Here's the correct like I found
https://github.com/spacy-io/spaCy/blob/master/spacy/tests/parser/test_parse_navigate.py

from spacy.

simonedu avatar simonedu commented on May 3, 2024

Thank you!

from spacy.

lock avatar lock commented on May 3, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from spacy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.