Package org.corrib.s3b.recommendations.impl

Examples of org.corrib.s3b.recommendations.impl.Recommendation


        //first we check how many recommendation items each book has
        int n = foundBooksItems.get(aBook).size();
       
        //then we simple count the inversion of n
        float accuracy = (float)1/(float)n;
        resultBooks.add(new Recommendation(aBook, accuracy));       
      }     
    }
    //more difficult situation...
    else {
      int s = asvalue.length;
       
      //we get the two dimensional table of results - in each row there are two columns: one with resource URI, second with recommendation item
      Node[][] items = this.query.listRankedItems(allResults.toArray(new Node[0]));

      Map<Node, HashSet<String>> foundBooksItems = new HashMap<Node, HashSet<String>>();
     
      for(int i=0; i<items.length; i++) {
        HashSet<String> tmp;
        if(foundBooksItems.containsKey(items[i][0])) {
          tmp = foundBooksItems.remove(items[i][0]);
        } else {
          tmp = new HashSet<String>();
        }
        if(items[i][1] instanceof Literal)
          tmp.add(((Literal)items[i][1]).getValue());
        else
          tmp.add(items[i][1].toString());
        foundBooksItems.put(items[i][0], tmp);
      }
     
      for(Node aBook : foundBooksItems.keySet()) {
        HashSet<String> itemsSet = foundBooksItems.get(aBook);
        //first we check how many recommendation items each book has
        int n = itemsSet.size();

        //then we compare both recommendation items sets and find the common part
        int m = RecommendationUtils.commonPart(asvalue, this.postprocess(itemsSet.toArray(new String[0])));

        //now we calculate the accuracy measure according to accuracy function (see documentation)
        float accuracy = 1 - (1 - (float)m/(float)s) - ((float)m/(float)s * (float)Math.pow(((float)(n-m)/(float)n), 2.0));
        resultBooks.add(new Recommendation(aBook, accuracy));
      }
    }
   
   
    this.setResultsArray(resultBooks);
View Full Code Here


       
        if(resultsArray != null) {       
          Set<Recommendation> tmp = new TreeSet<Recommendation>(resultsArray);

          while(tmp.size()> limit) {
            Recommendation toRemove = ((TreeSet<Recommendation>)tmp).first();
            tmp.remove(toRemove);
          }

          limitedResult = tmp;

          if(isOverall) {
            Set<Recommendation> tmp2 = new TreeSet<Recommendation>(resultsArray);
            for(Recommendation r : tmp2) {
              boolean wasFound = false;
              for(Recommendation r2 : overallRecommendation) {
                if(r2.getRecommendedItem().equals(r.getRecommendedItem())) {
                  overallRecommendation.remove(r2);
                  r2.setAccuracy(r2.getAccuracy() + weight*r.getAccuracy());
                  overallRecommendation.add(r2);
                  wasFound = true;
                  break;
                }
              }
              if(!wasFound) {
                overallRecommendation.add(new Recommendation(r.getRecommendedItem(), r.getAccuracy()*weight));
              }   
            }
          }
         
          if(limitedResult.size() > 0)
            prepareResult(limitedResult);
        }
        //-----------TEST--------------------
        for(Recommendation r : limitedResult)
          System.out.println(r);
        //!-----------TEST-------------------
       
        wholeResult[i] = type;
        wholeResult[i].setResultsArray((TreeSet<Recommendation>)limitedResult);
      } else {
        overallLimit = urpTable[i].getLimit();
      }     
    }
   
    if(isOverall && urpTable.length>1) {
     
      while(overallRecommendation.size() > overallLimit) {
        Recommendation toRemove = ((TreeSet<Recommendation>)overallRecommendation).first();
        overallRecommendation.remove(toRemove);
      }
     
      if(overallRecommendation.size() > 0){
        Recommendation highest = ((TreeSet<Recommendation>)overallRecommendation).last();
        float divider = highest.getAccuracy();
     
        for(Recommendation r : overallRecommendation)
          r.setAccuracy(r.getAccuracy() / divider);
      }
     
View Full Code Here

TOP

Related Classes of org.corrib.s3b.recommendations.impl.Recommendation

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.