## 3 Materials and Methods
### Deployment of the Proposed Approach  
The following steps show the work flow of the proposed approach during execution time. The process is shown in Figure 11. (1) Extracting relevant information from the context: the WSN extracts relevant information on itself and the monitored environment. The context information is directly mapped to the ontology; (2) Updating the instantiated ontology: the instantiated ontology is updated with new information. The values of the instantiated ontology change accordingly; (3) Rule selection and decision making: the reasoning engine recognizes the WSN states and finds which rules should be activated, as well as makes intelligent decisions; (4) Command execution: the WSN receives the command from the reasoning engine and acts consequently. The reasoning engine can be customized to the operating parameters of a WSN according to its particular application.  
With an example of decision-making on energy strategy, the entire process is shown in Figure 12. Monitoring tasks are set by a manager and conducted by the WSN. The monitoring middleware uses a database that is mainly responsible for receiving the data and some preprocessing.  
Figure 11: Work diagram of proposed approach.  
Figure 12: Workflow for case study.  
When the system is working, the database is connected through SQL and creates a communication thread for receiving and processing data. When processing is complete, data are stored in the corresponding database table using an SQL insert statement. The collected data are used to judge the water quality on the basis of an evaluation standard. The state machine monitors changes in the devices, data, observations, and water quality of the WSN. Any changes to these states are used to formulate an energy strategy. The decision-making steps based on the ontology and reasoning rules are as follows:  
_Step 1: Instantiation of current ontology._ The basic ontological structure is shown in Figure 1, and the reasoning rules have been introduced in Section 3.2. However, this is a basic program and cannot be directly processed by the inference engine. In this step, we create instances according to the known conditions. This case is mainly concerned with controlling the energy according to changes in the observed data, the main instances are \"WSN Node\": \"WSN Node-1\", \"Water Area\": \"Water Area-1\", \"Communicating Device\": \"Wireless Communicating Device1\", \"pH Data\": current Data, \"pH Data\": history Data, \"Communication Property\": \"Communication Frequency\", and \"Sensing Property\": \"Sample Frequency\".  
_Step 2: Creating object property contacts between instances._ In the ontology, properties are defined for all classes. After the instances are defined, the property contacts should be appended to each instance in the Protege editor, as shown in Figure 13.  
_Step 3: Reasoning according to SWRL rules._ This step requires a reasoning engine such as Jess [24]. Jess is a Java-based rule engine that consists of a rule base, fact base, and an execution engine. Jess combined with SWRL is a SWRLJessTab plug-in provided in the Protege-based tools. The Jess inference engine runs in the Protege editing environment, which displays the reasoning results. It uses the previously defined data rules. The decision result from Jess is presented in Figure 14.  
Figure 13: Some property contacts between instances.  
_Step 4: Implementation of decision results._ The decision results are converted to OWL files. The application layer reads the analysis results and uses them to determine if it should reconfigure the WSN.