Skip to content

Commit

Permalink
Merge pull request FeKozma#14 from FeKozma/procent_match
Browse files Browse the repository at this point in the history
feat: check the procent matched of a function
  • Loading branch information
FeKozma authored Feb 18, 2024
2 parents 20d2fd9 + 825f4ea commit 1927068
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/main/java/CodeCheck/OneFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class OneFunction {
public List<String> content = new ArrayList<>();

public int equals(OneFunction obj) {
if (obj.content.size() > 2 && obj.name.equals(name) && obj.removeLogAndCommentsAndMore().equals(removeLogAndCommentsAndMore()))
if (obj.content.size() > 2 && obj.name.equals(name) && obj.removeExtraInformationAndGetString().equals(removeExtraInformationAndGetString()))
return 1;
if (obj.name.equals(name) && obj.content.size() > 4 && content.size() > 4) return 2;
if (obj.name.equals(name)) return 3;
Expand All @@ -23,13 +23,25 @@ public int equals(OneFunction obj) {
public Comparison compare(OneFunction other, LLM llm) {
switch (equals(other)) {
case 1: return new Comparison(true, "Functions are identical").setFunctions(this, other);
case 2: return new Comparison(false, true, llmComparison(other, llm)).setFunctions(this, other);
case 2: return similar(other, llm);
case 3: return new Comparison(false, false, "Empty or closetherby");
default:
return new Comparison();
}
}

private Comparison similar(OneFunction obj, LLM llm) {
List<String> thisCont = removeExtraInformation();
List<String> objCont = obj.removeExtraInformation();

int matchingLines = objCont.stream().filter(objLine -> thisCont.contains(objLine)).toList().size();

if ((matchingLines + 0.0)/objCont.size() > 0.5 || matchingLines > 10)
return new Comparison(false, true, "Matching lines " + matchingLines + " out of " + objCont.size()).setFunctions(this, obj);
else
return new Comparison(false, true, llmComparison(obj, llm)).setFunctions(this, obj);
}

@Override
public String toString() {
return file + ":" + line + " (" + name + ")";
Expand Down Expand Up @@ -57,7 +69,16 @@ private String removeLogAndComments() {
return this.content.stream().filter(s -> !s.matches("^\\s*\\/\\/")).filter(s -> s.startsWith("Log")).reduce("", (s, s1) -> s + "\n" + s);
}

private String removeLogAndCommentsAndMore() {
return this.content.stream().filter(s -> !s.matches("^\\s*\\/\\/")).filter(s -> s.replace(" ", "").length() < 2).collect(Collectors.joining("\n"));
private String removeExtraInformationAndGetString() {
return String.join("\n", removeExtraInformation());
}

private List<String> removeExtraInformation() {
return this.content.stream()
.map(s -> s.replaceAll("(.*)(//.*)+", "$1"))
.filter(s -> !s.matches("^\\s*//"))
.map(s -> s.replace(" ", ""))
.filter(s -> !s.startsWith("Log"))
.filter(s -> !s.isEmpty()).toList();
}
}

0 comments on commit 1927068

Please sign in to comment.