%%capture
# If you are running this in Google Colab:
! pip install ucrel_api
from ucrel_api.api import UCREL_API
api = UCREL_API('a.moore@lancaster.ac.uk', 'http://ucrel-api.lancaster.ac.uk')
As shown it requires an email address and server address, of which the server address in this case is the address of the public UCREL Tool Chain. The email address is only used to detect misuse of the public UCREL Tool Chain. Please be kind to this public server, UCREL provides it free of charge and is not intended for extremely large numbers of repeated submission from the same site.
USAS
Once we have an API insance we can use it to call the USAS tagger:
text_to_process = ('Hope you have a nice day. '
'Works with SGML entities e.g. 5 > 4.'
'Also with MWE like New York.')
ucrel_doc = api.usas(text_to_process)
for index, sentence in enumerate(ucrel_doc.sentences):
print(f'Sentence {index}')
for token in sentence:
print(token)
if index == 0 or index == 1:
print('\n')
The return of the UCREL_API.usas
api call is a UCREL_Doc
instance, the UCREL_Doc
instance is made up of UCREL_Token
s. The USAS tagger provides both token level attributes and sentence segmentation as shown above.
Development
If you would like to develop on this library. Clone the repository and then install the regular requirements and the development requirements using:
pip install -e .[dev]
The -e
is an editable flag meaning that if you change anything in the library locally Python will keep track on those changes.
Package is created with nbdev
Note as it is created with nbdev the code and documentation is generated from the notebooks that are within the ./module_notebooks folder.
Note need to run the following once: nbdev_install_git_hooks
: "This will set up git hooks which will remove metadata from your notebooks when you commit, greatly reducing the chance you have a conflict."
The main workflow is the following:
- Edit the notebook(s) you want within ./module_notebooks folder. The README is generated from the ./module_notebooks/index.ipynb file.
- Run
nbdev_build_lib
to convert the notebook(s) into a Python module, which in this case will go into the ./ucrel_api folder. Note if you created a function in one python module and want to use it in another module then you will need to runnbdev_build_lib
first, as that python module code needs to be transfered from the ./module_notebooks folder. into the ./ucrel_api folder. - Create the documentation using
nbdev_build_docs
. - Optionally if you created tests run them using
make test
. When you do add tests in the notebooks you will need to import the function from the module and not rely on the function already expressed in the notebook, this is to ensure that code coverage is calculated correctly. - Optionally if you would like to see the documentation locally see the sub-section below.
- Git add the relevant notebook(s), python module code, and documentation.
Local documentation
The documentation can be ran locally via a docker container. The easiest way to run this container is through the make command:
make docker_docs_serve
NOTE This documentation does not update automatically, so it requires re-running this make command each time you want to see an updated version of the documentation.
PYPI Package release
To release an updated version of the package:
- Change the version number in ./settings.ini
- Build the library using
nbdev_build_lib
- Then make the package and upload it to PYPI using
make release
Acknowledgement
The work has been funded by the UCREL research centre at Lancaster University.