    001    /*
    002    @license.text@
    003     */
    004    package com.hammurapi.reasoning.tutorial.rules;
    005
    006    import com.hammurapi.reasoning.spi.Infer;
    007    import com.hammurapi.reasoning.tutorial.objectmodel.Father;
    008    import com.hammurapi.reasoning.tutorial.objectmodel.Mother;
    009    import com.hammurapi.reasoning.tutorial.objectmodel.Parent;
    010
    011    public class ParentRules {
    012
    013            /**
    014             * Male parent is father, female parent is mother.
    015             * @param parent
    016             * @return Brother or Sister.
    017             */
    018            @Infer({Father.class, Mother.class})
    019            public Parent infer(Parent parent) {
    020
    021                    if (parent.getSubject().isMale()) {
    022                            if (!(parent instanceof Father)) {
    023                                    return new  Father(parent.getSubject(), parent.getObject());
    024                            }
    025                    } else {
    026                            if (!(parent instanceof Mother)) {
    027                                    return new Mother(parent.getSubject(), parent.getObject());
    028                            }
    029                    }
    030                    return null;
    031            }
    032    }