<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Describing the Architecture of NegesAPI, an API for Spanish Negation Processing</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>José Valle-Aguilera</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Salud María Jiménez-Zafra</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>María Teresa Martín-Valdivia</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>L. Alfonso Ureña-López</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Computer Science Department, SINAI, CEATIC, Universidad de Jaén</institution>
          ,
          <addr-line>Campus Las Lagunillas, 23071, Jaén</addr-line>
          ,
          <country country="ES">Spain</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper, we present NegesAPI, an API for negation detection in Spanish texts using Machine Learning techniques, as well as its Web Application. We describe its architecture, the development technologies used and the integrated negation detection system. It is a powerful tool that can assist in diferent Natural Language Processing tasks.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Negation</kwd>
        <kwd>negation processing</kwd>
        <kwd>cue detection</kwd>
        <kwd>scope identification</kwd>
        <kwd>natural language processing</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>ple if a patient “no tiene cáncer” (does not have cancer)
and the entity “cáncer” is recognised, but the presence of
Negation is a grammatical phenomenon present in all negation is not detected, it changes the meaning of the
languages that can change the polarity of a sentence. It sentence and the diagnosis of the patient.
expresses the negative form of a sentence or statement There are various approaches to handle negation in
[1]. In Spanish there exist diferent types of negation de- NLP, such as rule-based approaches [2, 3], and traditional
pending on the elements used to negate: syntactic nega- machine learning [4, 5] and deep learning approaches
tion (no, nunca, nadie,...), lexical negation (impensable, [6, 7]. Rule-based approaches use a set of pre-defined
ilegible, imposible,...) and morphological negation (en la rules to detect negation cues and modify the meaning of
vida). Also, negation can be found in multiple ways, in- the sentence accordingly. Traditional machine learning
cluding the use of simple markers (one negation cue: No and deep learning approaches, on the other hand, use
sé cocinar), continuous markers (two or more consecu- annotated data to train models that can automatically
tive negation cues: Casi no llego a la presentación) and identify negation cues and their scope in a sentence.
discontinuous markers (two or more non-consecutively In this paper we describe the architecture of NegesAPI,
negation cues: No tengo nada de dinero para la comida). an API to detect negation cues and scopes in Spanish</p>
      <p>Therefore, negation can be very challenging to detect texts, that uses the machine learning approach of
Jiménezand process. In fact, the computational treatment of nega- Zafra et al. [5] and that is trained in the SFU Review
SPtion has not been solved due to its complexity. In Natural NEG corpus [8], which consists of 9,455 sentences from
Language Processing (NLP) negation is a phenomenon reviews on 8 domains (cars, hotels, washing machines,
of special interest, since it afects the polarity of texts, books, mobile phones, music, computers and movies).
such as opinions, where the opinion of a product can be This API can analyze any text in Spanish and annotate
drastically altered if negation is present. It also has an its negation automatically, to assist in other NLP tasks.
impact on information retrieval systems, where search- The rest of the paper is organized as follows: In Section
ing for “Películas que no sean de fantasía” (Non-fantasy 2 we provide a description of the API and its architecture.
iflms) is not the same as searching for “Películas que sean In Section 3 we describe the components in the
backde fantasía” (Fantasy films). It is also of special relevance end. The front-end components are set out in Section
for entity recognition in biomedicine, where for exam- 4. In Section 5 we present the negation system used by
NegesAPI. Finally, Section 6 summarizes the conclusions
and future work.</p>
    </sec>
    <sec id="sec-2">
      <title>2. System Description</title>
      <sec id="sec-2-1">
        <title>NegesAPI has two main modules, the API itself, and a Web Application, built on top of the API. Additionally, these two modules rely on diferent components, each one responsible of an specific task:</title>
        <p>• Data model: NegesAPI uses a relational database
