spaCy-to-NAF converter
Project description
spacy-to-naf
is a spaCy wrapper that converts text or
NAF input to NAF.
The converter minimally extracts a tokenized text
layer, and can additionally extract terms
, deps
, entities
and
chunks
layers.
Installation
To install spacy-to-naf
:
pip install spacy-to-naf
Download a spaCy model, eg. 'en-core-web-sm':
python -m spacy download en-core-web-sm
Usage
Specify the spaCy model and the NAF layers to create (the text
layer is always created).
from spacy_to_naf.converter import Converter
converter = Converter('en-core-web-sm', add_terms=True, add_deps=True, add_entities=True, add_chunks=True)
The input may be a naf or text directory or a text string.
Text input
To convert text to a file 'example.naf' in the current directory:
text = """The cat sat on the mat. Felix was his name."""
naf = converter.convert(text, 'example.naf', '.')
The converter additionally returns a NafParser object for further processing.
Processing files
To process text files from a 'text_in' to 'naf_out' directory:
converter.convert_files('text_in', 'naf_out')
Note that input text files are expected to end in '.txt'.
To process NAF files from 'naf_in' to 'naf_out':
converter.convert_naf_files('naf_in', 'naf_out')
Output files carry the same name as the input file, extension excepted.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file spacy-to-naf-0.1.0.tar.gz
.
File metadata
- Download URL: spacy-to-naf-0.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a22bd1f4f1b45e9db2bde7876a544d929c6dabf7ffca982b54f16be2f04476a |
|
MD5 | 934aba4dbb990289cf874e068233b264 |
|
BLAKE2b-256 | 8b140fc0df2b809250f964476a6d5ba8fc8e33a1fa2c34a514a62d6b864201dc |
File details
Details for the file spacy_to_naf-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: spacy_to_naf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a214a33b94996aacff60e0814f3c50524bd7029b25ca9e532f6080dcc27e8fed |
|
MD5 | 3e82538a7bb65e317e9bd3fccc3f4e29 |
|
BLAKE2b-256 | 6a98212dcff3623138d7ffb18a1d6b2b2672ae9ef5e8939aa09eac2ca299ed13 |