<!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>Smart usage of Mobile Phones Sensors within an Event Calculus Engine</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Valerio Mazza</string-name>
          <email>valerio.mazza@studio.unibo.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Michele Solimando</string-name>
          <email>michele.solimando@studio.unibo.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Dipartimento di Informatica - Scienza e Ingegneria Università di Bologna Viale Risorgimento</institution>
          ,
          <addr-line>2, 40136 Bologna</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In the following paper we show how we define and integrate an Event Calculus rule system, written by us with xtext Dsl on an android application to work with the mobile phone sensors, in order to smartly use them.</p>
      </abstract>
      <kwd-group>
        <kwd>Event Calculus</kwd>
        <kwd>Xtext</kwd>
        <kwd>DSL Language</kwd>
        <kwd>Drools</kwd>
        <kwd>Android</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction and Motivation</title>
      <p>Nowadays computer systems are so complex, in a way that even expert
programmers, have difficulties to verify whether they operate correctly. Moreover it is also
very difficult to introduce new features without weaken its internal logic.</p>
      <p>In literature there are a few proposal of logical formalisms which can be used to
mitigate these drawbacks. One of them, for instance, is the Event Calculus (EC). A
possible approach, in fact, consists in using a EC machinery that operates in the
deductive mode to monitor the application and verify that it is compliant with what it is
expected. Unfortunately, these frameworks are difficult to master either to build
advanced applications.</p>
      <p>The goal of this Paper, is to present a framework based on EC with a twofold
purpose. On one side we have developed in Xtext1 an Integrated Development
Environment (IDE) to allow a domain expert to express a problem in terms of EC concepts.
We chose Xtext/Xtend because is a statically typed functional and object-orient
language. It automatically compiles to readable Java code. We will describe this process
properly in the next chapters. On the other side we have defined a procedure that
automatically converts the given problem into an Android application2 which uses a
Drools3 implementation of Event Calculus.</p>
      <p>Consequently thanks to such a integrated system, a user with any level of
understanding, can leverage the complexity of defining an EC problem and automatically
build an Android application around it. In particular we show a case study in medical
rehabilitation that demonstrates the potential of this approach.</p>
      <p>This paper is organized as follows: in the follow section we present the framework
with the tools and the components of interest that we used. The third section shows
the potential of the system developed, taking as example a medical study case. The
last section illustrates the objective we have reached, our system limits and future
developments.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Framework</title>
      <p>We briefly describe the tools and components of our framework in order to
understand them.
2.1</p>
      <sec id="sec-2-1">
        <title>Event Calculus</title>
        <p>
          It is a logical formalism introduced by Kowalski and Sergot in 1986. There are
many different version with varying degrees of expressiveness and efficiency. In this
work we use the multivalued reactive variant (most efficient), Drools based, already
presented in [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ]. This particular version allows you to use any real value, instead of
only Boolean value, to represent the magnitudes of the domain.
        </p>
        <p>
          This formalism owes his fortune to the logical correctness and simplicity. In fact, it
is based on two concepts only: the Event that is the notification of an action occurred
in the considered domain in a specific time instant; and the Fluent that is single
measurable aspects of the domain that can change over time. The EC formalism is
completed by other axioms to report the relation between Event and Fluent. For more
details see [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ].
1 http://www.eclipse.org/Xtext
2 http://developer.android.com/index.html
3 http://www.jboss.org/drools
2.2
        </p>
      </sec>
      <sec id="sec-2-2">
        <title>Drools and ECA-rules</title>
        <p>Production rules are one the most common way to represent knowledge in many
areas of Artificial Intelligence (AI). Drool is a Production Rule System that use the
Modus Ponens (MP) as rule of inference. In this type of reasoning formally if one
proposition P implies a second proposition Q and P is true, it concludes that Q is also
true. Rules in PRSs are called instead productions and they primarily express some
behaviour that transforms the available information about the domain in new
information.</p>
        <p>Drools consists of many components: a Production Memory that contains all the
productions; a Working Memory that contains information about the current state of
the system, the knowledge and the assertions; an Agenda that contains all the
activations of all productions. The first action taken by PRS is the pattern matching, that is
to build a network of constraints. The algorithm used is RETE algorithm. This
algorithm filters the domain knowledge to identify the set of data that satisfies the
preconditions of some productions. The active productions are passed to the Agenda. Last
task of the PRS is the execution of the actions.</p>
        <p>The RETE algorithm can handle the ECA-rules (Event Condition Action) [2]. The
ECA-rules consists of three parts: an Event that triggers the invocation of the rule and,
if the Condition is satisfied, provoke the Action, a set of updates to the system.
2.3</p>
      </sec>
      <sec id="sec-2-3">
        <title>Domain Specific Language and Xtext</title>
        <p>A General Purpose Languages (GPLs) are designed to address a wide variety of
application domains, while Domain Specific Languages (DSLs) do not aim to solve
every problem in every domain, but focus on a specific restricted one in order to solve
problems inside it in a better way than a GPL language would do.</p>
        <p>Our approach exploits Xtext capabilities to define a DSL language for EC which
can be used by Xtext itself to guide the automatic conversion of any problem into a
working application built with a GPL, namely Drools. In addition, the Xtext
framework conveniently provides a mechanism to build an IDE for the given DSL language
with no additional efforts. Therefore the resulting tool allows to simplify the
expression of EC concepts while taking care of the translation of them toward the chosen
DSL.</p>
        <p>Our language is essentially intuitive because it is similar to the way in which the
humans represent knowledge and is readable because the syntax of the rules appears
like the spoken language understandable by all.
2.4</p>
      </sec>
      <sec id="sec-2-4">
        <title>Android</title>
        <p>Android is a Linux-based operating system designed for mobile devices such as
smartphones and tablet computers.</p>
        <p>While creating a standard android application, building up a logic to use the phone
sensors (and not just them) can be tricky, and not easily maintainable. When you start
having several different patterns of behavior to observe, the complexity of the
software increase sensibly. With our Event based language it takes less to create a fully
working logic, and it separates the two part of the application, making it cleaner and
less complex.
3</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Case Study</title>
      <p>The designed system shows its potential in our case study. We used our DSL to
assist doctors in tasks that involved physical effort, such as rehabilitation in
physiotherapy. Our goal is to present how different type of users can take advantage of our
development environment to simplify their everyday jobs, both doctors and patients.</p>
      <p>As we all know, in the last decades, life expectation is getting longer, causing bad
outcomes such as medical complications in the older age segment. Specifically, the
problems due to reduced joint mobility are particularly insidious because they
seriously affect the quality of elderly life style.</p>
      <p>We have formulated an EC problem to provide suggestions and incitements to the
patient, that are based on the performance during the exercises assigned from a
physiotherapist. The suggestions are notified through a simple Android application. The
innovation is, thanks to the powerful DSL implemented and the intrinsic logic of the
EC, that the physiotherapist will be able to sketch the important characteristic of the
particular exercise. He will also have the possibility to create a new one, or modify a
given one, without the action of an IT engineer.</p>
      <p>Let us see how the tools we presented before can help us to reach our goal.
3.1</p>
      <sec id="sec-3-1">
        <title>Workflow</title>
        <p>In the figure 1 we show the entire workflow of the system. In the figure there are
two types of users: the physical therapist, expert user of the system, and the patient,
passive user.</p>
        <p>Use
PHYSIOTHERAPIST
PATIENT</p>
        <p>IDE</p>
        <p>In the first place the Physiotherapist has to express an EC problem throughout the
editor built in the Xtext generated IDE as shown in figure 2. In this case the user of
our system is the physiotherapist, who will have in hand a series of Events which map
the smartphone sensor to the EC world.</p>
        <p>Consequently the physiotherapist will know exactly when a given Event that
represents, for istance the accelerometer behavior, is thrown, the Event will map a specific
pattern of movement, rather than standing or sitting. The system establishes a
correspondence between fluents and interface elements, giving the possibility to the
physiotherapist to decide how the application shows its notification of the thrown events.</p>
        <p>When the Physiotherapist is satisfied with the model (an example is presented in
next paragraph), he may request its conversion into an Android application. The
conversion is performed through additional buttons introduced in the IDE, as shown in
figure 3.</p>
        <p>The application will monitor the behavior of the patient acting accordingly as
indicated by the logic defined by the physiotherapist.</p>
        <p>In the end, the Physiotherapist, by connecting the patient smartphone to his PC,
will install the App directly into it.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Conclusion and future development</title>
      <p>The goal of realize an easy to approach language was met. The Editor as well is
simple but efficient in the implementation of the rules created.</p>
      <p>Our intention is to make something useful for the case of study we have. A
limitation of the application is surely the narrowed freedom to use the smartphone features.
In this regard, it could extend the mapping between events and sensors to make the
monitoring of patient activity more complete.</p>
      <p>Furthermore after careful field testing, followed closely by medical professionals,
we could build databases that inform us on unwanted behaviors that lead to
disagreeable consequences, for a timely prevention.</p>
      <p>From the theoretical point of view, the powerful logic EC engine can be expanded
with the use of the ECE-rules (Event Condition Expectation). The ECE-rules are
evolution of the well-known ECA-rules and they can express exceptions and anomalies
of the system.</p>
      <p>Another aspect that would increase the potential of our application, is the
possibility of having a fuzzy logic rather than exact, in order to express also approximate
reasoning (rather than exact), also very useful in our case study.</p>
      <sec id="sec-4-1">
        <title>Monitoring</title>
      </sec>
      <sec id="sec-4-2">
        <title>Complex</title>
      </sec>
      <sec id="sec-4-3">
        <title>Processes to verify</title>
      </sec>
      <sec id="sec-4-4">
        <title>System</title>
        <p>Schmidt, K.-U. a. Stuhmer, R. a. Stojanovic and Ljil-jana, Blending
complex event processing with the RETE algorithm, 2008.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <source>[1] [2] [3]</source>
          [4]
          <string-name>
            <given-names>S.</given-names>
            <surname>Bragaglia</surname>
          </string-name>
          , Conformance,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          <string-name>
            <given-names>L.</given-names>
            <surname>Bettini</surname>
          </string-name>
          ,
          <article-title>Implementing Domain Specific Languages with Xtext and Xtend</article-title>
          , Packt Publishing,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <string-name>
            <given-names>S.</given-names>
            <surname>Russel</surname>
          </string-name>
          and
          <string-name>
            <surname>N. P.</surname>
          </string-name>
          , Intelligenza Artificiale:
          <article-title>un approccio moderno</article-title>
          , Prentice Hall,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>