system that stores the user list and information 3.1. Request Management
about them, in order to implement a
login/register system. It should be noted that it does not The general request management architecture is
prestore any information about the processed and sented in Figure 1 . First, when any request is sent, it is
analyzed texts. It is built in MariaDB as it is open received by NGINX, serving as reverse proxy. Then,
NGsource and it is the default database system in INX sends the request to an specified port of the machine,
most Linux distributions. where Gunicorn is listening. Gunicorn is a Python WSGI</p>
        <p>HTTP Server for UNIX, and it can replicate instances of
• Views: The views contains all the information our flask application, named as workers. The requests are
that is presented in the client side of the web ap- forwarded to an specific instance of the Flask application,
plication, as well as the design and functionalities. where the request is resolved.</p>
        <p>The information is written in HTML, the design
is defined with CSS and minor functionalities
executed in the client are implemented in JavaScript. 3.1.1. NGINX web server
• Controller and routing: As routing for the web ap- NGINX is a web server and reverse proxy that is fast,
replication we use Flask, a powerful Python frame- liable, and secure. It can manage HTTP connections and
work with which we have created the diferent trafic by using various web acceleration techniques like
endpoints. Flask uses a routes file, where data load balancing, SSL termination, connection and request
validation is implemented and forms are created policing, static content ofload, and content caching.
NGor retrieved. This routes file serves as controller, INX can also act as a secure application gateway that
communicating with all other components when- passes trafic from users to applications using built-in
ever it is necessary. The API is also written in interfaces.</p>
        <p>Flask, but it has been previously generated using The reason to use NGINX as an application gateway
Swagger Documentation. is that it provides an all-in-one solution for HTTP
con• Negation system: The negation system is imple- nection management, load balancing, content caching,
mented in the API /analyze route. It uses the Ma- and trafic security. This makes it easier to manage and
chine Learning approach of Jiménez-Zafra et al. secure the application backend, improve scalability and
[5], with an updated version of the corpus SFU performance, and build highly available applications by
Review SP-NEG [1]. clustering application instances behind NGINX.
• Request management: Flask already implements
a WSGI server, the toolset of Werkzeug. Although 3.1.2. Gunicorn WSGI server
it is more than enough for a development
environment, it falls short in production, and it is
necessary to apply several technologies and tools
for a better user experience and system
scalability. To achieve that, NegesAPI uses the Gunicorn
WSGI HTTP server to replicate our Flask
application and NGINX as reverse proxy and application
gateway.</p>
      </sec>
      <sec id="sec-2-2">
        <title>Gunicorn (short for “Green Unicorn”) is a popular open</title>
        <p>source Python Web Server Gateway Interface (WSGI)
HTTP server. It allows Python web applications to be
served by communicating with web servers like NGINX
or Apache. Gunicorn is designed to be a lightweight and
simple HTTP server that can handle multiple requests
concurrently. Gunicorn is commonly used in
combination with popular web frameworks like Flask, Django,
Pyramid, and others to serve web applications with high
performance and reliability.</p>
        <p>We will use Gunicorn to replicate our Flask application,
improving our API reliability by providing redundancy
in case of server failures. Also, Gunicorn can improve
the performance of a web application by using multiple
worker processes to handle requests concurrently. This
allows the application to handle a larger number of
requests without slowing down or crashing. Scalability of
the system must be taken into account, with Gunicorn
we can easily adjust the number of workers, allowing
more instances of the application to run concurrently.</p>
      </sec>
      <sec id="sec-2-3">
        <title>These components are classified into Back-end and Front-end, the former being in charge of logic, routing and security, and the latter in charge of presenting information, design and functionality on the client side.</title>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Back-end</title>
      <p>The back-end is composed by all the server-side code,
frameworks, tools and database management systems
that are running in the server where the web
application is allocated. It receives requests from the front-end,
processes the data, and sends responses back to the
frontend.
database system that was created by the original
developers of MySQL. It is designed to be high-performing, stable,
and open-source, and is included as the default database
system in most Linux distributions and many cloud
services. To be able to communicate between the database
and the Flask application, we will create a component
called Database Model.</p>
      <p>The Database Model is a class written in Python that
