Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Core : Align to changes in master

  • Loading branch information...
commit ec59c137f450994ba13ca0f16c38c9d34424278c 1 parent 94341bd
@sotty sotty authored
View
28 drools-chance-core/src/main/java/org/drools/chance/reteoo/ChanceKnowledgeHelper.java
@@ -3,10 +3,12 @@
import org.drools.WorkingMemory;
import org.drools.base.DefaultKnowledgeHelper;
import org.drools.chance.ChanceHelper;
+import org.drools.chance.degree.simple.SimpleDegree;
import org.drools.chance.factmodel.ImperfectTraitProxy;
import org.drools.chance.degree.Degree;
import org.drools.chance.evaluation.Evaluation;
//import org.drools.factmodel.traits.LogicalTypeInconsistencyException;
+import org.drools.factmodel.traits.LogicalTypeInconsistencyException;
import org.drools.factmodel.traits.Thing;
@@ -38,6 +40,14 @@ public Evaluation getEvaluation( String label ) {
return getEvaluation().lookupLabel( label );
}
+ public <T, K> T don( Thing<K> core, Class<T> trait ) {
+ return don( core.getCore(), trait, SimpleDegree.TRUE );
+ }
+
+ public <T, K> T don( K core, Class<T> trait ) {
+ return don( core, trait, SimpleDegree.TRUE );
+ }
+
public <T, K> T don( Thing<K> core, Class<T> trait, Degree deg ) {
return don( core.getCore(), trait, deg );
}
@@ -47,18 +57,22 @@ public Evaluation getEvaluation( String label ) {
}
public <T, K> T don( K core, Class<T> trait, Degree deg, boolean logical ) {
+ if ( core instanceof Thing && ( (Thing) core ).getCore() != core ) {
+ return don( ((Thing) core).getCore(), trait, deg, logical );
+ }
try {
- T thing = applyTrait( core, trait, logical );
-
- ((ImperfectTraitProxy) thing).setDegree( deg );
-
- return doInsertTrait( thing, false );
- } catch ( Exception e ) {
- e.printStackTrace();
+ T thing = applyTrait( core, trait, deg, logical );
+ return thing;
+ } catch ( LogicalTypeInconsistencyException ltie ) {
+ ltie.printStackTrace();
return null;
}
}
+ protected <T> void configureTrait( T thing, Object value ) {
+ ((ImperfectTraitProxy) thing).setDegree( (Degree) value );
+ }
+
}
View
15 drools-chance-core/src/main/java/org/drools/chance/reteoo/builder/ChanceNodeFactory.java
@@ -1,6 +1,7 @@
package org.drools.chance.reteoo.builder;
+import org.drools.base.ValueType;
import org.drools.chance.rule.constraint.core.connectives.ConnectiveCore;
import org.drools.chance.reteoo.nodes.*;
import org.drools.common.BaseNode;
@@ -29,9 +30,17 @@ public TerminalNode buildTerminalNode(int id, LeftTupleSource source, Rule rule,
}
public ObjectTypeNode buildObjectTypeNode( int id, EntryPointNode objectSource, ObjectType objectType, BuildContext context ) {
- ChanceObjectTypeNode otn = new ChanceObjectTypeNode( id, objectSource, objectType, context );
- otn.setImperfect( ChanceObjectTypeNode.isImperfect( objectType ) );
- return otn;
+ if ( objectType.getValueType().equals( ValueType.TRAIT_TYPE ) ) {
+ ChanceTraitObjectTypeNode otn = new ChanceTraitObjectTypeNode( id, objectSource, objectType, context );
+ otn.setImperfect( ChanceObjectTypeNode.isImperfect( objectType ) );
+ return otn;
+ } else {
+ ChanceObjectTypeNode otn = new ChanceObjectTypeNode( id, objectSource, objectType, context );
+ otn.setImperfect( ChanceObjectTypeNode.isImperfect( objectType ) );
+ return otn;
+ }
+
+
}
public JoinNode buildJoinNode( int id, LeftTupleSource leftInput, ObjectSource rightInput, BetaConstraints binder, BuildContext context ) {
View
2  drools-chance-core/src/main/java/org/drools/chance/reteoo/builder/ChanceRuleBuilder.java
@@ -11,6 +11,8 @@ public ChanceRuleBuilder() {
this.utils.addBuilder( ChanceGroupElement.class,
new ChanceGroupElementBuilder() );
+ this.utils.addBuilder( GroupElement.class,
+ new GroupElementBuilder() );
this.utils.addBuilder( Pattern.class,
new ChancePatternBuilder() );
this.utils.addBuilder( EvalCondition.class,
View
75 ...s-chance-core/src/main/java/org/drools/chance/reteoo/nodes/ChanceTraitObjectTypeNode.java
@@ -0,0 +1,75 @@
+package org.drools.chance.reteoo.nodes;
+
+import org.drools.base.ClassObjectType;
+import org.drools.base.ValueType;
+import org.drools.chance.degree.Degree;
+import org.drools.chance.degree.simple.SimpleDegree;
+import org.drools.chance.evaluation.SimpleEvaluationImpl;
+import org.drools.chance.reteoo.ChanceFactHandle;
+import org.drools.chance.rule.constraint.core.evaluators.IsAEvaluatorDefinition;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.factmodel.traits.Trait;
+import org.drools.reteoo.EntryPointNode;
+import org.drools.reteoo.ModifyPreviousTuples;
+import org.drools.reteoo.ObjectTypeNode;
+import org.drools.reteoo.TraitObjectTypeNode;
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.spi.ObjectType;
+import org.drools.spi.PropagationContext;
+
+
+public class ChanceTraitObjectTypeNode extends TraitObjectTypeNode {
+
+ private boolean imperfect = false;
+
+ private IsAEvaluatorDefinition.ImperfectIsAEvaluator isA;
+
+ public ChanceTraitObjectTypeNode( int id, EntryPointNode source, ObjectType objectType, BuildContext context ) {
+ super( id, source, objectType, context );
+ }
+
+ public boolean isImperfect() {
+ return imperfect;
+ }
+
+ public void setImperfect(boolean imperfect) {
+ this.imperfect = imperfect;
+ if ( imperfect == true && isA == null ) {
+ isA = new IsAEvaluatorDefinition.ImperfectIsAEvaluator( ValueType.OBJECT_TYPE, false );
+ }
+ }
+
+
+ protected Degree match( InternalWorkingMemory wm, Object object ) {
+ if ( imperfect ) {
+ return isA.match( wm, object, ((ClassObjectType) getObjectType()).getClassType().getName() );
+ } else {
+ return SimpleDegree.TRUE;
+ }
+ }
+
+
+ @Override
+ public void assertObject( InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory ) {
+ Class<?> klass = ((ClassObjectType) this.getObjectType()).getClassType();
+ ((ChanceFactHandle) factHandle).addEvaluation( this.getId(),
+ new SimpleEvaluationImpl( this.getId(),
+ "this isA " + klass.getName(),
+ match( workingMemory, factHandle.getObject() ),
+ klass.getSimpleName() ) );
+ super.assertObject(factHandle, context, workingMemory);
+ }
+
+ @Override
+ public void modifyObject( InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, InternalWorkingMemory workingMemory ) {
+ Class<?> klass = ((ClassObjectType) this.getObjectType()).getClassType();
+ ((ChanceFactHandle) factHandle).addEvaluation( this.getId(),
+ new SimpleEvaluationImpl( this.getId(),
+ "this isA " + klass.getName(),
+ match( workingMemory, factHandle.getObject() ),
+ klass.getSimpleName() ) );
+ super.modifyObject( factHandle, modifyPreviousTuples, context, workingMemory ); //To change body of overridden methods use File | Settings | File Templates.
+ }
+}
+
View
4 drools-chance-core/src/test/resources/org/drools/chance/fuzzy/testFuzzyFacts.drl
@@ -15,6 +15,8 @@
*/
package org.drools.chance.test;
+import org.drools.factmodel.traits.Traitable;
+
import org.drools.chance.factmodel.Imperfect;
import org.drools.chance.factmodel.LinguisticPartition;
@@ -98,7 +100,7 @@ end
declare CoreX
-
+@Traitable
name : String = "philip"
weight : Double = 65.0
Please sign in to comment.
Something went wrong with that request. Please try again.