From d1268e6da85b48f10384a5838d692a8a7b3f3d4b Mon Sep 17 00:00:00 2001 From: lingutln Date: Wed, 10 Apr 2013 23:14:31 +0000 Subject: [PATCH] svn path=/; revision=465 --- .../src/ie/dcu/apps/ist/labelling/Labels.java | 18 ++++++- .../dcu/apps/ist/labelling/OntologyTerm.java | 3 +- .../dcu/apps/ist/views/SegmentationView.java | 50 +++++++++++++------ .../ist/widgets/AnnotatedImageControl.java | 32 +++--------- 4 files changed, 62 insertions(+), 41 deletions(-) diff --git a/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java b/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java index 0eafac8..db3cb68 100644 --- a/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java +++ b/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java @@ -9,6 +9,9 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import javax.xml.bind.DatatypeConverter; import javax.xml.parsers.*; @@ -58,7 +61,7 @@ public class Labels { OntologyTerm term = new OntologyTerm(); term.setAccessionId(array.getJSONObject(i).getString("accession_id")); - term.setName(array.getJSONObject(i).getString("match")); + term.setName(formatizeToUnescapeHTML(array.getJSONObject(i).getString("match"))); terms.add(term); } in.close(); @@ -74,6 +77,19 @@ public class Labels return terms; } + public static String formatizeToUnescapeHTML(String term) + { + Pattern pattern = Pattern.compile("&#[0-9]+"); + Matcher matcher = pattern.matcher(term); + StringBuffer formattedTerm = new StringBuffer(); + while (matcher.find()) { + String matchedText = matcher.group(); + matcher.appendReplacement(formattedTerm, matchedText + ";"); + } + matcher.appendTail(formattedTerm); + return formattedTerm.toString(); + } + diff --git a/Annotation/src/ie/dcu/apps/ist/labelling/OntologyTerm.java b/Annotation/src/ie/dcu/apps/ist/labelling/OntologyTerm.java index 76b22ab..39d30f7 100644 --- a/Annotation/src/ie/dcu/apps/ist/labelling/OntologyTerm.java +++ b/Annotation/src/ie/dcu/apps/ist/labelling/OntologyTerm.java @@ -4,6 +4,8 @@ package ie.dcu.apps.ist.labelling; import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.lang3.StringEscapeUtils; @@ -66,5 +68,4 @@ public class OntologyTerm { public OntologyTerm() { this.synonyms = new ArrayList(); } - } diff --git a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java index 246f4b4..aee4863 100644 --- a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java +++ b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java @@ -21,10 +21,11 @@ import java.net.*; import java.util.ArrayList; import java.util.Properties; import java.util.logging.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.action.*; -import org.eclipse.jface.action.Action; import org.eclipse.jface.operation.*; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; @@ -304,7 +305,7 @@ public class SegmentationView extends Composite { if(view.getContext().isEnabled()) { OntologyTerm term = new OntologyTerm(); - term.setName((String)comboLabel.getData(comboLabel.getText())); + term.setName((String)comboLabel.getData(formatizeToUnescapeHTML(comboLabel.getText()))); term.setAccessionId(parseAccessionIdFromComboLabel(comboLabel)); view.getContext().getEnabledMask().ontologyTerm = term; } @@ -313,6 +314,19 @@ public class SegmentationView extends Composite { }); } + public static String formatizeToUnescapeHTML(String term) + { + Pattern pattern = Pattern.compile("&#[0-9]+"); + Matcher matcher = pattern.matcher(term); + StringBuffer formattedTerm = new StringBuffer(); + while (matcher.find()) { + String matchedText = matcher.group(); + matcher.appendReplacement(formattedTerm, matchedText + ";"); + } + matcher.appendTail(formattedTerm); + return formattedTerm.toString(); + } + /** * For dropping down the labels on pressing the down arrow key just like "Google suggests" functionality. * @param e @@ -414,7 +428,7 @@ public class SegmentationView extends Composite { for (int j=0; j