Source src = Source.getSource(name);
BufferedReader r = null;
try{
r = new BufferedReader(new FileReader(file));
Concept c = null;
Pattern p = Pattern.compile("\"(.*)\"\\s*([A-Z_]*)\\s*(.*)?\\[.*\\]");
for(String l=r.readLine();l != null;l=r.readLine()){
if("[Term]".equals(l.trim())){
addConcept(list,c);
c = new Concept("X");
c.addSource(src);
}else if(c != null){
int i = l.indexOf(':');
if(i > -1){
String key = l.substring(0,i).trim();
String val = l.substring(i+1).trim();
// fill in values
if("id".equals(key)){
c.setCode(val);
}else if("name".equals(key)){
c.setSynonyms(new String [0]);
c.setName(val);
Term t = Term.getTerm(val);
t.setPreferred(true);
c.addTerm(t);
}else if("namespace".equals(key)){
c.addSemanticType(SemanticType.getSemanticType(val));
}else if("def".equals(key)){
Matcher m = p.matcher(val);
if(m.matches())
val = m.group(1);
c.addDefinition(Definition.getDefinition(val));
}else if(key != null && key.matches("(exact_|narrow_|broad_)?synonym")){
Matcher m = p.matcher(val);
String form = null;
if(m.matches()){
val = m.group(1);
form = m.group(2);
}
Term t = Term.getTerm(val);
if(form != null)
t.setForm(form);
c.addTerm(t);
}else if("is_a".equals(key)){
int j = val.indexOf("!");
if(j > -1)
val = val.substring(0,j).trim();
c.addRelatedConcept(Relation.BROADER,val);
Concept pr = list.get(val);
if(pr != null)
pr.addRelatedConcept(Relation.NARROWER,c.getCode());
}else if("relationship".equals(key)){
int j = val.indexOf("!");
int k = val.indexOf(" ");
if(k > -1){
String rel = val.substring(0,k).trim();