Package org.corrib.s3b.recommendations

Examples of org.corrib.s3b.recommendations.Recommendation


       
        if(type.getResultsArray() != null) {       
          Set<Recommendation> tmp = new TreeSet<Recommendation>(type.getResultsArray());

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

          limitedResult = tmp;

          if(isOverall) {
            Set<Recommendation> tmp2 = new TreeSet<Recommendation>(type.getResultsArray());
            for(Recommendation r : tmp2) {
              boolean wasFound = false;
              for(Recommendation r2 : overallRecommendation) {
                if(r2.getRecommendedBook().equals(r.getRecommendedBook())) {
                  overallRecommendation.remove(r2);
                  r2.setAccuracy(r2.getAccuracy() + weight*r.getAccuracy());
                  overallRecommendation.add(r2);
                  wasFound = true;
                  break;
                }
              }
              if(!wasFound) {
                overallRecommendation.add(new Recommendation(r.getRecommendedBook(), 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


        //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 = recItemsTable.length;
       
      //we get the two dimensional table of results - in each row there are two columns: one with resource URI, second with recommendation item
      Value[][] items = RecommendationUtils.performTwodimensionalTableQuery(Repository.JEROMEDL_REPOSITORY.getLocalRepository(),
          QueryLanguage.SERQL, RecommendationQueries.GENERAL_BOOK_ITEM_TABLE_QUERY.bookItemTableQuery(this.name.getUri(), allBooks.toArray()));

      Map<URI, HashSet<Value>> foundBooksItems = new HashMap<URI, HashSet<Value>>();
     
      for(int i=0; i<items.length; i++) {
        if(foundBooksItems.containsKey(items[i][0])) {
          HashSet<Value> tmp = foundBooksItems.remove(items[i][0]);
          tmp.add(items[i][1]);
          foundBooksItems.put((URI)items[i][0], tmp);
        } else {
          HashSet<Value> tmp = new HashSet<Value>();
          tmp.add(items[i][1]);
          foundBooksItems.put((URI)items[i][0], tmp);
        }
      }
     
      for(URI aBook : foundBooksItems.keySet()) {
        HashSet<Value> 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(recItemsTable, itemsSet.toArray());

        //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));
      }
    }
   
   
    //-----TEST------
View Full Code Here

        String[] words = RecommendationUtils.removeIrrelevantWords(items[i][1].toString().split("\\W?\\s"));       
        int n = words.length;
       
        //then we simply count the inversion of n
        float accuracy = (float)1/(float)n;
        resultBooks.add(new Recommendation((URI)items[i][0], accuracy));       
      }
    }
    //more difficult situation...
    else {
      int s = titleTable.length;
     
      for(int i=0; i<items.length; i++) {
       
        if(((URI)items[i][0]).equals(book)) //omitting the book we are looking recommendations for
          continue;
       
        //first we check how many words each found book has in the title
        String[] words = RecommendationUtils.removeIrrelevantWords(items[i][1].toString().split("\\W?\\s"));       
        int n = words.length;
       
        //then we compare both keywords sets and find the common part
        int m = RecommendationUtils.commonStringPart(titleTable, words);
       
        //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((URI)items[i][0], accuracy));   
      }
    }
   
    //-----TEST------
//    System.out.println();
View Full Code Here

        int n = SesameWrapper.performVectorQuery(Repository.JEROMEDL_REPOSITORY.getLocalRepository(),
            QueryLanguage.SERQL, RecommendationQueries.GENERAL_ITEM_QUERY.toString(aBook, RecommendationItemType.KEYWORD)).length;
       
        //then we simple count the inversion of n
        float accuracy = (float)1/(float)n;
        resultBooks.add(new Recommendation((URI)aBook, accuracy));       
      }     
    }
    //more difficult situation...
    else {
      int s = aValues.length;
      for(Value aBook : allBooks) {
       
        Value[] keywords = SesameWrapper.performVectorQuery(Repository.JEROMEDL_REPOSITORY.getLocalRepository(),
            QueryLanguage.SERQL, RecommendationQueries.GENERAL_ITEM_QUERY.toString(aBook, RecommendationItemType.KEYWORD));
       
        //first we check how many keywords each book has
        int n = keywords.length;
       
        //then we compare both keywords sets and find the common part
        int m = RecommendationUtils.commonPart(aValues, keywords);
       
        //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((URI)aBook, accuracy));
      }
    }
   
    //-----TEST------
    /*System.out.println();
 
View Full Code Here

        int n = SesameWrapper.performVectorQuery(Repository.JEROMEDL_REPOSITORY.getLocalRepository(),
            QueryLanguage.SERQL, RecommendationQueries.GENERAL_ITEM_QUERY.toString(aBook, RecommendationItemType.ANNOTATION)).length;
       
        //then we simple count the inversion of n
        float accuracy = (float)1/(float)n;
        resultBooks.add(new Recommendation((URI)aBook, accuracy));       
      }     
    }
    //more difficult situation...
    else {
      int s = aValues.length;
      for(Value aBook : allBooks) {
       
        Value[] annotations = SesameWrapper.performVectorQuery(Repository.JEROMEDL_REPOSITORY.getLocalRepository(),
            QueryLanguage.SERQL, RecommendationQueries.GENERAL_ITEM_QUERY.toString(aBook, RecommendationItemType.ANNOTATION));
       
        //first we check how many annotations each book has
        int n = annotations.length;
       
        //then we compare both annotations sets and find the common part
        int m = RecommendationUtils.commonPart(aValues, annotations);
       
        //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((URI)aBook, accuracy));
      }
    }
   
    //-----TEST------
    System.out.println();
View Full Code Here

        int n = SesameWrapper.performVectorQuery(Repository.JEROMEDL_REPOSITORY.getLocalRepository(),
            QueryLanguage.SERQL, RecommendationQueries.GENERAL_ITEM_QUERY.toString(aBook, RecommendationItemType.AUTHOR)).length;
       
        //then we simple count the inversion of n
        float accuracy = (float)1/(float)n;
        resultBooks.add(new Recommendation((URI)aBook, accuracy));       
      }     
    }
    //more difficult situation...
    else {
      int s = aValues.length;
      for(Value aBook : allBooks) {
       
        Value[] authors = SesameWrapper.performVectorQuery(Repository.JEROMEDL_REPOSITORY.getLocalRepository(),
            QueryLanguage.SERQL, RecommendationQueries.GENERAL_ITEM_QUERY.toString(aBook, RecommendationItemType.AUTHOR));
       
        //first we check how many authors each book has
        int n = authors.length;
       
        //then we compare both authors sets and find the common part
        int m = RecommendationUtils.commonPart(aValues, authors);
       
        //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((URI)aBook, accuracy));
      }
    }
   
    //-----TEST------
    System.out.println();
View Full Code Here

TOP

Related Classes of org.corrib.s3b.recommendations.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.