Package org.openquark.gems.client

Examples of org.openquark.gems.client.GemGraph


    /**
     * get the source representing the gem
     * @return the source function definition that represents the gem
     */
    public SourceModel.FunctionDefn getCalSource() {
        GemGraph gem = getGemGraph ();
       
        return gem.getCALSource();
    }
View Full Code Here


     * Builds the gem graph
     * @return true if the graph is created successfully
     */
    private boolean buildGemGraph () {
        try {
            gemGraph = new GemGraph ();
            DurationLogger logger = new DurationLogger ();
           
            addCollectorForMessage();
            addCollectorsForMessageProperties ();
            addCollectorsForMetrics();
View Full Code Here

        // 4) Repeat steps 2-3 to add other Gems
        // 5) Connect the Gems together using the connectGems() method on the GemGraph
        // 6) Repeat steps 2-5 as necessary to add all the Gems and connections for the GemGraph
        // 7) Typecheck the GemGraph to ensure that it is consistent
       
        GemGraph gemGraph = new GemGraph();
        gemGraph.getTargetCollector().setName("factorial");
       
        Gem productGem = gemFactory.makeFunctionalAgentGem(CAL_List.Functions.product);
        gemGraph.addGem(productGem);
       
        Gem upFromToGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.upFromTo);
        gemGraph.addGem(upFromToGem);

        // Create a Value gem to represent a BigInteger (Prelude.Integer) value for the number 1.
        Gem oneGem = new ValueGem(new LiteralValueNode(BigInteger.valueOf(1), calServices.getPreludeTypeConstants().getIntegerType()));
           
        gemGraph.addGem(oneGem);
       
        gemGraph.connectGems(oneGem.getOutputPart(), upFromToGem.getInputPart(0));
       
        gemGraph.connectGems(upFromToGem.getOutputPart(), productGem.getInputPart(0));
       
        gemGraph.connectGems(productGem.getOutputPart(), gemGraph.getTargetCollector().getInputPart(0));
       
        gemGraph.typeGemGraph(calServices.getTypeCheckInfo(GEM_GRAPH_TYPE_CHECKING_MODULE));
       
        return gemGraph;
    }
