merge branches
authorymh <ymh.work@gmail.com>
Thu, 08 Apr 2010 13:07:46 +0200
changeset 10 e5fa7f4cc117
parent 9 6746733ca0ad (current diff)
parent 8 9f3b0b3a56a4 (diff)
child 11 04fc255b94fd
merge branches
WebContent/WEB-INF/lib/jackson-core-asl-1.1.1.jar
src/fr/iri/thd/sonyengine/test/TestEngine.java
--- a/.classpath	Tue Mar 30 19:17:23 2010 +0200
+++ b/.classpath	Thu Apr 08 13:07:46 2010 +0200
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src"/>
+	<classpathentry excluding="fr/iri/thd/sonyengine/test/" kind="src" path="src"/>
+	<classpathentry kind="src" output="build_test/classes" path="test_src"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
 		<attributes>
 			<attribute name="owner.project.facets" value="jst.java"/>
@@ -13,6 +14,15 @@
 	</classpathentry>
 	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
 	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
-	<classpathentry kind="lib" path="lib/junit-4.8.1.jar"/>
+	<classpathentry kind="lib" path="lib/jackson-mapper-asl-1.5.0.jar">
+		<attributes>
+			<attribute name="org.eclipse.jst.component.nondependency" value=""/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/junit-4.8.1.jar">
+		<attributes>
+			<attribute name="org.eclipse.jst.component.nondependency" value=""/>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="output" path="build/classes"/>
 </classpath>
