Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Remove spurious Sys.outs, unnecessary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sotty committed Feb 9, 2013
1 parent 99e2513 commit 8274333
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 24 deletions.
Expand Up @@ -16,7 +16,6 @@

package org.drools.chance.common;

import com.google.common.collect.HashBasedTable;
import org.drools.chance.rule.constraint.core.connectives.ConnectiveFactory;
import org.drools.chance.rule.constraint.core.connectives.factories.fuzzy.linguistic.FuzzyConnectiveFactory;
import org.drools.chance.rule.constraint.core.connectives.factories.fuzzy.mvl.ManyValuedConnectiveFactory;
Expand All @@ -30,6 +29,8 @@
import org.drools.chance.distribution.ImpKind;
import org.drools.chance.distribution.ImpType;

import java.util.HashMap;


/**
* Level I (master) factory.
Expand All @@ -55,28 +56,44 @@
public class ChanceStrategyFactory<T> {


private static HashBasedTable<ImpKind,ImpType,ConnectiveFactory> cacheConnective = HashBasedTable.create();

private static HashMap<Pair<ImpKind,ImpType>,ConnectiveFactory> cacheConnective = new HashMap<Pair<ImpKind, ImpType>, ConnectiveFactory>();
private static ConnectiveFactory defaultFactory = new ManyValuedConnectiveFactory();

static {
cacheConnective.put( ImpKind.PROBABILITY, ImpType.DISCRETE, new DiscreteProbabilityConnectiveFactory() );
cacheConnective.put( ImpKind.PROBABILITY, ImpType.DIRICHLET, new DiscreteProbabilityConnectiveFactory() );
cacheConnective.put( ImpKind.FUZZINESS, ImpType.LINGUISTIC, new FuzzyConnectiveFactory() );
cacheConnective.put( ImpKind.FUZZINESS, ImpType.MVL, new ManyValuedConnectiveFactory() );
cacheConnective.put( ImpKind.FUZZINESS, ImpType.BASIC, new ManyValuedConnectiveFactory() );
cacheConnective.put( ImpKind.PROBABILITY, ImpType.BASIC, new ManyValuedConnectiveFactory() );
cacheConnective.put(
new Pair<ImpKind, ImpType>( ImpKind.PROBABILITY, ImpType.DISCRETE ),
new DiscreteProbabilityConnectiveFactory() );

cacheConnective.put(
new Pair<ImpKind, ImpType>( ImpKind.PROBABILITY, ImpType.DIRICHLET ),
new DiscreteProbabilityConnectiveFactory() );

cacheConnective.put(
new Pair<ImpKind, ImpType>( ImpKind.FUZZINESS, ImpType.LINGUISTIC ),
new FuzzyConnectiveFactory() );

cacheConnective.put(
new Pair<ImpKind, ImpType>( ImpKind.FUZZINESS, ImpType.MVL ),
new ManyValuedConnectiveFactory() );
cacheConnective.put(
new Pair<ImpKind, ImpType>( ImpKind.FUZZINESS, ImpType.BASIC ),
new ManyValuedConnectiveFactory() );
cacheConnective.put(
new Pair<ImpKind, ImpType>( ImpKind.PROBABILITY, ImpType.BASIC ),
new ManyValuedConnectiveFactory() );
}

public static void registerConnectiveFactory( ImpKind kind, ImpType model, ConnectiveFactory connFac ) {
cacheConnective.put( kind, model, connFac );
cacheConnective.put( new Pair<ImpKind, ImpType>( kind, model ), connFac );

}

public static ConnectiveFactory getConnectiveFactory( ImpKind kind, ImpType model ){
if ( kind == null || model == null ) {
return defaultFactory;
}
return cacheConnective.get( kind, model );
return cacheConnective.get( new Pair<ImpKind, ImpType>( kind, model ) );
}

public static void setDefaultFactory(ConnectiveFactory defaultFactory) {
Expand All @@ -89,19 +106,19 @@ public static void setDefaultFactory(ConnectiveFactory defaultFactory) {



private static HashBasedTable<ImpKind,ImpType,DistributionStrategyFactory> cache
= HashBasedTable.create();
private static HashMap<Pair<ImpKind,ImpType>,DistributionStrategyFactory> cache
= new HashMap<Pair<ImpKind, ImpType>, DistributionStrategyFactory>();

public static <T> DistributionStrategies buildStrategies(
ImpKind kind, ImpType model, DegreeType degreeType, Class<T> domainType) {

DistributionStrategyFactory<T> factory = cache.get(kind,model);
DistributionStrategyFactory<T> factory = cache.get( new Pair( kind,model ) );
return factory.<T>buildStrategies( degreeType, domainType );

}

public static <T> void register( ImpKind kind, ImpType model, DistributionStrategyFactory<T> factory ) {
cache.put( kind, model, factory );
cache.put( new Pair<ImpKind, ImpType>( kind, model ), factory );
}


Expand Down Expand Up @@ -179,6 +196,46 @@ public static void initDefaults() {



private static class Pair<X,Y> {

private X x;
private Y y;

Pair( X x, Y y ) {
this.x = x;
this.y = y;
}

public X getX() {
return x;
}

public Y getY() {
return y;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Pair pair = (Pair) o;

if (!x.equals(pair.x)) return false;
if (!y.equals(pair.y)) return false;

return true;
}

@Override
public int hashCode() {
int result = x.hashCode();
result = 31 * result + y.hashCode();
return result;
}
}





Expand Down
@@ -1,7 +1,5 @@
package org.drools.chance.rule.constraint.core.connectives.impl.godel;


import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;
import org.drools.chance.rule.constraint.core.connectives.ConnectiveCore;
import org.drools.chance.rule.constraint.core.connectives.impl.LogicConnectives;
import org.drools.chance.degree.Degree;
Expand Down
Expand Up @@ -38,7 +38,6 @@ when
presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
System.out.println( "Rule A " + $item.getType() );
modify ( $item ) {
addPresentationStyle( "readonly-inherited" );
}
Expand All @@ -55,7 +54,6 @@ when
presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
System.out.println("Rule B " + $item.getType());
modify ( $item ) {
addPresentationStyle( "readonly-inherited" );
}
Expand All @@ -75,7 +73,6 @@ when
presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
System.out.println("Rule C" + $item.getType());
modify ( $item ) {
removePresentationStyle( "readonly-inherited" );
}
Expand All @@ -93,7 +90,6 @@ when
presentationStyles contains "readonly" || presentationStyles contains "readonly-inherited" )
)
then
System.out.println("Rule D" + $item.getType());
modify ( $item ) {
removePresentationStyle( "readonly-inherited" );
}
Expand Down
Expand Up @@ -124,7 +124,7 @@ when
Size( formId == $formId, $max : num > 0 )
then
Progress p = new Progress( $formId, (int) Math.round( 100.0 * $num.doubleValue() / $max ) );
System.out.println( "Making progress.... " + p );
// System.out.println( "Making progress.... " + p );
insertLogical( p );
end

Expand Down
Expand Up @@ -324,7 +324,7 @@ when
$p : ProgressStatus( $formId, $percentage ; )
$s : SurveyGUIAdapter( itemId == $formId, progress != $percentage )
then
System.out.println("SETTING GUI PROGRESS TO " + $percentage );
// System.out.println("SETTING GUI PROGRESS TO " + $percentage );
modify ( $s ) {
setProgress( $percentage );
}
Expand All @@ -336,15 +336,15 @@ rule "Invalidations"
when
InvalidAnswer( $qid : questionId, $msg : reason, $type : type != "missing" )
then
System.out.println( "INVALIDATE ! " + $qid + " due to " + $type );
// System.out.println( "INVALIDATE ! " + $qid + " due to " + $type );
insert( new QuestionInvalidate( $qid ) );
end

rule "Finalizations"
when
Question( $qid : id, finalAnswer == true, answered == true )
then
System.out.println( "FINALIZE ! " + $qid );
// System.out.println( "FINALIZE ! " + $qid );
insert( new QuestionFinalize( $qid ) );
end

Expand Down

0 comments on commit 8274333

Please sign in to comment.