View Full Code Here

     * @param gemFactory used for creating value and function gems
     * @param calServices
     */
    public static GemGraph positiveOutlierDetectorGemGraph(GemFactory gemFactory, BasicCALServices calServices) throws TypeException {

        GemGraph gemGraph = new GemGraph();
        gemGraph.getTargetCollector().setName("positiveOutlierDetector");
       
        // A collector targeting the target collector. It will be an argument of the positiveOutlierDetector gem.
        CollectorGem sourceDataCollector = new CollectorGem();
        sourceDataCollector.setName("sourceData");
        gemGraph.addGem(sourceDataCollector);
       
        // Local collector: avg
        // Corresponding source: avg = Summary.average sourceData;
        CollectorGem avgCollector = new CollectorGem();
        avgCollector.setName("avg");
        gemGraph.addGem(avgCollector);
       
        // a ReflectorGem provides as output the value that is collected by the corresponding CollectorGem
        ReflectorGem sourceDataReflector1 = new ReflectorGem(sourceDataCollector);
        gemGraph.addGem(sourceDataReflector1);
       
        Gem averageGem = gemFactory.makeFunctionalAgentGem(CAL_Summary.Functions.average);
        gemGraph.addGem(averageGem);
       
        gemGraph.connectGems(sourceDataReflector1.getOutputPart(), averageGem.getInputPart(0));
       
        gemGraph.connectGems(averageGem.getOutputPart(), avgCollector.getInputPart(0));
       
        // Local collector: stdDev
        // Corresponding source: stdDev = Summary.populationStandardDeviation sourceData;
        CollectorGem stdDevCollector = new CollectorGem();
        stdDevCollector.setName("stdDev");
        gemGraph.addGem(stdDevCollector);
       
        ReflectorGem sourceDataReflector2 = new ReflectorGem(sourceDataCollector);
        gemGraph.addGem(sourceDataReflector2);
       
        Gem populationStdDevGem = gemFactory.makeFunctionalAgentGem(CAL_Summary.Functions.populationStandardDeviation);
        gemGraph.addGem(populationStdDevGem);
       
        gemGraph.connectGems(sourceDataReflector2.getOutputPart(), populationStdDevGem.getInputPart(0));
       
        gemGraph.connectGems(populationStdDevGem.getOutputPart(), stdDevCollector.getInputPart(0));
       
        // Local collector: isPositiveOutlier
        // Corresponding source: isPositiveOutlier x_1 = x_1 - avg >= x_2 * stdDev;
        CollectorGem isPositiveOutlierCollector = new CollectorGem();
        isPositiveOutlierCollector.setName("isPositiveOutlier");
        gemGraph.addGem(isPositiveOutlierCollector);
       
        Gem subtractGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.subtract);
        gemGraph.addGem(subtractGem);
       
        ReflectorGem avgReflector = new ReflectorGem(avgCollector);
        gemGraph.addGem(avgReflector);
       
        // Retarget the first input of subtract to the isPositiveOutlier collector
        //
        // This means that the first input of subtract is no longer an argument for the overall Gem defined by the
        // GemGraph's target collector, but rather a local argument for the isPositiveOutlier collector.
        gemGraph.retargetInputArgument(subtractGem.getInputPart(0), isPositiveOutlierCollector, -1);
        gemGraph.connectGems(avgReflector.getOutputPart(), subtractGem.getInputPart(1));
       
        Gem multiplyGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.multiply);
        gemGraph.addGem(multiplyGem);
       
        ReflectorGem stdDevReflector = new ReflectorGem(stdDevCollector);
        gemGraph.addGem(stdDevReflector);
       
        // Leave the first input of multiply targeting the target collector (it will be an argument of the positiveOutlierDetector gem),
        // but hook up the second input of multiply to the stdDev reflector
        gemGraph.connectGems(stdDevReflector.getOutputPart(), multiplyGem.getInputPart(1));
       
        Gem greaterThanEqualsGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.greaterThanEquals);
        gemGraph.addGem(greaterThanEqualsGem);
       
        gemGraph.connectGems(subtractGem.getOutputPart(), greaterThanEqualsGem.getInputPart(0));
        gemGraph.connectGems(multiplyGem.getOutputPart(), greaterThanEqualsGem.getInputPart(1));
       
        gemGraph.connectGems(greaterThanEqualsGem.getOutputPart(), isPositiveOutlierCollector.getInputPart(0));
       
        // Update the reflected inputs of the collector because one of the inputs in the gem tree was retargeted
        isPositiveOutlierCollector.updateReflectedInputs();
       
        // Construct the gem tree connected to the target collector
        ReflectorGem isPositiveOutlierReflector = new ReflectorGem(isPositiveOutlierCollector);
        gemGraph.addGem(isPositiveOutlierReflector);

        isPositiveOutlierReflector.getInputPart(0).setBurnt(true);
       
        ReflectorGem sourceDataReflector3 = new ReflectorGem(sourceDataCollector);
        gemGraph.addGem(sourceDataReflector3);
       
        Gem filterGem = gemFactory.makeFunctionalAgentGem(CAL_List.Functions.filter);
        gemGraph.addGem(filterGem);
       
        gemGraph.connectGems(isPositiveOutlierReflector.getOutputPart(), filterGem.getInputPart(0));
        gemGraph.connectGems(sourceDataReflector3.getOutputPart(), filterGem.getInputPart(1));
       
        gemGraph.connectGems(filterGem.getOutputPart(), gemGraph.getTargetCollector().getInputPart(0));
       
        gemGraph.typeGemGraph(calServices.getTypeCheckInfo(GEM_GRAPH_TYPE_CHECKING_MODULE));
       
        return gemGraph;
    }
