Skip to content

Blackbox #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: blackbox
Choose a base branch
from
32 changes: 32 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="CTD/src"/>
<classpathentry kind="src" path="data/F19_Project_3_2/task1/[email protected]_social-network_p32-task1_20191013053247"/>
<classpathentry kind="src" path="data/F19_Project_3_2/task2/[email protected]_social-network_p32-task2_20191013053354"/>
<classpathentry kind="src" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013050650"/>
<classpathentry kind="src" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013051101"/>
<classpathentry kind="src" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013051714"/>
<classpathentry kind="src" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013051925"/>
<classpathentry kind="src" path="HintEvaluation/src"/>
<classpathentry kind="src" path="HintServer/src"/>
<classpathentry kind="src" path="iSnap/src"/>
<classpathentry kind="src" path="JavaParser/src"/>
<classpathentry kind="src" path="QualityScore/src"/>
<classpathentry kind="src" path="SnapParser/src"/>
<classpathentry kind="src" path="Templater/src"/>
<classpathentry kind="lib" path="CTD/RTED_v1.1.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013184035/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013184306/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013185737/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task4/[email protected]_social-network_p32-task4_20191013190657/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task5/[email protected]_social-network_p32-task5_20191013193400/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task5/[email protected]_social-network_p32-task5_20191013193529/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task5/[email protected]_social-network_p32-task5_20191013193622/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="data/F19_Project_3_2/task5/[email protected]_social-network_p32-task5_20191013193716/target/undertow-server-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="HintEvaluation/apted.jar"/>
<classpathentry kind="lib" path="HintEvaluation/FITObjectGraphAPI-3.0.1.jar"/>
<classpathentry kind="lib" path="HintEvaluation/FITObjectGraphs-3.0.1.jar"/>
<classpathentry kind="lib" path="HintEvaluation/FITValidators-2.0.0.jar"/>
<classpathentry kind="output" path="CTD/target/classes"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Clustering</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
3 changes: 2 additions & 1 deletion CTD/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="RTED_v1.1.jar"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="RTED_v1.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
3 changes: 3 additions & 0 deletions CTD/src/edu/isnap/hint/HintConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public abstract class HintConfig implements Serializable {

/** If true, uses new version of SourceCheck with more global alignment */
public boolean sourceCheckV2 = false;

/** If true, uses reference solutions to get high-level hints */
public boolean useAnnotation = true;

/**
* Should return true if the hint generator can expect traces to keep consistent node IDs
Expand Down
18 changes: 18 additions & 0 deletions CTD/src/edu/isnap/hint/HintData.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.isnap.hint;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import edu.isnap.ctd.hint.CTDHintGenerator;
Expand All @@ -17,7 +18,15 @@ public class HintData {
public final double minGrade;
public final HintConfig config;
private final List<IDataModel> dataModels;
private LinkedHashMap<Integer, Node> referenceSolutions;

/**
* @param assignment the name of java file used in this assignment. Omit ".java".
* @param config
* @param minGrade
* @param consumer
* @param additionalConsumers
*/
public HintData(String assignment, HintConfig config, double minGrade,
IDataConsumer consumer, IDataConsumer... additionalConsumers) {
this.assignment = assignment;
Expand All @@ -29,6 +38,7 @@ public HintData(String assignment, HintConfig config, double minGrade,
for (IDataConsumer con : additionalConsumers) {
addDataModels(con.getRequiredData(this));
}
referenceSolutions = new LinkedHashMap<>();
}

private void addDataModels(IDataModel[] models) {
Expand Down Expand Up @@ -73,4 +83,12 @@ public CTDHintGenerator hintGenerator() {
public HintHighlighter hintHighlighter() {
return new HintHighlighter(this);
}

public LinkedHashMap<Integer, Node> getReferenceSolutions() {
return referenceSolutions;
}

public Node addReferenceSoltion(int clusterID, Node solution) {
return referenceSolutions.put(clusterID, solution);
}
}
25 changes: 19 additions & 6 deletions CTD/src/edu/isnap/hint/util/Alignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public static double normAlignCost(String[] sequenceA, String[] sequenceB, int i
}

// Credit: http://introcs.cs.princeton.edu/java/96optimization/Diff.java.html
/**
* @param sequenceA
* @param sequenceB
* @param insCost
* @param delCost
* @param subCost
* @return Levenshtein distance between "sequenceA" and "sequenceB"??
*/
public static int alignCost(String[] sequenceA, String[] sequenceB, int insCost, int delCost,
int subCost) {
int[][] opt = createAlignmentMatrix(sequenceA, sequenceB, insCost, delCost, subCost, false);
Expand Down Expand Up @@ -300,7 +308,7 @@ private static int correspondingIndexBefore(List<int[]> pairs, List<String> sequ
return closestA;
}

private static int[][] createAlignmentMatrix(String[] sequenceA, String[] sequenceB,
public static int[][] createAlignmentMatrix(String[] sequenceA, String[] sequenceB,
int insCost, int delCost, int subCost, boolean flipInvalid) {
// The penalties to apply
int matchCost = 0;
Expand Down Expand Up @@ -397,7 +405,7 @@ public static int[] reorderIndices(String[] from, String[] to, int[] toOrderGrou
return toIndices;
}

public static int getProgress(String[] from, String[] to, int orderReward, int unorderReward) {
public static double getProgress(String[] from, String[] to, int orderReward, int unorderReward) {
return (int) Math.round(getProgress(from, to, orderReward, unorderReward, 0));
}

Expand All @@ -417,14 +425,19 @@ public static double getProgress(String[] from, String[] to, int[] toOrderGroups
private static double getProgress(String[] from, String[] to, int[] toOrderGroups,
int orderReward, int unorderReward, double skipCost, int[] toIndices) {
// TODO: This can and should be much more efficient
// toList[k] = "\0" if the k-th node in c(b_{rj}) is in c(a_{ri})
List<String> toList = new LinkedList<>(Arrays.asList(to));

// If indices[k] = l, k-th node in c(a_{ri}) is l-th node in c(b_{rj})
// If indices[k] = -1, k-th node in c(a_{ri}) is not in c(b_{rj})
int[] indices = new int[from.length];
for (int i = 0; i < from.length; i++) {
String item = from[i];
int index = toList.indexOf(item);
if (index >= 0) {
toList.set(index, "\0");
if (index >= 0) { // i-th node in c(a_{ri}) is in c(b_{rj})
// if (orderReward == 1 && unorderReward == 1) {
toList.set(index, "\0"); // prevents multiple matches
// }
indices[i] = index;
} else {
indices[i] = -1;
Expand All @@ -437,7 +450,7 @@ private static double getProgress(String[] from, String[] to, int[] toOrderGroup
int lastIndex = -1;
int maxIndex = -1;
for (Integer index : indices) {
if (index < 0) continue;
if (index < 0) continue; // don't change reward if k-th node in c(a_{ri}) is not in c(b_{rj})
int adjIndex = index;
int group;
// System.out.println(index);
Expand Down Expand Up @@ -487,7 +500,7 @@ private static double getProgress(String[] from, String[] to, int[] toOrderGroup
* including duplicates
*/
public static int getMissingNodeCount(String[] from, String[] to) {
return to.length - getProgress(to, from, 1, 1);
return to.length - (int) getProgress(to, from, 1, 1);
}

public static void main(String[] args) {
Expand Down
27 changes: 27 additions & 0 deletions CTD/src/edu/isnap/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public abstract class Node extends StringHashable implements INode {
public final String value;
public final Node parent;
public final List<Node> children = new ArrayList<>();
private String studentID;
private String submissionTime;

public transient Object tag;
public final transient List<Canonicalization> canonicalizations = new ArrayList<>();
Expand Down Expand Up @@ -501,6 +503,10 @@ public String prettyPrintWithIDs() {
return prettyPrint(false, new HashMap<Node, String>());
}

/**
* @return a list of strings of types obtained by depth-first iteration of
* the AST rooted at this node
*/
public String[] depthFirstIteration() {
String[] array = new String[treeSize()];
depthFirstIteration(array, 0);
Expand Down Expand Up @@ -683,6 +689,11 @@ public static Node fromASTNode(ASTNode astNode, Node parent, NodeConstructor con
Node node = constructor.constructNode(parent, type, astNode.value, astNode.id);
node.readFromASTNode(astNode);
node.tag = astNode;
if (astNode.annotation != null) {
node.writableAnnotations();
TextHint hint = new TextHint(astNode.annotation, 1);
node.addTextHint(hint);
}
for (ASTNode child : astNode.children()) {
node.children.add(fromASTNode(child, node, constructor));
}
Expand All @@ -697,4 +708,20 @@ protected void readFromASTNode(ASTNode node) {
public String toString() {
return prettyPrint(true);
}

public String getStudentID() {
return studentID;
}

public void setStudentID(String studentID) {
this.studentID = studentID;
}

public String getSubmissionTime() {
return submissionTime;
}

public void setSubmissionTime(String submissionTime) {
this.submissionTime = submissionTime;
}
}
26 changes: 21 additions & 5 deletions CTD/src/edu/isnap/node/TextualNode.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package edu.isnap.node;

import java.util.Optional;

import org.json.JSONObject;

import java.util.Optional;
import org.json.JSONObject;
import edu.isnap.node.ASTNode.SourceLocation;
import edu.isnap.sourcecheck.NodeAlignment.Mapping;

public abstract class TextualNode extends Node {

public Optional<Boolean> correct = Optional.empty();
public Optional<Integer> cluster = Optional.empty();
private String source;

// TODO: Protect
Expand Down Expand Up @@ -49,7 +50,7 @@ public String getSource() {
String rootSource = ((TextualNode) root()).source;
if (startSourceLocation == null && endSourceLocation == null) return null;
return rootSource.substring(
toIndex(rootSource, startSourceLocation),
toIndex(rootSource, startSourceLocation) - 1,
toIndex(rootSource, endSourceLocation));
}

Expand Down Expand Up @@ -104,12 +105,27 @@ public SourceLocation getLocationOfChildIndex(int index) {
return null;
}

public static TextualNode fromJSON(JSONObject jsonAST, String source,
NodeConstructor constructor) {
public static TextualNode fromJSON(JSONObject jsonAST, String source, NodeConstructor constructor) {
ASTSnapshot astNode = ASTSnapshot.parse(jsonAST, source);
TextualNode node = (TextualNode) fromASTNode(astNode, constructor);
node.source = source;
node.correct = Optional.of(astNode.isCorrect);
return node;
}

/**
* Overloaded method to get clusterID
* @param jsonAST
* @param id
* @param source
* @param constructor
* @return
*/
public static TextualNode fromJSON(JSONObject jsonAST,String id, String source, NodeConstructor constructor) {
ASTSnapshot astNode = ASTSnapshot.parse(jsonAST, id, source);
TextualNode node = (TextualNode) fromASTNode(astNode, constructor);
node.source = source;
node.correct = Optional.of(astNode.isCorrect);
return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<EditHint> highlightConsensus(Node node) {
double consensusThreshold = 0.6;

List<Mapping> matches = NodeAlignment.findBestMatches(
node, solutions, getDistanceMeasure(config), config, nMatches);
node, getSolutions(), getDistanceMeasure(config), config, nMatches);

final int n = matches.size();
final int thresh = (int) Math.ceil(n * consensusThreshold);
Expand Down
Loading