Class LineMapper
- java.lang.Object
-
- uk.ac.warwick.dcs.sherlock.module.web.data.results.LineMapper
-
public class LineMapper extends java.lang.Object
Maps every line of a file that the system thinks is plagiarised to one or more "match ids" (stored in the code block object)
-
-
Constructor Summary
Constructors Constructor Description LineMapper(long fileId)
Initialise an empty instance of line mapperLineMapper(long fileId, java.util.List<FileMatch> matches)
Initialise the line mapper and fill with a list of matches
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
AddMatch(FileMatch match)
Fills the temp map with line numbers where matched code blocks start.void
Fill()
This function needs to be called after all the matches have been added using the "addMatch" method, it will then fill in the gaps from the start line number to the end line number for each code block.java.lang.String
getHighlightedLines()
Get the list of plagiarised line numbers converted to a comma separated list e.g.org.json.JSONObject
toJSON()
Convert this object to a JSON object, used by the JavaScript in the UI
-
-
-
Constructor Detail
-
LineMapper
public LineMapper(long fileId)
Initialise an empty instance of line mapper- Parameters:
fileId
- the id of the file being mapped
-
LineMapper
public LineMapper(long fileId, java.util.List<FileMatch> matches)
Initialise the line mapper and fill with a list of matches- Parameters:
fileId
- the id of the file being mappedmatches
- the list of matches to fill the map with
-
-
Method Detail
-
AddMatch
public void AddMatch(FileMatch match) throws MapperException
Fills the temp map with line numbers where matched code blocks start. If multiple matches start on the same line, the list should have multiple elements in it, all others should only contain one element.- Parameters:
match
- the match to insert into the map- Throws:
MapperException
- if add match was called after fill
-
Fill
public void Fill()
This function needs to be called after all the matches have been added using the "addMatch" method, it will then fill in the gaps from the start line number to the end line number for each code block. e.g. if there was a match from lines 2-4, the previous method would add an entry on line 2, while this method will add values on lines 3 and 4. If there are overlaps, it will pick the newest code block and if multiple code blocks start on the same line, it will pick the shortest one. e.g. If Block #1 has lines 2-7 and Block #2 has lines 3-5: 1: None 2: #1 3: #2 4: #2 5: #2 6: #1 7: #1 8: None This is not a perfect algorithm, and some matches/code blocks will not be displayed at all however there will be a list of matches on the page for the user to see all of them and it ensures that as many different matches are displayed as possible. The function also populates a "allMatches" map which has a list of every match found on each line. This is not currently used by anything else.
-
toJSON
public org.json.JSONObject toJSON()
Convert this object to a JSON object, used by the JavaScript in the UI- Returns:
- the JSON equivalent of this object
-
getHighlightedLines
public java.lang.String getHighlightedLines()
Get the list of plagiarised line numbers converted to a comma separated list e.g. if lines 2-10 are mapped to a match, this would return "2,3,4,5,6,7,8,9,10"- Returns:
- the comma separated list
-
-