    001    /*
    002    @license.text@
    003     */
    004    package com.hammurapi.reasoning.tutorial.rules;
    005
    006    import com.hammurapi.reasoning.spi.Condition;
    007    import com.hammurapi.reasoning.spi.Infer;
    008    import com.hammurapi.reasoning.tutorial.objectmodel.Husband;
    009    import com.hammurapi.reasoning.tutorial.objectmodel.Spouse;
    010    import com.hammurapi.reasoning.tutorial.objectmodel.Wife;
    011
    012    public class SpouseRules {
    013
    014            /**
    015             * If A is a spouse of B then B is a spouse of A.
    016             * @param spouse
    017             */
    018            @Infer
    019            public Spouse inferSpouse(Spouse spouse) {
    020                    return new Spouse(spouse.getObject(), spouse.getSubject());
    021            }
    022
    023            /**
    024             * Male spouse is husband.
    025             * @param spouse
    026             */
    027            @Infer
    028            public Husband inferHusband(@Condition("arg.getSubject().isMale() && !(arg instanceof com.hammurapi.reasoning.tutorial.objectmodel.Husband)") Spouse spouse) {
    029                    return new Husband(spouse.getSubject(), spouse.getObject());
    030            }
    031
    032            /**
    033             * Female spouse is wife.
    034             * @param spouse
    035             */
    036            @Infer
    037            public Wife inferWife(@Condition("!arg.getSubject().isMale() && !(arg instanceof com.hammurapi.reasoning.tutorial.objectmodel.Wife)") Spouse spouse) {
    038                    return new Wife(spouse.getSubject(), spouse.getObject());
    039            }
    040    }