    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.Child;
    009    import com.hammurapi.reasoning.tutorial.objectmodel.Daughter;
    010    import com.hammurapi.reasoning.tutorial.objectmodel.Father;
    011    import com.hammurapi.reasoning.tutorial.objectmodel.GrandDaughter;
    012    import com.hammurapi.reasoning.tutorial.objectmodel.GrandFather;
    013    import com.hammurapi.reasoning.tutorial.objectmodel.GrandMother;
    014    import com.hammurapi.reasoning.tutorial.objectmodel.GrandSon;
    015    import com.hammurapi.reasoning.tutorial.objectmodel.Mother;
    016    import com.hammurapi.reasoning.tutorial.objectmodel.Parent;
    017    import com.hammurapi.reasoning.tutorial.objectmodel.Son;
    018
    019    public class GrandRules {
    020
    021            /**
    022             * Son of child is a grandson.
    023             * @param son
    024             * @param parent
    025             * @return
    026             */
    027            @Infer
    028            @Condition("son, parent: son.getObject().equals(parent.getObject())")
    029            public GrandSon infer(Son son, Parent parent) {
    030                    return new GrandSon(son.getSubject(), parent.getSubject());
    031            }
    032
    033            /**
    034             * Daughter of child is a granddaughter.
    035             * @param daughter
    036             * @param parent
    037             * @return
    038             */
    039            @Infer
    040            @Condition("daughter, parent: daughter.getObject().equals(parent.getObject())")
    041            public GrandDaughter infer(Daughter daughter, Parent parent) {
    042                    return new GrandDaughter(daughter.getSubject(), parent.getSubject());
    043            }
    044
    045            /**
    046             * Father of parent is grandparent.
    047             * @param child
    048             * @param father
    049             * @return
    050             */
    051            @Infer
    052            @Condition("child, father: child.getObject().equals(father.getObject())")
    053            public GrandFather infer(Child child, Father father) {
    054                    return new GrandFather(father.getSubject(), child.getSubject());
    055            }
    056
    057            /**
    058             * Mother of parent is grandmother.
    059             * @param child
    060             * @param mother
    061             * @return
    062             */
    063            @Infer
    064            @Condition("child, mother: child.getObject().equals(mother.getObject())")
    065            public GrandMother infer(Child child, Mother mother) {
    066                    return new GrandMother(mother.getSubject(), child.getSubject());
    067            }
    068
    069    }