implements all the necessary functions to communicate
with the database. It builds the SQL statements needed
to create, read, update and delete any element in the
database. This way the connection and communication
with the database is abstracted from the other
components, leaving a cleaner and more maintainable code.</p>
      <sec id="sec-3-1">
        <title>3.2. Flask Application</title>
        <sec id="sec-3-1-1">
          <title>Finally, the main Flask application will have all the end</title>
          <p>points and user management, it will be in charge of
loading the models and the negation system, as well as
connecting the database with the application and displaying
the diferent views that will be available in the web.</p>
          <p>Regarding the security aspect of our application, with
Flask we can make use of diferent libraries to implement
forms, data validators, session data, login, logout and
CSRF protection:
• Flask-Login: Flask-Login is a Python library for</p>
          <p>Flask web applications that enables user
authentication and authorization. This library helps in
managing user sessions, securing user data, and
restricting access to specific parts of the appli- 3.4. API security
cation for authenticated users only. Flask-Login
allows defining a User model that represents the To ensure the API security, we need to implement an
users in the application and implementing login authentication system in the web application and link
and registration views to handle user authenti- it to the API requests, so that every call is identified. In
cation. It also enables protecting views and end- each call to an endpoint where you need identification, a
points by requiring users to log in before access- JSON Web Token must be added in the request header.
ing them.
• Flask-WTF: Flask-WTF is a Python library that 3.4.1. JSON Web Tokens
simplifies the process of creating and validating A JSON Web Token (JWT) is a secure method of
transmitweb forms in Flask applications. With Flask-WTF, ting information a JSON object between parties in web
forms can be created using Python classes and applications. It is a compact and self-contained format
rendered in HTML templates. It includes various consisting of three parts: header, payload, and signature.
form fields such as text fields, checkboxes, radio The header includes information about the type of token
buttons, and dropdown menus, among others, and algorithm used to sign it, while the payload contains
and supports form validation that helps prevent the claims or information that the token carries, such as
common errors like missing required fields and user ID or role. The signature is a cryptographic
signainvalid data types. Flask-WTF’s built-in security ture that verifies the token’s integrity and ensures it has
features protect against CSRF attacks and enable not been tampered with. The stateless nature of JWTs
secure file uploads. means that NegesAPI do not need to track user sessions
or login credentials and can rely on JWTs to validate a</p>
        </sec>
      </sec>
      <sec id="sec-3-2">
        <title>3.3. Database system and database model user’s identity for each request.</title>
        <p>NegesAPI implements JWTs as an API Key, provided
As database management system we will use MariaDB. in the /profile page of each user, with an expiration date
MariaDB Server is a widely used open source relational
of 24 hours and the option to regenerate a new one. This
can easily be implemented with the jwt Python module,
and starting each authorized request with the header
“Authorization: Bearer userJwt”, being userJwt the user’s
token.
and debugging, and create client code in various
programming languages. Swagger uses a machine-readable
format called OpenAPI Specification, which describes the
structure of the API, including endpoints, parameters,
request/response formats, and authentication mechanisms.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Front-end</title>
      <p>The code executed in the client-side, normally interpreted
by web navigators, is called front-end. It is the
responsible to provide an interface with which the user can
interact. NegesAPI ofers a simple and intuitive
interface, with OpenAPI 3.0.0 documentation standards. In
addition, it includes a test environment for the negation
analyzer, a user profile tab and a tutorial on how to use
the tool.</p>
      <sec id="sec-4-1">
        <title>4.1. API documentation and test</title>
        <sec id="sec-4-1-1">
          <title>The Documentation page (Figure 2 ) provides a easy to</title>
          <p>use test environment to try the diferent endpoints, the
mandatory data, formats and response codes, without
writing any code or command. This page is perfect to try
the diferent output formats and it also provides a cURL
example of how to create this request.</p>
          <p>This documentation page has been generated using
