<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Skhare</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Skhare"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Skhare"/>
	<updated>2026-04-16T19:25:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=82240</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=82240"/>
		<updated>2013-10-31T04:13:54Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
In word-order graph vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Re-factoring =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Re-factoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
&lt;br /&gt;
* '''Miscellaneous'''&lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
 end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* After complete re-factoring, the grade for the class DegreeOfRelevance changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/ Ruby_on_Rails] and [http://en.wikipedia.org/wiki/Test_automation Automated Testing] go hand in hand. Rails ships in with a built-in test framework and if we want, we can replace the existing with Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails either don't test their projects at all, or at best only add a few test specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&amp;lt;ref&amp;gt;http://www.agiledata.org/essays/tdd.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; that adding extra work seems unimportant. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features demanded by clients or bosses. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/ Test-driven_development] is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring it to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*[http://en.wikipedia.org/wiki/ Behavior-driven_development] combines the general techniques and principles of TDD to provide software developers and business analysts to collaborate on productive software development.&lt;br /&gt;
&lt;br /&gt;
We have used the BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png|&amp;lt;ref&amp;gt;http://agilefeedback.blogspot.com/2012/07/tdd-do-you-speak.html&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used [http://en.wikipedia.org/wiki/Cucumber_(software) Cucumber] &amp;lt;ref&amp;gt;http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-testing-web-apps-with-capybara-and-cucumber&amp;lt;/ref&amp;gt;for testing.&lt;br /&gt;
The Given, When, Then syntax used by Cucumber is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when it comes across that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks &amp;lt;ref&amp;gt;https://github.com/cucumber/cucumber/wiki/Hooks &amp;lt;/ref&amp;gt;which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
[[File:cucumber.png|frame|none]]&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
The original Expertiza code had lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
Even simple steps like submitting an assignment and performing reviews took a lot of debugging and bug fixing in various other files not related to our class DegreeOfRelevance.&lt;br /&gt;
Lot of routes were missing from the routes.rb file, which we fixed. Here is one of the sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There were many errors related to Aspell gem, which is used as a spell-checker for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:aspell-error.png|frame|none|Aspell error]]&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also, we tested the functionality of the class using Cucumber, behavior driven approach.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=82239</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=82239"/>
		<updated>2013-10-31T04:13:23Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
In word-order graph vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Re-factoring =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Re-factoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
&lt;br /&gt;
* '''Miscellaneous'''&lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
 end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* After complete re-factoring, the grade for the class DegreeOfRelevance changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/ Ruby_on_Rails] and [http://en.wikipedia.org/wiki/Test_automation Automated Testing] go hand in hand. Rails ships in with a built-in test framework and if we want, we can replace the existing with Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails either don't test their projects at all, or at best only add a few test specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&amp;lt;ref&amp;gt;http://www.agiledata.org/essays/tdd.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; that adding extra work seems unimportant. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features demanded by clients or bosses. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/ Test-driven_development] is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring it to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*[http://en.wikipedia.org/wiki/ Behavior-driven_development] combines the general techniques and principles of TDD to provide software developers and business analysts to collaborate on productive software development.&lt;br /&gt;
&lt;br /&gt;
We have used the BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png|&amp;lt;ref&amp;gt;http://agilefeedback.blogspot.com/2012/07/tdd-do-you-speak.html&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used [http://en.wikipedia.org/wiki/Cucumber_(software) Cucumber] &amp;lt;ref&amp;gt;http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-testing-web-apps-with-capybara-and-cucumber&amp;lt;/ref&amp;gt;for testing.&lt;br /&gt;
The Given, When, Then syntax used by Cucumber is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when it comes across that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks &amp;lt;ref&amp;gt;https://github.com/cucumber/cucumber/wiki/Hooks &amp;lt;/ref&amp;gt;which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
[[File:cucumber.png|frame|none]]&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
The original Expertiza code had lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
Even simple steps like submitting an assignment and performing reviews took a lot of debugging and bug fixing in various other files not related to our class DegreeOfRelevance.&lt;br /&gt;
Lot of routes were missing from the routes.rb file, which we fixed. Here is one of the sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
There were many errors related to Aspell gem, which is used as a spell-checker for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
[[File:aspell-error.png|frame|none|Aspell error]]&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also, we tested the functionality of the class using Cucumber, behavior driven approach.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Aspell-error.png&amp;diff=82235</id>
		<title>File:Aspell-error.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Aspell-error.png&amp;diff=82235"/>
		<updated>2013-10-31T04:11:32Z</updated>

		<summary type="html">&lt;p&gt;Skhare: uploaded a new version of &amp;amp;quot;File:Aspell-error.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Aspell-error.png&amp;diff=82234</id>
		<title>File:Aspell-error.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Aspell-error.png&amp;diff=82234"/>
		<updated>2013-10-31T04:11:32Z</updated>

		<summary type="html">&lt;p&gt;Skhare: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=82222</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=82222"/>
		<updated>2013-10-31T03:56:28Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
In word-order graph vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Re-factoring =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Re-factoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
&lt;br /&gt;
* '''Miscellaneous'''&lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
 end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* After complete re-factoring, the grade for the class DegreeOfRelevance changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/ Ruby_on_Rails] and [http://en.wikipedia.org/wiki/Test_automation Automated Testing] go hand in hand. Rails ships in with a built-in test framework and if we want, we can replace the existing with Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails either don't test their projects at all, or at best only add a few test specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; that adding extra work seems unimportant. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features demanded by clients or bosses. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/ Test-driven_development] is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring it to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*[http://en.wikipedia.org/wiki/ Behavior-driven_development] combines the general techniques and principles of TDD to provide software developers and business analysts to collaborate on productive software development.&lt;br /&gt;
&lt;br /&gt;
We have used the BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png|&amp;lt;ref&amp;gt;http://agilefeedback.blogspot.com/2012/07/tdd-do-you-speak.html&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used [http://en.wikipedia.org/wiki/Cucumber_(software) Cucumber] for testing.&lt;br /&gt;
The Given, When, Then syntax used by Cucumber is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when it comes across that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
[[File:cucumber.png|frame|none]]&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original Expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. Lot of routes were missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also, we tested the functionality of the class using Cucumber, behavior driven approach.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
* [http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-testing-web-apps-with-capybara-and-cucumber Testing with Cucumber ]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/cucumber/cucumber/wiki/Hooks Cucumber Hooks]&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81746</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81746"/>
		<updated>2013-10-31T00:55:24Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Re-factoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Re-factoring =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Re-factoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
&lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
 end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* After complete re-factoring, the grade for the class DegreeOfRelevance changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81741</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81741"/>
		<updated>2013-10-31T00:53:48Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Re-factoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Re-factoring =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Re-factoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
 end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* After complete re-factoring, the grade for the class DegreeOfRelevance changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81738</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81738"/>
		<updated>2013-10-31T00:52:07Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Re-factoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Re-factoring =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Re-factoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
 end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81734</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81734"/>
		<updated>2013-10-31T00:50:15Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Re-factoring =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Re-factoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81732</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81732"/>
		<updated>2013-10-31T00:49:17Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
=== Types of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81726</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81726"/>
		<updated>2013-10-31T00:44:57Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
After complete refactoring, we could find that the grade according to Code Climate for the main class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphEdges:&lt;br /&gt;
This class compares edges from across two graphs. Related methods compare_edges_non_syntax_diff and compare_edges_syntax_diff are grouped together in this class. This ensures that this class is just responsible for making comparison between graph edges and return the appropriate metric to the main class DegreeOfRelevance.&lt;br /&gt;
&lt;br /&gt;
* Class  CompareGraphVertices:&lt;br /&gt;
This class is responsible for comparing every vertex of submission graph with every vertex of review graph. This class contains only one method compare_vertices. Its sole responsibility is comparing vertices and calculating the appropriate metrics required by the main class(DegreeOfRelevance).&lt;br /&gt;
&lt;br /&gt;
* Class CompareGraphSVOEdges:&lt;br /&gt;
This class is responsible for making comparison between edges of type SUBJECT-VERB-OBJECT.Related methods - compare_SVO_edges and compare_SVO_diff_syntax are grouped together in this class.&lt;br /&gt;
&lt;br /&gt;
The whole purpose of creating such a design is to make clear separation of logic in different classes. Although each of these classes contain helper methods to be used by the main method(get_relevance) to calculate relevance, yet this kind of design improves maintainability and readability of code for any programmer who is new to this code. The figure below illustrates the concept used in the design.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81703</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81703"/>
		<updated>2013-10-31T00:29:58Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
After complete refactoring, we could find that the grade according to Code Climate for the main class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. We have grouped together similar functionality in one class. Following is a brief description of the classes.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81610</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81610"/>
		<updated>2013-10-30T23:42:37Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** CompareGraphEdges&lt;br /&gt;
** CompareGraphSVOEdges&lt;br /&gt;
** CompareGraphVertices&lt;br /&gt;
** DegreeOfRelevance&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
After complete refactoring, we could find that the grade according to Code Climate for the main class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class DegreeOfRelevance calculates the scaled relevance using the formula described above. It calculates the relevance based on comparisons done between submission and review graphs. As described above, the following types of comparisons are made between the graphs and various metrics are generated which are used to find the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81598</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81598"/>
		<updated>2013-10-30T23:37:30Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
After complete refactoring, we could find that the grade according to Code Climate for the main class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
We were successful in refactoring the given class of Degree of Relevance by using the ideas of Template design pattern and adapting its implementation according to our needs.&lt;br /&gt;
According to Code-Climate the grade for the previous class was 'F', while after refactoring the class the grade is 'C'.&lt;br /&gt;
Also we successfully tested the functionality using Cucumber.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;editttttt later&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81596</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81596"/>
		<updated>2013-10-30T23:36:12Z</updated>

		<summary type="html">&lt;p&gt;Skhare: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
