## 3 Using a Knowledge Graph for a Home Service Robot
### Home Service Reasoning Based on SWRL Rules  
The robot uses the knowledge graph system to obtain and analyze the data in the ontology knowledge base to perform semantic cognition of the home environment. According to the user's identity, behavior, habits, and the environmental information, the robot can determine which services should be provided using the SWRL rule base. The subclasses, instances, and attributes of the environment and user domains in the home environment domain ontology can be combined using the SWRL rule and the subclasses and instances in the service domain as the conclusion of the SWRL rule. A decision-making template for service tasks is established by correlating the three categories in the home environment domain ontology. As shown in Figure 3, the template indicates that the service task that the robot should provide is determined according to the environmental, user identity, and behavior information in the home environment. The establishment of the SWRL rule base should consider the conditions of various services and determine the various service modes that may occur in the home environment and the execution logic of the service tasks. An appropriate system and scale will substantially enhance the robot's ability to provide services. In addition, the construction and description of the SWRL-based service inference rules can be divided into three steps:  
* Determine the types, locations, and operations of the service and define them;
* Comprehensively analyze various factors affecting the service and clarify the preconditions by defining their classes and attributes;
* Determine the type and operation mode of the service. Use \"water delivery\" as a service example. First, determine that the service object is user Alan, and the operation object includes the water cups, which are defined. Then analyze the factors affecting the water delivery, which may include \"User [PERSON] is sitting in the bedroom, and it is time for drinking water\". The service operation mode corresponding to the \"water delivery\" service is \"send\". To further enhance the water delivery service, we consider additional conditions, such as the environmental temperature. For example, if the temperature inside the home exceeds a certain threshold (e.g., 30 degrees Celsius), the service robot should proactively deliver water to help prevent dehydration. Therefore, the SWRL rules for the water delivery service are established as follows:  
User (Alan) ~ StateUser (sit) ~ Location (bedroom) ~ Time (t1) ~ hasUserState (Alan,sit) ~ hasLocation (Alan, bedroom) ~ hasTime (sit, t1) ~ operateOn (send, cup). User (Alan) ~ Location (home) ~ Temperature (temp) ~ greaterThan (temp, 30) ~ isLocatedIn (Alan, home) ~ hasTemperature (home, temp) ~ operateOn (send, cup). These rules ensure that the service robot can intelligently decide when to deliver water based on both user behavior and environmental conditions. The combination of basic  
Figure 3: Template for developing the service inference SWRL rule base. and extended rules allows the robot to dynamically adapt its actions to various situations, enhancing the efficiency and responsiveness of the water delivery service. The service inference rule base serves as an essential foundation for the robot's decision making in service tasks, and it must account for abnormal factors that may occur in real household scenarios. Therefore, the robot must respond appropriately to highly unusual situations involving individuals or environmental conditions, such as a user falling, fainting, requiring rescue, or encountering abnormal environmental conditions like extreme temperatures or harmful gas concentrations. For instance, in the case of a user fainting, the robot should provide an emergency call service. The SWRL rule for establishing this emergency call service is as follows:  
StateUser(sleep) \" Location(?x) \" swrlb: booleanNot (?x, bed) \(\rightarrow\) operateOn(call, family).