Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.0 kB
2
Indexable
Never
@POST
    @Path("movieReview/{movieId}")
    @Produces(MediaType.TEXT_PLAIN)
    public Response reviewMovie(@PathParam("movieId") String movieId, String content) {
        if (content.length() == 0) return Response.ok("Write a review!").build();
          if (moviesMap.containsKey(movieId)) {
            int score = 0;
            for(String word: content.split(" ")){
                System.out.println(word);
                if(wordsPositive.contains(word)) score++;
                if(wordsNegative.contains(word)) score--;
            }

            if(score > 0){
                moviesMap.get(movieId).recordPositiveSentimentReview();
                return Response.ok("POSITIVE").build();
            }

            if(score < 0){
                moviesMap.get(movieId).recordNegativeSentimentReview();
                return Response.ok("NEGATIVE").build();
            }

            return Response.ok("NEUTRAL").build();
           } 
          return Response.ok("Movie does NOT exist!").build(); 
    }