if("org.LexGrid.concepts.Concept".equals(name)){
Map<String,Object> content = processElement(element);
// setup some usefull values
String cui = ""+content.get("_entityCode");
Concept concept = new Concept(cui);
String preferredName = null;
// set synonyms and terms
List<Term> terms = new ArrayList<Term>();
List<String> synonyms = new ArrayList<String>();
Set<Source> sources = new HashSet<Source>();
if(content.containsKey("_presentationList")){
for(Map m: (List<Map>) content.get("_presentationList")){
if("org.LexGrid.concepts.Presentation".equals(m.get("name"))){
String pt = ""+m.get("_isPreferred");
String text = null;
String lang = (String) m.get("_language");
String form = (String) m.get("_representationalForm");
Source src = null;
// get content
Map tm = ((List<Map>) m.get("_value")).get(0);
if("org.LexGrid.commonTypes.Text".equals(tm.get("name"))){
text = ""+tm.get("_content");
synonyms.add(text.trim());
}
// get source
List<Map> sl = (List<Map>) m.get("_sourceList");
if(sl != null && !sl.isEmpty()){
Map sm = sl.get(0);
if("org.LexGrid.commonTypes.Source".equals(sm.get("name"))){
String s = (String) sm.get("_content");
if(s != null){
src = new Source(s);
sources.add(src);
}
}
}
if(text != null){
Term term = new Term(text);
term.setPreferred(Boolean.parseBoolean(pt));
term.setLanguage(lang);
term.setForm(form);
if(src != null)
term.setSource(src);
terms.add(term);
}
}
}
}
// set definitions and terms
List<Definition> defs = new ArrayList<Definition>();
if(content.containsKey("_definitionList")){
for(Map m: (List<Map>) content.get("_definitionList")){
if("org.LexGrid.concepts.Definition".equals(m.get("name"))){
String text = null;
Source src = null;
Map tm = ((List<Map>) m.get("_value")).get(0);
if("org.LexGrid.commonTypes.Text".equals(tm.get("name"))){
text = ""+tm.get("_content");
}
// get source
List<Map> sl = (List<Map>) m.get("_sourceList");
if(sl != null && !sl.isEmpty()){
Map sm = sl.get(0);
if("org.LexGrid.commonTypes.Source".equals(sm.get("name"))){
String s = (String) sm.get("_content");
if(s != null){
src = new Source(s);
}
}
}
if(text != null){
Definition d = new Definition(text);
if(src != null)
d.setSource(src);
defs.add(d);
}
}
}
}
// set preferred name
if(content.containsKey("_entityDescription")){
for(Map m: (List<Map>) content.get("_entityDescription")){
if("org.LexGrid.commonTypes.EntityDescription" .equals(m.get("name"))){
preferredName = ""+m.get("_content");
}
}
}
// get properties
// set definitions and terms
Properties props = new Properties();
if(content.containsKey("_propertyList")){
for(Map m: (List<Map>) content.get("_propertyList")){
if("org.LexGrid.commonTypes.Property".equals(m.get("name"))){
String value = null;
String prop = (String) m.get("_propertyName");
Map tm = ((List<Map>) m.get("_value")).get(0);
if("org.LexGrid.commonTypes.Text".equals(tm.get("name"))){
value = (String) tm.get("_content");
}
if(prop != null && value != null){
props.setProperty(prop, value);
}
}
}
}
// set name
concept.setName(preferredName);
concept.setTerminology(this);
concept.setSynonyms(synonyms.toArray(new String [0]));
concept.setTerms(terms.toArray(new Term [0]));
concept.setDefinitions(defs.toArray(new Definition[0]));
concept.setSources(sources.toArray(new Source [0]));
concept.setProperties(props);
if(props.containsKey("Semantic_Type")){
concept.setSemanticTypes(new SemanticType []{new SemanticType(props.getProperty("Semantic_Type"))});
}
concept.setInitialized(true);
return concept;
}
}