[LON-CAPA-cvs] cvs: loncom /homework grades.pm

www lon-capa-cvs@mail.lon-capa.org
Wed, 30 Apr 2003 20:16:03 -0000


www		Wed Apr 30 16:16:03 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  Bug 108: Plagiarism check on essay responses.
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.87 loncom/homework/grades.pm:1.88
--- loncom/homework/grades.pm:1.87	Wed Apr 30 11:52:28 2003
+++ loncom/homework/grades.pm	Wed Apr 30 16:16:02 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.87 2003/04/30 15:52:28 www Exp $
+# $Id: grades.pm,v 1.88 2003/04/30 20:16:02 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -237,7 +237,7 @@
     $uessay=~s/\W+/ /gs;
 
 # these will be returned. Do not care if not at least 50 percent similar
-    my $limit=0.5;
+    my $limit=0.6;
     my $sname='';
     my $sdom='';
     my $scrsid='';
@@ -246,22 +246,22 @@
     foreach my $tkey (keys %oldessays) {
 	my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
 # ... except the same student
-        if (($tname ne $uname) && ($tdom ne $udom)) {
+        if (($tname ne $uname) || ($tdom ne $udom)) {
 	    my $tessay=$oldessays{$tkey};
             $tessay=~s/\W+/ /gs;
 # String similarity gives up if not even limit
-            my $tsimilar=&String::Similarity::similar($uessay,$tessay,$limit);
+            my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
 # Found one
             if ($tsimilar>$limit) {
 		$limit=$tsimilar;
                 $sname=$tname;
-                $sdom=$sdom;
+                $sdom=$tdom;
                 $scrsid=$tcrsid;
                 $sessay=$oldessays{$tkey};
             }
         } 
     }
-    if ($limit>0.5) {
+    if ($limit>0.6) {
        return ($sname,$sdom,$scrsid,$sessay,$limit);
     } else {
        return ('','','','',0);
@@ -1122,6 +1122,9 @@
 	$request->print($prnmsg);
 
 	if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
+#
+# Print out the keyword options line
+#
 	    $request->print(<<KEYWORDS);
 &nbsp;<b>Keyword Options:</b>&nbsp;
 <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>&nbsp; &nbsp;
@@ -1129,6 +1132,14 @@
  CLASS="page">Paste Selection to List</a>&nbsp; &nbsp;
 <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
 KEYWORDS
+#
+# Load the other essays for similarity check
+#
+            my $essayurl=&Apache::lonnet::declutter($url);
+	    my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
+	    $apath=&Apache::lonnet::escape($apath);
+	    $apath=~s/\W/\_/gs;
+	    %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
         }
     }
 
@@ -1236,6 +1247,15 @@
 			my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
 			if ($part eq ($partid.'_'.$respid)) {
 			    my ($ressub,$subval) = split(/:/,$_,2);
+# Similarity check
+                            my $similar='';
+                            my ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
+                            if ($osim) {
+				$osim=int($osim*100.0);
+				$similar='<hr /><h3><font color="#FF0000">Essay is '.$osim.'% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
+                                '</font></h3><blockquote><i>'.
+                                &keywords_highlight($oessay).'</i></blockquote><hr />';
+                            }
 			    $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 				$partid.'</b> <font color="#999999">( ID '.$respid.
 				' )</font>&nbsp; &nbsp;'.
@@ -1243,8 +1263,8 @@
                                 '<a href="'.
                                 &Apache::lonnet::tokenwrapper($record{"resource.$partid.$respid.uploadedurl"}).
    '"><img src="/adm/lonIcons/unknown.gif" border=0"> File uploaded by student</a> <font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />':'').
-                                '<b>Answer: </b>'.
-				&keywords_highlight($subval).'</td></tr>'."\n"
+                                '<b>Answer: </b><blockquote>'.
+				&keywords_highlight($subval).'</blockquote><br />&nbsp;'.$similar.'</td></tr>'."\n"
 				if ($ENV{'form.lastSub'} eq 'lastonly' || 
 				    ($ENV{'form.lastSub'} eq 'hdgrade' && 
 				     $$handgrade{$part} =~ /:yes$/));