a Swagger tool, named Swagger Editor. Swagger is an
open-source set of tools that provides a standardized way
of documenting RESTful APIs. It comes with tools that
can generate API documentation, perform API testing</p>
        </sec>
      </sec>
      <sec id="sec-4-2">
        <title>4.2. Profile tab</title>
        <sec id="sec-4-2-1">
          <title>The profile tab (Figure 3) contains all user information,</title>
          <p>such as name, email, password and API key. Here we
can display, copy and regenerate our API key, change the
user’s password and delete the account.</p>
          <p>The API Key is the JWT generated in the back-end,
necessary to make API requests that needs identification.</p>
        </sec>
      </sec>
      <sec id="sec-4-3">
        <title>4.3. Tutorial tab</title>
        <sec id="sec-4-3-1">
          <title>NegesAPI also ofers a step-by-step guide on how to use the API, either from the browser if you want to test it or if you want to implement it a programming language using the cURL tool.</title>
          <p>It also adds code snippets, output examples and
descriptions of the diferent analyzer options, negation
annotations and output formats.</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5. Negation system</title>
      <sec id="sec-5-1">
        <title>NegesAPI uses an updated version of the corpus SFU Review SP-NEG [8] and the negation detection model of Jiménez-Zafra et al. [5].</title>
      </sec>
      <sec id="sec-5-2">
        <title>The corpus SFU Review SP-NEG has been updated to</title>
        <p>match the latest improvements in FreeLing 4.2, since we
use this tool as a feature extraction method. This corpus
used a deprecated tag set generated with FreeLing 4.0
[9, 10], which needed to be updated in order to make the
negation system work.</p>
        <p>The negation detection system models the negation
processing as a sequence labelling task, for that reason,
it makes use of a CRF algorithm [11], as it has shown its
efectiveness in this task [ 12, 13, 14]. This is because CRF
makes predictions based on the elements in the sequence,
not only in the current one, and negation cues and scopes
behaves the same way. The results of its efectiveness
using 10-fold cross validation are: i) Negation cues
detection (Precision=92.70, Recall=82.09, F1-score=87.07), ii)
Scope identification (Precision=90.77, Recall=63.64,
F1score=74.79).</p>
        <p>More information on the corpus and the system
development can be found in [15].</p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>6. Conclusion and future works</title>
      <p>NegesAPI is a powerful API that can assist diferent tasks
in NLP and can be easily implemented in multiples
scenarios, providing a fast and precise prediction of the
negation cues and scopes in any Spanish text. In future
works, we can improve NegesAPI so that it will add the
negation cues in the scope, prefixing the negator to the
negation word. It is also important that NegesAPI can be
used in any type of algorithm and technology, therefore
a future work would be to adapt the output suitable for
Deep Learning algorithms. In addition, we plan to test
its accuracy in diferent types of texts (reviews, posts,
tweets, clinical texts, etc.). NegesAPI can provide a lot
of relevant information to information retrieval systems,
to detect negation in the searches that can be made, for
better efectiveness. This knowledge could be used, for
example, to distinguish "Películas que sean de fantasía"
from "Películas que no sean de fantasía", or any other
search with negation.</p>
    </sec>
    <sec id="sec-7">
      <title>Acknowledgements</title>
      <sec id="sec-7-1">
        <title>This work has been partially supported by Project</title>
        <p>CONSENSO (PID2021-122263OB-C21), Project
MODERATES (TED2021-130145B-I00) and Project
SocialTox (PDC2022-133146-C21) funded by
MCIN/AEI/10.13039/501100011033 and by the
European Union NextGenerationEU/PRTR, Project
PRECOM (SUBV-00016) funded by the Ministry of
Consumer Afairs of the Spanish Government, Project
FedDAP (PID2020-116118GA-I00) supported by
MICINN/AEI/10.13039/501100011033 and WeLee project
(1380939, FEDER Andalucía 2014-2020) funded by
the Andalusian Regional Government. Salud María
Jiménez-Zafra has been partially supported by a grant
from Fondo Social Europeo and the Administration of
the Junta de Andalucía (DOC_01073).
[6] F. Fancellu, A. Lopez, B. Webber, Neural networks
for negation scope detection, in: Proceedings of the
54th annual meeting of the Association for
Computational Linguistics (volume 1: long papers), 2016,
pp. 495–504.
[7] O. S. Pabón, O. Montenegro, M. Torrente, A. R.</p>
        <p>González, M. Provencio, E. Menasalvas, Negation
