[isidorus-cvs] r521 - in branches/gdl-frontend/src/anaToMia/GDL_TmEngine: lib src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine test/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Tue Jun 28 12:24:37 UTC 2011


Author: lgiessmann
Date: Tue Jun 28 05:24:36 2011
New Revision: 521

Log:
gdl-frontend: Topic Maps Engine: added a unit-test for the JTM 1.1 export

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_TmEngine/lib/GDL_TopicMaps_Model.jar
   branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java
   branches/gdl-frontend/src/anaToMia/GDL_TmEngine/test/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngineTest.java

Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/lib/GDL_TopicMaps_Model.jar
==============================================================================
Binary file (source and/or target). No diff available.

Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java	Tue Jun 28 03:29:56 2011	(r520)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java	Tue Jun 28 05:24:36 2011	(r521)
@@ -1280,7 +1280,16 @@
 		// scope
 		ArrayList<Topic> scopeTopics = new ArrayList<Topic>();
 		for(int i = 0; i != variant.getScope().length(); ++i){
-			scopeTopics.add(variant.getScope().get(i));
+			int j = 0;
+			for( ; j != variant.getParent().getScope().length(); ++j){
+				if(variant.getParent().getScope().get(j).equals(variant.getScope().get(i))){
+					break;
+				}
+			}
+
+			if(j == variant.getParent().getScope().length()){
+				scopeTopics.add(variant.getScope().get(i));
+			}
 		}
 		json += exportReferences(scopeTopics, "scope", prefixes) + ",";
 
@@ -1335,6 +1344,23 @@
 	}
 
 
+	private String exportParent(TopicMap parent, Prefixes prefixes) throws ExporterException {
+		Locator parentIdentifier = null;
+
+		if(parent.getItemIdentifiers().length() != 0){
+			parentIdentifier = parent.getItemIdentifiers().get(0);
+		} else {
+			parentIdentifier = parent.getLocator();
+		}
+
+		if(parentIdentifier == null){
+			throw new ExporterException("a parent must have at least one identifier to be serailised");
+		} else {
+			return "\"parent\":[\"ii:"  + curie(parentIdentifier, prefixes) + "\"]";
+		}
+	}
+	
+	
 	private String exportParent(Topic parent, Prefixes prefixes) throws ExporterException {
 		Locator parentIdentifier = null;
 		String idType = "ii:";
@@ -1350,7 +1376,7 @@
 		}
 
 		if(parentIdentifier == null){
-			throw new ExporterException("a parent must have at least one identifeir to be serailised");
+			throw new ExporterException("a parent must have at least one identifier to be serailised");
 		} else {
 			return "\"parent\":[\"" + idType + curie(parentIdentifier, prefixes) + "\"]";
 		}
@@ -1367,7 +1393,7 @@
 		}
 
 		if(parentIdentifier == null){
-			throw new ExporterException("a parent must have at least one identifeir to be serailised");
+			throw new ExporterException("a parent must have at least one identifier to be serailised");
 		} else {
 			return "\"parent\":[\"ii:"  + curie(parentIdentifier, prefixes) + "\"]";
 		}
@@ -1560,7 +1586,7 @@
 
 		private void initPrefixes(ArrayList<String[]> prefixes, Topic topic) throws ExporterException{
 			// parent
-			addPrefixOfReifiableReference(prefixes, topic.getTopicMap());
+			addPrefixOfTopicMapReference(prefixes, topic.getTopicMap());
 
 			// subject_identifiers
 			addPrefixesOfIdentifiers(prefixes, topic.getSubjectIdentifiers());
@@ -1658,7 +1684,7 @@
 			}
 
 			// parent
-			addPrefixOfReifiableReference(prefixes, association.getParent());
+			addPrefixOfTopicMapReference(prefixes, association.getParent());
 
 			// item_idenifiers
 			addPrefixesOfIdentifiers(prefixes, association.getItemIdentifiers());
@@ -1711,6 +1737,19 @@
 				}
 			}
 		}
