Skip to content

Commit

Permalink
Merge pull request #158 from SOBotics/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
FelixSFD authored Mar 2, 2018
2 parents 95646e5 + 1d41f01 commit 0a358a7
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>de.felixsfd.stackoverflow</groupId>
<artifactId>guttenberg</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>

<dependencies>
<dependency>
Expand Down
31 changes: 18 additions & 13 deletions src/main/java/org/sobotics/guttenberg/entities/PostMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sobotics.guttenberg.reasons.Reason;
import org.sobotics.guttenberg.utils.FilePathUtils;

/**
Expand All @@ -23,6 +22,7 @@ public class PostMatch implements Comparable<PostMatch>{
private Post original;
private List<String> reasons = new ArrayList<String>();
private double totalScore = 0;
private String copyPastorReasonString = "";

public PostMatch(Post targetPost, Post originalPost) {
this.target = targetPost;
Expand All @@ -37,16 +37,6 @@ public Post getOriginal() {
return this.original;
}

@Deprecated
public void addReason(Reason reason) {
if (!reasons.contains(reason.description())) {
//add reason
this.reasons.add(reason.description());
//add score
this.totalScore += reason.score();
}
}

public void addReason(String reason, double score) {
if (!reasons.contains(reason)) {
//add reason
Expand All @@ -56,10 +46,25 @@ public void addReason(String reason, double score) {
}
}

public void addReasonToCopyPastorString(String reason, double score) {
if (!reasons.contains(reason)) {
double roundedScore = Math.round(score*100.0)/100.0;

if (copyPastorReasonString.length() > 0)
this.copyPastorReasonString += ",";

this.copyPastorReasonString += reason + ":" + roundedScore;
}
}

public List<String> getReasonStrings() {
return this.reasons;
}

public String getCopyPastorReasonString() {
return this.copyPastorReasonString;
}

public double getTotalScore() {
return this.totalScore;
}
Expand Down Expand Up @@ -99,8 +104,8 @@ public boolean isValidMatch() {
boolean minimumTimeSpanChecked = minutes >= 5;

//#130: Time-span for reposts: 0 minutes
if (this.target.getAnswerID() == this.original.getAnswerID())
minimumTimeSpanChecked = minutes >= 0;
if (this.isRepost())
minimumTimeSpanChecked = targetCreation.getEpochSecond() > originalCreation.getEpochSecond();

return lengthOne >= minimumLength && lengthTwo >= minimumLength && minimumTimeSpanChecked;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/sobotics/guttenberg/finders/PlagFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public List<PostMatch> matchesForReasons(boolean ignoringScores) {
alreadyExists = true;
existingMatch.addReason(reason.description(i), scores.get(n));

existingMatch.addReasonToCopyPastorString(reason.description(i, false), scores.get(n));

matches.set(i, existingMatch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String print(PostMatch match) {
double roundedTotalScore = Math.round(match.getTotalScore()*100.0)/100.0;

try {
reportLink = PostUtils.storeReport(match.getTarget(), match.getOriginal());
reportLink = PostUtils.storeReport(match);
}
catch (IOException e) {
LOGGER.warn(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ExactParagraphMatch implements Reason {
private List<Double> scoreList = new ArrayList<Double>();
private double score = -1;

public static final String LABEL = "Exact paragraph match";

public ExactParagraphMatch(Post target, List<Post> originalPosts) {
this.target = target;
this.originals = originalPosts;
Expand Down Expand Up @@ -74,15 +76,20 @@ public boolean check() {

return matched;
}

@Override
public String description() {
return "Exact paragraph match";
public String description(int index) {
return LABEL;
}

@Override
public String description(int index) {
return "Exact paragraph match";
public String description(int index, boolean includingScore) {
if (includingScore) {
double roundedScore = Math.round(this.scoreList.get(index)*100.0)/100.0;
return score() >= 0 ? LABEL + " "+roundedScore : LABEL;
} else {
return LABEL;
}
}

@Override
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/sobotics/guttenberg/reasons/Reason.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ public interface Reason {
/**
* The description of the reason
*
* @parameter index The index in the `matchedPosts()`-array
*
* @return a short description of the reason like "String similarity"
* */
@Deprecated
public String description();
public String description(int index);