--- a/.settings/org.eclipse.wst.common.component	Tue Mar 30 19:17:23 2010 +0200
+++ b/.settings/org.eclipse.wst.common.component	Thu Apr 08 13:07:46 2010 +0200
@@ -1,9 +1,10 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-modules id="moduleCoreId" project-version="1.5.0">
-<wb-module deploy-name="mosatags.sonyengine">
-<wb-resource deploy-path="/" source-path="/WebContent"/>
-<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
-<property name="context-root" value="mosatags.sonyengine"/>
-<property name="java-output-path" value="/mosatags.sonyengine/build/classes"/>
-</wb-module>
-</project-modules>
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+<wb-module deploy-name="mosatags.sonyengine">
+<wb-resource deploy-path="/" source-path="/WebContent"/>
+<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
+        <wb-resource deploy-path="/WEB-INF/classes" source-path="/test_src"/>
+<property name="context-root" value="mosatags.sonyengine"/>
+<property name="java-output-path" value="/mosatags.sonyengine/build/classes"/>
+</wb-module>
+</project-modules>
Binary file WebContent/WEB-INF/lib/jackson-core-asl-1.1.1.jar has changed
Binary file WebContent/WEB-INF/lib/jackson-core-asl-1.5.0.jar has changed
Binary file lib/jackson-mapper-asl-1.5.0.jar has changed
--- a/src/fr/iri/thd/sonyengine/test/TestEngine.java	Tue Mar 30 19:17:23 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,553 +0,0 @@
-package fr.iri.thd.sonyengine.test;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.ws.rs.core.MediaType;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import com.sleepycat.persist.EntityCursor;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.representation.Form;
-
-import fr.iri.thd.sonyengine.core.DataAccessor;
-import fr.iri.thd.sonyengine.core.DbEnv;
-
-/*
- * 
- * import java.io.File;
-
-import core.Tag;
-
-/**
- * A class to test ThdEngine
- *
- * @author pachet
- *
-public class ThdEngineTest {
-
- public static void main(String[] args) {
- testSimpleExampleManual();
-//   testSimpleExampleFile();
- // testUniversCineFile();
- }
-
- /**
- * Tests the engine with a small set of movies and tags, entered
-"manually", one by one
- private static void testSimpleExampleManual() {
- ThdEngine engine = ThdEngine.getEngine();
- engine.createMovieFragment("ref1");
- engine.createMovieFragment("ref2");
- engine.createMovieFragment("ref3");
- engine.createMovieFragment("ref4");
- engine.createMovieFragment("ref5");
- engine.createMovieFragment("ref6");
- engine.createMovieFragment("ref7");
-
- engine.addTag("crayon", "ref1");
- engine.addTag("carte", "ref1");
- engine.addTag("bateau", "ref1");
- engine.addTag("voiture", "ref1");
- engine.addTag("car", "ref1");
-
- engine.addTag("enfant", "ref2");
- engine.addTag("famille", "ref2");
- engine.addTag("violon", "ref2");
- engine.addTag("maison", "ref2");
- engine.addTag("hopital", "ref2");
-
- engine.addTag("enfant", "ref3");
- engine.addTag("famille", "ref3");
- engine.addTag("violon", "ref3");
- engine.addTag("maison", "ref3");
- engine.addTag("ordinateur", "ref3");
- engine.addTag("fenetre", "ref3");
- engine.addTag("voiture", "ref3");
- engine.addTag("guitare", "ref3");
- engine.addTag("carte", "ref3");
-
- engine.addTag("enfant", "ref4");
- engine.addTag("famille", "ref4");
- engine.addTag("violon", "ref4");
- engine.addTag("bateau", "ref4");
- engine.addTag("ordinateur", "ref4");
- engine.addTag("fenetre", "ref4");
- engine.addTag("stylo", "ref4");
- engine.addTag("perroquet", "ref4");
- engine.addTag("crayon", "ref4");
- engine.addTag("tele", "ref4");
- engine.addTag("bateau", "ref4");
-
- engine.addTag("ordinateur", "ref5");
- engine.addTag("crayon", "ref5");
- engine.addTag("fenetre", "ref5");
- engine.addTag("hopital", "ref5");
- engine.addTag("carte", "ref5");
- engine.addTag("tele", "ref5");
- engine.addTag("stylo", "ref5");
- engine.addTag("perroquet", "ref5");
- engine.addTag("bateau", "ref5");
- engine.addTag("guitare", "ref5");
-
- engine.addTag("maison", "ref6");
- engine.addTag("perroquet", "ref6");
- engine.addTag("stylo", "ref6");
- engine.addTag("guitare", "ref6");
- engine.addTag("hopital", "ref6");
- engine.addTag("tele", "ref6");
- engine.addTag("car", "ref6");
- engine.addTag("voiture", "ref6");
- engine.addTag("fenetre", "ref6");
-
- engine.addTag("car", "ref7");
- engine.addTag("voiture", "ref7");
-
- engine.reTrain();
- engine.showAllTagValues();
-
- //Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
-
- while (neighbor != null) {
-  System.out.println(neighbor.getMovieRef() + " distance: "
-    + neighbor.getDistance());
-  neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
-    true);
- }
- System.out.println("cannot find any better");
- }
-
- /**
- * Tests the engine with a xcl file containing references of movies and
- * their tags. esult should be the same than testSimpleExampleManual()
- public static void testSimpleExampleFile() {
- ThdEngine engine = ThdEngine.getEngine();
- engine.loadFromTextFile(new File("./Sessions/Essai.csv"));
- System.out.println("number of movies read: "
-   + engine.getAllMovieFragments().size());
-
- engine.reTrain();
- engine.showAllTagValues();
-
- Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
-
- while (neighbor != null) {
-  System.out.println(neighbor.getMovieRef() + " distance: "
-    + neighbor.getDistance());
-  neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
-    true);
- }
- System.out.println("cannot find any better");
- }
-
- /**
- * Tests the engine with a xcl file containing references of movies and
- * their tags
- public static void testUniversCineFile() {
- ThdEngine engine = ThdEngine.getEngine();
- engine.loadFromTextFile(new File("./Sessions/MovieFrame2.csv"));
- System.out.println("number of movies read: "
-   + engine.getAllMovieFragments().size());
- ThdMovieFragment sobibor = engine
-   .movieFragmentNamed("Sobibor, 14 octobre 1943, 16 heures");
- engine.reTrain();
-
- Tag T_enfant = engine.tagNamed("Enfant");
- System.out.println(sobibor);
- System.out.println(T_enfant);
-
- engine.tagNamed("Enfant").valueFor(sobibor);
-
- Neighbor neighbor = engine.findMore(sobibor.getName(), "Enfant", .05f,
-   true);
-
- while (neighbor != null) {
-  System.out.println(neighbor.getMovieRef() + " distance: "
-    + neighbor.getDistance());
-  neighbor = engine.findMore(neighbor.getMovieRef(), "Enfant", .05f,
-    true);
- }
- System.out.println("cannot find any better");
- }
-
-}
-
- * 
- * 
- * 
- * 
- * 
- */
-
-
-
-public class TestEngine {
-
-	public static final String BASE_URL = "http://localhost:9080/sonyengine/";
-	public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
-
-	private DbEnv dbenv = null;
-	private File databasePathFile = null;
-	private String baseurl = null;
-			
-	@Before
-	public void setup()
-	{
-		String databasepath = System.getProperty("database_path");
-		if(databasepath == null)
-			databasepath = DATABASE_PATH;
-		databasePathFile = new File(databasepath);
-		
-		this.baseurl = System.getProperty("baseurl");
-		if(this.baseurl == null)
-			this.baseurl = BASE_URL;
-		
-		if(this.baseurl != null) {
-			if(!this.baseurl.endsWith("/")) {
-				this.baseurl += "/";
-			}
-		}
-	}
-	
-	@After
-	public void teardown() {
-	
-		if(dbenv != null)
-			dbenv.close();
-	}
-	
-	@Test
-	public void testCreateMovieFragment() {
-				
-		String movieName = "movie" + System.currentTimeMillis();
-		
-		Client c = Client.create();
-		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
-		
-		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
-				
-		Assert.assertNotNull(response);
-		
-		
-		dbenv = new DbEnv();
-		dbenv.setup(databasePathFile, true, true);
-
-		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
-		
-		EntityCursor<String> cursor = da.movieFragmentById.keys();
-		
-		for (String key : cursor) {
-			Assert.assertNotNull(key);
-		}
-		
-		cursor.close();
-		
-		Assert.assertTrue(da.movieFragmentById.contains(movieName));
-		
-	}
-
-	@Test
-	public void testCreateMovieFragmentForm() {
-				
-		String movieName = "movie" + System.currentTimeMillis();
-		
-		Client c = Client.create();
-		
-		Form form = new Form();
-		form.add("id", movieName);
-		
-		WebResource res = c.resource(this.baseurl + "segment/create");		
-
-		String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, form);
-				
-		Assert.assertNotNull(response);
-		
-		dbenv = new DbEnv();
-		dbenv.setup(databasePathFile, true, true);
-
-		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
-		
-		EntityCursor<String> cursor = da.movieFragmentById.keys();
-		
-		for (String key : cursor) {
-			Assert.assertNotNull(key);
-		}
-		
-		cursor.close();
-		
-		Assert.assertTrue(da.movieFragmentById.contains(movieName));
-		
-	}
-
-	
-	@Test
-	public void testCreateTag() {
-
-		String movieName = "movie" + System.currentTimeMillis();
-		String tagName = "tag" + System.currentTimeMillis();;
-		
-		Client c = Client.create();
-		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
-		String response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-				
-		Assert.assertNotNull(response);
-		
-		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName);
-		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
-
-		Assert.assertNotNull(response);
-
-		dbenv = new DbEnv();
-		dbenv.setup(databasePathFile, true, true);
-
-		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-		
-		Assert.assertTrue(da.tagByName.contains(tagName));
-		
-	}
-
-	@Test
-	public void testCreateTagList() {
-
-		String movieName = "movie" + System.currentTimeMillis();
-		
-		List<String> tagNames = new ArrayList<String>();
-		
-		for(int i=0; i< 10; i++) {
-			try {
-				Thread.sleep(1);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-			tagNames.add("tag" + System.currentTimeMillis());
-		}
-		
-		Client c = Client.create();
-		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
-		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
-				
-		Assert.assertNotNull(response);
-		
-		String xml = "<tags>";
-		for(String tagName: tagNames) {
-			xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
-		}
-		xml += "</tags>";
-		
-		res = c.resource(this.baseurl).path("tag").path("add");
-		Form form = new Form();
-		form.add("xml", xml);
-		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
-		Assert.assertNotNull(response);
-
-		dbenv = new DbEnv();
-		dbenv.setup(databasePathFile, true, true);
-
-		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-		
-		for(String tagName: tagNames) {		
-			Assert.assertTrue(da.tagByName.contains(tagName));
-		}
-		
-	}
-	
-	@Test
-	public void testCreateSequenceList() {
-
-		List<String> movieIds = new ArrayList<String>();
-		
-		for(int i=0; i< 10; i++) {
-			try {
-				Thread.sleep(1);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-			movieIds.add("movie" + System.currentTimeMillis());
-		}
-				
-		String xml = "<segments>";
-		for(String sequenceId: movieIds) {
-			xml += String.format("<segment id=\"%s\"/>", sequenceId);
-		}
-		xml += "</segments>";
-		
-		Client c = Client.create();
-		WebResource res = c.resource(this.baseurl).path("segment").path("createall");
-		Form form = new Form();
-		form.add("xml", xml);
-		String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
-		Assert.assertNotNull(response);
-
-		dbenv = new DbEnv();
-		dbenv.setup(databasePathFile, true, true);
-
-		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-		
-		for(String sequenceId: movieIds) {		
-			Assert.assertTrue(da.movieFragmentById.contains(sequenceId));
-		}
-		
-	}
-	
-	
-	@Test
-	public void testReset() {
-		Client c = Client.create();
-		WebResource res = c.resource(this.baseurl);
-		String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
-		
-		Assert.assertEquals(response, "ok");
-		
-		dbenv = new DbEnv();
-		dbenv.setup(databasePathFile, true, true);
-
-		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
-
-		Assert.assertEquals(0, da.movieFragmentById.count());
-		Assert.assertEquals(0, da.tagById.count());
-		Assert.assertEquals(0, da.tagByName.count());
-		Assert.assertEquals(0, da.tagBySegment.count());		
-		
-	}
-	
-	@Test
-	public void testTrain() {
-
-		Client c = Client.create();
-		WebResource res = c.resource(this.baseurl);
-		String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
-		
-		String[] ids = new String[]{"ref1","ref2","ref3","ref4","ref5","ref6", "ref7"};
-
-		String xmlSegment = "<segments>";
-		for(String sequenceId: ids) {
-			xmlSegment += String.format("<segment id=\"%s\"/>", sequenceId);
-		}
-		xmlSegment += "</segments>";
-
-		c = Client.create();
-		res = c.resource(this.baseurl).path("segment").path("createall");
-		Form form = new Form();
-		form.add("xml", xmlSegment);
-		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
-		Assert.assertNotNull(response);
-
-		
-		ArrayList<String[]> tags = new ArrayList<String[]>();
-		tags.add(new String[]{"crayon", "ref1"});
-		tags.add(new String[]{"carte", "ref1"});
-		tags.add(new String[]{"bateau", "ref1"});
-		tags.add(new String[]{"voiture", "ref1"});
-		tags.add(new String[]{"car", "ref1"});
-
-		tags.add(new String[]{"enfant", "ref2"});
-		tags.add(new String[]{"famille", "ref2"});
-		tags.add(new String[]{"violon", "ref2"});
-		tags.add(new String[]{"maison", "ref2"});
-		tags.add(new String[]{"hopital", "ref2"});
-
-		tags.add(new String[]{"enfant", "ref3"});
-		tags.add(new String[]{"famille", "ref3"});
-		tags.add(new String[]{"violon", "ref3"});
-		tags.add(new String[]{"maison", "ref3"});
-		tags.add(new String[]{"ordinateur", "ref3"});
-		tags.add(new String[]{"fenetre", "ref3"});
-		tags.add(new String[]{"voiture", "ref3"});
-		tags.add(new String[]{"guitare", "ref3"});
-		tags.add(new String[]{"carte", "ref3"});
-
-		tags.add(new String[]{"enfant", "ref4"});
-		tags.add(new String[]{"famille", "ref4"});
-		tags.add(new String[]{"violon", "ref4"});
-		tags.add(new String[]{"bateau", "ref4"});
-		tags.add(new String[]{"ordinateur", "ref4"});
-		tags.add(new String[]{"fenetre", "ref4"});
-		tags.add(new String[]{"stylo", "ref4"});
-		tags.add(new String[]{"perroquet", "ref4"});
-		tags.add(new String[]{"crayon", "ref4"});
-		tags.add(new String[]{"tele", "ref4"});
-		tags.add(new String[]{"bateau", "ref4"});
-		
-		tags.add(new String[]{"ordinateur", "ref5"});
-		tags.add(new String[]{"crayon", "ref5"});
-		tags.add(new String[]{"fenetre", "ref5"});
-		tags.add(new String[]{"hopital", "ref5"});
-		tags.add(new String[]{"carte", "ref5"});
-		tags.add(new String[]{"tele", "ref5"});
-		tags.add(new String[]{"stylo", "ref5"});
-		tags.add(new String[]{"perroquet", "ref5"});
-		tags.add(new String[]{"bateau", "ref5"});
-		tags.add(new String[]{"guitare", "ref5"});
-		
-		tags.add(new String[]{"maison", "ref6"});
-		tags.add(new String[]{"perroquet", "ref6"});
-		tags.add(new String[]{"stylo", "ref6"});
-		tags.add(new String[]{"guitare", "ref6"});
-		tags.add(new String[]{"hopital", "ref6"});
-		tags.add(new String[]{"tele", "ref6"});
-		tags.add(new String[]{"car", "ref6"});
-		tags.add(new String[]{"voiture", "ref6"});
-		tags.add(new String[]{"fenetre", "ref6"});
-		
-		tags.add(new String[]{"car", "ref7"});
-		tags.add(new String[]{"voiture", "ref7"});
-
-		String xmlTags = "<tags>";
-		for(String[] tagdef: tags) {
-			xmlTags += String.format("<tag name=\"%s\" segment=\"%s\"/>", (Object[])tagdef);
-		}
-		xmlTags += "</tags>";
-
-		res = c.resource(this.baseurl).path("tag").path("add");
-		form = new Form();
-		form.add("xml", xmlTags);
-		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
-
-		Assert.assertNotNull(response);
-
-		//"engine/find/{segment}/{tag}/{percent}/{more}"
-		//Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
-		res = c.resource(this.baseurl).path("engine").path("find").path("ref1").path("enfant").path("0.05").path("true");
-		response = res.accept(MediaType.APPLICATION_XML_TYPE).get(String.class);
-		Assert.assertNotNull(response);
-		
-		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-    	InputSource source = new InputSource(new StringReader(response));
-    	Document doc = null;
-		try {
-			doc = factory.newDocumentBuilder().parse(source);
-		} catch (SAXException e) {
-			e.printStackTrace();
-		} catch (IOException e) {
-			e.printStackTrace();
-		} catch (ParserConfigurationException e) {
-			e.printStackTrace();
-		}
-		
-		NodeList nodes = doc.getElementsByTagName("neighbor");
-		
-		Assert.assertEquals(1, nodes.getLength());
-		
-	}
-	
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fr/iri/thd/sonyengine/test/TestEngineResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -0,0 +1,390 @@
+package fr.iri.thd.sonyengine.test.old;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.representation.Form;
+
+import fr.iri.thd.sonyengine.core.DataAccessor;
+import fr.iri.thd.sonyengine.core.DbEnv;
+
+/*
+ * 
+ * import java.io.File;
+
+import core.Tag;
+
+/**
+ * A class to test ThdEngine
+ *
+ * @author pachet
+ *
+public class ThdEngineTest {
+
+ public static void main(String[] args) {
+ testSimpleExampleManual();
+//   testSimpleExampleFile();
+ // testUniversCineFile();
+ }
+
+ /**
+ * Tests the engine with a small set of movies and tags, entered
+"manually", one by one
+ private static void testSimpleExampleManual() {
+ ThdEngine engine = ThdEngine.getEngine();
+ engine.createMovieFragment("ref1");
+ engine.createMovieFragment("ref2");
+ engine.createMovieFragment("ref3");
+ engine.createMovieFragment("ref4");
+ engine.createMovieFragment("ref5");
+ engine.createMovieFragment("ref6");
+ engine.createMovieFragment("ref7");
+
+ engine.addTag("crayon", "ref1");
+ engine.addTag("carte", "ref1");
+ engine.addTag("bateau", "ref1");
+ engine.addTag("voiture", "ref1");
+ engine.addTag("car", "ref1");
+
+ engine.addTag("enfant", "ref2");
+ engine.addTag("famille", "ref2");
+ engine.addTag("violon", "ref2");
+ engine.addTag("maison", "ref2");
+ engine.addTag("hopital", "ref2");
+
+ engine.addTag("enfant", "ref3");
+ engine.addTag("famille", "ref3");
+ engine.addTag("violon", "ref3");
+ engine.addTag("maison", "ref3");
+ engine.addTag("ordinateur", "ref3");
+ engine.addTag("fenetre", "ref3");
+ engine.addTag("voiture", "ref3");
+ engine.addTag("guitare", "ref3");
+ engine.addTag("carte", "ref3");
+
+ engine.addTag("enfant", "ref4");
+ engine.addTag("famille", "ref4");
+ engine.addTag("violon", "ref4");
+ engine.addTag("bateau", "ref4");
+ engine.addTag("ordinateur", "ref4");
+ engine.addTag("fenetre", "ref4");
+ engine.addTag("stylo", "ref4");
+ engine.addTag("perroquet", "ref4");
+ engine.addTag("crayon", "ref4");
+ engine.addTag("tele", "ref4");
+ engine.addTag("bateau", "ref4");
+
+ engine.addTag("ordinateur", "ref5");
+ engine.addTag("crayon", "ref5");
+ engine.addTag("fenetre", "ref5");
+ engine.addTag("hopital", "ref5");
+ engine.addTag("carte", "ref5");
+ engine.addTag("tele", "ref5");
+ engine.addTag("stylo", "ref5");
+ engine.addTag("perroquet", "ref5");
+ engine.addTag("bateau", "ref5");
+ engine.addTag("guitare", "ref5");
+
+ engine.addTag("maison", "ref6");
+ engine.addTag("perroquet", "ref6");
+ engine.addTag("stylo", "ref6");
+ engine.addTag("guitare", "ref6");
+ engine.addTag("hopital", "ref6");
+ engine.addTag("tele", "ref6");
+ engine.addTag("car", "ref6");
+ engine.addTag("voiture", "ref6");
+ engine.addTag("fenetre", "ref6");
+
+ engine.addTag("car", "ref7");
+ engine.addTag("voiture", "ref7");
+
+ engine.reTrain();
+ engine.showAllTagValues();
+
+ //Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
+
+ while (neighbor != null) {
+  System.out.println(neighbor.getMovieRef() + " distance: "
+    + neighbor.getDistance());
+  neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
+    true);
+ }
+ System.out.println("cannot find any better");
+ }
+
+ /**
+ * Tests the engine with a xcl file containing references of movies and
+ * their tags. esult should be the same than testSimpleExampleManual()
+ public static void testSimpleExampleFile() {
+ ThdEngine engine = ThdEngine.getEngine();
+ engine.loadFromTextFile(new File("./Sessions/Essai.csv"));
+ System.out.println("number of movies read: "
+   + engine.getAllMovieFragments().size());
+
+ engine.reTrain();
+ engine.showAllTagValues();
+
+ Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
+
+ while (neighbor != null) {
+  System.out.println(neighbor.getMovieRef() + " distance: "
+    + neighbor.getDistance());
+  neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
+    true);
+ }
+ System.out.println("cannot find any better");
+ }
+
+ /**
+ * Tests the engine with a xcl file containing references of movies and
+ * their tags
+ public static void testUniversCineFile() {
+ ThdEngine engine = ThdEngine.getEngine();
+ engine.loadFromTextFile(new File("./Sessions/MovieFrame2.csv"));
+ System.out.println("number of movies read: "
+   + engine.getAllMovieFragments().size());
+ ThdMovieFragment sobibor = engine
+   .movieFragmentNamed("Sobibor, 14 octobre 1943, 16 heures");
+ engine.reTrain();
+
+ Tag T_enfant = engine.tagNamed("Enfant");
+ System.out.println(sobibor);
+ System.out.println(T_enfant);
+
+ engine.tagNamed("Enfant").valueFor(sobibor);
+
+ Neighbor neighbor = engine.findMore(sobibor.getName(), "Enfant", .05f,
+   true);
+
+ while (neighbor != null) {
+  System.out.println(neighbor.getMovieRef() + " distance: "
+    + neighbor.getDistance());
+  neighbor = engine.findMore(neighbor.getMovieRef(), "Enfant", .05f,
+    true);
+ }
+ System.out.println("cannot find any better");
+ }
+
+}
+
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+
+
+public class TestEngineResource {
+
+	public static final String BASE_URL = "http://localhost:9080/sonyengine/";
+	public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
+
+	private DbEnv dbenv = null;
+	private File databasePathFile = null;
+	private String baseurl = null;
+			
+	@Before
+	public void setup()
+	{
+		String databasepath = System.getProperty("database_path");
+		if(databasepath == null)
+			databasepath = DATABASE_PATH;
+		databasePathFile = new File(databasepath);
+		
+		this.baseurl = System.getProperty("baseurl");
+		if(this.baseurl == null)
+			this.baseurl = BASE_URL;
+	}
+	
+	@After
+	public void teardown() {
+	
+		if(dbenv != null)
+			dbenv.close();
+	}
+	
+
+	
+	
+	
+	@Test
+	public void testCreateSequenceList() {
+
+		List<String> movieIds = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			movieIds.add("movie" + System.currentTimeMillis());
+		}
+				
+		String xml = "<segments>";
+		for(String sequenceId: movieIds) {
+			xml += String.format("<segment id=\"%s\"/>", sequenceId);
+		}
+		xml += "</segments>";
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl).path("segment").path("createall");
+		Form form = new Form();
+		form.add("xml", xml);
+		String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		for(String sequenceId: movieIds) {		
+			Assert.assertTrue(da.movieFragmentById.contains(sequenceId));
+		}
+		
+	}
+	
+	
+	@Test
+	public void testReset() {
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl);
+		String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
+		
+		Assert.assertEquals(response, "ok");
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		Assert.assertEquals(0, da.movieFragmentById.count());
+		Assert.assertEquals(0, da.tagById.count());
+		Assert.assertEquals(0, da.tagByName.count());
+		Assert.assertEquals(0, da.tagBySegment.count());		
+		
+	}
+	
+	
+	@Test
+	public void testClearTagsForm() {
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		List<String> tagNames = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			tagNames.add("tag" + System.currentTimeMillis());
+		}
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		String xml = "<tags>";
+		for(String tagName: tagNames) {
+			xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
+		}
+		xml += "</tags>";
+		
+		res = c.resource(this.baseurl).path("tag").path("add");
+		Form form = new Form();
+		form.add("xml", xml);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		form = new Form();
+		form.add("id", movieName);
+		
+		res = c.resource(this.baseurl).path("segment").path("cleartags");
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(String.class,form);
+		
+		Assert.assertEquals("ok", response);
+
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		
+		da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		Assert.assertFalse(da.tagBySegment.contains(movieName));
+		
+		
+	}
+
+	@Test
+	public void testClearTagsPath() {
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		List<String> tagNames = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			tagNames.add("tag" + System.currentTimeMillis());
+		}
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		String xml = "<tags>";
+		for(String tagName: tagNames) {
+			xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
+		}
+		xml += "</tags>";
+		
+		res = c.resource(this.baseurl).path("tag").path("add");
+		Form form = new Form();
+		form.add("xml", xml);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+				
+		res = c.resource(this.baseurl).path("segment").path("cleartags").path(movieName);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(String.class);
+		
+		Assert.assertEquals("ok", response);
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+				
+		Assert.assertFalse(da.tagBySegment.contains(movieName));
+		
+	}
+
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fr/iri/thd/sonyengine/test/TestMovieFragmentResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -0,0 +1,323 @@
+package fr.iri.thd.sonyengine.test.old;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import com.sleepycat.persist.EntityCursor;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.representation.Form;
+
+import fr.iri.thd.sonyengine.core.DataAccessor;
+import fr.iri.thd.sonyengine.core.DbEnv;
+
+
+public class TestMovieFragmentResource {
+
+	public static final String BASE_URL = "http://localhost:9080/sonyengine/";
+	public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
+
+	private DbEnv dbenv = null;
+	private File databasePathFile = null;
+	private String baseurl = null;
+			
+	@Before
+	public void setup()
+	{
+		String databasepath = System.getProperty("database_path");
+		if(databasepath == null)
+			databasepath = DATABASE_PATH;
+		this.databasePathFile = new File(databasepath);
+		
+		this.baseurl = System.getProperty("baseurl");
+		if(this.baseurl == null)
+			this.baseurl = BASE_URL;
+	}
+	
+	@After
+	public void teardown() {
+	
+		if(dbenv != null)
+			dbenv.close();
+	}
+	
+	@Test
+	public void testCreateMovieFragment() {
+				
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		
+		EntityCursor<String> cursor = da.movieFragmentById.keys();
+		
+		for (String key : cursor) {
+			Assert.assertNotNull(key);
+		}
+		
+		cursor.close();
+		
+		Assert.assertTrue(da.movieFragmentById.contains(movieName));
+		
+	}
+
+	@Test
+	public void testCreateMovieFragmentForm() {
+				
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		Client c = Client.create();
+		
+		Form form = new Form();
+		form.add("id", movieName);
+		
+		WebResource res = c.resource(this.baseurl + "segment/create");		
+
+		String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, form);
+				
+		Assert.assertNotNull(response);
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		
+		EntityCursor<String> cursor = da.movieFragmentById.keys();
+		
+		for (String key : cursor) {
+			Assert.assertNotNull(key);
+		}
+		
+		cursor.close();
+		
+		Assert.assertTrue(da.movieFragmentById.contains(movieName));
+		
+	}
+
+	@Test
+	public void testCreateMovieFragmentFormRetrain() throws InterruptedException {
+						
+		Client c = Client.create();
+		WebResource.Builder res = c.resource(this.baseurl + "segment/create").type(MediaType.APPLICATION_FORM_URLENCODED);		
+		List<String> movieNames = new ArrayList<String>();
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+		
+		Form form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "true");
+		
+		String response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		Thread.sleep(1);
+		movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+
+		form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "false");
+		
+		response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		Thread.sleep(1);
+		movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+		
+		form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "foo");
+		
+		response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		Thread.sleep(1);
+		movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+		
+		form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "1");
+		
+		response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		
+		EntityCursor<String> cursor = da.movieFragmentById.keys();
+		
+		for (String key : cursor) {
+			Assert.assertNotNull(key);
+		}
+		
+		cursor.close();
+		
+		for (String name : movieNames) {
+			Assert.assertTrue(da.movieFragmentById.contains(name));	
+		}
+		
+		
+	}
+
+	@Test
+	public void testTrain() {
+
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl);
+		String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
+		
+		String[] ids = new String[]{"ref1","ref2","ref3","ref4","ref5","ref6", "ref7"};
+
+		String xmlSegment = "<segments>";
+		for(String sequenceId: ids) {
+			xmlSegment += String.format("<segment id=\"%s\"/>", sequenceId);
+		}
+		xmlSegment += "</segments>";
+
+		c = Client.create();
+		res = c.resource(this.baseurl).path("segment").path("createall");
+		Form form = new Form();
+		form.add("xml", xmlSegment);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		
+		ArrayList<String[]> tags = new ArrayList<String[]>();
+		tags.add(new String[]{"crayon", "ref1"});
+		tags.add(new String[]{"carte", "ref1"});
+		tags.add(new String[]{"bateau", "ref1"});
+		tags.add(new String[]{"voiture", "ref1"});
+		tags.add(new String[]{"car", "ref1"});
+
+		tags.add(new String[]{"enfant", "ref2"});
+		tags.add(new String[]{"famille", "ref2"});
+		tags.add(new String[]{"violon", "ref2"});
+		tags.add(new String[]{"maison", "ref2"});
+		tags.add(new String[]{"hopital", "ref2"});
+
+		tags.add(new String[]{"enfant", "ref3"});
+		tags.add(new String[]{"famille", "ref3"});
+		tags.add(new String[]{"violon", "ref3"});
+		tags.add(new String[]{"maison", "ref3"});
+		tags.add(new String[]{"ordinateur", "ref3"});
+		tags.add(new String[]{"fenetre", "ref3"});
+		tags.add(new String[]{"voiture", "ref3"});
+		tags.add(new String[]{"guitare", "ref3"});
+		tags.add(new String[]{"carte", "ref3"});
+
+		tags.add(new String[]{"enfant", "ref4"});
+		tags.add(new String[]{"famille", "ref4"});
+		tags.add(new String[]{"violon", "ref4"});
+		tags.add(new String[]{"bateau", "ref4"});
+		tags.add(new String[]{"ordinateur", "ref4"});
+		tags.add(new String[]{"fenetre", "ref4"});
+		tags.add(new String[]{"stylo", "ref4"});
+		tags.add(new String[]{"perroquet", "ref4"});
+		tags.add(new String[]{"crayon", "ref4"});
+		tags.add(new String[]{"tele", "ref4"});
+		tags.add(new String[]{"bateau", "ref4"});
+		
+		tags.add(new String[]{"ordinateur", "ref5"});
+		tags.add(new String[]{"crayon", "ref5"});
+		tags.add(new String[]{"fenetre", "ref5"});
+		tags.add(new String[]{"hopital", "ref5"});
+		tags.add(new String[]{"carte", "ref5"});
+		tags.add(new String[]{"tele", "ref5"});
+		tags.add(new String[]{"stylo", "ref5"});
+		tags.add(new String[]{"perroquet", "ref5"});
+		tags.add(new String[]{"bateau", "ref5"});
+		tags.add(new String[]{"guitare", "ref5"});
+		
+		tags.add(new String[]{"maison", "ref6"});
+		tags.add(new String[]{"perroquet", "ref6"});
+		tags.add(new String[]{"stylo", "ref6"});
+		tags.add(new String[]{"guitare", "ref6"});
+		tags.add(new String[]{"hopital", "ref6"});
+		tags.add(new String[]{"tele", "ref6"});
+		tags.add(new String[]{"car", "ref6"});
+		tags.add(new String[]{"voiture", "ref6"});
+		tags.add(new String[]{"fenetre", "ref6"});
+		
+		tags.add(new String[]{"car", "ref7"});
+		tags.add(new String[]{"voiture", "ref7"});
+
+		String xmlTags = "<tags>";
+		for(String[] tagdef: tags) {
+			xmlTags += String.format("<tag name=\"%s\" segment=\"%s\"/>", (Object[])tagdef);
+		}
+		xmlTags += "</tags>";
+
+		res = c.resource(this.baseurl).path("tag").path("add");
+		form = new Form();
+		form.add("xml", xmlTags);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		//"engine/find/{segment}/{tag}/{percent}/{more}"
+		//Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
+		res = c.resource(this.baseurl).path("engine").path("find").path("ref1").path("enfant").path("0.05").path("true");
+		response = res.accept(MediaType.APPLICATION_XML_TYPE).get(String.class);
+		Assert.assertNotNull(response);
+		
+		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+    	InputSource source = new InputSource(new StringReader(response));
+    	Document doc = null;
+		try {
+			doc = factory.newDocumentBuilder().parse(source);
+		} catch (SAXException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} catch (ParserConfigurationException e) {
+			e.printStackTrace();
+		}
+		
+		NodeList nodes = doc.getElementsByTagName("neighbor");
+		
+		Assert.assertEquals(1, nodes.getLength());
+		
+	}
+
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fr/iri/thd/sonyengine/test/TestTagResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -0,0 +1,224 @@
+package fr.iri.thd.sonyengine.test.old;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonLocation;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.representation.Form;
+
+import fr.iri.thd.sonyengine.core.DataAccessor;
+import fr.iri.thd.sonyengine.core.DbEnv;
+
+public class TestTagResource {
+
+	public static final String BASE_URL = "http://localhost:9080/sonyengine/";
+	public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
+
+	private DbEnv dbenv = null;
+	private File databasePathFile = null;
+	private String baseurl = null;
+			
+	@Before
+	public void setup()
+	{
+		String databasepath = System.getProperty("database_path");
+		if(databasepath == null)
+			databasepath = DATABASE_PATH;
+		databasePathFile = new File(databasepath);
+		
+		this.baseurl = System.getProperty("baseurl");
+		if(this.baseurl == null)
+			this.baseurl = BASE_URL;
+	}
+	
+	@After
+	public void teardown() {
+	
+		if(dbenv != null)
+			dbenv.close();
+	}
+	
+	@Test
+	public void testCreateTag() {
+
+		String movieName = "movie" + System.currentTimeMillis();
+		String tagName = "tag" + System.currentTimeMillis();;
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName);
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		Assert.assertTrue(da.tagByName.contains(tagName));
+		
+	}
+
+	@Test
+	public void testCreateTagRetrain() throws InterruptedException, JsonParseException, JsonMappingException, IOException {
+
+		List<String> tagNames = new ArrayList<String>();
+		
+		Client c = Client.create();
+		ObjectMapper mapper = new ObjectMapper();
+
+		WebResource res = null;
+		String response = null;
+		String tagName = null;
+		Map<String, Object> resMap = null;
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+		
+		res = c.resource(this.baseurl + "segment/create/" + movieName);
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(movieName, resMap.get("id"));
+		
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("true");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		Thread.sleep(1);
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+				
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("false");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		Thread.sleep(1);
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+				
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("foo");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		Thread.sleep(1);
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+				
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("1");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		for (String tag : tagNames) {
+			Assert.assertTrue(da.tagByName.contains(tag));
+		}
+		
+	}
+	
+	
+	@Test
+	public void testCreateTagList() throws JsonParseException, JsonMappingException, IOException {
+
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		List<String> tagNames = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			tagNames.add("tag" + System.currentTimeMillis());
+		}
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		String xml = "<tags>";
+		for(String tagName: tagNames) {
+			xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
+		}
+		xml += "</tags>";
+		
+		res = c.resource(this.baseurl).path("tag").path("add");
+		Form form = new Form();
+		form.add("xml", xml);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+		
+		ObjectMapper mapper = new ObjectMapper();
+		List<Map<String,Object>> resList = mapper.readValue(response, new TypeReference<List<Map<String, Object>>>(){});
+
+		Assert.assertEquals(tagNames, resList.size());
+		for (Map<String, Object> map : resList) {
+			Assert.assertEquals(movieName,map.get("segment"));
+			Assert.assertTrue(tagNames.contains(map.get("name")));
+		}
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		Assert.assertTrue(da.tagBySegment.contains(movieName));
+
+		for(String tagName: tagNames) {		
+			Assert.assertTrue(da.tagByName.contains(tagName));
+		}
+		
+	}
+
+}
--- a/src/fr/iri/thd/sonyengine/web/MovieFragmentResource.java	Tue Mar 30 19:17:23 2010 +0200
+++ b/src/fr/iri/thd/sonyengine/web/MovieFragmentResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -32,7 +32,7 @@
 public class MovieFragmentResource {
 
 	
-	private MovieFragment create(String id, ServletContext context) {
+	private MovieFragment create(String id, boolean retrain, ServletContext context) {
 
 		ThdEngine.getEngine().createMovieFragment(id);
 		
@@ -44,7 +44,8 @@
 		da.movieFragmentById.put(fragment);
 		dbenv.sync();
 		
-		ThdEngine.getEngine().reTrain();
+		if(retrain)
+			ThdEngine.getEngine().reTrain();
 		
 		return fragment;
 		
@@ -55,22 +56,31 @@
 	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public MovieFragment createPath(@PathParam("id") String id, @Context ServletContext context) {
   
-		return this.create(id, context);
+		return this.create(id, true, context);
     }
+
+	@POST
+	@Path("create/{id}/{retrain}")
+	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+    public MovieFragment createPath(@PathParam("id") String id, @PathParam("retrain") Boolean retrain, @Context ServletContext context) {
+  
+		return this.create(id, (retrain != null && retrain.booleanValue()), context);
+    }
+
 	
 	@POST
 	@Path("create")
 	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-    public MovieFragment createForm(@FormParam("id") String id, @Context ServletContext context) {
-		return this.create(id, context);		
+    public MovieFragment createForm(@FormParam("id") String id, @FormParam("retrain") Boolean retrain, @Context ServletContext context) {
+		return this.create(id, (retrain != null && retrain.booleanValue()), context);		
     }
 	
 	@POST
 	@Path("createall")
 	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-	public List<MovieFragment> createAll(@FormParam("xml") String xmldocstr, @Context ServletContext context) {
+	public List<MovieFragment> createAll(@FormParam("xml") String xmldocstr, @FormParam("retrain") Boolean retrain ,@Context ServletContext context) {
 
 		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     	InputSource source = new InputSource(new StringReader(xmldocstr));
@@ -103,19 +113,58 @@
     	}
 
 		dbenv.sync();
-    	
-    	ThdEngine.getEngine().reTrain();
+
+		if(retrain != null && retrain.booleanValue())
+			ThdEngine.getEngine().reTrain();
     	
     	return list;
 
 	}
+	
+	private void clearTags(String id, boolean retrain, ServletContext context) {
 
-    public void find(String id, String tag, Float separation, Boolean b) {
-    }
+		ThdEngine.getEngine().clearTags(id);
+		
+		DbEnv dbenv = (DbEnv)context.getAttribute(ServletContainer.DB_ENV_ATTRIBUTE);
+		
+		DataAccessor da = new DataAccessor(dbenv.getEntityStore());
+		da.tagBySegment.delete(id);
+		dbenv.sync();
+		
+		if(retrain)
+			ThdEngine.getEngine().reTrain();
+	}
 
+	@POST
+	@Path("cleartags/{id}")
+	@Produces(MediaType.TEXT_PLAIN)
+	public String clearTagsPath(@PathParam("id") String id, @Context ServletContext context) {
+		
+		this.clearTags(id, true, context);
+		return "ok";
+	}
 
-    public void get(String id) {
-    }
+	
+	@POST
+	@Path("cleartags/{id}/{retrain}")
+	@Produces(MediaType.TEXT_PLAIN)
+	public String clearTagsPath(@PathParam("id") String id, @PathParam("retrain") Boolean retrain, @Context ServletContext context) {
+		
+		this.clearTags(id, (retrain != null && retrain.booleanValue()), context);
+		return "ok";
+	}
+
+	@POST
+	@Path("cleartags")
+	@Produces(MediaType.TEXT_PLAIN)
+	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+	public String clearTagsForm(@FormParam("id") String id, @FormParam("retrain") Boolean retrain, @Context ServletContext context) {
+		
+		this.clearTags(id, (retrain != null && retrain.booleanValue()), context);
+		return "ok";
+	}
+
+	
 }
 
 
--- a/src/fr/iri/thd/sonyengine/web/TagResource.java	Tue Mar 30 19:17:23 2010 +0200
+++ b/src/fr/iri/thd/sonyengine/web/TagResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -32,11 +32,19 @@
 @Path ("tag")
 public class TagResource {
 
-    
     @Path("add/{id}/{movieFragment}")
     @POST
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
-    public Tag add(@PathParam("id") String tagName, @PathParam("movieFragment") String movieSegmentRef,@Context ServletContext context) {
+    public Tag add(@PathParam("id") String tagName, @PathParam("movieFragment") String movieSegmentRef, @Context ServletContext context) {
+    	return this.add(tagName, movieSegmentRef, Boolean.TRUE, context);
+    }
+
+	
+    
+    @Path("add/{id}/{movieFragment}/{retrain}")
+    @POST
+    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+    public Tag add(@PathParam("id") String tagName, @PathParam("movieFragment") String movieSegmentRef, @PathParam("retrain") Boolean retrain, @Context ServletContext context) {
     	ThdEngine.getEngine().addTag(tagName, movieSegmentRef);
 
     	DbEnv dbenv = (DbEnv)context.getAttribute(ServletContainer.DB_ENV_ATTRIBUTE);
@@ -48,8 +56,8 @@
 		da.tagById.put(tag);
 		dbenv.sync();
 
-		
-		ThdEngine.getEngine().reTrain();
+		if(retrain != null && retrain.booleanValue())
+			ThdEngine.getEngine().reTrain();
 
 		return tag;	
 		
@@ -59,7 +67,7 @@
     @POST
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
-    public List<Tag> add(@FormParam("xml") String xmldocstr, @Context ServletContext context) {
+    public List<Tag> add(@FormParam("xml") String xmldocstr, @FormParam("retrain") Boolean retrain, @Context ServletContext context) {
     	
     	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     	InputSource source = new InputSource(new StringReader(xmldocstr));
@@ -94,7 +102,8 @@
 
 		dbenv.sync();
     	
-    	ThdEngine.getEngine().reTrain();
+		if(retrain != null && retrain.booleanValue())
+			ThdEngine.getEngine().reTrain();
     	
     	return list;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_src/fr/iri/thd/sonyengine/test/AllTests.java	Thu Apr 08 13:07:46 2010 +0200
@@ -0,0 +1,13 @@
+package fr.iri.thd.sonyengine.test;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+
+@RunWith(Suite.class)
+@SuiteClasses({TestEngineResource.class, TestMovieFragmentResource.class, TestTagResource.class})
+public class AllTests {
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_src/fr/iri/thd/sonyengine/test/TestEngineResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -0,0 +1,389 @@
+package fr.iri.thd.sonyengine.test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.representation.Form;
+
+import fr.iri.thd.sonyengine.core.DataAccessor;
+import fr.iri.thd.sonyengine.core.DbEnv;
+
+/*
+ * 
+ * import java.io.File;
+
+import core.Tag;
+
+/**
+ * A class to test ThdEngine
+ *
+ * @author pachet
+ *
+public class ThdEngineTest {
+
+ public static void main(String[] args) {
+ testSimpleExampleManual();
+//   testSimpleExampleFile();
+ // testUniversCineFile();
+ }
+
+ /**
+ * Tests the engine with a small set of movies and tags, entered
+"manually", one by one
+ private static void testSimpleExampleManual() {
+ ThdEngine engine = ThdEngine.getEngine();
+ engine.createMovieFragment("ref1");
+ engine.createMovieFragment("ref2");
+ engine.createMovieFragment("ref3");
+ engine.createMovieFragment("ref4");
+ engine.createMovieFragment("ref5");
+ engine.createMovieFragment("ref6");
+ engine.createMovieFragment("ref7");
+
+ engine.addTag("crayon", "ref1");
+ engine.addTag("carte", "ref1");
+ engine.addTag("bateau", "ref1");
+ engine.addTag("voiture", "ref1");
+ engine.addTag("car", "ref1");
+
+ engine.addTag("enfant", "ref2");
+ engine.addTag("famille", "ref2");
+ engine.addTag("violon", "ref2");
+ engine.addTag("maison", "ref2");
+ engine.addTag("hopital", "ref2");
+
+ engine.addTag("enfant", "ref3");
+ engine.addTag("famille", "ref3");
+ engine.addTag("violon", "ref3");
+ engine.addTag("maison", "ref3");
+ engine.addTag("ordinateur", "ref3");
+ engine.addTag("fenetre", "ref3");
+ engine.addTag("voiture", "ref3");
+ engine.addTag("guitare", "ref3");
+ engine.addTag("carte", "ref3");
+
+ engine.addTag("enfant", "ref4");
+ engine.addTag("famille", "ref4");
+ engine.addTag("violon", "ref4");
+ engine.addTag("bateau", "ref4");
+ engine.addTag("ordinateur", "ref4");
+ engine.addTag("fenetre", "ref4");
+ engine.addTag("stylo", "ref4");
+ engine.addTag("perroquet", "ref4");
+ engine.addTag("crayon", "ref4");
+ engine.addTag("tele", "ref4");
+ engine.addTag("bateau", "ref4");
+
+ engine.addTag("ordinateur", "ref5");
+ engine.addTag("crayon", "ref5");
+ engine.addTag("fenetre", "ref5");
+ engine.addTag("hopital", "ref5");
+ engine.addTag("carte", "ref5");
+ engine.addTag("tele", "ref5");
+ engine.addTag("stylo", "ref5");
+ engine.addTag("perroquet", "ref5");
+ engine.addTag("bateau", "ref5");
+ engine.addTag("guitare", "ref5");
+
+ engine.addTag("maison", "ref6");
+ engine.addTag("perroquet", "ref6");
+ engine.addTag("stylo", "ref6");
+ engine.addTag("guitare", "ref6");
+ engine.addTag("hopital", "ref6");
+ engine.addTag("tele", "ref6");
+ engine.addTag("car", "ref6");
+ engine.addTag("voiture", "ref6");
+ engine.addTag("fenetre", "ref6");
+
+ engine.addTag("car", "ref7");
+ engine.addTag("voiture", "ref7");
+
+ engine.reTrain();
+ engine.showAllTagValues();
+
+ //Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
+
+ while (neighbor != null) {
+  System.out.println(neighbor.getMovieRef() + " distance: "
+    + neighbor.getDistance());
+  neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
+    true);
+ }
+ System.out.println("cannot find any better");
+ }
+
+ /**
+ * Tests the engine with a xcl file containing references of movies and
+ * their tags. esult should be the same than testSimpleExampleManual()
+ public static void testSimpleExampleFile() {
+ ThdEngine engine = ThdEngine.getEngine();
+ engine.loadFromTextFile(new File("./Sessions/Essai.csv"));
+ System.out.println("number of movies read: "
+   + engine.getAllMovieFragments().size());
+
+ engine.reTrain();
+ engine.showAllTagValues();
+
+ Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
+
+ while (neighbor != null) {
+  System.out.println(neighbor.getMovieRef() + " distance: "
+    + neighbor.getDistance());
+  neighbor = engine.findMore(neighbor.getMovieRef(), "enfant", .05f,
+    true);
+ }
+ System.out.println("cannot find any better");
+ }
+
+ /**
+ * Tests the engine with a xcl file containing references of movies and
+ * their tags
+ public static void testUniversCineFile() {
+ ThdEngine engine = ThdEngine.getEngine();
+ engine.loadFromTextFile(new File("./Sessions/MovieFrame2.csv"));
+ System.out.println("number of movies read: "
+   + engine.getAllMovieFragments().size());
+ ThdMovieFragment sobibor = engine
+   .movieFragmentNamed("Sobibor, 14 octobre 1943, 16 heures");
+ engine.reTrain();
+
+ Tag T_enfant = engine.tagNamed("Enfant");
+ System.out.println(sobibor);
+ System.out.println(T_enfant);
+
+ engine.tagNamed("Enfant").valueFor(sobibor);
+
+ Neighbor neighbor = engine.findMore(sobibor.getName(), "Enfant", .05f,
+   true);
+
+ while (neighbor != null) {
+  System.out.println(neighbor.getMovieRef() + " distance: "
+    + neighbor.getDistance());
+  neighbor = engine.findMore(neighbor.getMovieRef(), "Enfant", .05f,
+    true);
+ }
+ System.out.println("cannot find any better");
+ }
+
+}
+
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+
+
+public class TestEngineResource {
+
+	public static final String BASE_URL = "http://localhost:9080/sonyengine/";
+	public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
+
+	private DbEnv dbenv = null;
+	private File databasePathFile = null;
+	private String baseurl = null;
+			
+	@Before
+	public void setup()
+	{
+		String databasepath = System.getProperty("database_path");
+		if(databasepath == null)
+			databasepath = DATABASE_PATH;
+		databasePathFile = new File(databasepath);
+		
+		this.baseurl = System.getProperty("baseurl");
+		if(this.baseurl == null)
+			this.baseurl = BASE_URL;
+	}
+	
+	@After
+	public void teardown() {
+	
+		if(dbenv != null)
+			dbenv.close();
+	}
+	
+
+	
+	
+	
+	@Test
+	public void testCreateSequenceList() {
+
+		List<String> movieIds = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			movieIds.add("movie" + System.currentTimeMillis());
+		}
+				
+		String xml = "<segments>";
+		for(String sequenceId: movieIds) {
+			xml += String.format("<segment id=\"%s\"/>", sequenceId);
+		}
+		xml += "</segments>";
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl).path("segment").path("createall");
+		Form form = new Form();
+		form.add("xml", xml);
+		String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		for(String sequenceId: movieIds) {		
+			Assert.assertTrue(da.movieFragmentById.contains(sequenceId));
+		}
+		
+	}
+	
+	
+	@Test
+	public void testReset() {
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl);
+		String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
+		
+		Assert.assertEquals(response, "ok");
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		Assert.assertEquals(0, da.movieFragmentById.count());
+		Assert.assertEquals(0, da.tagById.count());
+		Assert.assertEquals(0, da.tagByName.count());
+		Assert.assertEquals(0, da.tagBySegment.count());		
+		
+	}
+	
+	
+	@Test
+	public void testClearTagsForm() {
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		List<String> tagNames = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			tagNames.add("tag" + System.currentTimeMillis());
+		}
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		String xml = "<tags>";
+		for(String tagName: tagNames) {
+			xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
+		}
+		xml += "</tags>";
+		
+		res = c.resource(this.baseurl).path("tag").path("add");
+		Form form = new Form();
+		form.add("xml", xml);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		form = new Form();
+		form.add("id", movieName);
+		
+		res = c.resource(this.baseurl).path("segment").path("cleartags");
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(String.class,form);
+		
+		Assert.assertEquals("ok", response);
+
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		
+		da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		Assert.assertFalse(da.tagBySegment.contains(movieName));
+		
+		
+	}
+
+	@Test
+	public void testClearTagsPath() {
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		List<String> tagNames = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			tagNames.add("tag" + System.currentTimeMillis());
+		}
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		String xml = "<tags>";
+		for(String tagName: tagNames) {
+			xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
+		}
+		xml += "</tags>";
+		
+		res = c.resource(this.baseurl).path("tag").path("add");
+		Form form = new Form();
+		form.add("xml", xml);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+				
+		res = c.resource(this.baseurl).path("segment").path("cleartags").path(movieName);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(String.class);
+		
+		Assert.assertEquals("ok", response);
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+				
+		Assert.assertFalse(da.tagBySegment.contains(movieName));
+		
+	}
+
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_src/fr/iri/thd/sonyengine/test/TestMovieFragmentResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -0,0 +1,322 @@
+package fr.iri.thd.sonyengine.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import com.sleepycat.persist.EntityCursor;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.representation.Form;
+
+import fr.iri.thd.sonyengine.core.DataAccessor;
+import fr.iri.thd.sonyengine.core.DbEnv;
+
+public class TestMovieFragmentResource {
+
+	public static final String BASE_URL = "http://localhost:9080/sonyengine/";
+	public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
+
+	private DbEnv dbenv = null;
+	private File databasePathFile = null;
+	private String baseurl = null;
+			
+	@Before
+	public void setup()
+	{
+		String databasepath = System.getProperty("database_path");
+		if(databasepath == null)
+			databasepath = DATABASE_PATH;
+		this.databasePathFile = new File(databasepath);
+		
+		this.baseurl = System.getProperty("baseurl");
+		if(this.baseurl == null)
+			this.baseurl = BASE_URL;
+	}
+	
+	@After
+	public void teardown() {
+	
+		if(dbenv != null)
+			dbenv.close();
+	}
+	
+	@Test
+	public void testCreateMovieFragment() {
+				
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		
+		EntityCursor<String> cursor = da.movieFragmentById.keys();
+		
+		for (String key : cursor) {
+			Assert.assertNotNull(key);
+		}
+		
+		cursor.close();
+		
+		Assert.assertTrue(da.movieFragmentById.contains(movieName));
+		
+	}
+
+	@Test
+	public void testCreateMovieFragmentForm() {
+				
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		Client c = Client.create();
+		
+		Form form = new Form();
+		form.add("id", movieName);
+		
+		WebResource res = c.resource(this.baseurl + "segment/create");		
+
+		String response = res.type(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, form);
+				
+		Assert.assertNotNull(response);
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		
+		EntityCursor<String> cursor = da.movieFragmentById.keys();
+		
+		for (String key : cursor) {
+			Assert.assertNotNull(key);
+		}
+		
+		cursor.close();
+		
+		Assert.assertTrue(da.movieFragmentById.contains(movieName));
+		
+	}
+
+	@Test
+	public void testCreateMovieFragmentFormRetrain() throws InterruptedException {
+						
+		Client c = Client.create();
+		WebResource.Builder res = c.resource(this.baseurl + "segment/create").type(MediaType.APPLICATION_FORM_URLENCODED);		
+		List<String> movieNames = new ArrayList<String>();
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+		
+		Form form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "true");
+		
+		String response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		Thread.sleep(1);
+		movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+
+		form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "false");
+		
+		response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		Thread.sleep(1);
+		movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+		
+		form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "foo");
+		
+		response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		Thread.sleep(1);
+		movieName = "movie" + System.currentTimeMillis();
+		movieNames.add(movieName);
+		
+		form = new Form();
+		form.add("id", movieName);
+		form.add("retrain", "1");
+		
+		response = res.post(String.class, form);
+				
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><movieFragment><id>"+movieName+"</id></movieFragment>",response);
+
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		
+		EntityCursor<String> cursor = da.movieFragmentById.keys();
+		
+		for (String key : cursor) {
+			Assert.assertNotNull(key);
+		}
+		
+		cursor.close();
+		
+		for (String name : movieNames) {
+			Assert.assertTrue(da.movieFragmentById.contains(name));	
+		}
+		
+		
+	}
+
+	@Test
+	public void testTrain() {
+
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl);
+		String response = res.path("engine").path("reset").accept(MediaType.TEXT_PLAIN).post(String.class);
+		
+		String[] ids = new String[]{"ref1","ref2","ref3","ref4","ref5","ref6", "ref7"};
+
+		String xmlSegment = "<segments>";
+		for(String sequenceId: ids) {
+			xmlSegment += String.format("<segment id=\"%s\"/>", sequenceId);
+		}
+		xmlSegment += "</segments>";
+
+		c = Client.create();
+		res = c.resource(this.baseurl).path("segment").path("createall");
+		Form form = new Form();
+		form.add("xml", xmlSegment);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		
+		ArrayList<String[]> tags = new ArrayList<String[]>();
+		tags.add(new String[]{"crayon", "ref1"});
+		tags.add(new String[]{"carte", "ref1"});
+		tags.add(new String[]{"bateau", "ref1"});
+		tags.add(new String[]{"voiture", "ref1"});
+		tags.add(new String[]{"car", "ref1"});
+
+		tags.add(new String[]{"enfant", "ref2"});
+		tags.add(new String[]{"famille", "ref2"});
+		tags.add(new String[]{"violon", "ref2"});
+		tags.add(new String[]{"maison", "ref2"});
+		tags.add(new String[]{"hopital", "ref2"});
+
+		tags.add(new String[]{"enfant", "ref3"});
+		tags.add(new String[]{"famille", "ref3"});
+		tags.add(new String[]{"violon", "ref3"});
+		tags.add(new String[]{"maison", "ref3"});
+		tags.add(new String[]{"ordinateur", "ref3"});
+		tags.add(new String[]{"fenetre", "ref3"});
+		tags.add(new String[]{"voiture", "ref3"});
+		tags.add(new String[]{"guitare", "ref3"});
+		tags.add(new String[]{"carte", "ref3"});
+
+		tags.add(new String[]{"enfant", "ref4"});
+		tags.add(new String[]{"famille", "ref4"});
+		tags.add(new String[]{"violon", "ref4"});
+		tags.add(new String[]{"bateau", "ref4"});
+		tags.add(new String[]{"ordinateur", "ref4"});
+		tags.add(new String[]{"fenetre", "ref4"});
+		tags.add(new String[]{"stylo", "ref4"});
+		tags.add(new String[]{"perroquet", "ref4"});
+		tags.add(new String[]{"crayon", "ref4"});
+		tags.add(new String[]{"tele", "ref4"});
+		tags.add(new String[]{"bateau", "ref4"});
+		
+		tags.add(new String[]{"ordinateur", "ref5"});
+		tags.add(new String[]{"crayon", "ref5"});
+		tags.add(new String[]{"fenetre", "ref5"});
+		tags.add(new String[]{"hopital", "ref5"});
+		tags.add(new String[]{"carte", "ref5"});
+		tags.add(new String[]{"tele", "ref5"});
+		tags.add(new String[]{"stylo", "ref5"});
+		tags.add(new String[]{"perroquet", "ref5"});
+		tags.add(new String[]{"bateau", "ref5"});
+		tags.add(new String[]{"guitare", "ref5"});
+		
+		tags.add(new String[]{"maison", "ref6"});
+		tags.add(new String[]{"perroquet", "ref6"});
+		tags.add(new String[]{"stylo", "ref6"});
+		tags.add(new String[]{"guitare", "ref6"});
+		tags.add(new String[]{"hopital", "ref6"});
+		tags.add(new String[]{"tele", "ref6"});
+		tags.add(new String[]{"car", "ref6"});
+		tags.add(new String[]{"voiture", "ref6"});
+		tags.add(new String[]{"fenetre", "ref6"});
+		
+		tags.add(new String[]{"car", "ref7"});
+		tags.add(new String[]{"voiture", "ref7"});
+
+		String xmlTags = "<tags>";
+		for(String[] tagdef: tags) {
+			xmlTags += String.format("<tag name=\"%s\" segment=\"%s\"/>", (Object[])tagdef);
+		}
+		xmlTags += "</tags>";
+
+		res = c.resource(this.baseurl).path("tag").path("add");
+		form = new Form();
+		form.add("xml", xmlTags);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+
+		//"engine/find/{segment}/{tag}/{percent}/{more}"
+		//Neighbor neighbor = engine.findMore("ref1", "enfant", .05f, true);
+		res = c.resource(this.baseurl).path("engine").path("find").path("ref1").path("enfant").path("0.05").path("true");
+		response = res.accept(MediaType.APPLICATION_XML_TYPE).get(String.class);
+		Assert.assertNotNull(response);
+		
+		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+    	InputSource source = new InputSource(new StringReader(response));
+    	Document doc = null;
+		try {
+			doc = factory.newDocumentBuilder().parse(source);
+		} catch (SAXException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} catch (ParserConfigurationException e) {
+			e.printStackTrace();
+		}
+		
+		NodeList nodes = doc.getElementsByTagName("neighbor");
+		
+		Assert.assertEquals(1, nodes.getLength());
+		
+	}
+
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_src/fr/iri/thd/sonyengine/test/TestTagResource.java	Thu Apr 08 13:07:46 2010 +0200
@@ -0,0 +1,227 @@
+package fr.iri.thd.sonyengine.test;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.representation.Form;
+
+import fr.iri.thd.sonyengine.core.DataAccessor;
+import fr.iri.thd.sonyengine.core.DbEnv;
+
+public class TestTagResource {
+
+	public static final String BASE_URL = "http://localhost:9080/sonyengine/";
+	public static final String DATABASE_PATH = "/Users/ymh/dev/tmp/db";
+
+	private DbEnv dbenv = null;
+	private File databasePathFile = null;
+	private String baseurl = null;
+			
+	@Before
+	public void setup()
+	{
+		String databasepath = System.getProperty("database_path");
+		if(databasepath == null)
+			databasepath = DATABASE_PATH;
+		databasePathFile = new File(databasepath);
+		
+		this.baseurl = System.getProperty("baseurl");
+		if(this.baseurl == null)
+			this.baseurl = BASE_URL;
+	}
+	
+	@After
+	public void teardown() {
+	
+		if(dbenv != null)
+			dbenv.close();
+	}
+	
+	@Test
+	public void testCreateTag() {
+
+		String movieName = "movie" + System.currentTimeMillis();
+		String tagName = "tag" + System.currentTimeMillis();;
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName);
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		Assert.assertTrue(da.tagByName.contains(tagName));
+		
+	}
+
+	@Test
+	public void testCreateTagRetrain() throws InterruptedException, JsonParseException, JsonMappingException, IOException {
+
+		List<String> tagNames = new ArrayList<String>();
+		
+		Client c = Client.create();
+		ObjectMapper mapper = new ObjectMapper();
+
+		WebResource res = null;
+		String response = null;
+		String tagName = null;
+		Map<String, Object> resMap = null;
+		
+		String movieName = "movie" + System.currentTimeMillis();
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+		
+		res = c.resource(this.baseurl + "segment/create/" + movieName);
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(movieName, resMap.get("id"));
+		
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("true");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		Thread.sleep(1);
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+				
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("false");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		Thread.sleep(1);
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+				
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("foo");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		Thread.sleep(1);
+		tagName = "tag" + System.currentTimeMillis();
+		tagNames.add(tagName);
+				
+		res = c.resource(this.baseurl).path("tag").path("add").path(tagName).path(movieName).path("1");
+		response = res.accept(MediaType.APPLICATION_JSON_TYPE).post(String.class);
+
+		Assert.assertNotNull(response);
+		resMap = mapper.readValue(response, new TypeReference<Map<String, Object>>(){} );
+		Assert.assertEquals(tagName,resMap.get("name"));
+		Assert.assertEquals(movieName, resMap.get("segment"));
+
+		
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+		
+		for (String tag : tagNames) {
+			Assert.assertTrue(da.tagByName.contains(tag));
+		}
+		
+	}
+	
+	
+	@SuppressWarnings("unchecked")
+	@Test
+	public void testCreateTagList() throws JsonParseException, JsonMappingException, IOException {
+
+		String movieName = "movie" + System.currentTimeMillis();
+		
+		List<String> tagNames = new ArrayList<String>();
+		
+		for(int i=0; i< 10; i++) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			tagNames.add("tag" + System.currentTimeMillis());
+		}
+		
+		Client c = Client.create();
+		WebResource res = c.resource(this.baseurl + "segment/create/" + movieName);
+		String response = res.accept(MediaType.APPLICATION_XML_TYPE).post(String.class);
+				
+		Assert.assertNotNull(response);
+		
+		String xml = "<tags>";
+		for(String tagName: tagNames) {
+			xml += String.format("<tag name=\"%s\" segment=\"%s\"/>", tagName, movieName);
+		}
+		xml += "</tags>";
+		
+		res = c.resource(this.baseurl).path("tag").path("add");
+		Form form = new Form();
+		form.add("xml", xml);
+		response = res.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON_TYPE).post(String.class, form);
+
+		Assert.assertNotNull(response);
+		
+		ObjectMapper mapper = new ObjectMapper();
+		TypeReference<Map<String, Object>> typeref = new TypeReference<Map<String, Object>>(){};
+		Map<String,Object> resList = mapper.readValue(response, typeref);
+		
+		Assert.assertNotNull(resList);
+				
+		List<Map<String,Object>> tagList = (List<Map<String,Object>>)resList.get("tag");
+		
+		Assert.assertEquals(tagNames.size(), tagList.size());
+		for (Map<String, Object> map : tagList) {
+			Assert.assertEquals(movieName,map.get("segment"));
+			Assert.assertTrue(tagNames.contains(map.get("name")));
+		}
+
+		dbenv = new DbEnv();
+		dbenv.setup(databasePathFile, true, true);
+
+		DataAccessor da = new DataAccessor(this.dbenv.getEntityStore());
+
+		Assert.assertTrue(da.tagBySegment.contains(movieName));
+
+		for(String tagName: tagNames) {		
+			Assert.assertTrue(da.tagByName.contains(tagName));
+		}
+		
+	}
+
+}