TGrep search implementation for NTLK trees.
Copyright (c) 16 March, 2013 Will Roberts <wildwilhelm@gmail.com>.
Licensed under the MIT License (see source file tgrep.py for details).
This module supports TGrep2 syntax for matching parts of NLTK Trees. Note that many tgrep operators implemented here require the tree passed to be a ParentedTree.
Tgrep tutorial: http://www.stanford.edu/dept/linguistics/corpora/cas-tut-tgrep.html
Tgrep2 manual: http://tedlab.mit.edu/~dr/Tgrep2/tgrep2.pdf
Tgrep2 source: http://tedlab.mit.edu/~dr/Tgrep2/
Requirements:
Python 2.6 or better, or Python 3.2 or better
future (for Python 2)
NLTK, version 3.0.0 or better
pyparsing
$ sudo pip install nltk_tgrep
Usage:
>>> from nltk.tree import ParentedTree
>>> import nltk_tgrep
>>> tree = ParentedTree.fromstring('(S (NP (DT the) (JJ big) (NN dog)) (VP bit) (NP (DT a) (NN cat)))')
>>> nltk_tgrep.tgrep_nodes(tree, 'NN')
[ParentedTree('NN', ['dog']), ParentedTree('NN', ['cat'])]
>>> nltk_tgrep.tgrep_positions(tree, 'NN')
[(0, 2), (2, 1)]
>>> nltk_tgrep.tgrep_nodes(tree, 'DT')
[ParentedTree('DT', ['the']), ParentedTree('DT', ['a'])]
>>> nltk_tgrep.tgrep_nodes(tree, 'DT $ JJ')
[ParentedTree('DT', ['the'])]
This implementation adds syntax to select nodes based on their NLTK tree position. This syntax is N plus a Python tuple representing the tree position. For instance, N(), N(0,), N(0,0) are valid node selectors. Example:
>>> tree = ParentedTree.fromstring('(S (NP (DT the) (JJ big) (NN dog)) (VP bit) (NP (DT a) (NN cat)))')
>>> tree[0,0]
ParentedTree('DT', ['the'])
>>> tree[0,0].treeposition()
(0, 0)
>>> nltk_tgrep.tgrep_nodes(tree, 'N(0,0)')
[ParentedTree('DT', ['the'])]
Caveats:
Link modifiers: “?” and “=” are not implemented.
Tgrep compatibility: Using “@” for “!”, “{” for “<”, “}” for “>” are not implemented.
The “=” and “~” links are not implemented.
Known Issues:
There are some issues with link relations involving leaf nodes (which are represented as bare strings in NLTK trees). For instance, consider the tree:
(S (A x))
The search string * !>> S should select all nodes which are not dominated in some way by an S node (i.e., all nodes which are not descendants of an S). Clearly, in this tree, the only node which fulfills this criterion is the top node (since it is not dominated by anything). However, the code here will find both the top node and the leaf node x. This is because we cannot recover the parent of the leaf, since it is stored as a bare string.
A possible workaround, when performing this kind of search, would be to filter out all leaf nodes.
Metadata
Release files for nltk_tgrep 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nltk_tgrep-1.0.6.tar.gz | 16.8 kB | Without provenance | Details for nltk_tgrep-1.0.6.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nltk_tgrep-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for nltk_tgrep-1.0.6-py3-none-any.whl |
| nltk_tgrep-1.0.6-py2-none-any.whl | Python 2 | none | any | Details for nltk_tgrep-1.0.6-py2-none-any.whl |
Total release size: 54.3 kB
Release files / nltk_tgrep-1.0.6.tar.gz
| Download URL | nltk_tgrep-1.0.6.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
516cd367f9a679609bd1c92840c50216aec8b8f60e5aafa68fb9a54b1463e8fb
|
|
BLAKE2b-256 checksum How to use checksums |
6236f0f0d6adafad35b1463a7fcade050e963bf221e3f249d16e96f79007e037
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / nltk_tgrep-1.0.6-py3-none-any.whl
| Download URL | nltk_tgrep-1.0.6-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f946c780550d5a801c3e6d7278cee878d0a43153bf43070d87371f9b876eeed
|
|
BLAKE2b-256 checksum How to use checksums |
20363f69546f68f3f820fa186f859e8e13742d5fe24be3e7796464384cfe3590
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / nltk_tgrep-1.0.6-py2-none-any.whl
| Download URL | nltk_tgrep-1.0.6-py2-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
7c22f3e2e6262e2312382097ee8d91d853f33a61d2a55cd40ffed997534b0ce6
|
|
BLAKE2b-256 checksum How to use checksums |
89dc1787ccf705662482c6a8704bc02df3d538bd9e2beae8e0386a7824cccc91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for nltk_tgrep 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.