[MOBY-guts] biomoby commit
Eddie Kawas
kawas at pub.open-bio.org
Wed Feb 9 18:26:41 UTC 2005
kawas
Wed Feb 9 13:26:41 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-serv31128/org/biomoby/client/gui/serviceInstanceCreationTool
Modified Files:
MobyUtilities.java
Log Message:
Fixed GetRelations so that it executes quickly and doesnt spin off
into infinite loops with bad input - Eddie
moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool MobyUtilities.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool/MobyUtilities.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool/MobyUtilities.java 2005/02/08 01:50:31 1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/gui/serviceInstanceCreationTool/MobyUtilities.java 2005/02/09 18:26:41 1.3
@@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.StringTokenizer;
@@ -12,6 +13,9 @@
import javax.swing.tree.TreePath;
+import org.biomoby.client.gui.util.MobyObjectPrimitiveExtractor;
+import org.biomoby.client.gui.util.Triples;
+
/**
* Utilities that are useful for retrieving information about certain objects, parsing objects, etc.
* @author Eddie Kawas
@@ -21,12 +25,6 @@
*/
public class MobyUtilities {
- // 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>
@@ -40,44 +38,31 @@
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 p = Pattern.compile("(^urn:lsid:biomoby.org:objectclass:\\S+$)",
Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(name);
isLSID = m.matches();
+ if (isLSID) {
+ int x = name.lastIndexOf(":")+1;
+ name = name.substring(x);
+ }
- 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());
+ MobyObjectPrimitiveExtractor mope = new MobyObjectPrimitiveExtractor();
+ ArrayList al = mope.getPrimitives(name);
+ for (Iterator x = al.iterator(); x.hasNext();) {
+ Triples t = (Triples)x.next();
+ if (t.getType() == Triples.HAS) {
+ llHas.add(t.getPrimitive());
+ }
+ if (t.getType() == Triples.HASA) {
+ llHasa.add(t.getPrimitive());
}
}
- if (parent.equals("")) {
- return null;
- }
+ // set up the return list
LinkedList listToReturn = new LinkedList();
- listToReturn.addFirst(parent);
+ listToReturn.addFirst("Object");
listToReturn.add(llHas);
listToReturn.add(llHasa);
return listToReturn;
@@ -172,9 +157,9 @@
}
public static void main(String[] args) throws IOException {
- LinkedList ll = MobyUtilities.GetRelations("genbank-flatfile");
+ LinkedList ll = MobyUtilities.GetRelations("DNASequence");
System.out.println(ll.toString());
- ll = MobyUtilities.GetRelations("urn:lsid:biomoby.org:objectclass:Object");
+ ll = MobyUtilities.GetRelations("urn:lsid:biomoby.org:objectclass:DNASequence");
System.out.println(ll.toString());
}
}
\ No newline at end of file
More information about the MOBY-guts
mailing list