CSC/ECE 517 Spring 2021 - E2112. Integrate Suggestion Detection Algorithm: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(41 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Introduction==
==Introduction==
=== Team ===
=== Team ===
Dr. Gehringer (mentor)
Dr. Gehringer (mentor),
John Bumgardner (mentor)
* Harsh Kachhadia (hmkachha)
* Harsh Kachhadia (hmkachha)
* Parimal Mehta (pmehta3)
* Parimal Mehta (pmehta3)
Line 7: Line 8:
* Jordan Farthing (mjfarthi)
* Jordan Farthing (mjfarthi)


==Project plan==
==Project Background==
===Problem statement===
 
Peer-review systems like Expertiza utilize a lot of students’ input to determine each other’s performance. At the same time, we hope students learn from the reviews they receive to improve their own performance. In order to make this happen, we would like to have everyone give quality reviews instead of generic ones. Currently we have a few classifiers that can detect useful features of review comments, such as whether they contain suggestions. The suggestion-detection algorithm has been coded as a web service, and other detection algorithms, such as problem detection and sentiment analysis, also exist as newer web services..but they need to be integrated properly using API calls in expertiza code.
Peer-review systems like Expertiza utilize a lot of students’ input to determine each other’s performance. At the same time, we hope students learn from the reviews they receive to improve their own performance. In order to make this happen, we would like to have everyone give quality reviews instead of generic ones. Currently we have a few classifiers that can detect useful features of review comments, such as whether they contain suggestions. The suggestion-detection algorithm has been coded as a web service, and other detection algorithms, such as problem detection and sentiment analysis, also exist as newer web services..but they need to be integrated properly using API calls in expertiza code.


=== Implementation Overview ===
Initially, we had planned to work on the work already done by the previous students [https://github.com/expertiza/expertiza/pull/1427 Spring 2019 pull request]. But later on we faced many issues such as: 1) The API call links were outdated 2) The new link that we found were incompatible with the previous work 3) The planned task of adding new API calls as per Carl Colglaizer's Framework turned out to be irrelevant or not required for this project, so we dropped it. 
So we decided to start with integrating these API Calls from scratch.
'''Features we added in this project'''
* Setting up a config file 'review_metric.yml' where instructor can select what review metric to display for the current assignments
* Based on the selection made by professor, API calls (sentiment, problem, sugegstion) are made and a colorful table is displayed below the review form for student to review
* The total time taken for making these API calls will be displayed below the table.
'''Files that are modified or added in this project'''
* review_metrics.yml
* response.html.erb
* _response_analysis.html.erb
* response_controller.rb
* load_config.rb
* response_controller_spec.rb
'''Design Pattern'''
In order to achieve the primary tasks of integrating the API along with making the application more extensible, the team implemented a more extensive application of the '''Facade''' design pattern to decouple the details of the calling the APIs from the caller method (here - makeArequest method). This design pattern helped us achieve the decoupling and abstraction of implementation code base (makeARequest Function) of API call from the calling function (getReviewFeedback function). Later, refactoring of _response_analysis.html.erb partial further decoupled the implementation. Thus, in a nutshell, application of facade pattern along with some refactoring lead to a decoupled implementation of integration of all 3 API calls.
=== UI Screenshots===
* '''Frontend: '''This image shows the flow of control for a '''reviewer'''.
[[File:Steps_metric.png|800px]]
=== Control Flow ===
[[File:Review_metric.png]]
To inspect implementation in detail, check out the 'Javascript Functionality'
=== Javascript Functionality ===


===How it will work===
In the partial view file _response_analysis.html.erb file, we added new javascript functions to make, process and display output of API calls.


In order to make the API call, the _response_analysis.html.erb will be responsible for sending a JSON input to the web service. The input will contain the review comment submitted by the user in the following format:
* ''' review_metric.yml config file'''


Below is a sample input
In this file, the configuration for this functionality on which metrics to display in the table, can be set by the
  Sample Input:
instructor. Instructor can change which metric to display or not display in feedback by changing the value for that
  {
particular metric as 'true' or 'false'.
  "reviews":[{
 
  "text":"review text here",
[[File:Configfile.png|800px]]
  "metrics":["problem","suggestion","sentiment"]
 
  },{
 
  "text":"another review here",
* ''' response_controller.rb'''
  "metrics":["problem"]
 
  },{
In this file, we added a method 'fetch_review_metric' which fetches the configurations set by instructor in the review_metric.yml file by
  "text":"more text, maybe a large para or whatever you like",
the instructor and passes those fetched values to the response.html.erb view using the 'new' or 'edit' method.
  "metrics":["sentiment", "suggestion"]
 
  },{
[[File:Response_controller.png|800px]]
  ...
 
  }]
 
  }
* ''' response.html.rb'''
 
Here, we added a line that renders the partial _response_analysis.html.erb after the Save button to show the 'get review feedback' button and
display the metrics table. Also, we fetch the passed configuration data here.
 
[[File:response_html.png|800px]]


Once the request is send, we expect the output to be in the following format:


Sample Output: (as 'suggestion' and 'volume' as you might expect)
* ''' _response_analysis.html.erb - fetch_response_comments() function'''


{
This function fetches the comments written by the user in the review form and formats the collected comments as per the expectation of the API
  "sentiment_score": 0.9,
   calls.
  "sentiment_tone": "Positive",
  "suggestions": "absent",
  "suggestions_chances": 10.17,
  "text": "This is an excellent project. Keep up the great work",
   "total_volume": 10,
  "volume_without_stopwords": 6
}


[[File:Fetchcomments.png|800px]]


The output (which is a JSON) will be parsed and the suggestion metrics such as the tone and presence of suggestion will be extracted so the user will be able to view a summarized result of how well their review comments were. In addition, an average score will be computed based on the scores they received for each comment section, and the result will be presented in a colorful format to the user after they hit the submit button.


=== Flowchart to Describe Plan of Action and Flow of control ===
* ''' _response_analysis.html.erb - getReviewFeedback() function'''


[[FIle:Planfile.png]]
This function makes calls to respective APIs and get their output based on the configuration received from the review_metrics.yml file.


[[File:Makesapicalls.png|800px]]


===Previous work and our Plan of Action===


[https://github.com/expertiza/expertiza/pull/1427 Spring 2019 pull request]
* ''' _response_analysis.html.erb - makeARequest() function'''
* They had a functional suggestion detection API call that successfully communicated with the PeerLogic Server and retrieved the output, but as PeerLogic Server is no longer functioning, '''we need to make an API call to the new server(Peer Reviews NLP Server) and corresponding codes changes have to made.'''  


* They included their API call in response_controller.rb using JavaScript and Ruby, which '''needs to be Refactored into a single model file'''.
This is the driver function for making API call request to any url and data that is passed to it.


* Expertiza team also has '''a new web service for problem detection(in a review response) and sentiment analysis. That needs to be integrated by making corresponding API calls too.'''
[[File:Makearequest.png|800px]]


* They were able to display the cumulative output for the reviews on a new page. They displayed all of the information returned from the endpoint. '''But the display did not contain the problem detection API output nor did it record or display the time taken for to receive back the response''' from the Peer Reviews NLP Server.


* '''The time taken needs to be displayed on the UI.''' (UI from previous work is shown, which will be reworked upon.)
* ''' _response_analysis.html.erb - combine_api_output() function'''


* Since '''the new files they added are too clunky, badly named, files are too long (such as response_controller.rb), etc'''. The previous work '''needs to be refactored and reworked upon to have a smooth and lag-free implementation.
This function combines the output received from different API responses, combines them and formats the combined data to one that is suitable for  
'''
table generation.
* Since the code is added in the controller, which will be refactored as mentioned above points, and '''tests for the same needs to be written too.'''


[[File:Combineapioutput.png|800px]]


===Design Patterns===
In order to achieve the primary tasks of integrating the API along with making the application more extensible, the team proposes using a more extensive application of the '''Facade''' design pattern to decouple the details of the calling of Peer Reviews NLP API from the caller controller (here - response_controller). This design pattern will help us achieve the decoupling and abstraction of implementation code base of API call from the calling controller just like mailers in rails. Later, refactoring of response controller and metrics.rb model will further decouple the implementation. Thus, in a nutshell, application of facade pattern along with some refactoring will lead to a decoupled implementation of integration of Peer Reviews NLP API call.


* ''' _response_analysis.html.erb - generateTable() function'''


=== Sample UI Screenshots that will be worked upon ===
This code generates a colorful table dynamically on the UI so that the reviewer can get a visual feedback on the comments that he/she wrote.


* '''Frontend: '''This image shows the flow of control for a '''student reviewer'''.
[[File:Generatetable.png|800px]]
[[File:Steps_.png]]


* '''Frontend: '''The image shows the information regarding the reviews sent by the APIs to the '''student reviewer'''
[[File:Conf_page.png]]


=== API Details/Endpoints Appendix I ===
=== API Details/Endpoints Appendix I ===
Line 91: Line 120:
(We can't make the API links unclickable for this design doc, but clicking on them won't lead you anywhere. They are just endpoints and are mentioned here for reference only.)
(We can't make the API links unclickable for this design doc, but clicking on them won't lead you anywhere. They are just endpoints and are mentioned here for reference only.)


* https://peer-reviews-nlp.herokuapp.com/all for all metrics at once
* http://152.7.99.200:5000/problem for problem metrics only
* https://peer-reviews-nlp.herokuapp.com/volume for volume metrics only
* https://peerlogic.csc.ncsu.edu/sentiment/analyze_reviews_bulk for sentiment metrics only
* https://peer-reviews-nlp.herokuapp.com/sentiment for sentiment metrics only
* http://152.7.99.200:5000/suggestions for suggestions metrics only
* https://peer-reviews-nlp.herokuapp.com/suggestions for suggestions metrics only


===API Action===
In order to make the API call, the partial view "_response_analysis.html.erb" is rendered in "response.html.erb" view file which will be responsible for sending a JSON input to the web service. The input will contain the review comment written by the user and when the student hits the "Get review feedback button" the comments will be sent to these api calls in the following json format:
Below is a sample input
  '''Sample Input:'''
    {"reviews" : [
    {
          "id" : 1,
          "text" : "Comment 1."
    },
    {
          "id" : 2,       
          "text" : "Comment 2."
    }
                ]}
Once the request is sent, we expect the output to be in the following format:
'''Sample Output: (for sentiment analysis API call)'''
    {"sentiments": [
        {
            "id": 1,
            "neg": "0.00",
            "neu": "0.95",
            "pos": "0.05",
            "sentiment": "0.11",
            "text": "Comment 1."
        },
        {
            "id": 2,
            "neg": "0.00",
            "neu": "0.95",
            "pos": "0.05",
            "sentiment": "0.11",
            "text": "Comment 2."
        }
    ]}
'''Sample Output: (for problem detection API call)'''
    {"reviews": [
        {
            "id": 1,
            "problems": "Present",
            "text": "Comment 1."
        },
        {
            "id": 2,
            "problems": "Present",
            "text": "Comment 2."
        }
    ]}
'''Sample Output: (for suggestion detection API call)'''
    {"reviews": [
        {
            "id": 1,
            "suggestions": "Present",
            "text": "Comment 1."
        },
        {
            "id": 2,
            "suggestions": "Present",
            "text": "Comment 2."
        }
    ]}
These outputs (which is a JSON) will be parsed and the concerned metrics such as the sentiment, problem and suggestion will be extracted so the user will be able to view a summarized result of how well their review comments are. In addition, the result will be presented in a colorful tabular format to the user after they hit the "Get Review Feedback" button. Also, the total time taken for making these API calls will be displayed below the table.


==Testing plan==
==Testing plan==
We aims to perform extensive testing for this project in order to achieve better reliability for this implementation.
We aim to perform automatic and manual testing for this project in order to achieve better reliability for this implementation.


Projects files that will be changed(projected) and will be tested:
As for this project, very few lines of code have been written in ruby (fetch_review_metric method in response_controller.rb) we will be testing that method in response controller using rspec tests.


'''Rspec tests for the same have been written in response_controller_spec.rb'''


* _response_analysis.html.erb
[[File:Rspectests.png|800px]]
 
===View Tests===
* The functionality was written on the client side in javascript solely in _response_analysis.html.erb
* To test this view, any type of review must be accessible as a student.
* There is a button at the bottom of the review called 'Get Review Feedback'.
* When pressing button, API calls are issued and the metrics will show up within the table (a sample of which is displayed below).
* API calls are slow and will take time to process until the 'Loading...' text disappears.
* You can modify the comments and click the 'Get Review Feedback' button again to get new feedback, that too can be achieved without the need of saving the review, but still saving the review first is a better option to approach this.
* All the review feedback for the comments will be displayed in a colorful table.
 
 
=== Sample image of the table ===
 
[[File:Metric_table.png]]


=== Tests ===
==Important Links==
* The functionality was written client side in javascript solely in _response_analysis.html.erb
* To test this view, any type of review must be accessible as a student
* There is a button at the bottom of the review called Get Review Feedback.
* When pressing button, API calls are issued and the metrics will show up within the table.
* API calls are slow and will take time to process on click
* Save review will allow for a new metric calculation to occur
* All functionality associated with this table will be displayed


=== View Tests ===
* [https://github.com/expertiza/expertiza/pull/1952 Github Pull Request]
* [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Spring_2021_-_E2112._Integrate_Suggestion_Detection_Algorithm Expertiza wiki page link] (the link is mentioned here for records. It redirects to this same page.)
* [https://docs.google.com/document/d/1uzr5pybVKYr_K1Q8wSd4t-Id9nqTt3k1ePseDjY-RJg/edit#heading=h.fxfungdw1d5r Google Doc Project Description]
* [https://github.com/harshkachhadia/expertiza/tree/beta Github Repository Link for this expertiza fork]  (make sure you change branch to 'beta' branch if the page doesn't load by default to beta branch)
* [https://youtu.be/OYZvNVa3GZ8 Youtube Video Link]

Latest revision as of 19:33, 11 May 2021

Introduction

Team

Dr. Gehringer (mentor), John Bumgardner (mentor)

  • Harsh Kachhadia (hmkachha)
  • Parimal Mehta (pmehta3)
  • Jatin Chinchkar (jchinch)
  • Jordan Farthing (mjfarthi)

Project Background

Peer-review systems like Expertiza utilize a lot of students’ input to determine each other’s performance. At the same time, we hope students learn from the reviews they receive to improve their own performance. In order to make this happen, we would like to have everyone give quality reviews instead of generic ones. Currently we have a few classifiers that can detect useful features of review comments, such as whether they contain suggestions. The suggestion-detection algorithm has been coded as a web service, and other detection algorithms, such as problem detection and sentiment analysis, also exist as newer web services..but they need to be integrated properly using API calls in expertiza code.

Implementation Overview

Initially, we had planned to work on the work already done by the previous students Spring 2019 pull request. But later on we faced many issues such as: 1) The API call links were outdated 2) The new link that we found were incompatible with the previous work 3) The planned task of adding new API calls as per Carl Colglaizer's Framework turned out to be irrelevant or not required for this project, so we dropped it.

So we decided to start with integrating these API Calls from scratch.


Features we added in this project

  • Setting up a config file 'review_metric.yml' where instructor can select what review metric to display for the current assignments
  • Based on the selection made by professor, API calls (sentiment, problem, sugegstion) are made and a colorful table is displayed below the review form for student to review
  • The total time taken for making these API calls will be displayed below the table.

Files that are modified or added in this project

  • review_metrics.yml
  • response.html.erb
  • _response_analysis.html.erb
  • response_controller.rb
  • load_config.rb
  • response_controller_spec.rb

Design Pattern

In order to achieve the primary tasks of integrating the API along with making the application more extensible, the team implemented a more extensive application of the Facade design pattern to decouple the details of the calling the APIs from the caller method (here - makeArequest method). This design pattern helped us achieve the decoupling and abstraction of implementation code base (makeARequest Function) of API call from the calling function (getReviewFeedback function). Later, refactoring of _response_analysis.html.erb partial further decoupled the implementation. Thus, in a nutshell, application of facade pattern along with some refactoring lead to a decoupled implementation of integration of all 3 API calls.

UI Screenshots

  • Frontend: This image shows the flow of control for a reviewer.

Control Flow


To inspect implementation in detail, check out the 'Javascript Functionality'

Javascript Functionality

In the partial view file _response_analysis.html.erb file, we added new javascript functions to make, process and display output of API calls.

  • review_metric.yml config file
In this file, the configuration for this functionality on which metrics to display in the table, can be set by the
instructor. Instructor can change which metric to display or not display in feedback by changing the value for that
particular metric as 'true' or 'false'.


  • response_controller.rb
In this file, we added a method 'fetch_review_metric' which fetches the configurations set by instructor in the review_metric.yml file by 
the instructor and passes those fetched values to the response.html.erb view using the 'new' or 'edit' method.


  • response.html.rb
Here, we added a line that renders the partial _response_analysis.html.erb after the Save button to show the 'get review feedback' button and 
display the metrics table. Also, we fetch the passed configuration data here.


  • _response_analysis.html.erb - fetch_response_comments() function
This function fetches the comments written by the user in the review form and formats the collected comments as per the expectation of the API
 calls.


  • _response_analysis.html.erb - getReviewFeedback() function
This function makes calls to respective APIs and get their output based on the configuration received from the review_metrics.yml file.


  • _response_analysis.html.erb - makeARequest() function
This is the driver function for making API call request to any url and data that is passed to it.


  • _response_analysis.html.erb - combine_api_output() function
This function combines the output received from different API responses, combines them and formats the combined data to one that is suitable for 
table generation.


  • _response_analysis.html.erb - generateTable() function
This code generates a colorful table dynamically on the UI so that the reviewer can get a visual feedback on the comments that he/she wrote.


API Details/Endpoints Appendix I

Here are the various endpoints for the deployment of Suggestion Detection Algorithm.

(We can't make the API links unclickable for this design doc, but clicking on them won't lead you anywhere. They are just endpoints and are mentioned here for reference only.)

API Action

In order to make the API call, the partial view "_response_analysis.html.erb" is rendered in "response.html.erb" view file which will be responsible for sending a JSON input to the web service. The input will contain the review comment written by the user and when the student hits the "Get review feedback button" the comments will be sent to these api calls in the following json format:

Below is a sample input

 Sample Input:

   {"reviews" : [
   { 
         "id" : 1,
         "text" : "Comment 1."
   },
   {
         "id" : 2,        
         "text" : "Comment 2."
   } 
               ]}

Once the request is sent, we expect the output to be in the following format:

Sample Output: (for sentiment analysis API call)

   {"sentiments": [
       {
           "id": 1,
           "neg": "0.00",
           "neu": "0.95",
           "pos": "0.05",
           "sentiment": "0.11",
           "text": "Comment 1."
       },
       {
           "id": 2,
           "neg": "0.00",
           "neu": "0.95",
           "pos": "0.05",
           "sentiment": "0.11",
           "text": "Comment 2."
       }
   ]}

Sample Output: (for problem detection API call)

   {"reviews": [
       {
           "id": 1,
           "problems": "Present",
           "text": "Comment 1."
       },
       {
           "id": 2,
           "problems": "Present",
           "text": "Comment 2."
       }
   ]}

Sample Output: (for suggestion detection API call)

   {"reviews": [
       {
           "id": 1,
           "suggestions": "Present",
           "text": "Comment 1."
       },
       {
           "id": 2,
           "suggestions": "Present",
           "text": "Comment 2."
       }
   ]}

These outputs (which is a JSON) will be parsed and the concerned metrics such as the sentiment, problem and suggestion will be extracted so the user will be able to view a summarized result of how well their review comments are. In addition, the result will be presented in a colorful tabular format to the user after they hit the "Get Review Feedback" button. Also, the total time taken for making these API calls will be displayed below the table.

Testing plan

We aim to perform automatic and manual testing for this project in order to achieve better reliability for this implementation.

As for this project, very few lines of code have been written in ruby (fetch_review_metric method in response_controller.rb) we will be testing that method in response controller using rspec tests.

Rspec tests for the same have been written in response_controller_spec.rb

View Tests

  • The functionality was written on the client side in javascript solely in _response_analysis.html.erb
  • To test this view, any type of review must be accessible as a student.
  • There is a button at the bottom of the review called 'Get Review Feedback'.
  • When pressing button, API calls are issued and the metrics will show up within the table (a sample of which is displayed below).
  • API calls are slow and will take time to process until the 'Loading...' text disappears.
  • You can modify the comments and click the 'Get Review Feedback' button again to get new feedback, that too can be achieved without the need of saving the review, but still saving the review first is a better option to approach this.
  • All the review feedback for the comments will be displayed in a colorful table.


Sample image of the table

Important Links