Skip to main content

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_text_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spacy-to-naf-0.2.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

spacy_to_naf-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file spacy-to-naf-0.2.0.tar.gz.

File metadata

  • Download URL: spacy-to-naf-0.2.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for spacy-to-naf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 96fe6100a2bfb2177bb5b1f345411315f256851c04cb4b90cf03f1b0f06b1225
MD5 b119a6d0207ba57e9cd9500186bd5127
BLAKE2b-256 5762e1ed71623f7ff422ce2fdf21a313e1cbc31223a4cfa530639b7304d67dad

See more details on using hashes here.

File details

Details for the file spacy_to_naf-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spacy_to_naf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bc054fa48ad797f22ac6a4b1e8f444a60a33cf7f51ed175a8fd7ad02964f0ca
MD5 45d81563a609e376538610136d315492
BLAKE2b-256 cdd052cbc299900de98235a518f150d048df9a86b15dfcd6a6862b41741a809d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page