+		
+		
+		private void addPrefixOfTopicMapReference(ArrayList<String[]> prefixes, TopicMap tm){
+			if(tm != null){
+				Locator loc = null;
+				if(tm.getItemIdentifiers().length() != 0) {
+					loc = tm.getItemIdentifiers().get(0);
+				} else {
+					loc = tm.getLocator();
+				}
+				addPrefixOfIdentifier(prefixes, loc);
+			}
+		}
 
 
 		private void addPrefixOfTopicReference(ArrayList<String[]> prefixes, Topic topic) throws ExporterException{
@@ -1783,7 +1822,7 @@
 			int idxSlash = uri.lastIndexOf("/");
 			int idxSharp = uri.lastIndexOf("#");
 			int lastPos = idxSlash < idxSharp ? idxSharp : idxSlash;
-			String prefix = uri.substring(0, lastPos);
+			String prefix = uri.substring(0, lastPos + 1);
 			String suffix = uri.substring(lastPos);
 			suffix = suffix == null ? "" : suffix;
 
@@ -1801,7 +1840,7 @@
 			}
 
 			// no match => throw an exception
-			throw new ExporterException("could not found a qualifier for the name space \"" + uri + "\"");
+			throw new ExporterException("could not find a qualifier for the name space \"" + uri + "\"");
 		}
 
 

Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/test/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngineTest.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/test/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngineTest.java	Tue Jun 28 03:29:56 2011	(r520)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/test/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngineTest.java	Tue Jun 28 05:24:36 2011	(r521)
@@ -475,7 +475,137 @@
 	
 	
 	public void testJTM11export(){
-		// TODO: JTM 1.1 export 	
+		try {
+			jtme = new JtmsTmEngine();
+			TopicMap tm1 = jtme.createTopicMap(tmLocator1);
+			tm1.createTopicBySubjectIdentifier(tm1.createLocator("http://psi.topincs.com/person"));
+			jtme.createDefaultNameType(tm1);
+			Topic thomasVinterberg = jtme.importTopic(jtmTop, tm1);
+			tm1.createTopicBySubjectIdentifier(tm1.createLocator("http://psi.topincs.com/date-of-birth"));
+			Occurrence occ = jtme.importOccurrence(jtmOccurrence, tm1);
+			Topic movie = tm1.createTopicBySubjectIdentifier(tm1.createLocator("http://psi.topincs.com/movie"));
+			tm1.createTopicBySubjectIdentifier(tm1.createLocator("http://psi.topincs.com/director"));
+			tm1.createTopicBySubjectIdentifier(tm1.createLocator("http://psi.topincs.com/author"));
+			tm1.createTopicBySubjectIdentifier(tm1.createLocator("http://psi.topincs.com/work"));
+			tm1.createTopicBySubjectIdentifier(tm1.createLocator("http://psi.topincs.com/title"));
+			jtme.importTopicMap(jtmTm, tm1);
+			tm1.getTopicBySubjectLocator(tm1.createLocator("http://psi.topincs.com/movies/slDearWendy"));
+			Association assoc = tm1.getAssociations().get(0);
+			assoc.addItemIdentifier(tm1.createLocator("http://psi.topincs.com/association-ii"));
+			
+			String jtmMovie = jtme.exportTm(movie);
+			String jtmThomasVinterberg = jtme.exportTm(thomasVinterberg);
+			String jtmVinterbergOccurrence = jtme.exportTm(occ);
+			String jtmVinterbergRole = jtme.exportTm(thomasVinterberg.getRolesPlayed().get(0));
+			String jtmTm = jtme.exportTm(tm1);
+			
+			String jtmMovieExpected = "{\"version\":\"1.1\"," +
+									   "\"prefixes\":{" +
+									       "\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"," +
+									       "\"pref_1\":\"http://us.isidor.gdl.anaToMia/\"," +
+									       "\"pref_2\":\"http://psi.topincs.com/\"" +
+									   "}," +
+									   "\"item_type\":\"topic\"," +
+									   "\"parent\":[" +
+									       "\"ii:[pref_1:tm-1]\"" +
+									   "]," +
+									   "\"subject_identifiers\":[" +
+									       "\"[pref_2:movie]\"" +
+									   "]," +
+									   "\"subject_locators\":null," +
+									   "\"item_identifiers\":null," +
+									   "\"names\":null," +
+									   "\"occurrences\":null," +
+									   "\"instance_of\":null" +
+									"}";
+			assertEquals(jtmMovieExpected, jtmMovie);
+			
+			String jtmVinterbergOccurrenceExpected = "{\"version\":\"1.1\"," +
+													  "\"prefixes\":{" +
+													      "\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"," +
+													      "\"pref_1\":\"http://psi.topincs.com/people/\"," +
+													      "\"pref_2\":\"http://psi.topincs.com/\"" +
+													  "}," +
+													  "\"item_type\":\"occurrence\"," +
+													  "\"parent\":[" +
+													      "\"si:[pref_1:thomas-vinterberg]\"" +
+													  "]," +
+													  "\"item_identifiers\":null," +
+													  "\"reifier\":null," +
+													  "\"type\":\"si:[pref_2:date-of-birth]\"," +
+													  "\"scope\":null," +
+													  "\"datatype\":\"[xsd:date]\"," +
+													  "\"value\":\"1969-05-19\"" +
+													 "}";
+			assertEquals(jtmVinterbergOccurrenceExpected, jtmVinterbergOccurrence);
+			
+			String jtmThomasVinterbergExpected = "{\"version\":\"1.1\"," +
+												  "\"prefixes\":{" +
+												      "\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"," +
+												      "\"pref_1\":\"http://us.isidor.gdl.anaToMia/\"," +
+												      "\"pref_2\":\"http://psi.topincs.com/people/\"," +
+												      "\"pref_3\":\"http://psi.topicmaps.org/iso13250/model/\"," +
+												      "\"pref_4\":\"http://psi.topincs.com/\"" +
+												  "}," +
+												  "\"item_type\":\"topic\"," +
+												  "\"parent\":[" +
+												      "\"ii:[pref_1:tm-1]\"" +
+												  "]," +
+												  "\"subject_identifiers\":[" +
+												      "\"[pref_2:thomas-vinterberg]\"" +
+												  "]," +
+												  "\"subject_locators\":null," +
+												  "\"item_identifiers\":null," +
+												  "\"names\":[" +
+												      "{" +
+												          "\"item_identifiers\":null," +
+												          "\"reifier\":null," +
+												          "\"scope\":null," +
+												          "\"variants\":null," +
+												          "\"value\":\"Thomas Vinterberg\"," +
+												          "\"type\":\"si:[pref_3:topic-name]\"" +
+												      "}" +
+												  "]," +
+												  "\"occurrences\":[" +
+												      "{" +
+												          "\"item_identifiers\":null," +
+												          "\"reifier\":null," +
+												          "\"type\":\"si:[pref_4:date-of-birth]\"," +
+												          "\"scope\":null," +
+												          "\"datatype\":\"[xsd:date]\"," +
+												          "\"value\":\"1969-05-19\"" +
+												      "}" +
+												   "]," +
+												  "\"instance_of\":[" +
+												      "\"si:[pref_4:person]\"" +
+												  "]" +
+												 "}";
+			assertEquals(jtmThomasVinterbergExpected, jtmThomasVinterberg);		
+			
+			String jtmVinterbergRoleExpected = "{\"version\":\"1.1\"," +
+												"\"prefixes\":{" +
+												    "\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"," +
+												    "\"pref_1\":\"http://psi.topincs.com/people/\"," +
+												    "\"pref_2\":\"http://psi.topincs.com/\"" +
+												"}," +
+												"\"item_type\":\"role\"," +
+												"\"parent\":[" +
+												    "\"ii:[pref_2:association-ii]\"" +
+												"]," +
+												"\"item_identifiers\":null," +
+												"\"reifier\":null," +
+												"\"player\":\"si:[pref_1:thomas-vinterberg]\"," +
+												"\"type\":\"si:[pref_2:author]\"" +
+											  "}";
+			
+			assertEquals(jtmVinterbergRoleExpected, jtmVinterbergRole);		
+			
+			String jtmTmExpected = "{\"version\":\"1.1\",\"prefixes\":{\"xsd\":\"http://www.w3.org/2001/XMLSchema#\",\"pref_1\":\"http://us.isidor.gdl.anaToMia/\",\"pref_2\":\"http://psi.topincs.com/\",\"pref_3\":\"http://psi.topicmaps.org/iso13250/model/\",\"pref_4\":\"http://psi.topincs.com/people/\",\"pref_5\":\"http://psi.topincs.com/movies/\",\"pref_6\":\"http://www.topicmaps.org/xtm/1.0/country.xtm#\"},\"item_type\":\"topicmap\",\"item_identifiers\":null,\"reifier\":null,\"topics\":[{\"subject_identifiers\":[\"[pref_2:person]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_3:topic-name]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_4:thomas-vinterberg]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":[{\"item_identifiers\":null,\"reifier\":null,\"scope\":null,\"variants\":null,\"value\":\"Thomas Vinterberg\",\"type\":\"si:[pref_3:topic-name]\"}],\"occurrences\":[{\"item_identifiers\":null,\"reifier\":null,\"type\":\"si:[pref_2:date-of-birth]\",\"scope\":null,\"datatype\":\"[xsd:date]\",\"value\":\"1969-05-19\"}],\"instance_of\":[\"si:[pref_2:person]\"]},{\"subject_identifiers\":[\"[pref_2:date-of-birth]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_2:movie]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_2:director]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_2:author]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_2:work]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_2:title]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":null,\"subject_locators\":null,\"item_identifiers\":[\"[pref_5:reifier-1]\"],\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_5:dear-wendy]\"],\"subject_locators\":[\"[pref_5:sl-dear-wendy]\",\"[pref_5:slDearWendy]\"],\"item_identifiers\":null,\"names\":[{\"item_identifiers\":[\"[pref_5:ii-1]\",\"[pref_5:ii-2]\"],\"reifier\":null,\"scope\":[\"si:[pref_6:US]\",\"si:[pref_6:DE]\"],\"variants\":[{\"item_identifiers\":[\"[pref_5:variant-ii]\"],\"reifier\":null,\"scope\":[\"si:[pref_6:PL]\"],\"datatype\":\"[xsd:string]\",\"value\":\"Dear Wendy (PL)\"}],\"value\":\"Dear Wendy\",\"type\":\"si:[pref_2:title]\"}],\"occurrences\":[{\"item_identifiers\":null,\"reifier\":\"ii: [pref_5:reifier-1]\",\"type\":\"si:[pref_2:publication-year]\",\"scope\":null,\"datatype\":\"[xsd:gYear]\",\"value\":\"2005\"}],\"instance_of\":[\"si:[pref_2:movie]\"]},{\"subject_identifiers\":[\"[pref_6:US]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_6:PL]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_2:publication-year]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null},{\"subject_identifiers\":[\"[pref_6:DE]\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null,\"instance_of\":null}],\"associations\":[{\"item_identifiers\":[\"[pref_2:association-ii]\"],\"reifier\":null,\"scope\":null,\"roles\":[{\"item_identifiers\":null,\"reifier\":null,\"player\":\"si:[pref_5:dear-wendy]\",\"type\":\"si:[pref_2:work]\"},{\"item_identifiers\":null,\"reifier\":null,\"player\":\"si:[pref_4:thomas-vinterberg]\",\"type\":\"si:[pref_2:author]\"}],\"type\":\"si:[pref_2:director]\"}]}";
+			assertEquals(jtmTmExpected, jtmTm);
+		}catch(Exception e){
+			System.err.println("caught error in testJtm11export(): " + e.getLocalizedMessage());
+			assertNull(e.getLocalizedMessage());
+		}
 	}
 
 




More information about the Isidorus-cvs mailing list