and uncertainty detection in clinical texts written
in spanish: a deep learning-based approach, PeerJ</p>
        <p>Computer Science 8 (2022) e913.
[8] S. M. Jiménez-Zafra, M. Taulé, M. T. Martín-Valdivia,</p>
        <p>L. A. Urena-López, M. A. Martí, Sfu review
spneg: a spanish corpus annotated with negation for
sentiment analysis. a typology of negation patterns,
Language Resources and Evaluation 52 (2018) 533–
569.
[9] L. Padró, E. Stanilovsky, Freeling 3.0: Towards</p>
        <p>wider multilinguality, in: LREC2012, 2012.
[10] M. Marimon, L. Padró, J. Turmo Borras, Coreference
resolution in freeling 4.0, in: LREC 2018: 11th
International Conference on Language, Resources
and Evaluation: Miyazaki, Japan: May 7-12, 2018:
proceedings book, 2018, pp. 376–381.
[11] J. Laferty, A. McCallum, F. C. Pereira, Conditional
random fields: Probabilistic models for segmenting
and labeling sequence data (2001).
[1] S. M. Jiménez-Zafra, R. Morante, M. T. Martín- [12] I. Councill, R. McDonald, L. Velikovich, What’s
Valdivia, L. A. U. Lopez, Corpora annotated with great and what’s not: learning to classify the scope
negation: An overview, Computational Linguistics of negation for improved sentiment analysis (2010).
46 (2020) 1–52. [13] H. Loharja, L. Padró, J. Turmo Borras, Negation
[2] J. C. de Albornoz, L. Plaza, A. Díaz, M. Ballesteros, cues detection using crf on spanish product review
Ucm-i: A rule-based syntactic approach for resolv- texts, in: NEGES 2018: Workshop on Negation
ing the scope of negation, in: * SEM 2012: The First in Spanish: Seville, Spain: September 19-21, 2018:
Joint Conference on Lexical and Computational proceedings book, 2018, pp. 49–54.
Semantics–Volume 1: Proceedings of the main con- [14] L. Domınguez-Mas, F. Ronzano, L. I. Furlong,
Superference and the shared task, and Volume 2: Pro- vised learning approaches to detect negation cues
ceedings of the Sixth International Workshop on in spanish reviews, in: Proceedings of the Iberian
Semantic Evaluation (SemEval 2012), 2012, pp. 282– Languages Evaluation Forum (IberLEF 2019), CEUR
287. Workshop Proceedings, Bilbao, Spain. CEURWS,
[3] Y. Peng, X. Wang, L. Lu, M. Bagheri, R. Summers, 2019.</p>
        <p>Z. Lu, Negbio: a high-performance tool for nega- [15] J. Valle-Aguilera, S. M. Jiménez-Zafra, M. T.
Martíntion and uncertainty detection in radiology reports, Valdivia, L. A. Ureña-López, NegesAPI: An API for
AMIA Summits on Translational Science Proceed- Negation Cue Detection and Scope Identification
ings 2018 (2018) 188. in Spanish, Procesamiento del Lenguaje Natural 71
[4] N. P. Cruz, M. Taboada, R. Mitkov, A machine- (2023).</p>
        <p>learning approach to negation and speculation
detection for sentiment analysis, Journal of the
Association for Information Science and Technology 67
(2016) 2118–2136.
[5] S. M. Jiménez-Zafra, R. Morante, E. Blanco, M.-T.</p>
        <p>Martín-Valdivia, L. A. U. López, Detecting negation
cues and scopes in spanish, in: Proceedings of
the Twelfth Language Resources and Evaluation
Conference, 2020, pp. 6902–6911.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list />
  </back>
</article>