Comments (12)
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.
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.
Yes, I'll add tests that verify:
for token in tokens:
for child in token.children:
child.head == token
from spacy.
Leaving this issue open until I test and document this feature properly, but I think I've got this covered now.
from spacy.
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.
@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.
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.
Documentation now contains some information about navigating the parse trees. I'll write a tutorial for this in the future as well.
from spacy.
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.
@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.
Thank you!
from spacy.
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)
- Fuzzy Matching not working HOT 1
- Unable to finetune transformer based ner model after initial tuning
- Undesired whitespace normalization of Korean text
- Suggestion: Normalize or Translate the parsing labels for German and English dependency labelling
- Code example discrepancy for `Span.lemma_` in API docs HOT 1
- Signature docs error in API docs for `MorphAnalysis.__contains__` HOT 2
- Import broken python 3.9 HOT 1
- Luminous
- Converting into exe file through pyinstaller-> spacy cannot find factory for 'curated transformer' HOT 1
- Spacy problem with whitespace or punctuation HOT 1
- config.cfg error from spacy init config command
- Possible ORG misidentification HOT 1
- SpaCy is not building today HOT 2
- How can I contribute.
- spacy Transformers shows 0 in Losses_trf while training
- The `transition_parser` in `Spacy` is not compatible with the use of cuda for inference
- ⚠ Aborting and saving the final best model. Encountered exception: RuntimeError('Invalid argument')
- ⚠ Aborting and saving the final best model. Encountered exception: RuntimeError('Invalid argument') RuntimeError: Invalid argument
- Warning: [W017] Alias 'Barack Obama' already exists in the Knowledge Base.
- Why does displacy only support showing one span key?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spacy.