[MOBY-guts] biomoby commit
Eddie Kawas
kawas at pub.open-bio.org
Tue Feb 8 01:50:32 UTC 2005
kawas
Mon Feb 7 20:50:31 EST 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool
In directory pub.open-bio.org:/tmp/cvs-serv20700/org/biomoby/client/gui/serviceInstanceCreationTool
Modified Files:
MobyUtilities.java
Log Message:
Fixed GetRelations so that the name argument can be an LSID - Eddie
moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool MobyUtilities.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool/MobyUtilities.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool/MobyUtilities.java 2004/09/27 21:29:14 1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool/MobyUtilities.java 2005/02/08 01:50:31 1.2
@@ -7,6 +7,8 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.swing.tree.TreePath;
@@ -19,147 +21,160 @@
*/
public class MobyUtilities {
- // strings that when concatenated return the attributes, articlename, etc of an object
- final private static String MURL = new String("http://mobycentral.cbr.nrc.ca/cgi-bin/types/Objects?name=");
- final private static String MURL2 = new String("&lsid_name");
-
- /**
- * PRE: None.<p>
- * POST: a linked list of all the relations is returned, such that:<p>
- * => The first item in the list is a string representation of the parent<p>
- * => The second item is a linked list of all the 'HAS' container relationships<p>
- * => The third item is a linked list of all the 'HASA' container relationships
- * @param name, the name of the object to query for.
- * @return returns a linked list {String, LinkedList, LinkedList} of relationships
- */
- public static LinkedList GetRelations(String name) throws IOException {
- URL url = null;
- url = new URL(MURL + name + MURL2);
- BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
- String input;
- String parent = "";
- LinkedList llHas = new LinkedList();
- LinkedList llHasa = new LinkedList();
-
- while ((input = in.readLine()) != null) {
- StringTokenizer st = new StringTokenizer(input, "\t");
- if (st.countTokens() > 2) {
- st.nextToken(); // object name that was queried
- StringTokenizer lsid = new StringTokenizer(st.nextToken(), ":");
- String relation = "";
- while (lsid.hasMoreTokens())
- relation = lsid.nextToken(); // isa, hasa, etc
- if (relation.equalsIgnoreCase("isa"))
- parent = st.nextToken();
- else if (relation.equalsIgnoreCase("has"))
- llHas.add(st.nextToken());
- else if (relation.equalsIgnoreCase("hasa"))
- llHasa.add(st.nextToken());
- }
- }
- if (parent.equals("")) {
- return null;
- }
- LinkedList listToReturn = new LinkedList();
- listToReturn.addFirst(parent);
- listToReturn.add(llHas);
- listToReturn.add(llHasa);
- return listToReturn;
- }
-
- /**
- *
- * PRE: None.<p>
- * POST: a Pair object is returned if the String could be parsed, otherwise, null is returned.
- * @param rel - the string representation of the relation in the form Attribute(articleName), i.e. Integer(Count).
- * @return returns a fully constructed Pair object if the relation was valid, otherwise, null is returned.
- */
- public static Pair ParseRelation(String rel) {
- // integer(length) == attribute(articlename)
- Pair p = null;
- int x = -1;
- String attribute, articleName;
- if ((x = rel.indexOf("(")) >= 0) {
- attribute = rel.substring(0, x);
- articleName = rel.substring(x + 1, rel.length() - 1);
- p = new Pair(articleName, attribute);
- }
-
- return p;
- }
-
- /**
- *
- * PRE: None.<p>
- * POST: Returns the leaf object in a TreePath if path is not null, otherwise, null is returned.
- * @param path - a TreePath containing the object of interest.
- * @return returns the name of the leaf object contained in the path.
- */
- public static String GetObject(TreePath path) {
- if (path == null)
- return null;
- String s = path.toString();
- int start = s.lastIndexOf(", ");
- int end = s.indexOf("]");
- if (start < 0) {
- start = 0;
- }
- int space = -1;
- if ((space = s.lastIndexOf(" ")) >= 0) {
- s = s.substring(space + 1, end);
- } else
- s = s.substring(start + 1, end);
- return s;
- }
-
- /**
- *
- * PRE: ll is a valid linkedlist, panelDetails is a valid MobyUserPanel.<p>
- * POST: All the relations of child are outputted to the MobyUserPanel panelDetails.
- * @param ll - a linked list created via GetRelations()
- * @param panelDetails - the MobyUserPanel to output the relationships
- * @param child - the object that GetRelations() was called with.
- */
- public static String WriteToPanel(LinkedList ll, String child) {
- //System.out.println(ll);
- StringBuffer sb = new StringBuffer("");
- sb.append(child + System.getProperty("line.separator") + "ISA: " + System.getProperty("line.separator") + "\t");
- String parent = (String) ll.removeFirst();
- sb.append(parent + System.getProperty("line.separator"));
- LinkedList llhas = (LinkedList) ll.removeFirst();
- if (llhas != null) {
- sb.append("Has: ");
- Iterator i = llhas.iterator();
- while (i.hasNext()) {
- Pair p = MobyUtilities.ParseRelation((String) i.next());
- if (p != null)
- sb.append(
- System.getProperty("line.separator")
- + "\t"
- + p.getAttribute()
- + " - "
- + p.getArticlename()
- + " ");
- }
- sb.append(System.getProperty("line.separator"));
- }
- LinkedList llhasa = (LinkedList) ll.removeFirst();
- if (llhasa != null) {
- sb.append("Hasa: ");
- Iterator i = llhasa.iterator();
- while (i.hasNext()) {
- Pair p = MobyUtilities.ParseRelation((String) i.next());
- if (p != null)
- sb.append(
- System.getProperty("line.separator")
- + "\t"
- + p.getAttribute()
- + "->"
- + p.getArticlename()
- + " ");
- }
- }
- return sb.toString();
- }
-
-}
+ // strings that when concatenated return the attributes, articlename, etc of an object
+ final private static String URL_OBJECT = new String(
+ "http://mobycentral.cbr.nrc.ca/cgi-bin/types/Objects?name=");
+
+ final private static String URL_LSID = new String(
+ "http://mobycentral.cbr.nrc.ca/cgi-bin/types/Objects?lsid_name=");
+
+ /**
+ * PRE: None.<p>
+ * POST: a linked list of all the relations is returned, such that:<p>
+ * => The first item in the list is a string representation of the parent<p>
+ * => The second item is a linked list of all the 'HAS' container relationships<p>
+ * => The third item is a linked list of all the 'HASA' container relationships
+ * @param name, the name of the object to query for - can be an Moby Object LSID.
+ * @return returns a linked list {String, LinkedList, LinkedList} of relationships
+ */
+ public static LinkedList GetRelations(String name) throws IOException {
+ URL url = null;
+ boolean isLSID = false;
+ // TODO check if name == lsid
+ Pattern p = Pattern.compile("(^urn:lsid:biomoby.org:objectclass:\\S+)",
+ Pattern.CASE_INSENSITIVE);
+ Matcher m = p.matcher(name);
+ isLSID = m.matches();
+
+ if (!isLSID)
+ url = new URL(URL_OBJECT + name);
+ else
+ url = new URL(URL_LSID + name);
+ BufferedReader in = new BufferedReader(new InputStreamReader(url
+ .openStream()));
+ String input;
+ String parent = "Object";
+ LinkedList llHas = new LinkedList();
+ LinkedList llHasa = new LinkedList();
+
+ while ((input = in.readLine()) != null) {
+ StringTokenizer st = new StringTokenizer(input, "\t");
+ if (st.countTokens() > 2) {
+ st.nextToken(); // object name that was queried
+ StringTokenizer lsid = new StringTokenizer(st.nextToken(), ":");
+ String relation = "";
+ while (lsid.hasMoreTokens())
+ relation = lsid.nextToken(); // isa, hasa, etc
+ if (relation.equalsIgnoreCase("isa"))
+ parent = st.nextToken();
+ else if (relation.equalsIgnoreCase("has"))
+ llHas.add(st.nextToken());
+ else if (relation.equalsIgnoreCase("hasa"))
+ llHasa.add(st.nextToken());
+ }
+ }
+ if (parent.equals("")) {
+ return null;
+ }
+ LinkedList listToReturn = new LinkedList();
+ listToReturn.addFirst(parent);
+ listToReturn.add(llHas);
+ listToReturn.add(llHasa);
+ return listToReturn;
+ }
+
+ /**
+ *
+ * PRE: None.<p>
+ * POST: a Pair object is returned if the String could be parsed, otherwise, null is returned.
+ * @param rel - the string representation of the relation in the form Attribute(articleName), i.e. Integer(Count).
+ * @return returns a fully constructed Pair object if the relation was valid, otherwise, null is returned.
+ */
+ public static Pair ParseRelation(String rel) {
+ // integer(length) == attribute(articlename)
+ Pair p = null;
+ int x = -1;
+ String attribute, articleName;
+ if ((x = rel.indexOf("(")) >= 0) {
+ attribute = rel.substring(0, x);
+ articleName = rel.substring(x + 1, rel.length() - 1);
+ p = new Pair(articleName, attribute);
+ }
+
+ return p;
+ }
+
+ /**
+ *
+ * PRE: None.<p>
+ * POST: Returns the leaf object in a TreePath if path is not null, otherwise, null is returned.
+ * @param path - a TreePath containing the object of interest.
+ * @return returns the name of the leaf object contained in the path.
+ */
+ public static String GetObject(TreePath path) {
+ if (path == null)
+ return null;
+ String s = path.toString();
+ int start = s.lastIndexOf(", ");
+ int end = s.indexOf("]");
+ if (start < 0) {
+ start = 0;
+ }
+ int space = -1;
+ if ((space = s.lastIndexOf(" ")) >= 0) {
+ s = s.substring(space + 1, end);
+ } else
+ s = s.substring(start + 1, end);
+ return s;
+ }
+
+ /**
+ *
+ * PRE: ll is a valid linkedlist, panelDetails is a valid MobyUserPanel.<p>
+ * POST: All the relations of child are outputted to the MobyUserPanel panelDetails.
+ * @param ll - a linked list created via GetRelations()
+ * @param panelDetails - the MobyUserPanel to output the relationships
+ * @param child - the object that GetRelations() was called with.
+ */
+ public static String WriteToPanel(LinkedList ll, String child) {
+ //System.out.println(ll);
+ StringBuffer sb = new StringBuffer("");
+ sb.append(child + System.getProperty("line.separator") + "ISA: "
+ + System.getProperty("line.separator") + "\t");
+ String parent = (String) ll.removeFirst();
+ sb.append(parent + System.getProperty("line.separator"));
+ LinkedList llhas = (LinkedList) ll.removeFirst();
+ if (llhas != null) {
+ sb.append("Has: ");
+ Iterator i = llhas.iterator();
+ while (i.hasNext()) {
+ Pair p = MobyUtilities.ParseRelation((String) i.next());
+ if (p != null)
+ sb.append(System.getProperty("line.separator") + "\t"
+ + p.getAttribute() + " - " + p.getArticlename()
+ + " ");
+ }
+ sb.append(System.getProperty("line.separator"));
+ }
+ LinkedList llhasa = (LinkedList) ll.removeFirst();
+ if (llhasa != null) {
+ sb.append("Hasa: ");
+ Iterator i = llhasa.iterator();
+ while (i.hasNext()) {
+ Pair p = MobyUtilities.ParseRelation((String) i.next());
+ if (p != null)
+ sb.append(System.getProperty("line.separator") + "\t"
+ + p.getAttribute() + "->" + p.getArticlename()
+ + " ");
+ }
+ }
+ return sb.toString();
+ }
+
+ public static void main(String[] args) throws IOException {
+ LinkedList ll = MobyUtilities.GetRelations("genbank-flatfile");
+ System.out.println(ll.toString());
+ ll = MobyUtilities.GetRelations("urn:lsid:biomoby.org:objectclass:Object");
+ System.out.println(ll.toString());
+ }
+}
\ No newline at end of file
More information about the MOBY-guts
mailing list