Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.test;
- import org.drools.factmodel.traits.Traitable;
- import org.drools.factmodel.traits.Entity;
- import org.drools.factmodel.traits.Thing;
- global java.util.List list;
- declare Place
- @Traitable
- name : String @key
- end
- declare trait Location
- end
- declare trait Lake extends Location
- name : String
- end
- declare trait Country extends Location
- name : String
- end
- declare trait City extends Location
- name : String
- end
- declare IsIn
- src : Place
- tgt : Place
- end
- query is_in( Place $p, Class $type, Location $q )
- ( IsIn( $p, $x ; ) and $q := Location( core == $x, this isA $type ) )
- or
- ( IsIn( $p, $x ; ) and is_in( $x, $type, $q ; ) )
- end
- rule "Init"
- when
- then
- Place p1 = new Place( "Italy" );
- insert( p1 );
- don( p1, Country.class );
- Place p2 = new Place( "LakeOfGarda" );
- insert( p2 );
- don( p2, Lake.class );
- Place p3 = new Place( "LakeOfComo" );
- insert( p3 );
- don( p3, Lake.class );
- Place p4 = new Place( "Como" );
- insert( p4 );
- don( p4, City.class );
- insert( new IsIn( p2, p1 ) );
- insert( new IsIn( p3, p1 ) );
- insert( new IsIn( p4, p3 ) );
- end
- rule "PlacesInItaly"
- when
- $s : String()
- $p : Place( name == $s )
- is_in( $p, Country.class, $q ; )
- $q := Country( $name : name == "Italy" )
- then
- System.out.println( "Checking " + $p + " in " + $q );
- list.add( $name );
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement