Skip to main content

Alpino Query

DOI PyPI version Actions Status

pip install alpino-query

When running locally without installing, instead of alpino-query use python -m alpino_query.

Parse

Parse a (tokenized) sentence using the Alpino instance running on gretel.hum.uu.nl.

For example:

alpino-query parse Dit is een voorbeeldzin.

It also works when the sentence is passed as a single argument.

alpino-query parse "Dit is een voorbeeldzin ."

Mark

Mark which part of the treebank should be selected for filtering. It has three inputs:

  1. Lassy/Alpino XML
  2. the tokens of the sentence
  3. for each token specify the properties which should be marked

For example:

alpino-query mark "$(<tests/data/001.xml)" "Dit is een voorbeeldzin ." "pos pos pos pos pos"

It is also possible to mark multiple properties for a token, this is done by separating them with a comma. Each of these can also be specified to be negated. These will then be marked as 'exclude' in the tree.

alpino-query mark "$(<tests/data/001.xml)" "Dit is een voorbeeldzin ." "pos pos,-word,rel pos pos pos"

Subtree

Generates a subtree containing only the marked properties. It will also contain additional attributes to mark that properties should be excluded and/or case sensitive.

The second argument can be empty, cat, rel or both (i.e. catrel or cat,rel). This indicates which attributes should be removed from the top node. When only one node is left in the subtree, this argument is ignored.

alpino-query subtree "$(<tests/data/001.marked.xml)" cat

XPath

Generates an XPath to query a treebank from the generated subtree. Second argument indicates whether a query should be generated which is order-sensitive.

alpino-query xpath "$(<tests/data/001.subtree.xml)" 0

Using as Module

from alpino_query import AlpinoQuery

tokens = ["Dit", "is", "een", "voorbeeldzin", "."]
attributes = ["pos", "pos,-word,rel", "pos", "pos", "pos"]

query = AlpinoQuery()
alpino_xml = query.parse(tokens)
query.mark(alpino_xml, tokens, attributes)
print(query.marked_xml) # query.marked contains the lxml Element

query.generate_subtree(["rel", "cat"])
print(query.subtree_xml) # query.subtree contains the lxml Element

query.generate_xpath(False) # True to make order sensitive
print(query.xpath)

Considerations

Exclusive

When querying a node this could be exclusive in multiple ways. For example:

  • a node should not be a noun node[@pos!="noun"]
  • it should not have a node which is a noun not(node[@pos="noun"])

The first statement does require the existence of a node, whereas the second also holds true if there is no node at all. When a token is only exclusive (e.g. not a noun) a query of the second form will be generated, if a token has both inclusive and exclusive properties a query of the first form will be generated.

Relations

@cat and @rel are always preserved for nodes which have children. The only way for this to be dropped is for when all the children are removed by specifying the na property for the child tokens.

Upload to PyPi

pip install twine
python setup.py sdist
twine upload dist/*

Credits

This was original part of the GrETEL codebase and is (still) used by its Example Based Search functionality.

License

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (cc-by-sa-4.0). See the LICENSE file for license rights and limitations.

Metadata

Release files for alpino-query 2.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alpino-query 2.1.12
File Size Uploaded Provenance Actions
alpino-query-2.1.12.tar.gz 17.2 kB Without provenance Details for alpino-query-2.1.12.tar.gz

Release files / alpino-query-2.1.12.tar.gz

Download URL alpino-query-2.1.12.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
814f06bec6103526aa85a284a21231801dad094f0e744759dbf97dbca1918461
BLAKE2b-256 checksum
How to use checksums
e6a0b3439831f7815872365dcea19cb12de80d9bad189a9f12a8c12131361c37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.17

Security for alpino-query 2.1.12

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page