Reviews are text-based feedback provided by a reviewer to the author of a submission. Reviews are used not only in education to assess student work, but also in e-commerce applications, to assess the quality of products on sites like Amazon, e-bay etc. Since reviews play a crucial role in providing feedback to people who make assessment decisions (e.g. deciding a student’s grade, choosing to purchase a product) it is important to find out how relevant reviews are to a submission &amp;lt;ref&amp;gt;http://repository.lib.ncsu.edu/ir/handle/1840.16/8813&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The class ''DegreeOfRelevance'' in Expertiza is used to calculate how relevant one piece of text is to another. It calculates relevance between the submitted work and reviews(or meta reviews) for an assignment. It is important to do this evaluation to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact students' grade.&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' presently contains long and complex methods and a lot of duplicated code. It has been assigned grade &amp;quot;F&amp;quot; by [https://codeclimate.com/ Code Climate], on metrics such as code complexity, duplication, lines of code per method etc. Since this file is important for the research on Expertiza, it should be re-factored to reduce complexity and duplication issues and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly.&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. &lt;br /&gt;
&lt;br /&gt;
[[File:ModifiedEq.png|frame|none|Formula used in Expertiza‎]]&lt;br /&gt;
&lt;br /&gt;
For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from [http://en.wikipedia.org/wiki/Template_method_pattern Template design pattern] to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses, allowing us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to segregate the functionality, making a logical separation of code.&lt;br /&gt;
* These classes are:&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
* Extracted common code in methods that can be re-used.&lt;br /&gt;
&lt;br /&gt;
After complete refactoring, we could find that the grade according to Code Climate for the main class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
=References=&lt;br /&gt;
http://sourcemaking.com/design_patterns/template_method&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81545</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81545"/>
		<updated>2013-10-30T23:15:32Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81544</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81544"/>
		<updated>2013-10-30T23:15:13Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:16.png&amp;diff=81543</id>
		<title>File:16.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:16.png&amp;diff=81543"/>
		<updated>2013-10-30T23:14:35Z</updated>

		<summary type="html">&lt;p&gt;Skhare: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81541</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81541"/>
		<updated>2013-10-30T23:14:17Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
Encountered following error when trying to give permission to user to review other's work.&lt;br /&gt;
[[File:16.png|frame|none|Error while trying to assign review permission]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81531</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81531"/>
		<updated>2013-10-30T23:11:06Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
[[File:12.png|frame|none|Routing error‎]]&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81528</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81528"/>
		<updated>2013-10-30T23:10:06Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance &amp;lt;ref&amp;gt;http://www.smartinsights.com/wp-content/uploads/2012/05/relevance-rankmaniac.jpg&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates [http://en.wikipedia.org/wiki/Relevance relevance] between submission and review [http://en.wikipedia.org/wiki/Graph_%28data_structure%29 graphs]. The algorithm present in the file implements a variance of [http://en.wikipedia.org/wiki/Dependency_graph dependency graphs] called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. [http://nlp.stanford.edu/software/tagger.shtml Stanford NLP POS tagger] is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of [http://en.wikipedia.org/wiki/Text_normalization normalizations] (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. The match is referred to as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, [http://en.wikipedia.org/wiki/Metadata_discovery#Lexical_Matching lexical] and [http://en.wikipedia.org/wiki/Nominalization nominalized]. E&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and E&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this case, only single and double edges are considered, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Structurem.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and T&amp;lt;sub&amp;gt;r&amp;lt;/sub&amp;gt; and T&amp;lt;sub&amp;gt;s&amp;lt;/sub&amp;gt; are the number of double edges in the review and submission texts respectively. match&amp;lt;sub&amp;gt;ord&amp;lt;/sub&amp;gt; and match&amp;lt;sub&amp;gt;voice&amp;lt;/sub&amp;gt; are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to ''degree_of_relevance.rb''. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
 alpha = 0.55&lt;br /&gt;
 beta = 0.35&lt;br /&gt;
 gamma = 0.1 &lt;br /&gt;
&lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of type SUBJECT-VERB-OBJECT. The comparison done is between edges of same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
This method also does comparison between edges of type SUBJECT-VERB-OBJECT. However, the comparison done is between edges of different types.&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' is buried deep inside models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in ''response_controller.rb'' which renders the page where user fills up the review. On submission, it calls ''create'' method of the same file, which then redirects to ''saving'' method in the same file again. ''saving'' makes a call to ''calculate_metareview_metrics'' in ''automated_metareview.rb'' which eventually calls ''get_relevance'' in ''degree_of_relevance.rb''. The figure below shows the flow in the code.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed. I have attached a sample routing error we faced.&lt;br /&gt;
[[File:12.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
4. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
5. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:12.png&amp;diff=81522</id>
		<title>File:12.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:12.png&amp;diff=81522"/>
		<updated>2013-10-30T23:08:21Z</updated>

		<summary type="html">&lt;p&gt;Skhare: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81454</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81454"/>
		<updated>2013-10-30T22:30:45Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed.&lt;br /&gt;
&lt;br /&gt;
4. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
5. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81453</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81453"/>
		<updated>2013-10-30T22:30:34Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed.&lt;br /&gt;
&lt;br /&gt;
4. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
5. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81446</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81446"/>
		<updated>2013-10-30T22:26:15Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed.&lt;br /&gt;
&lt;br /&gt;
4. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
5. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81443</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81443"/>
		<updated>2013-10-30T22:25:49Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed.&lt;br /&gt;
&lt;br /&gt;
4. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
5. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81441</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81441"/>
		<updated>2013-10-30T22:25:32Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet WordNet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
As shown in the figure above ,the main class degree_of_relevance.rb calls the helper methods in the classes to the right to get the appropriate metrics required for evaluating relevance. This implements delegation of functionality to helper classes making a clear segregation of role of each class.&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed.&lt;br /&gt;
&lt;br /&gt;
4. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
5. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81434</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81434"/>
		<updated>2013-10-30T22:22:56Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
''degree_of_relevance.rb'' file calculates relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined punctuation list. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Wordnet] is used to identify [http://en.wikipedia.org/wiki/Semantic_relatedness semantic relatedness] between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png|frame|none|Main class calling helper classes]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&lt;br /&gt;
[[File:Test-driven development.png]]&lt;br /&gt;
&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
[[File:TestDrivenGameDevelopment1.png]]&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Steps for Testing==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
&lt;br /&gt;
1. The original expertiza code had a lot of bugs and the application was throwing a lot of errors at each step.&lt;br /&gt;
&lt;br /&gt;
2. Even simple steps like submitting an assignment and performing reviews took a lot of debugging and fixing bugs in various other files not related to our class (degree_of_relevance.rb).&lt;br /&gt;
&lt;br /&gt;
3. There a lot of routes missing from the routes.rb file, which we fixed.&lt;br /&gt;
&lt;br /&gt;
4. Overall effort spent in debugging and fixing the existing code took is almost twice that spent on refactoring the class.&lt;br /&gt;
&lt;br /&gt;
5. There were a lot of errors related to  Aspell gem which is needed for spell-checker to be used for checking relevance between the submissions and reviews.&lt;br /&gt;
&lt;br /&gt;
6. We were in touch of another group facing similar problems and they even tried to contact Lakshmi to resolve the issues.&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81351</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81351"/>
		<updated>2013-10-30T21:16:20Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* New Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and deferring some steps to subclasses (used in Template design pattern), allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&amp;lt;&amp;lt;image of the flowchart&amp;gt;&amp;gt;&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;image&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber with Capybara for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Capybara==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Procedure:==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81347</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81347"/>
		<updated>2013-10-30T21:12:28Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
* Reduced duplication significantly.&lt;br /&gt;
* Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
* Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
* The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&amp;lt;&amp;lt;image of the flowchart&amp;gt;&amp;gt;&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;image&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber with Capybara for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Capybara==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Procedure:==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81340</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81340"/>
		<updated>2013-10-30T21:10:24Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compared with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
1. Reduced duplication significantly.&lt;br /&gt;
2. Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
3. Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
4. The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&amp;lt;&amp;lt;image of the flowchart&amp;gt;&amp;gt;&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;image&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber with Capybara for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Capybara==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Procedure:==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81337</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81337"/>
		<updated>2013-10-30T21:09:14Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
1. Reduced duplication significantly.&lt;br /&gt;
2. Lines of code per method reduced from 75 to 25. This makes the code more readable and maintainable.&lt;br /&gt;
3. Improved the design of classes by making logical separation of code into different classes.&lt;br /&gt;
4. The grade for the refactored class changed from &amp;quot;F&amp;quot; to &amp;quot;C&amp;quot; according to codeclimate.&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&amp;lt;&amp;lt;image of the flowchart&amp;gt;&amp;gt;&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;image&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber with Capybara for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Capybara==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Procedure:==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81334</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81334"/>
		<updated>2013-10-30T21:06:11Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
We have achieved the following after refactoring:&lt;br /&gt;
1. Reduced duplication significantly.&lt;br /&gt;
2. Lines of code per method reduced from&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&amp;lt;&amp;lt;image of the flowchart&amp;gt;&amp;gt;&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;image&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber with Capybara for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Capybara==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Procedure:==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81332</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81332"/>
		<updated>2013-10-30T21:03:43Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&amp;lt;&amp;lt;image of the flowchart&amp;gt;&amp;gt;&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;image&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber with Capybara for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Capybara==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Procedure:==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81329</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81329"/>
		<updated>2013-10-30T21:02:54Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
* '''Re-written some methods containing complicated logic'''. &lt;br /&gt;
&lt;br /&gt;
Below is a sample of code that we have re-written to make the logic more simple and maintainable. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    result = EQUAL&lt;br /&gt;
    if(!edge1.label.nil? and !edge2.label .nil?)&lt;br /&gt;
      if(edge1.label.downcase == edge2.label.downcase)&lt;br /&gt;
        result = EQUAL #divide by 1&lt;br /&gt;
      else&lt;br /&gt;
        result = DISTINCT #divide by 2&lt;br /&gt;
      end&lt;br /&gt;
    elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null&lt;br /&gt;
        result = DISTINCT&lt;br /&gt;
    elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!&lt;br /&gt;
        result = EQUAL&lt;br /&gt;
    end  &lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_labels(edge1, edge2)&lt;br /&gt;
    if(((!edge1.label.nil? &amp;amp;&amp;amp; !edge2.label.nil?) &amp;amp;&amp;amp;(edge1.label.downcase == edge2.label.downcase)) ||&lt;br /&gt;
        (edge1.label.nil? and edge2.label.nil?))&lt;br /&gt;
      result = EQUAL&lt;br /&gt;
    else&lt;br /&gt;
      result = DISTINCT&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
  end # end of method&lt;br /&gt;
&lt;br /&gt;
= Testing =&lt;br /&gt;
&lt;br /&gt;
Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking like Capybara, Rspec etc. Testing is pretty important in Rails—yet many people developing in Rails are either not testing their projects at all, or at best only adding a few token specs on model validations.&lt;br /&gt;
 &lt;br /&gt;
 If it's worth building, it's worth testing.&lt;br /&gt;
 If it's not worth testing, why are you wasting your time working on it?&lt;br /&gt;
&lt;br /&gt;
There are several reasons for this. Perhaps working with Ruby or web frameworks is a novel enough concept; adding an extra layer of work seems like just that—extra work. Or maybe there is a perceived time constraint—spending time on writing tests takes time away from writing the features our clients or bosses demand. Or maybe the habit of defining “test” as clicking links in the browser is too hard to break.&lt;br /&gt;
Testing helps us find defects in our applications. But, it also ensures that the developers follow the release plan and the rule-set of necessary requirements, instead of just developing carelessly.&lt;br /&gt;
Testing can be done in two approaches:&lt;br /&gt;
*Test Driven Development:&lt;br /&gt;
Test-Driven Development (TDD) is a way of driving the design of code by writing a test which expresses what you intend the code to do, making that test pass, and continuously refactoring to keep the design as simple as possible.&lt;br /&gt;
&amp;lt;&amp;lt;image of the flowchart&amp;gt;&amp;gt;&lt;br /&gt;
*Behaviour Driven Development&lt;br /&gt;
Behavior-driven development (abbreviated BDD) is a software development process based on test-driven development (TDD). Behavior-driven development combines the general techniques and principles of TDD to provide software developers and business analysts with shared tools and a shared process to collaborate on software development, with the aim of delivering &amp;quot;software that matters&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We have used BDD approach, in which the tests are described in a natural language, which makes them more accessible to people outside of development or testing teams. &lt;br /&gt;
Tests are small, automated Ruby programs that automatically test different parts of your applications, It can apply at multiple levels, e.g., Customer Tests, Integration Tests, Unit Tests.&lt;br /&gt;
In this approach, we have to follow a rigorous cycle. Start by writing a failing test (Red.) Implement the simplest solution that will cause the test to pass (Green.) Search for duplication and remove it (Refactor.) &amp;quot;RED-GREEN-REFACTOR&amp;quot; has become almost a mantra for many TDD practitioners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;&amp;lt;image&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cucumber==&lt;br /&gt;
&lt;br /&gt;
Of the various tools available we have used Cucumber with Capybara for testing.Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.&lt;br /&gt;
&lt;br /&gt;
Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. &lt;br /&gt;
Because behaviour driven development is partly about understanding what the client wants before you begin coding, Cucumber aims to make its tests readable by clients (AKA, non-programmers). So, Tests are written in plain language like gherkin in the form of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.&lt;br /&gt;
&lt;br /&gt;
The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:&lt;br /&gt;
&lt;br /&gt;
*'''Given''' provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.&lt;br /&gt;
*'''When''' specifies the set of actions that triggers the test, such as user or subsystem actions.&lt;br /&gt;
*'''Then''' specifies the expected result of the test.&lt;br /&gt;
&lt;br /&gt;
As Cucumber doesn’t know how to interpret the features by itself, the next step is to create step definitions explaining it what to do when finding that step in one of the scenarios. The step definitions are written in Ruby. This gives much flexibility on how the test steps are executed&lt;br /&gt;
&lt;br /&gt;
==Capybara==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Procedure:==&lt;br /&gt;
*First of all, we have to include the required gems for our tests in the '''Gemfile'''.&lt;br /&gt;
 group :test do&lt;br /&gt;
   gem 'capybara'&lt;br /&gt;
   gem 'cucumber-rails', require: false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Then, write the actual tests in the feature file, '''deg_rel_set.feature''' located in the features folder.&lt;br /&gt;
The degree or relevance file that we are dealing with consists of six major functions.We have written tests for implementing all the six functions.&lt;br /&gt;
The major feature is to test the degree of relevance by finding the comparison between the expected values and the actual values of the Submission and Review Graphs.&lt;br /&gt;
&lt;br /&gt;
 Feature: To check degree of Relevance&lt;br /&gt;
   In order to check the various methods of the class&lt;br /&gt;
   As an Administrator&lt;br /&gt;
   I want to check if the actual and expected values match.&lt;br /&gt;
&lt;br /&gt;
 @one&lt;br /&gt;
  Scenario: Check actual v/s expected values&lt;br /&gt;
    Given Instance of the class is created&lt;br /&gt;
    When I compare actual value and expected value of &amp;quot;compare_vertices&amp;quot;&lt;br /&gt;
    Then It will return true if both are equal.&lt;br /&gt;
&lt;br /&gt;
Similarly, we have tested all the six major modules of degree of relevance like comparing edges, vertices and subject-verb objects.&lt;br /&gt;
&lt;br /&gt;
*Cucumber feature files are written to be readable to non-programmers, so we have to implement step definitions for undefined steps, provided by Cucumber. Cucumber will load any files in the folder features/step_definitions for steps. We have created a step file, '''deg_relev_step.rb'''.&lt;br /&gt;
&lt;br /&gt;
 Given /^Instance of the class is created$/ do&lt;br /&gt;
   @inst=DegreeOfRelevance.new&lt;br /&gt;
 end&lt;br /&gt;
 When /^I compare (\d+) and &amp;quot;(\S+)&amp;quot;$/ do |qty|&lt;br /&gt;
  actual=qty&lt;br /&gt;
  if(assert_equal(qty,@inst.compare_vertices(@vertex_match,@pos_tagger, @review_vertices, @subm_vertices, @num_rev_vert, @num_sub_vert, @speller) ))&lt;br /&gt;
  step(&amp;quot;It will return true&amp;quot;)&lt;br /&gt;
  else&lt;br /&gt;
  step(“It will return false”)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 Then /^It will return true$/  do&lt;br /&gt;
   #print true or false&lt;br /&gt;
 End&lt;br /&gt;
&lt;br /&gt;
*The dummy model/data is created in the setup function defined in the class Deg_rel_setup present in '''lib/deg_rel_setup.rb'''. It generates a graph of submissions and reviews and then executes the 6 different methods.&lt;br /&gt;
&lt;br /&gt;
 class Deg_rel_setup&lt;br /&gt;
   def setup&lt;br /&gt;
    #set up nodes and graphs&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle. we can put them in the '''support/env.rb''' file or any other file under the support directory, for example in a file called '''support/hooks.rb'''. There is no association between where the hook is defined and which scenario/step it is run for, but you can use tagged hooks, if we want more fine grained control.&lt;br /&gt;
&lt;br /&gt;
All defined hooks are run whenever the relevant event occurs.&lt;br /&gt;
Before hooks will be run before the first step of each scenario. They will run in the same order of which they are registered.&lt;br /&gt;
&lt;br /&gt;
 Before do &lt;br /&gt;
   # Do something before each scenario. &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Sometimes we may want a certain hook to run only for certain scenarios. This can be achieved by associating a Before, After,Around or AfterStep hook with one or more tags. We have used a tag named one, and hence the following code snippet will be executed everytime before the implementation of tag one.&lt;br /&gt;
&lt;br /&gt;
 Before ('@one') do&lt;br /&gt;
   set= Deg_rel_setup.new&lt;br /&gt;
   set.setup&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
*To run the test we simply need to execute, &lt;br /&gt;
 rake db:migrate		                   #To initialize the test database&lt;br /&gt;
 cucumber features/deg_rel.feature	   #This will execute the feature along with it's step definitons	&lt;br /&gt;
&lt;br /&gt;
&amp;lt;output scrrenshot&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the end, though, the most important thing is that tests are reliable and understandable, even if they’re not quite as optimized as they could be, they are a great way to start an application. We should keep taking advantage of the fully automated test suites available and use tests to drive development and ferret out potential bugs in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81248</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81248"/>
		<updated>2013-10-30T20:04:39Z</updated>

		<summary type="html">&lt;p&gt;Skhare: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81238</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81238"/>
		<updated>2013-10-30T20:00:28Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81236</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81236"/>
		<updated>2013-10-30T20:00:05Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* '''Move out common code in re-usable method:'''&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* '''Reduce number of lines of code per method'''.&lt;br /&gt;
&lt;br /&gt;
We ensured that each method should be short enough to fit in less than one screen length(no need to scroll). &lt;br /&gt;
** Combined conditions together in one statement instead of nesting them inside one another.&lt;br /&gt;
** Took out code that can be re-used or logically separated in separate methods.&lt;br /&gt;
** Removed commented debug statements.&lt;br /&gt;
** &lt;br /&gt;
&lt;br /&gt;
Code sample before Refactoring:&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code sample after Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81231</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81231"/>
		<updated>2013-10-30T19:55:40Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
* Reduce number of lines of code per method.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
 def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
  # puts(&amp;quot;*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}&amp;quot;)   &lt;br /&gt;
  best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
  cum_edge_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new  &lt;br /&gt;
  for i in (0..num_rev_edg - 1)&lt;br /&gt;
    if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)&lt;br /&gt;
      #skipping edges with frequent words for vertices&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      #identifying best match for edges&lt;br /&gt;
      for j in (0..num_sub_edg - 1) &lt;br /&gt;
        if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)&lt;br /&gt;
          #checking if the subm token is a frequent word&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))&lt;br /&gt;
            next&lt;br /&gt;
          end &lt;br /&gt;
          #for S-V with S-V or V-O with V-O&lt;br /&gt;
          if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] = 0.0&lt;br /&gt;
            end&lt;br /&gt;
            #-- Vertex and SRL&lt;br /&gt;
            best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          #for S-V with V-O or V-O with S-V&lt;br /&gt;
          elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)&lt;br /&gt;
            #taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!&lt;br /&gt;
            sum = 0.0&lt;br /&gt;
            cou = 0&lt;br /&gt;
            if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end&lt;br /&gt;
            if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)&lt;br /&gt;
              sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]&lt;br /&gt;
              cou +=1&lt;br /&gt;
            end  &lt;br /&gt;
            if(cou &amp;gt; 0)&lt;br /&gt;
              best_SV_VS_match[i][j] = sum.to_f/cou.to_f&lt;br /&gt;
            else&lt;br /&gt;
              best_SV_VS_match[i][j] =0.0&lt;br /&gt;
            end&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(best_SV_VS_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = best_SV_VS_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end #end of the if condition&lt;br /&gt;
      end #end of the for loop for submission edges&lt;br /&gt;
        &lt;br /&gt;
      if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}&amp;quot;)&lt;br /&gt;
        cum_edge_match = cum_edge_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop for review edges&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&lt;br /&gt;
 def compare_edges_diff_types(vertex_match, rev, subm, num_rev_edg, num_sub_edg)&lt;br /&gt;
    best_SV_VS_match = Array.new(num_rev_edg){Array.new}&lt;br /&gt;
    cum_edge_match = max = 0.0&lt;br /&gt;
    count = flag = 0&lt;br /&gt;
    wnet = WordnetBasedSimilarity.new&lt;br /&gt;
    for i in (0..num_rev_edg - 1)&lt;br /&gt;
      if(edge_nil_cond_check(rev[i]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, rev[i]))&lt;br /&gt;
        #identifying best match for edges&lt;br /&gt;
        for j in (0..num_sub_edg - 1)&lt;br /&gt;
          if(edge_nil_cond_check(subm[j]) &amp;amp;&amp;amp; !wnet_frequent_word_check(wnet, subm[j]))&lt;br /&gt;
            #for S-V with S-V or V-O with V-O&lt;br /&gt;
            if(edge_symm_vertex_type_check(rev[i],subm[j]) || edge_asymm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
              if(edge_symm_vertex_type_check(rev[i],subm[j]))&lt;br /&gt;
                cou, sum = sum_cou_asymm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              else&lt;br /&gt;
                cou, sum = sum_cou_symm_calculation(vertex_match, rev[i], subm[j])&lt;br /&gt;
              end&lt;br /&gt;
              max, best_SV_VS_match[i][j] = max_calculation(cou,sum, rev[i], subm[j], max)&lt;br /&gt;
              flag = 1&lt;br /&gt;
            end&lt;br /&gt;
          end #end of the if condition&lt;br /&gt;
        end #end of the for loop for submission edges&lt;br /&gt;
        flag_cond_var_set(:cum_edge_match, :max, :count, :flag, binding)&lt;br /&gt;
      end&lt;br /&gt;
    end #end of 'for' loop for the review's edges&lt;br /&gt;
    return calculate_avg_match(cum_edge_match, count)&lt;br /&gt;
  end #end of the method&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81222</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81222"/>
		<updated>2013-10-30T19:48:46Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81220</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81220"/>
		<updated>2013-10-30T19:48:06Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* New Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81219</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81219"/>
		<updated>2013-10-30T19:47:38Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required. This implements nil condition check on an edge of the graph and if the id of the vertex is not invalid(negative).&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81217</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81217"/>
		<updated>2013-10-30T19:46:03Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required.&lt;br /&gt;
&lt;br /&gt;
 def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81214</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81214"/>
		<updated>2013-10-30T19:45:12Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required.&lt;br /&gt;
&lt;br /&gt;
def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81206</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81206"/>
		<updated>2013-10-30T19:41:33Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81205</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81205"/>
		<updated>2013-10-30T19:40:51Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Types of Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def edge_nil_cond_check(edge)&lt;br /&gt;
   return (!edge.nil? &amp;amp;&amp;amp; edge.in_vertex.node_id != -1 &amp;amp;&amp;amp; edge.out_vertex.node_id != -1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81204</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81204"/>
		<updated>2013-10-30T19:39:49Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
==== Types of Refactoring ====&lt;br /&gt;
&lt;br /&gt;
The following are the three main types of refactoring we have done in our project.&lt;br /&gt;
&lt;br /&gt;
* Move out common code in re-usable method:&lt;br /&gt;
&lt;br /&gt;
The following is a sample of the duplicated code which was present in many methods. We moved it to a separate method and just called this method with appropriate parameters wherever required.&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81182</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=81182"/>
		<updated>2013-10-30T19:26:52Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb is buried deep under models and to bring control to this file, the tester needs to undertake some tasks. The diagram below gives a quick look into what needs to be done.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
Once a review is submitted, the further flow is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow2.png|frame|none|Flow in the code(filename and corresponding methods called‎)]]&lt;br /&gt;
&lt;br /&gt;
When a user tries to review an existing work, it calls ''new'' method in response_controller.rb which renders the page where user fills up the review. On submission, it calls ''create'' of the same file, which then redirects to ''saving'' in the same file again. Saving makes a call to ''calculate_metareview_metrics'' in automated_metareview.rb which eventually calls ''get_relevance'' in degree_of_relevance.rb.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=80853</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=80853"/>
		<updated>2013-10-30T17:27:44Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