/**
* The description of the reason
*
* @parameter index The index in the `matchedPosts()`-array
* @parameter includingScore if false, the score won't be included in the description
*
* @return a short description of the reason like "String similarity"
* */
public String description(int index);
String description(int index, boolean includingScore);

/**
* The score that specific reason reached. This has no influence on whether a post is reported or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class StringSimilarity implements Reason {
private double score = -1;
private boolean ignoringScore = false;

public static final String LABEL = "String similarity";

public StringSimilarity(Post target, List<Post> originalPosts) {
this.target = target;
this.originals = originalPosts;
Expand Down Expand Up @@ -136,17 +138,20 @@ public boolean check() {

return matched;
}

@Override
public String description() {
double roundedScore = Math.round(this.score()*100.0)/100.0;
return score() >= 0 ? "String similarity "+roundedScore : "String similarity";
public String description(int index) {
return description(index, true);
}

@Override
public String description(int index) {
double roundedScore = Math.round(this.scoreList.get(index)*100.0)/100.0;
return score() >= 0 ? "String similarity "+roundedScore : "String similarity";
public String description(int index, boolean includingScore) {
if (includingScore) {
double roundedScore = Math.round(this.scoreList.get(index)*100.0)/100.0;
return score() >= 0 ? LABEL + " "+roundedScore : LABEL;
} else {
return LABEL;
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sobotics/guttenberg/utils/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static JsonObject getRelatedQuestionsById(Integer questionId, String site
}

public static JsonObject getLinkedQuestionsById(Integer questionId, String site, String apiKey) throws IOException{
String questionIdUrl = "https://api.stackexchange.com/2.2/questions/"+questionId+"/related";
String questionIdUrl = "https://api.stackexchange.com/2.2/questions/"+questionId+"/linked";
return JsonUtils.get(questionIdUrl,"site",site,"key",apiKey);
}

Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/sobotics/guttenberg/utils/PostUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.LoggerFactory;
import org.sobotics.guttenberg.clients.Guttenberg;
import org.sobotics.guttenberg.entities.Post;
import org.sobotics.guttenberg.entities.PostMatch;
import org.sobotics.guttenberg.entities.SOUser;

import com.google.gson.JsonArray;
Expand Down Expand Up @@ -206,7 +207,51 @@ public static Integer getIdFromLink(String link) {

}

public static String storeReport(PostMatch match) throws IOException {
Properties prop = Guttenberg.getLoginProperties();

String targetUsername = "";
String targetUserLink = "";
String originalUsername = "";
String originalUserLink = "";

Post target = match.getTarget();
Post original = match.getOriginal();



if (target.getAnswerer() != null) {
targetUsername = target.getAnswerer().getUsername();
targetUserLink = "https://stackoverflow.com/users/" + target.getAnswerer().getUserId() + "/";
}

if (original.getAnswerer() != null) {
originalUsername = original.getAnswerer().getUsername();
originalUserLink = "https://stackoverflow.com/users/" + original.getAnswerer().getUserId() + "/";
}

String url = prop.getProperty("copypastor_url", "http://localhost:5000")+"/posts/create";
JsonObject output = JsonUtils.post(url,
"key", prop.getProperty("copypastor_key", "no_key"),
"url_one","//stackoverflow.com/a/"+target.getAnswerID(),
"url_two","//stackoverflow.com/a/"+original.getAnswerID(),
"title_one","Possible Plagiarism",
"title_two", "Original Post",
"date_one",""+target.getAnswerCreationDate().getEpochSecond(),
"date_two",""+original.getAnswerCreationDate().getEpochSecond(),
"body_one",target.getUnescapedBodyMarkdown(),
"body_two",original.getUnescapedBodyMarkdown(),
"username_one", targetUsername,
"username_two", originalUsername,
"user_url_one", targetUserLink,
"user_url_two", originalUserLink,
"score", ""+match.getTotalScore(),
"reasons", match.getCopyPastorReasonString());

return prop.getProperty("copypastor_url", "http://localhost:5000") + "/posts/" + output.get("post_id").getAsString();
}

@Deprecated
public static String storeReport(Post target, Post original) throws IOException {
Properties prop = Guttenberg.getLoginProperties();

Expand Down

0 comments on commit 0a358a7

Please sign in to comment.