View Full Code Here

     * @param gemFactory
     * @param calServices
     */
    public static GemGraph demoMapGemGraph(GemFactory gemFactory, BasicCALServices calServices) throws TypeException {

        GemGraph gemGraph = new GemGraph();
        gemGraph.getTargetCollector().setName("demoMap");
       
        // Two collectors forming the two arguments of the demoMap gem.
        CollectorGem mapFunctionCollector = new CollectorGem();
        mapFunctionCollector.setName("mapFunction");
        gemGraph.addGem(mapFunctionCollector);
       
        CollectorGem listCollector = new CollectorGem();
        listCollector.setName("list");
        gemGraph.addGem(listCollector);
       
        // Construct the test for checking whether the 'list' value is the empty list.
        Gem isEmptyGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.isEmpty);
        gemGraph.addGem(isEmptyGem);
       
        ReflectorGem listReflector1 = new ReflectorGem(listCollector);
        gemGraph.addGem(listReflector1);

        // Construct the gem tree for the case when 'list' is not empty.
       
        // The head of the returned Cons is: mapFunction (List.head list)
        // which uses the apply gem to apply the mapFunction to its argument.
        gemGraph.connectGems(listReflector1.getOutputPart(), isEmptyGem.getInputPart(0));

        Gem headGem = gemFactory.makeFunctionalAgentGem(CAL_List.Functions.head);
        gemGraph.addGem(headGem);
       
        ReflectorGem listReflector2 = new ReflectorGem(listCollector);
        gemGraph.addGem(listReflector2);
       
        gemGraph.connectGems(listReflector2.getOutputPart(), headGem.getInputPart(0));
       
        Gem applyGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.apply);
        gemGraph.addGem(applyGem);
       
        ReflectorGem mapFunctionReflector1 = new ReflectorGem(mapFunctionCollector);
        gemGraph.addGem(mapFunctionReflector1);
       
        gemGraph.connectGems(mapFunctionReflector1.getOutputPart(), applyGem.getInputPart(0));
        gemGraph.connectGems(headGem.getOutputPart(), applyGem.getInputPart(1));
       
        // The tail of the returned Cons is: demoMap mapFunction (List.tail list)
        Gem tailGem = gemFactory.makeFunctionalAgentGem(CAL_List.Functions.tail);
        gemGraph.addGem(tailGem);

        ReflectorGem listReflector3 = new ReflectorGem(listCollector);
        gemGraph.addGem(listReflector3);
       
        gemGraph.connectGems(listReflector3.getOutputPart(), tailGem.getInputPart(0));
       
        ReflectorGem demoMapReflector = new ReflectorGem(gemGraph.getTargetCollector());
        gemGraph.addGem(demoMapReflector);
       
        ReflectorGem mapFunctionReflector2 = new ReflectorGem(mapFunctionCollector);
        gemGraph.addGem(mapFunctionReflector2);
       
        Gem consGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.DataConstructors.Cons);
        gemGraph.addGem(consGem);
       
        gemGraph.connectGems(applyGem.getOutputPart(), consGem.getInputPart(0));
        gemGraph.connectGems(demoMapReflector.getOutputPart(), consGem.getInputPart(1));
       
        // Construct the conditional branch (using the iff gem). The false case returns the value
        // generated by the gem tree defined above. In the true case, Nil (the empty list) is returned.
        Gem iffGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.iff);
        gemGraph.addGem(iffGem);
       
        Gem nilGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.DataConstructors.Nil);
        gemGraph.addGem(nilGem);
       
        gemGraph.connectGems(isEmptyGem.getOutputPart(), iffGem.getInputPart(0));
        gemGraph.connectGems(nilGem.getOutputPart(), iffGem.getInputPart(1));
        gemGraph.connectGems(consGem.getOutputPart(), iffGem.getInputPart(2));
       
        // Connect the gems to the target collector
        gemGraph.connectGems(iffGem.getOutputPart(), gemGraph.getTargetCollector().getInputPart(0));
       
        gemGraph.connectGems(mapFunctionReflector2.getOutputPart(), demoMapReflector.getInputPart(0));
       
        gemGraph.connectGems(tailGem.getOutputPart(), demoMapReflector.getInputPart(1));
       
        gemGraph.typeGemGraph(calServices.getTypeCheckInfo(GEM_GRAPH_TYPE_CHECKING_MODULE));
       
        return gemGraph;
    }
View Full Code Here

TOP

Related Classes of org.openquark.gems.client.GemGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.