* Using Debugger keyword&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
def compare_vertices(pos_tagger, rev, subm, num_rev_vert, num_sub_vert, speller)&lt;br /&gt;
  #for double dimensional arrays, one of the dimensions should be initialized&lt;br /&gt;
  @vertex_match = Array.new(num_rev_vert){Array.new}&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new&lt;br /&gt;
  cum_vertex_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  for i in (0..num_rev_vert - 1)&lt;br /&gt;
    if(!rev.nil? and !rev[i].nil?)&lt;br /&gt;
      rev[i].node_id = i&lt;br /&gt;
      # puts(&amp;quot;%%%%%%%%%%% Token #{rev[i].name} ::: POS tags:: rev[i].pos_tag:: #{rev[i].pos_tag} :: rev[i].node_id #{rev[i].node_id}&amp;quot;)&lt;br /&gt;
      #skipping frequent words from vertex comparison&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].name))&lt;br /&gt;
        next #ruby equivalent for continue &lt;br /&gt;
      end&lt;br /&gt;
      #looking for the best match&lt;br /&gt;
      #j tracks every element in the set of all vertices, some of which are null&lt;br /&gt;
      for j in (0..num_sub_vert - 1)&lt;br /&gt;
        if(!subm[j].nil?)&lt;br /&gt;
          if(subm[j].node_id == -1)&lt;br /&gt;
            subm[j].node_id = j&lt;br /&gt;
          end&lt;br /&gt;
          # puts(&amp;quot;%%%%%%%%%%% Token #{subm[j].name} ::: POS tags:: subm[j].pos_tag:: #{subm[j].pos_tag} subm[j].node_id #{subm[j].node_id}&amp;quot;)&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].name))&lt;br /&gt;
            next #ruby equivalent for continue &lt;br /&gt;
          end&lt;br /&gt;
          #comparing only if one of the two vertices is a noun&lt;br /&gt;
          if(rev[i].pos_tag.include?(&amp;quot;NN&amp;quot;) and subm[j].pos_tag.include?(&amp;quot;NN&amp;quot;))&lt;br /&gt;
            @vertex_match[i][j] = wnet.compare_strings(rev[i], subm[j], speller)    &lt;br /&gt;
            #only if the &amp;quot;if&amp;quot; condition is satisfied, since there could be null objects in between and you dont want unnecess. increments&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(@vertex_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = @vertex_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end #end of for loop for the submission vertices&lt;br /&gt;
      if(flag != 0)#if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].name}-- #{max}&amp;quot;)&lt;br /&gt;
        cum_vertex_match = cum_vertex_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop&lt;br /&gt;
  avg_match = 0.0&lt;br /&gt;
  if(count &amp;gt; 0)&lt;br /&gt;
    avg_match = cum_vertex_match/ count&lt;br /&gt;
  end&lt;br /&gt;
  return avg_match  &lt;br /&gt;
