## 5 Reasoning about WSN Contexts: the Implementation of Contextualising Rules  
Different forms of contextual reasoning are involved to carry out the reasoning mechanisms of inferring and connecting contexts. [PERSON], in his work about the foundation of a theory of contextual reasoning, identifies three fundamental dimensions of contexts (_partiality_, _approximation_ and _perspective_) and their relation with three forms of contextual reasoning (_localised_, _push and pop_ and _shifting reasoning_). Thus, depending on the context dimension different mechanisms of context reasoning will be used [23]. If the focus is on the _partiality_ context dimension the reasoning mechanism will be _localised_ reasoning. The partiality is the portion of domain that is represented, and in our case it is composed by the four types of contexts: sensing, node, network and organisational contexts. The localised reasoning does not consider all that is known about a domain, but rather a subset of the knowledge [12,23]. In this approach, the reasoning is kept locally based on the local WSN status, and it is linked with other WSN's status and with the dynamic interoperability (global model) using the bridge rules. For instance, if the local context of a node is low level of energy, the consequence could be to sleep the node. But if this context is connected with an emergency context, then the node must continue sensing instead of sleeping. The inference process in the dynamic interoperability domain could generate different knowledge and different decision-making actions depending on the local and global models. Moreover, when the contexts depend on the level of approximation it is possible to change the contexts granularity by adding (pushing) or extracting (popping) some metadata elements into the context box. For instance the \"where\" context could change according if the approximation is at sensing, node, network, or organisational contexts. Then, adding node location contexts (individual node locations) will determine the network location context (network coverage area). Thus, if the focus is on the _degree of approximation_, the reasoning about WSN contexts will be _push and pop_ reasoning. Finally, if the focus is on the changing the value of metadata (_perspective_ dimension) the reasoning about WSN contexts will be a _shifting_ reasoning. This form of reasoning is called shifting because the changing of metadata value shifts the WSN contexts. For instance, when the NodeNeighbours metadata change its value from 12 neighbours to 0 neighbour, the perspective from which the WSN is observed changes radically from a high density context to an isolation context. In our approach the WSN contexts are inferred from the WSN's status using metadata elements. Therefore, we introduce contextualising rules to reason over WSN status using data and metadata that describe the sensing system, the current network configuration, and the environment restrictions. The contextualising rules are deductive rules (_if-then-else_) and are fed by the current WSN metadata. Some of these metadata are static and established by default (e.g. access restrictions, security level, and owner). Meanwhile, others are dynamic and automatically extracted from the WSN (e.g. energy level, node location). The dynamics of a WSN's status should be automatically captured and self-describedthrough metadata and some of them can be derived by the data itself (e.g. the accelerometer data help to infer if the node is moving or fixing). The implementation of the contextualising rules has been achieved by using the Jess rule engine (Figure 3). Jess is a rule-based system that uses rules to derive conclusions from premises. The premises are the _if_ first part of rules, meanwhile the conclusions are the _then_ second part of rules.