Sara Magliacane avatar Sara Magliacane committed 223db01

restructuring Experiment3 in order to have more fine-grained results

Comments (0)

Files changed (2)

src/nl/vu/recoprov/baseclasses/DependencyGraph.java

 
 public class DependencyGraph extends TreeMap<String, DependencyNode>{
 
+
+	private static final long serialVersionUID = 1L;
+
 	private HashMap<Integer, ArrayList<LabelledEdge>> incidendencyMatrix;
 	
 	public HashMap<Integer, String> translationMap;

src/nl/vu/recoprov/experiments/Experiment3.java

 
 import java.io.File;
 import java.io.FileWriter;
+import java.io.IOException;
+
 import nl.vu.recoprov.CompletePipeline;
 import nl.vu.recoprov.ProvDMtranslator;
 import nl.vu.recoprov.baseclasses.DependencyGraph;
 	
 	private static DependencyGraph baselineGraph = null;
 	
+	private static DependencyGraph depGraph;
 
-	
+	private static ProvDMtranslator provtranslator = new  ProvDMtranslator();
 
 	
 	
 	
 	
 	public static void main(String[] args) throws Exception {
-		
+
 		System.out.println("Experiment 3: Plagiarism Detection Corpus");
-		
+
 		File dir = new File(dirfile);
 		dirfile = dir.getAbsolutePath();
-		
+
 		File json = new File(jsonfile);
 		jsonfile = json.getAbsolutePath();
-		
+
 		PROVReader provreader = new PROVReader(dirfile, jsonfile);
-		ProvDMtranslator provtranslator = new  ProvDMtranslator();
-
-		ConfigurationDefaults.LUCENE_THRESHOLD = 0.01;
-
-		// use only Lucene
-		DependencyGraph depGraph1 = createGraph();
-		depGraph1 = new LuceneSimilaritySignal().computeSignal(depGraph1);
-		//depGraph1 = new LuceneInverseSimilarity().computeSignal(depGraph1);
-		//depGraph1 = new BackwardTemporalFilter().filterSignals(depGraph1);
-		depGraph1 = new LuceneThresholdFilter().filterSignals(depGraph1);
-		depGraph1 = new WeightedSumAggregator().aggregateSignals(depGraph1);
-		provtranslator.translate(depGraph1, "graphLucene.gv");
-		System.out.println("Done with baseline graph (Lucene)");
-		
-		
-		DependencyGraph depGraph =  provreader.generatePANDepGraph();
-		provtranslator.translate(depGraph, "graphCorpus.gv");
-		System.out.println("Done with reference graph");
-		// Compare with Transitive Closure
-		DependencyGraph depGraphT = new TransitiveClosure()
-				.aggregateSignals(depGraph);
-		provtranslator.translate(depGraphT, "graphCorpus_Trans.gv");
-		
-		
-		
-		DependencyGraph depGraph2 = createGraph();
-		depGraph2 = new LuceneMoreLikeThisSignal().computeSignal(depGraph2);
-		//depGraph1 = new LuceneInverseSimilarity().computeSignal(depGraph1);
-		depGraph2 = new TextContainmentFilter().filterSignals(depGraph2);
-		depGraph2 = new LuceneThresholdFilter().filterSignals(depGraph2);
-		depGraph2 = new WeightedSumAggregator().aggregateSignals(depGraph2);
-		provtranslator.translate(depGraph2, "graphLucene_BackFilter.gv");
-		System.out.println("Done with reduced graph (Lucene more like this)");
-		
-		
+
 		File logfile = new File("log" + System.currentTimeMillis() + ".txt");
 		FileWriter writer = new FileWriter(logfile);
-		
-		//writer.append("Original \n" + depGraph + "\n \n \n");
-		
-		writer.append("\n\nLucene: \n");
-		String temp = depGraph.similarToGraph(depGraph1).toString();
-		writer.append(temp);
-		
-		writer.append("\n\nLucene - MoreLikeThis: \n");
-		String temp2 = depGraph.similarToGraph(depGraph2).toString();
-		writer.append(temp2);
-		
-		writer.append("\n\n \n Predicted\n" + depGraph1 + "\n");
-		
-		writer.append("\n\n \n Reduced \n" + depGraph2 + "\n");
-		
-		writer.flush();
 
+		// useful for small experiments
+		//double[] thresholds = { 0, 0.01, 0.05, 0.1, 0.2, 0.3 };
 
-		
-		
-//		writer.append("\n\nLucene- TransitiveClosure: \n");
-//		DependencyGraph depGraph11 = new TransitiveClosure()
-//				.aggregateSignals(depGraph1);
-//		writer.append((depGraphT.similarToGraph(depGraph11).toString()));
-//		new ProvDMtranslator().translate(depGraph11,
-//				"graphLucene_BackFilter_Trans.gv");
-//		
-//		depGraph1 = null;
-//		depGraph11 = null;
-//
-//		// use Lucene and metadata similarity
-//		DependencyGraph depGraph2 = createGraph();
-//		depGraph2 = new LuceneSimilaritySignal().computeSignal(depGraph2);
-//		depGraph2 = new MetadataSimilaritySignal().computeSignal(depGraph2);
-//		depGraph2 = new BackwardTemporalFilter().filterSignals(depGraph2);
-//		depGraph2 = new WeightedSumAggregator().aggregateSignals(depGraph2);
-//		writer.append("\n\nLucene, Metadata - Filter: \n");
-//		writer.append(depGraph.similarToGraph(depGraph2).toString());
-//		writer.append("\n" + depGraph2.toBooleanArray() + "\n");
-//		new ProvDMtranslator().translate(depGraph2,
-//				"graphLuceneMetadata_BackFilter.gv");
-//		writer.flush();
-//
-//		writer.append("\n\nLucene, Metadata- TransitiveClosure: \n");
-//		DependencyGraph depGraph12 = new TransitiveClosure()
-//				.aggregateSignals(depGraph2);
-//		System.out.println(depGraphT.similarToGraph(depGraph12).toString());
-//		writer.append((depGraphT.similarToGraph(depGraph12).toString()));
-//		new ProvDMtranslator().translate(depGraph12,
-//				"graphLuceneMetadata_BackFilter_Trans.gv");
-//		
-//		depGraph2 = null;
-//		depGraph12 = null;
-//
-//		DependencyGraph depGraph3 = createGraph();
-//		depGraph3 = new LuceneSimilaritySignal().computeSignal(depGraph3);
-//		depGraph3 = new MetadataSimilaritySignal().computeSignal(depGraph3);
-//		depGraph3 = new LuceneInverseSimilarity().computeSignal(depGraph3);
-//		depGraph3 = new BackwardTemporalFilter().filterSignals(depGraph3);
-//		depGraph3 = new WeightedSumAggregator().aggregateSignals(depGraph3);
-//		writer.append("\n\nLucene, Metadata, Inverse - Filter: \n");
-//		writer.append(depGraph.similarToGraph(depGraph3).toString());
-//		writer.append("\n" + depGraph3.toBooleanArray() + "\n");
-//		new ProvDMtranslator().translate(depGraph3,
-//				"graphLuceneMetadata_Inverse_BackFilter.gv");
-//		writer.flush();
-//
-//		writer.append("\n\nLucene, Metadata- TransitiveClosure: \n");
-//		DependencyGraph depGraph13 = new TransitiveClosure()
-//				.aggregateSignals(depGraph3);
-//		System.out.println(depGraphT.similarToGraph(depGraph13).toString());
-//		writer.append((depGraphT.similarToGraph(depGraph13).toString()));
-//		new ProvDMtranslator().translate(depGraph13,
-//				"graphLuceneMetadataInverse_BackFilter_Trans.gv");
-//		
-//		depGraph3 = null;
-//		depGraph13 = null;
-//		
-//		System.gc();
-//
-//		DependencyGraph depGraph4 = createGraph();
-//		depGraph4 = new LuceneSimilaritySignal().computeSignal(depGraph4);
-//		depGraph4 = new MetadataSimilaritySignal().computeSignal(depGraph4);
-//		depGraph4 = new LuceneInverseSimilarity().computeSignal(depGraph4);
-//		depGraph4 = new ImageSimilaritySignal().computeSignal(depGraph4);
-//		depGraph4 = new MatchTitleInContentSignal().computeSignal(depGraph4);
-//		depGraph4 = new BackwardTemporalFilter().filterSignals(depGraph4);
-//		depGraph4 = new WeightedSumAggregator().aggregateSignals(depGraph4);
-//		writer.append("\n\nLucene, Metadata, Image, Inverse - Filter: \n");
-//		writer.append(depGraph.similarToGraph(depGraph4).toString());
-//		writer.append("\n" + depGraph4.toBooleanArray() + "\n");
-//		new ProvDMtranslator().translate(depGraph4,
-//				"graphLuceneMetadataImageInverse_BackFilter.gv");
-//		writer.flush();
-//
-//		writer.append("\n\nLucene, Metadata, Image, Inverse - TransitiveClosure: \n");
-//		DependencyGraph depGraph14 = new TransitiveClosure()
-//				.aggregateSignals(depGraph4);
-//		System.out.println(depGraphT.similarToGraph(depGraph14).toString());
-//		writer.append((depGraphT.similarToGraph(depGraph14).toString()));
-//		new ProvDMtranslator().translate(depGraph14,
-//				"graphLuceneMetadataInverseImage_BackFilter_Trans.gv");
-//
-//		// transitive reduction
-//
-//		// String cmd = "tred " + ;
-//		// Runtime run = Runtime.getRuntime();
-//		// Process pr = run.exec(cmd);
-//		// pr.waitFor();
-//		// BufferedReader buf = new BufferedReader(new
-//		// InputStreamReader(pr.getInputStream()));
-//		// String line = "";
-//		// while ((line=buf.readLine())!=null) {
-//		// System.out.println(line);
-//		// }
-//
-//		// Compare with Transitive Closure - currently not working
-//		// DependencyGraph depGraphTR = new
-//		// TransitiveReductionFilter().filterSignals(depGraphT);
-//		// new ProvDMtranslator().translate(depGraphTR,
-//		// "graphCorpus_TransR.gv");
-//		//
-//		// writer.append("\n\nLucene, Metadata, Match title and Image- TransitiveClosure - Transitive Reduction: \n");
-//		// depGraph14 = new
-//		// TransitiveReductionFilter().filterSignals(depGraph14);
-//		// writer.append(depGraphTR.similarToGraph(depGraph14).toString());
-//		// new ProvDMtranslator().translate(depGraph14,
-//		// "graphLuceneMetadataTitleImage_BackFilter_TransR.gv");
-//		//
-//		// writer.append("\n\nLucene, Metadata, Match title and Image- TransitiveClosure - Transitive Reduction - compared to original: \n");
-//		// writer.append(depGraph.similarToGraph(depGraph14).toString());
+		double[] thresholds = { 0.1};
+		for (double threshold : thresholds) {
+
+			ConfigurationDefaults.LUCENE_THRESHOLD = threshold;
+
+			// use only Lucene
+			DependencyGraph depGraph1 = createGraph();
+			depGraph1 = new LuceneSimilaritySignal().computeSignal(depGraph1);
+			depGraph1 = new LuceneThresholdFilter().filterSignals(depGraph1);
+			depGraph1 = new WeightedSumAggregator().aggregateSignals(depGraph1);
+			System.out.println("Done with baseline graph (Lucene)");
+
+			depGraph = provreader.generatePANDepGraph();
+			provtranslator.translate(depGraph, "graphCorpus.gv");
+			System.out.println("Done with reference graph");
+			// Compare with Transitive Closure
+			DependencyGraph depGraphT = new TransitiveClosure()
+					.aggregateSignals(depGraph);
+			provtranslator.translate(depGraphT, "graphCorpus_Trans.gv");
+
+			writeResults(depGraph1, "Lucene", writer);
 
+			depGraph1 = createGraph();
+			depGraph1 = new LuceneMoreLikeThisSignal().computeSignal(depGraph1);
+			depGraph1 = new LuceneThresholdFilter().filterSignals(depGraph1);
+			depGraph1 = new WeightedSumAggregator().aggregateSignals(depGraph1);
+			System.out.println("Done with Lucene more like this");
+			writeResults(depGraph1, "LuceneMoreLikeThis", writer);
+
+			depGraph1 = createGraph();
+			depGraph1 = new LuceneSimilaritySignal().computeSignal(depGraph1);
+			depGraph1 = new LuceneThresholdFilter().filterSignals(depGraph1);
+			depGraph1 = new TextContainmentFilter().filterSignals(depGraph1);
+			depGraph1 = new WeightedSumAggregator().aggregateSignals(depGraph1);
+			System.out.println("Done with Lucene + Filter");
+			writeResults(depGraph1, "LuceneFilter", writer);
+
+			depGraph1 = createGraph();
+			depGraph1 = new LuceneMoreLikeThisSignal().computeSignal(depGraph1);
+			depGraph1 = new LuceneThresholdFilter().filterSignals(depGraph1);
+			depGraph1 = new TextContainmentFilter().filterSignals(depGraph1);
+			depGraph1 = new WeightedSumAggregator().aggregateSignals(depGraph1);
+			System.out.println("Done with Lucene more like this + Filter");
+			writeResults(depGraph1, "LuceneMoreLikeThisFilter", writer);
+		}
 		writer.flush();
 		writer.close();
 
 	}
+	
+	private static void writeResults(DependencyGraph predicted, String message, FileWriter writer) throws IOException{
+		writer.append("\n\n"+ message +" \nLucene Threshold: " + ConfigurationDefaults.LUCENE_THRESHOLD + "\n");
+		String temp = depGraph.similarToGraph(predicted).toString();
+		writer.append(temp);
+		writer.flush();
+		
+		provtranslator.translate(predicted, "graph"+message+"_"+ConfigurationDefaults.LUCENE_THRESHOLD+".gv");
+		System.out.println("Done with baseline graph (Lucene)");
+	
+	}
+	
 
  		
 	public static DependencyGraph createGraph(){
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.