end #end of compare_vertices&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=80849</id>
		<title>CSC/ECE 517 Fall 2013/oss ssv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ssv&amp;diff=80849"/>
		<updated>2013-10-30T17:26:58Z</updated>

		<summary type="html">&lt;p&gt;Skhare: /* Design of classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring and testing — degree_of_relevance.rb =&lt;br /&gt;
[[File:RelevanceJoke.png|frame|Relevance]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
The class degree_of_relevance.rb is used to how relevant one piece of text is to another piece of text.  It is used to evaluate the relevance between the submitted work and review(or metareview) for an assignment. It is important to evaluate the reviews for a submitted work to ensure that if the review is not relevant to the submission, it is considered to be invalid and does not impact student's grade. &lt;br /&gt;
This class contains a lot of duplicated code and has long and complex methods. It has been assigned grade &amp;quot;F&amp;quot;, according to metric like code complexity, duplication, lines of code per method etc. Since this class is important for the research on expertiza, it should be re-factored to reduce its complexity, duplication and introduce coding best practices. Our task for this project is to re-factor this class and test it thoroughly. This class can be found at the following location in expertiza source code - Expertiza\expertiza\app\models\automated_metareview&lt;br /&gt;
&lt;br /&gt;
= Theory of Relevance =&lt;br /&gt;
&lt;br /&gt;
Relevance between two texts can be defined as:&lt;br /&gt;
&lt;br /&gt;
[[File:Relevance.png|frame|none|Definition of Relevance‎]]&lt;br /&gt;
&lt;br /&gt;
degree_of_relevance.rb file calculates the relevance between submission and review graphs. The algorithm present in the file implements a variance of dependency graphs called word-order graph to capture both governance and ordering information crucial to obtaining more accurate results. &lt;br /&gt;
&lt;br /&gt;
== Word-order graph generation ==&lt;br /&gt;
&lt;br /&gt;
Vertices represent noun, verb, adjective or adverbial words or phrases in a text, and edges represent relationships between vertices. The first step to graph generation is dividing input text into segments on the basis of a predefined list of punctuation. The text is then tagged with part-of-speech information which is used to determine how to group words into phrases while still maintaining the order. Stanford NLP POS tagger is used to generate the tagged text. The vertex and edges are created using the algorithm below. Graph edges that are subsequently created are then labeled with dependency(word-modifier) information.&lt;br /&gt;
&lt;br /&gt;
[[File:MainAlgo.png|frame|none|Algorithm to create vertices and edges‎]]&lt;br /&gt;
&lt;br /&gt;
WordNet is used to identify semantic relatedness between two terms. The comparison between reviews and submissions would involve checking for relatedness across verb, adjective or adverbial forms, checking for cases of normalizations (noun form of adjectives) etc.&lt;br /&gt;
&lt;br /&gt;
== Lexico-Semantic Graph-based Matching ==&lt;br /&gt;
&lt;br /&gt;
=== Phrase or token matching ===&lt;br /&gt;
&lt;br /&gt;
In phrase or token matching, vertices containing phrases or tokens are compared across graphs. This matching succeeds in capturing semantic relatedness between single or compound words. &lt;br /&gt;
&lt;br /&gt;
[[File:Phrase.png|frame|none|Phrase-matching‎]]&lt;br /&gt;
&lt;br /&gt;
=== Context matching ===&lt;br /&gt;
&lt;br /&gt;
Context matching compares edges with same and different syntax, and edges of different types across two text graphs. We refer to the match as context matching since contiguous phrases, which capture additional context information, are chosen from a graph for comparison with those in another. Edge labels capture grammatical relations, and play an important role in matching.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Context-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(e) and s(e) refer to review and submission edges. The formula calculates the average for each of the above three types of matches ordered, lexical and nominalized. Er and Es represent the sets of review and submission edges.&lt;br /&gt;
&lt;br /&gt;
=== Sentence structure matching ===&lt;br /&gt;
&lt;br /&gt;
Sentence structure matching compares double edges (two contiguous edges), which constitute a complete segment (e.g. subject–verb–object), across graphs. In this work we consider only single and double edges, and not more contiguous edges (triple edges etc.), for text matching. The matching captures similarity across segments and it captures voice changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Context.png|frame|none|Structure-matching‎]]&lt;br /&gt;
&lt;br /&gt;
r(t) and s(t) refer to double edges, and Tr and Ts are the number of double edges in the review and submission texts respectively. matchord and matchvoice are the averages of the best ordered and voice change matches.&lt;br /&gt;
&lt;br /&gt;
= Existing Design =&lt;br /&gt;
&lt;br /&gt;
The current design has a method ''get_relevance'' which is a single entry point to degree_of_relevance.rb. It takes as input submission and review graphs in array form along with other important parameters. The algorithm is broken down into different parts each of which is handled by a different helper method. The results obtained from these methods are used in the following formula to obtain degree of relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:RelevanceFormula.png|frame|none|Formula to calculate relevance‎]]&lt;br /&gt;
&lt;br /&gt;
The implementation in Expertiza leaves room for applying separate weights to different types of matches instead of a fixed value of 0.33 in above formula. For example, a possible set of values could be:&lt;br /&gt;
    alpha = 0.55&lt;br /&gt;
    beta = 0.35&lt;br /&gt;
    gamma = 0.1 &lt;br /&gt;
The rule generally followed is alpha &amp;gt; beta &amp;gt; gamma&lt;br /&gt;
&lt;br /&gt;
== Helper Methods ==&lt;br /&gt;
&lt;br /&gt;
The helper methods used by ''get_relevance'' are:&lt;br /&gt;
&lt;br /&gt;
=== compare_vertices ===&lt;br /&gt;
&lt;br /&gt;
This method compares the vertices from across the two graphs(submission and revision) to identify matches and quantify various metrics. Every vertex is compared with every other vertex to obtain the comparison results.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_non_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This is the method where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done to identify matches and quantify various metrics. It compares edges of the same type ie SUBJECT-VERB edges are matched with SUBJECT-VERB matches.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_syntax_diff ===&lt;br /&gt;
&lt;br /&gt;
This method handles comparisons between edges of type SUBJECT-VERB with VERB-OBJECT. It also does comparison between SUBJECT-OBJECT and VERB_VERB edges. It compares edges of the same type.&lt;br /&gt;
&lt;br /&gt;
=== compare_edges_diff_types ===&lt;br /&gt;
&lt;br /&gt;
This method does comparison between edges of different types. Comparisons related to SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT are handled and relevant results returned.&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_edges ===&lt;br /&gt;
&lt;br /&gt;
=== compare_SVO_diff_syntax ===&lt;br /&gt;
&lt;br /&gt;
== Program Flow ==&lt;br /&gt;
&lt;br /&gt;
[[File:ProgramFlow1.png|frame|none|Initial setup‎]]&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== New Design and Refactoring ==&lt;br /&gt;
&lt;br /&gt;
=== New Design ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We have taken ideas from the Template design pattern to improve the design of the class. Although we did not directly implement this design pattern on the class, the idea of defining a skeleton of an algorithm in one class, and defering some steps to subclasses, allowed us to come up with a similar design which segregates different functionality to different classes. The following is a brief outline of the changes made:&lt;br /&gt;
&lt;br /&gt;
* Divided the code into 4 classes to  segregate the functionality making a logical separation of code.&lt;br /&gt;
* These classes are -&lt;br /&gt;
** compare_graph_edges.rb&lt;br /&gt;
** compare_graph_svo_edges.rb&lt;br /&gt;
** compare_graph_vertices.rb&lt;br /&gt;
** degree_of_relevance.rb&lt;br /&gt;
&lt;br /&gt;
* Extracted common code in methods that be re-used.&lt;br /&gt;
* After refactoring the grade according to codeclimate for the class is &amp;quot;C&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Design of classes ====&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calculates the scaled relevance using the formula described above. It calculates the relevance based on comparison of submission and review graphs. As described above the following types of comparison is made between the graphs and various metrics is calculated which is used to calculate the relevance:&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_edges.rb:&lt;br /&gt;
** Comparing edges of graphs with non syntax difference: In this SUBJECT-VERB edges are compred with SUBJECT-VERB matches where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done.&lt;br /&gt;
** Comparing edges with syntax diff: Compares the edges from across the two graphs to identify matches and quantify various metrics. Compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons.&lt;br /&gt;
** Comparing edges with diff types: Compares the edges from across the two graphs to identify matches and quantify various metrics compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done. (Different type comparisons)&lt;br /&gt;
&lt;br /&gt;
All the above functions are grouped in one class - compare_graph_edges.rb.&lt;br /&gt;
&lt;br /&gt;
* Class  compare_graph_vertices.rb:&lt;br /&gt;
** Comparing vertices of the corresponding graphs: Every vertex is compared with every other vertex. Compares the vertices from across the two graphs to identify matches and quantify various metrics.&lt;br /&gt;
&lt;br /&gt;
This method is factored out to the class - compare_graph_vertices.rb&lt;br /&gt;
&lt;br /&gt;
* Class compare_graph_SVO_edges&lt;br /&gt;
&lt;br /&gt;
** comparing SVO edges.&lt;br /&gt;
** compare SVO edges with different syntax.&lt;br /&gt;
&lt;br /&gt;
These methods are grouped in the compare_graph_SVO_edges.rb class.&lt;br /&gt;
&lt;br /&gt;
The main class degree_of_relevance.rb calls each of these methods to get the appropriate metrics required for evaluating relevance.&lt;br /&gt;
&lt;br /&gt;
[[File:class design.png]]&lt;br /&gt;
&lt;br /&gt;
'''Using Debugger keyword'''&lt;br /&gt;
&lt;br /&gt;
def compare_vertices(pos_tagger, rev, subm, num_rev_vert, num_sub_vert, speller)&lt;br /&gt;
  #for double dimensional arrays, one of the dimensions should be initialized&lt;br /&gt;
  @vertex_match = Array.new(num_rev_vert){Array.new}&lt;br /&gt;
  wnet = WordnetBasedSimilarity.new&lt;br /&gt;
  cum_vertex_match = 0.0&lt;br /&gt;
  count = 0&lt;br /&gt;
  max = 0.0&lt;br /&gt;
  flag = 0&lt;br /&gt;
  for i in (0..num_rev_vert - 1)&lt;br /&gt;
    if(!rev.nil? and !rev[i].nil?)&lt;br /&gt;
      rev[i].node_id = i&lt;br /&gt;
      # puts(&amp;quot;%%%%%%%%%%% Token #{rev[i].name} ::: POS tags:: rev[i].pos_tag:: #{rev[i].pos_tag} :: rev[i].node_id #{rev[i].node_id}&amp;quot;)&lt;br /&gt;
      #skipping frequent words from vertex comparison&lt;br /&gt;
      if(wnet.is_frequent_word(rev[i].name))&lt;br /&gt;
        next #ruby equivalent for continue &lt;br /&gt;
      end&lt;br /&gt;
      #looking for the best match&lt;br /&gt;
      #j tracks every element in the set of all vertices, some of which are null&lt;br /&gt;
      for j in (0..num_sub_vert - 1)&lt;br /&gt;
        if(!subm[j].nil?)&lt;br /&gt;
          if(subm[j].node_id == -1)&lt;br /&gt;
            subm[j].node_id = j&lt;br /&gt;
          end&lt;br /&gt;
          # puts(&amp;quot;%%%%%%%%%%% Token #{subm[j].name} ::: POS tags:: subm[j].pos_tag:: #{subm[j].pos_tag} subm[j].node_id #{subm[j].node_id}&amp;quot;)&lt;br /&gt;
          if(wnet.is_frequent_word(subm[j].name))&lt;br /&gt;
            next #ruby equivalent for continue &lt;br /&gt;
          end&lt;br /&gt;
          #comparing only if one of the two vertices is a noun&lt;br /&gt;
          if(rev[i].pos_tag.include?(&amp;quot;NN&amp;quot;) and subm[j].pos_tag.include?(&amp;quot;NN&amp;quot;))&lt;br /&gt;
            @vertex_match[i][j] = wnet.compare_strings(rev[i], subm[j], speller)    &lt;br /&gt;
            #only if the &amp;quot;if&amp;quot; condition is satisfied, since there could be null objects in between and you dont want unnecess. increments&lt;br /&gt;
            flag = 1&lt;br /&gt;
            if(@vertex_match[i][j] &amp;gt; max)&lt;br /&gt;
              max = @vertex_match[i][j]&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end #end of for loop for the submission vertices&lt;br /&gt;
      if(flag != 0)#if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with&lt;br /&gt;
        # puts(&amp;quot;**** Best match for:: #{rev[i].name}-- #{max}&amp;quot;)&lt;br /&gt;
        cum_vertex_match = cum_vertex_match + max&lt;br /&gt;
        count+=1&lt;br /&gt;
        max = 0.0 #re-initialize&lt;br /&gt;
        flag = 0&lt;br /&gt;
      end&lt;br /&gt;
    end #end of if condition&lt;br /&gt;
  end #end of for loop&lt;br /&gt;
  avg_match = 0.0&lt;br /&gt;
  if(count &amp;gt; 0)&lt;br /&gt;
    avg_match = cum_vertex_match/ count&lt;br /&gt;
  end&lt;br /&gt;
  return avg_match  &lt;br /&gt;
end #end of compare_vertices&lt;br /&gt;
&lt;br /&gt;
= How to run the code =&lt;br /&gt;
&lt;br /&gt;
Here is a sample of the refactored code compared with original code.&lt;br /&gt;
&lt;br /&gt;
= Testing = &lt;br /&gt;
= Conclusion =&lt;br /&gt;
= References =&lt;/div&gt;</summary>
		<author><name>Skhare</name></author>
	</entry>
</feed>