@Override protected void onInit(final JSONValue data) { try { final JSONArray criteria = data.isArray(); this.criteria.clear(); for (int i = 0; i < criteria.size(); i++) { final JSONObject searchTypeJSON = criteria.get(i).isObject(); final Map<String, Criterion> searchType = new LinkedHashMap<String, Criterion>(); for (int j = 0; j < searchTypeJSON.get("elements").isArray().size(); j++) { final Criterion criterion = Criterion.readMe(j, searchTypeJSON); if (j == 0 && (selectedCriterion == null && i == 0 || selectedCriterion != null && criterion.displaytype.equalsIgnoreCase(selectedCriterion.displaytype))) { selectedCriterion = criterion; selectedCriterionHistory.put(selectedCriterion.displaytype, selectedCriterion); } searchType.put(criterion.getName(), criterion); } this.criteria.put( searchTypeJSON.get("displaytype").isString().stringValue().trim(), searchType); } } catch (final Exception e) { getLogger().severe(getClass().getName().replace("Impl", "") + ".onInit() : " + e); } }
public Split getBestSplit(ExampleSet inputSet, Attribute attribute, String labelName) { SortedExampleSet exampleSet = new SortedExampleSet((ExampleSet) inputSet.clone(), attribute, SortedExampleSet.INCREASING); Attribute labelAttribute = exampleSet.getAttributes().getLabel(); int labelIndex = labelAttribute.getMapping().mapString(labelName); double oldLabel = Double.NaN; double bestSplit = Double.NaN; double lastValue = Double.NaN; double bestBenefit = Double.NEGATIVE_INFINITY; double bestTotalWeight = 0; int bestSplitType = Split.LESS_SPLIT; // initiating online counting of benefit: only 2 Datascans needed then criterion.reinitOnlineCounting(exampleSet); for (Example e : exampleSet) { double currentValue = e.getValue(attribute); double label = e.getValue(labelAttribute); if ((Double.isNaN(oldLabel)) || (oldLabel != label) && (lastValue != currentValue)) { double splitValue = (lastValue + currentValue) / 2.0d; double[] benefits; if (labelName == null) { benefits = criterion.getOnlineBenefit(e); } else { benefits = criterion.getOnlineBenefit(e, labelIndex); } // online method returns both possible relations in one array(greater / smaller) in one // array if ((benefits[0] > minValue) && (benefits[0] > 0) && (benefits[1] > 0) && ((benefits[0] > bestBenefit) || ((benefits[0] == bestBenefit) && (benefits[1] > bestTotalWeight)))) { bestBenefit = benefits[0]; bestSplit = splitValue; bestTotalWeight = benefits[1]; bestSplitType = Split.LESS_SPLIT; } if ((benefits[2] > minValue) && (benefits[2] > 0) && (benefits[3] > 0) && ((benefits[2] > bestBenefit) || ((benefits[2] == bestBenefit) && (benefits[3] > bestTotalWeight)))) { bestBenefit = benefits[2]; bestSplit = splitValue; bestTotalWeight = benefits[3]; bestSplitType = Split.GREATER_SPLIT; } oldLabel = label; } lastValue = currentValue; criterion.update(e); } return new Split(bestSplit, new double[] {bestBenefit, bestTotalWeight}, bestSplitType); }
@Override public TypedValue[] getTypedValues(Criteria crit, CriteriaQuery criteriaQuery) throws HibernateException { final ArrayList<TypedValue> typedValues = new ArrayList<TypedValue>(); for (Criterion condition : conditions) { final TypedValue[] subValues = condition.getTypedValues(crit, criteriaQuery); Collections.addAll(typedValues, subValues); } return typedValues.toArray(new TypedValue[typedValues.size()]); }
public void removeCriterion(Criterion criterion) { if (criterion != null) { Iterator<Criterion> iter = getCriteria().iterator(); while (iter.hasNext()) { Criterion c = iter.next(); if (c.equals(criterion)) { iter.remove(); break; } } } }
/** {@inheritDoc} */ @Override public Object[] getValues() { List<Object> params = new ArrayList<Object>(); for (Criterion criterion : criteria) { if (criterion != null) { params.addAll(Arrays.asList(criterion.getValues())); } } return params.toArray(); }
public void addCriterion(Criterion criterion) throws SubscriptionRepositoryException { // Validate criterion object if (criterion == null) { throw new SubscriptionRepositoryException( "Attempted to add null criterion to subscription criteria list"); } // Validate key if ((criterion.getKey() == null) || "".equals(criterion.getKey().trim())) { throw new SubscriptionRepositoryException( "Attempted to add criterion with an invalid key to subscription criteria list - key: " + criterion.getKey()); } else { // Trim key prior to storage criterion.setKey(criterion.getKey().trim()); } // Valiedate value if ((criterion.getValue() == null) || "".equals(criterion.getValue().trim())) { throw new SubscriptionRepositoryException( "Attempted to add criterion to the subscription criteria list with an invalid value for key: " + criterion.getKey()); } getCriteria().add(criterion); }
/** * create a new startpopulation and run GA. * * @param populationSize * @param criterion * @param value * @return Individual * @author jochen */ public Individual startAlgorithm(int populationSize, Criterion criterion, int value) { this.populationSize = populationSize; this.criterion = criterion; if (criterion.equals(Criterion.GENERATIONS)) { totalGenerations = value; } else if (criterion.equals(Criterion.TIMENOIMPROVEMENTS)) { maxTimeNoImprovements = value; } else if (criterion.equals(Criterion.GENERATIONSNOIMPROVEMENTS)) { maxGenerationsNoImprovements = value; } return startAlgorithm(); }
private void toHqlString(Iterator it, StringBuffer buffer, QueryBuilder builder) { Criterion criterion = (Criterion) it.next(); String hqlStr = criterion.toHqlString(builder); if (hqlStr != null) { if (first) { first = false; } else { buffer.append(' ').append(operation).append(' '); } buffer.append(hqlStr); } if (it.hasNext()) { toHqlString(it, buffer, builder); } }
public boolean isMatchedBy(Object o) { if (this.criterionList.isEmpty()) { return false; } Iterator iterator = this.criterionList.iterator(); while (iterator.hasNext()) { Criterion c = (Criterion) iterator.next(); if (!c.isMatchedBy(o)) { return false; } } return true; }
/** {@inheritDoc} */ @Override public String toEjbQl(QueryBuilder parent) { StringBuilder sb = new StringBuilder(); for (Iterator<Criterion> it = criteria.iterator(); it.hasNext(); ) { Criterion criterion = it.next(); if (criterion != null) { sb.append(criterion.toEjbQl(this)); if (it.hasNext()) { sb.append(" AND "); } } } return sb.toString(); }
private void completePanel() { if (criterion != null) { jtfCode.setText(criterion.getCode()); jtfCode.setEditable(false); jtfLibelle.setText(criterion.getLibelle()); jcbSortOrder.setSelectedIndex((criterion.getSortOrder() > 0) ? 0 : 1); jcbPlacementCriterion.setSelected(criterion.isPlacement()); jcbClassementCriterion.setSelected(criterion.isClassement()); jcbSortOrder.setEnabled(!parent.getWorkConfiguration().isOfficialProfile()); jcbPlacementCriterion.setEnabled(!parent.getWorkConfiguration().isOfficialProfile()); jcbClassementCriterion.setEnabled(!parent.getWorkConfiguration().isOfficialProfile()); } }
@Override public void initializeFromJSON(Project project, JSONObject obj) throws JSONException { super.initializeFromJSON(project, obj); if (obj.has("caseSensitive") && !obj.isNull("caseSensitive")) { caseSensitive = obj.getBoolean("caseSensitive"); collator.setStrength(Collator.IDENTICAL); } }
private JSONValue toJson() { final JSONObject data = null == restoreddata ? new JSONObject() : restoreddata; try { data.put("historyversion", new JSONString(SearchPanelModel.historyversion)); data.put("selectedtype", new JSONString(selectedCriterion.displaytype)); final Iterator<String> iter = criteria.keySet().iterator(); while (iter.hasNext()) { final String searchTypeKey = iter.next(); if (!selectedCriterionHistory.containsKey(searchTypeKey)) { continue; } final JSONObject searchdata = new JSONObject(); final JSONObject userdata = new JSONObject(); searchdata.put(Context.get().getChallengeLogin().toLowerCase(), userdata); userdata.put( "selectedcriterion", new JSONString(selectedCriterionHistory.get(searchTypeKey).getName())); final JSONObject criteriadata = new JSONObject(); for (final Criterion criterion : criteria.get(searchTypeKey).values()) { final String s = CriterionHistory.Writer.toJson(criterion.getHistory()); criteriadata.put(criterion.getName(), JSONParser.parseStrict(s)); } userdata.put("criteria", criteriadata); if (searchhistory.containsKey(searchTypeKey)) { userdata.put( "searchhistory", JSONParser.parseStrict( SearchHistory.Writer.toJson(searchhistory.get(searchTypeKey)))); } if (accesshistory.containsKey(searchTypeKey)) { userdata.put( "accesshistory", JSONParser.parseStrict( AccessHistory.Writer.toJson(accesshistory.get(searchTypeKey)))); } data.put(selectedCriterionHistory.get(searchTypeKey).getType().toLowerCase(), searchdata); } } catch (final Exception e) { getLogger().severe("SearchModel.toJson() : " + e); } return data; }
/** @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { if (e.getSource() == jbValider) { if (criterion == null) { criterion = new Criterion(jtfCode.getText()); parent .getWorkConfiguration() .getCriteriaPopulation() .put(criterion, new ArrayList<CriterionElement>()); parent.getWorkConfiguration().getListCriteria().add(criterion); } criterion.setSortOrder( (jcbSortOrder.getSelectedIndex() == 1) ? Criterion.SORT_DESC : Criterion.SORT_ASC); criterion.setLibelle(jtfLibelle.getText()); criterion.setPlacement(jcbPlacementCriterion.isSelected()); criterion.setClassement(jcbClassementCriterion.isSelected()); setVisible(false); } else if (e.getSource() == jbAnnuler) { setVisible(false); } }
public boolean matches(Criteria criteria) { score = 0; boolean kill = false; boolean anyMatches = false; for (Criterion criterion : criteria) { Answer answer = answers.get(criterion.getAnswer().getQuestionText()); boolean match = criterion.getWeight() == Weight.DontCare || answer.match(criterion.getAnswer()); if (!match && criterion.getWeight() == Weight.MustMatch) { kill = true; } if (match) { score += criterion.getWeight().getValue(); } anyMatches |= match; // ... } if (kill) return false; return anyMatches; }
/** @return a {@link Criterion} using this field as a literal value */ public Criterion asCriterion() { return Criterion.literal(this); }
/** * Does ... * * @poseidon-object-id [I14fcf14m109d9b01fb5mm5d8c] * @param Root * @param caseStep */ public void handle(GuidelineAgent guidelineAgent, Case_Step caseStep) { // TODO: case step'in ici // rule in rule outlara gore, optionlardan birisini sececek // fakat su anda random birini seciyor // The decision_detail attribute may have a subguideline. // If there is, according to GLIF specs, it should be executed // before the decision criterion of this step if (caseStep.getDecision_detail() != null) { // create a new guideline handler // decision_detai's type is Nestable in fact, but it is casted to Guideline // TODO: If necessary, Macro case will also be handled. Nestable nestable = FactoryRetriever.retrieveNestable( guidelineAgent.getGuidelineURI(), caseStep.getDecision_detail()); if (nestable instanceof Guideline) { new GuidelineHandler().handle(guidelineAgent, (Guideline) nestable); } else if (nestable instanceof Macro) { // TODO: if necessary, it will be implemented. } } // //////message to monitoring Vector<String> messageVector = new Vector<String>(); messageVector.add(GuidelineHistoryFrame.UPDATE_STATUS); messageVector.add(caseStep.getName()); messageVector.add(StatusInfo.STEP_STATUS_COMMITTED); guidelineAgent.messageToMonitoring(messageVector, true); try { logger.info("CASE STEP START"); ArrayList optionsList = (ArrayList) caseStep.getOptions(); int listSize = optionsList.size(); // /// ExpressionHandler expressionHandler = new ExpressionHandler(); Guideline_Step nextStep = null; for (int i = 0; i < listSize; ++i) { Decision_Option opt = (Decision_Option) optionsList.get(i); Case_Condition cond = FactoryRetriever.retrieveCase_condition(guidelineAgent.getGuidelineURI(), opt); Guideline_Expression expr = cond.getCase_value(); Criterion cr = (Criterion) FactoryRetriever.retrieveExpression(guidelineAgent.getGuidelineURI(), expr); messageVector = new Vector<String>(); messageVector.add(GuidelineHistoryFrame.UPDATE_STATUS); messageVector.add(opt.getName()); messageVector.add(StatusInfo.STEP_STATUS_RUNNING); guidelineAgent.messageToMonitoring(messageVector); Collection getDataItems = cr.getGet_Data_Items(); Iterator it = getDataItems.iterator(); while (it.hasNext()) { Get_Data_Action gda = (Get_Data_Action) it.next(); new GetDataActionHandler().handle(guidelineAgent, caseStep, gda); } logger.info("SPECIFICATION:" + cr.getSpecification()); Boolean result = new Boolean(true); if (cr.getSpecification() != null) { result = (Boolean) expressionHandler.handle( guidelineAgent, caseStep, cr.getSpecification(), guidelineAgent.getGuidelineURI()); } logger.info("BOOL RESULT:" + result); Collection expressions = cr.getLet_expressions(); if (expressions != null) { for (Iterator iterator = expressions.iterator(); iterator.hasNext(); ) { Let_Expression expression = (Let_Expression) iterator.next(); String toBeDeleteds = expression.getIdentifier(); String variables[] = toBeDeleteds.split(","); for (int j = 0; j < variables.length; j++) { String variable = variables[j].trim(); // Logger.getLogger(this.getClass()).log(Level.DEBUG, // (":::::variable:: %" + variable+"%"); guidelineAgent.removeGlobalVariable(variable); } } } if (result) { nextStep = ((Decision_Option) optionsList.get(i)).getDestination(); messageVector = new Vector<String>(); messageVector.add(GuidelineHistoryFrame.UPDATE_STATUS); messageVector.add(opt.getName()); messageVector.add(StatusInfo.STEP_STATUS_COMMITTED); guidelineAgent.messageToMonitoring(messageVector, true); break; } else { messageVector = new Vector<String>(); messageVector.add(GuidelineHistoryFrame.UPDATE_STATUS); messageVector.add(opt.getName()); messageVector.add(StatusInfo.STEP_STATUS_ABORTED); guidelineAgent.messageToMonitoring(messageVector, true); } } /* * Random rand = new Random(); * Guideline_Step nextStep = ((Decision_Option)optionsList.get((rand.nextInt(listSize)))).getDestination(); */ // there some Decision_Step instances (in GLIF examples) which have null Destinations, // so we have to be sure that our random gives us a complete one. // TODO: In our instances, we will not let it. There this code will be removed. while (nextStep == null) { nextStep = caseStep.getDefault_next_step(); messageVector = new Vector<String>(); messageVector.add(GuidelineHistoryFrame.UPDATE_STATUS); messageVector.add(caseStep.getName() + GuidelineGraph.DEFAULT_STEP_POSTFIX); messageVector.add(StatusInfo.STEP_STATUS_COMMITTED); guidelineAgent.messageToMonitoring(messageVector, true); } new GuidelineStepHandler().handle(guidelineAgent, nextStep); } catch (Exception exc) { exc.printStackTrace(); } // }
public Criterion getParentCriterion(Criterion goal, String criterionName) { if (goal.getName().equals(criterionName)) return null; return goal.getParentCriterion(criterionName); }
public Boolean handle( GuidelineAgent guidelineAgent, Guideline_Step guidelineStep, Criterion eligibilityCriteria) { MonitoringMessageEntity messageEntity; logger.info("ELIGIBILTY HANDLE START"); Logger.getLogger(this.getClass()) .log(Level.DEBUG, ("Eligibility Criteria:" + eligibilityCriteria.getName2())); // TODO: Message to Monitoring in the beginning messageEntity = new MonitoringMessageEntity(); if (guidelineStep != null) { messageEntity.setStepName(guidelineStep.getName2()); } else { messageEntity.setStepName(eligibilityCriteria.getName2()); } messageEntity.setType("Eligibility Criteria"); messageEntity.setMonitoringInfo("Starting eligibility check."); // First get the needed getDataAction array from the Criterion. Collection getDataActions = eligibilityCriteria.getGet_Data_Items(); // Create an instance of the GetDataActionHandler. GetDataActionHandler getDataActionHandler = new GetDataActionHandler(); // For each getDataAction, call the handler. for (Iterator i = getDataActions.iterator(); i.hasNext(); ) { getDataActionHandler.handle(guidelineAgent, guidelineStep, (Get_Data_Action) i.next()); } // Get let expressions and execute them. Collection letExpressions = eligibilityCriteria.getLet_expressions(); // For each letExpression, call the letExpressionHandler. LetExpressionHandler letExpressionHandler = new LetExpressionHandler(); for (Iterator i = letExpressions.iterator(); i.hasNext(); ) { letExpressionHandler.handle(guidelineAgent, guidelineStep, (Let_Expression) i.next()); } ExpressionHandler expressionHandler = new ExpressionHandler(); Boolean result = (Boolean) expressionHandler.handle( guidelineAgent, guidelineStep, eligibilityCriteria.getSpecification(), guidelineAgent.getGuidelineURI()); Logger.getLogger(this.getClass()) .log(Level.DEBUG, ("The result of the eligibility criteria is: " + result)); // TODO: // A monitoring message has to be sent now. messageEntity.setMonitoringInfo("Finishing eligibility check. The result is: " + result); // TODO: // Result needs to returned. But, which result? ExpressionHandler's??? // How is Eligibility Criteria going to return its outcome? Either it will get it from // expression handler and pass it on to GuidelineHandler or a better to store it in the // global variable pool of the GuidelineAgent and check it after calling // EligibilityCriteriaHandler. logger.info("ELIGIBILTY HANDLE END"); return result; }