Examples of Recommendation


Examples of com.springone.myrestaurants.domain.Recommendation

      List<Recommendation> recommendations = new ArrayList<Recommendation>();
      for (Recommendation r : updatedUser.getRecommendations()) {
        recommendations.add(r);
      }
      Assert.assertEquals("user should now have correct number of recommendations", 1, recommendations.size());
      Recommendation r = recommendations.get(0);
      Assert.assertEquals("recommendation should have correct rating", 3, r.getStars());
      Assert.assertEquals("recommendation should have correct comment", "Pretty Good", r.getComment());
      Assert.assertEquals("recommendation should have correct restaurant id", new Long(22), r.getRestaurant().getId());
      Assert.assertEquals("recommendation should have correct restaurant name", "Subway Sandwiches & Salads", r.getRestaurant().getName());
    }
View Full Code Here

Examples of org.brickred.socialauth.Recommendation

        LOG.debug("Recommendations count "
            + recommendations.getLength());
        recommendationsArr = new Recommendation[recommendations
            .getLength()];
        for (int i = 0; i < recommendations.getLength(); i++) {
          Recommendation recommendationObj = new Recommendation();
          Element recommendationEl = (Element) recommendations
              .item(i);
          String rid = XMLParseUtil.getElementData(recommendationEl,
              "id");
          if (rid != null) {
            recommendationObj.setRecommendationId(rid);
          }
          String text = XMLParseUtil.getElementData(recommendationEl,
              "recommendation-text");
          if (text != null) {
            recommendationObj.setRecommendationText(text);
          }

          String code = XMLParseUtil.getElementData(recommendationEl,
              "code");
          if (code != null) {
            recommendationObj.setRecommendationType(code);
          }

          NodeList recommenderNodes = recommendationEl
              .getElementsByTagName("recommender");
          if (recommenderNodes != null
              && recommenderNodes.getLength() > 0) {
            Element recommenderEl = (Element) recommenderNodes
                .item(0);
            String recommenderId = XMLParseUtil.getElementData(
                recommenderEl, "id");
            if (recommenderId != null) {
              recommendationObj.setRecommenderId(recommenderId);
            }
            String fname = XMLParseUtil.getElementData(
                recommenderEl, "first-name");
            if (fname != null) {
              recommendationObj.setRecommenderFirstName(fname);
            }
            String lname = XMLParseUtil.getElementData(
                recommenderEl, "last-name");
            if (lname != null) {
              recommendationObj.setRecommenderLastName(lname);
            }

          }
          recommendationsArr[i] = recommendationObj;
        }
View Full Code Here

Examples of org.brickred.socialauth.Recommendation

        LOG.debug("Recommendations count "
            + recommendations.getLength());
        recommendationsArr = new Recommendation[recommendations
            .getLength()];
        for (int i = 0; i < recommendations.getLength(); i++) {
          Recommendation recommendationObj = new Recommendation();
          Element recommendationEl = (Element) recommendations
              .item(i);
          String rid = XMLParseUtil.getElementData(recommendationEl,
              "id");
          if (rid != null) {
            recommendationObj.setRecommendationId(rid);
          }
          String text = XMLParseUtil.getElementData(recommendationEl,
              "recommendation-text");
          if (text != null) {
            recommendationObj.setRecommendationText(text);
          }

          String code = XMLParseUtil.getElementData(recommendationEl,
              "code");
          if (code != null) {
            recommendationObj.setRecommendationType(code);
          }

          NodeList recommenderNodes = recommendationEl
              .getElementsByTagName("recommender");
          if (recommenderNodes != null
              && recommenderNodes.getLength() > 0) {
            Element recommenderEl = (Element) recommenderNodes
                .item(0);
            String recommenderId = XMLParseUtil.getElementData(
                recommenderEl, "id");
            if (recommenderId != null) {
              recommendationObj.setRecommenderId(recommenderId);
            }
            String fname = XMLParseUtil.getElementData(
                recommenderEl, "first-name");
            if (fname != null) {
              recommendationObj.setRecommenderFirstName(fname);
            }
            String lname = XMLParseUtil.getElementData(
                recommenderEl, "last-name");
            if (lname != null) {
              recommendationObj.setRecommenderLastName(lname);
            }

          }
          recommendationsArr[i] = recommendationObj;
        }
View Full Code Here

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

Examples of org.corrib.s3b.recommendations.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 = 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

Examples of org.corrib.s3b.recommendations.Recommendation

        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

Examples of org.corrib.s3b.recommendations.Recommendation

        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

Examples of org.corrib.s3b.recommendations.Recommendation

        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

Examples of org.corrib.s3b.recommendations.Recommendation

        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

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
TOP
Copyright © 2018 www.massapi.com. 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.