Exemplo n.º 1
0
  /**
   * Loadengine.
   *
   * @param amalString the amal string
   */
  public final void loadengine(final String amalString) {

    this.setProject(engine.createProjectFromPRJ());
    this.setCb((DefaultCaseBase) project.getCaseBases().get(this.getEngine().getCasebase()));
    this.setMyConcept(project.getConceptByID(engine.getConceptName()));

    List<AmalgamationFct> amalList = this.getMyConcept().getAvailableAmalgamFcts();
    for (AmalgamationFct amalFct : amalList) {

      if (amalFct.getName().contentEquals(amalString)) {

        this.setAmalgam(amalFct);
      }
    }
    this.getMyConcept().setActiveAmalgamFct(amalgam);
  }
Exemplo n.º 2
0
  /**
   * Retrieve.
   *
   * @param querySet the query set
   * @param numberOfCases the numberOfCases
   * @return the array list
   */
  public final ArrayList<AttributeSet> retrieve(
      final AttributeSet querySet, final Integer numberOfCases) {

    int localNumberOfCases = numberOfCases;

    // result data
    ArrayList<AttributeSet> resultData = new ArrayList<AttributeSet>();

    // create a new retrieval
    Retrieval ret = new Retrieval(this.getMyConcept(), this.getCb());
    // specify the retrieval method
    ret.setRetrievalMethod(RetrievalMethod.RETRIEVE_SORTED);
    // create a query instance
    Instance query = ret.getQueryInstance();

    // DEFINE QUERY
    for (Attribute attr : querySet) {

      if (attr.getType().contentEquals("String")) {

        StringDesc stringDesc = (StringDesc) myConcept.getAllAttributeDescs().get(attr.getName());
        try {
          query.addAttribute(stringDesc, stringDesc.getAttribute(attr.getValue()));
        } catch (ParseException e) {
          System.out.println("could not parse integer");
          e.printStackTrace();
        }
      }

      if (attr.getType().contentEquals("Integer")) {

        IntegerDesc intDesc = (IntegerDesc) myConcept.getAllAttributeDescs().get(attr.getName());
        try {
          query.addAttribute(intDesc, intDesc.getAttribute(attr.getValue()));
        } catch (ParseException e) {
          System.out.println("could not parse integer");
          e.printStackTrace();
        }
      }

      if (attr.getType().contentEquals("Symbol")) {

        System.out.println("Sym" + attr);

        SymbolDesc symDesc = (SymbolDesc) myConcept.getAllAttributeDescs().get(attr.getName());
        query.addAttribute(symDesc, symDesc.getAttribute(attr.getValue()));
      }
    }

    // perform retrieval
    ret.start();
    // get the retrieval result
    List<Pair<Instance, Similarity>> result = ret.getResult();
    // get the case name

    if (result.size() > 0) {

      ArrayList<Hashtable<String, String>> entityList = new ArrayList<Hashtable<String, String>>();

      // if more case results are requested than we have in our case base
      // at all:
      if (localNumberOfCases >= cb.getCases().size()) {
        localNumberOfCases = cb.getCases().size();
      }

      for (int i = 0; i < localNumberOfCases; i++) {

        // clone attribute set
        Object cloneObject = DeepCopy.copy(querySet);
        AttributeSet resultSet = (AttributeSet) cloneObject;

        entityList.add(
            getAttributes(
                result.get(i), project.getConceptByID(this.getEngine().getConceptName())));

        String casename = result.get(i).getFirst().getName();
        Double similarity = round(result.get(i).getSecond().getValue(), 2);

        resultSet.get("Similarity").setValue(similarity.toString());
        resultSet.get("Case").setValue(casename);

        Iterator<Map.Entry<String, String>> resultIterator =
            entityList.get(i).entrySet().iterator();
        while (resultIterator.hasNext()) {

          Map.Entry<String, String> entry = resultIterator.next();

          Attribute attr = resultSet.get(entry.getKey());

          if (attr != null) {

            attr.setValue(entry.getValue());
          }
        }

        resultData.add(resultSet);
      }

    } else {
      System.out.println("Retrieval Result is empty");
    }

    return resultData;
  }