-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlagResult.py
195 lines (168 loc) · 7.21 KB
/
PlagResult.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# -*- coding: utf-8 -*-
# $Id$
#
# Copyright (c) 2006 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECAssignmentBox.
#
# ECAssignmentBox is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# ECAssignmentBox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ECAssignmentBox; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#===============================================================================
#Author: Christian Dervaric
#
#Description:
#This module contains the class PlagResult. PlagResult is an object holding
#informations about the result of the plagiarism tests called from PlagChecker.
#===============================================================================
from errors import NoValidArgumentError, OutOfRangeError, NoIdentifierSetError
class PlagResult(object):
"""Class for the result of the comparison of two texts for plagiarism.
"""
def __init__(self, id1 = None , id2 = None):
"""Initializes the PlagResult object."""
self.tiles = []
self.similarity = 0.0
self.id1 = id1
self.id2 = id2
self.id1StringLength = 0
self.id2StringLength = 0
self.algName = ""
self.normName = ""
self.suspectedPlagiarism = False
#===============================================================================
# GETTER AND SETTER
#===============================================================================
def setTiles(self, tiles):
"""Set tiles found in the Test for plagiarism."""
if type(tiles) != type([]):
raise NoValidArgumentError
else:
self.tiles = tiles
def getTiles(self):
rf_tiles = self.tiles
rf_tiles=sorted(rf_tiles, key=lambda x: x[0])
# print enumerate(rf_tiles)
rf = []
i = 0
for tile in rf_tiles:
# print i
# print tile[0]
if i == 0:
rf.append(tile)
i = i + 1
continue
if rf[i - 1][0] == tile[0]:
continue
else:
rf.append(tile)
i = i + 1
return rf
# def getRefineTiles(self):
# rf_tiles = self.tiles
# # print enumerate(rf_tiles)
# rf = []
# i=0
# for tile in rf_tiles:
# # print i
# # print tile[0]
# if i == 0:
# rf.append(tile)
# i=i+1
# continue
# if rf[i - 1][0] == tile[0]:
# continue
# else:
# rf.append(tile)
# i=i+1
#return rf
def setSimilarity(self, similarity):
"""Set similarity calculated in the Test for plagiarism."""
if not (0 <= similarity <= 1):
raise OutOfRangeError
else:
self.similarity = similarity
def getSimilarity(self):
"""Get similarity calculated in the Test for plagiarism."""
return self.similarity
def setIdentifier(self, id1, id2):
"""Set identifier for each compared text."""
self.id1 = id1
self.id2 = id2
def getIdentifier(self):
"""Get the identifier for the compared texts."""
if self.id1 == None or self.id2 == None:
raise NoIdentifierSetError
return [self.id1, self.id2]
def containsIdentifier(self, id):
"""Checks if the given identifier is one of the identifier of this result."""
return id==self.id1 or id==self.id2
def setIdStringLength(self, id1StringLength, id2StringLength):
"""Set the string length of the identifier strings. Important for Visualization."""
self.id1StringLength = id1StringLength
self.id2StringLength = id2StringLength
def getIdStringLength(self):
"""Get the string length of the identifier strings as a List[id1strlength, id2strlenght].
Important for Visualization.
"""
return [self.id1StringLength, self.id2StringLength]
def setSuspectedPlagiarism(self, value):
"""set boolean value: True means there is plagiarism suspicion other False"""
if type(value) != type(True):
raise NoValidArgumentError
self.suspectedPlagiarism = value
def isSuspectPlagiarism(self):
"""Returns boolean value indicating if there is plagiarism suspcicion."""
return self.suspectedPlagiarism
def setAlgorithmName(self, algName):
"""Sets the algorithm id used for the comparison."""
self.algName = algName
def getAlgorithmName(self):
"""Gets the algorithm id used for the comparison."""
return self.algName
def setNormalizerName(self, normName):
"""Sets the normalizer id used for the comparison."""
self.normName = normName
def getNormalizerName(self):
"""Gets the normalizer id used for the comparison."""
return self.normName
#===============================================================================
# Comparison
#===============================================================================
def __eq__(self, other):
"""Method to compare if this object is equal to another one: this == other"""
if other == None:
return False
elif (set(self.getIdentifier()) == set(other.getIdentifier())
and self.getSimilarity() == other.getSimilarity()
and set(self.getTiles()) == set(other.getTiles())
and set(self.getIdStringLength()) == set(other.getIdStringLength())):
return True
return False
def __ne__(self, other):
"""Method to compare if this object ist NOT equal with another object: this != other"""
return not self.__eq__(other)
#===============================================================================
# String Representation
#===============================================================================
def __str__(self):
"""Returns the informal string representation of this PlagResult object."""
return ('PlagResult:\n'
+ ' Identifier: ' + str(self.getIdentifier()) + '\n'
+ ' Similarity: ' + str(self.getSimilarity()) + '\n'
+ ' Tiles: ' + str(self.getTiles()) + '\n'
+ ' supected Plagiarism: ' + str(self.isSuspectPlagiarism()) + '\n')
def __repr__(self):
"""Returns the form string representation of this PlagResult object."""
return "%s %s %s %s" %(str(self.getIdentifier()), str(self.getSimilarity()),
str(self.getTiles()), str(self.isSuspectPlagiarism()))