Commit b34c4362 authored by Pascal Reuss's avatar Pascal Reuss

Merge branch 'feature-issue-2' into 'mycbr-3.0.1'

String Similarity Measure Test

Added test for the string similarity measure that target Issue #2. However, I could not verify the problems.
parents c4aa8713 ee26e643
......@@ -3,8 +3,8 @@
*
* Copyright (c) 2009
* Thomas Roth-Berghofer, Armin Stahl & Deutsches Forschungszentrum für Künstliche Intelligenz DFKI GmbH
* Further contributors: myCBR Team (see http://mycbr-project.net/contact.html for further information
* about the myCBR Team).
* Further contributors: myCBR Team (see http://mycbr-project.net/contact.html for further information
* about the myCBR Team).
* All rights reserved.
*
* myCBR is free software; you can redistribute it and/or modify
......@@ -23,7 +23,7 @@
*
* Since myCBR uses some modules, you should be aware of their licenses for
* which you should have received a copy along with this program, too.
*
*
* endOfLic */
package test.junittest;
......@@ -43,7 +43,7 @@ import java.util.Date;
*
* @author myCBR Team
*/
public class StressTests {
public class StressTestsLoading {
// @Test
......
package test.junittest;
import de.dfki.mycbr.core.DefaultCaseBase;
import de.dfki.mycbr.core.Project;
import de.dfki.mycbr.core.casebase.Instance;
import de.dfki.mycbr.core.model.Concept;
import de.dfki.mycbr.core.retrieval.Retrieval;
import org.junit.Test;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by kerstin on 3/28/14.
*/
public class StressTestsRetrieval {
// Attributes grow exponentially
@Test
public void testRetievalIncreasingCases (){
int noAtts = 20;
int cases = 1;
int noCaseStep = cases;
int maxNoCases = 200;
long duration = 0L;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
FileWriter fw = null;
try {
fw = new FileWriter(System.getProperty("user.dir") + "/src/test/projects/StressTest/testRetievalIncreasingCasesAndAttributes"+maxNoCases+".csv");
PrintWriter pw = new PrintWriter(fw);
pw.print("noAtts");
pw.print(",");
pw.print("noCases");
pw.print(",");
pw.print("duration");
pw.print("\n");
StressTestFramework stf = new StressTestFramework();
String projectPath = stf.initStressTestFramework(noAtts, cases);
Project p = new Project(projectPath);
while (p.isImporting()){
Thread.sleep(1);
}
cases++;
Concept mainDesc = p.getConceptByID("main");
DefaultCaseBase cb = (DefaultCaseBase) p.getCaseBases().get("casebase");
// create query
Retrieval r = new Retrieval(mainDesc, cb);
Instance query = r.getQueryInstance();
do{
// add Case
String caseName = "case" + String.valueOf(cases);
Instance instance = mainDesc.addInstance(caseName);
for (String attName : mainDesc.getAttributeDescs().keySet()){
instance.addAttribute(mainDesc.getAttributeDesc(attName), (int) (Math.random() * 100));
}
cb.addCase(instance);
for (String attName : mainDesc.getAttributeDescs().keySet()){
query.addAttribute(mainDesc.getAttributeDesc(attName), (int) (Math.random() * 100));
}
// do retrieval
Date start = new Date();
r.setRetrievalMethod(Retrieval.RetrievalMethod.RETRIEVE_SORTED);
r.start();
Date end = new Date();
duration = end.getTime() - start.getTime();
// adding results to writer
double dur = ((double) duration) / 1000;
DecimalFormat decFormat = new DecimalFormat("###,###,##0.000");
decFormat.format(dur);
pw.print(noAtts);
pw.print(",");
pw.print(r.getResult().size());
pw.print(",");
pw.print(dur);
pw.print("\n");
// counting
cases++;
} while (cases < maxNoCases);
pw.flush();
pw.close();
fw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
......@@ -3,8 +3,8 @@
*
* Copyright (c) 2009
* Thomas Roth-Berghofer, Armin Stahl & Deutsches Forschungszentrum f&uuml;r K&uuml;nstliche Intelligenz DFKI GmbH
* Further contributors: myCBR Team (see http://mycbr-project.net/contact.html for further information
* about the myCBR Team).
* Further contributors: myCBR Team (see http://mycbr-project.net/contact.html for further information
* about the myCBR Team).
* All rights reserved.
*
* myCBR is free software; you can redistribute it and/or modify
......@@ -23,7 +23,7 @@
*
* Since myCBR uses some modules, you should be aware of their licenses for
* which you should have received a copy along with this program, too.
*
*
* endOfLic */
package test.junittest.similarity;
......@@ -41,27 +41,29 @@ import test.junittest.TestFramework;
*
*/
public class StringFunctionTest extends TestCase {
/**
* Test method for {@link de.dfki.mycbr.core.similarity.StringFct#calculateSimilarity(Attribute, Attribute)}.
* Test method for {@link de.dfki.mycbr.core.similarity.StringFct calculateSimilarity(Attribute, Attribute)}.
*/
@Test
public void testCalculateSimilarityEQUALITY() {
try {
TestFramework frame = new TestFramework();
StringFct f = frame.dealerDesc.addStringFct(StringConfig.EQUALITY, "f1", true);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24"), frame.dealerDesc.getStringAttribute("Car23")).getValue() == 0.0);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24"), frame.dealerDesc.getStringAttribute("Car24")).getValue() == 1.00);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24 Car24"), frame.dealerDesc.getStringAttribute("Car24")).getValue() == 0.0);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24 Car24"), frame.dealerDesc.getStringAttribute("Car24 Car24")).getValue() == 1.0);
} catch (Exception exp) {
assertTrue("Excpetion in StringFctTest: testCalculateSimilarityEQUALITY",false);
}
}
/**
* Test method for {@link de.dfki.mycbr.core.similarity.StringFct#calculateSimilarity(Attribute, Attribute)}.
* Test method for {@link de.dfki.mycbr.core.similarity.StringFct calculateSimilarity(Attribute, Attribute)}.
*/
@Test
public void testCalculateSimilarityNGRAM() {
......@@ -72,11 +74,14 @@ public class StringFunctionTest extends TestCase {
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24"), frame.dealerDesc.getStringAttribute("Car23")).getRoundedValue() == 0.5);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24"), frame.dealerDesc.getStringAttribute("Car24")).getRoundedValue() == 1.00);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24 Car24"), frame.dealerDesc.getStringAttribute("Car24")).getRoundedValue() == 0.5);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("Car24 Car24"), frame.dealerDesc.getStringAttribute("Car24 Car24")).getRoundedValue() == 1.0);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("trtr"), frame.dealerDesc.getStringAttribute("trtritri")).getRoundedValue() == 0.4);
assertTrue(f.calculateSimilarity(frame.dealerDesc.getStringAttribute("tritrtr"), frame.dealerDesc.getStringAttribute("tritr")).getRoundedValue() == 0.6);
} catch (Exception exp) {
assertTrue("Excpetion in StringFctTest: testCalculateSimilarityEQUALITY",false);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment