[MOBY-guts] biomoby commit

Eddie Kawas kawas at pub.open-bio.org
Thu Oct 20 19:07:06 UTC 2005


kawas
Thu Oct 20 15:07:06 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended
In directory pub.open-bio.org:/tmp/cvs-serv29684/org/biomoby/shared/extended

Modified Files:
	NamespaceParser.java 
Log Message:
finished the logic using what is currently available in the rdf document that describes the namespace ontology.

moby-live/Java/src/main/org/biomoby/shared/extended NamespaceParser.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.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/shared/extended/NamespaceParser.java	2005/10/18 18:37:13	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.java	2005/10/20 19:07:06	1.2
@@ -14,10 +14,24 @@
 import com.hp.hpl.jena.rdf.model.Model;
 import com.hp.hpl.jena.rdf.model.ModelFactory;
 import com.hp.hpl.jena.rdf.model.RDFReader;
+import com.hp.hpl.jena.rdf.model.ResIterator;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.vocabulary.RDFS;
 
 /**
  * 
  * @author Eddie created Oct 18, 2005
+ * This class parses the RDF document that describes the namespace ontology.<p>
+ * An example of how to use this class is below:
+ * <pre><code>
+        NamespaceParser p = new NamespaceParser("http://biomoby.org/RESOURCES/MOBY-S/Namespaces");
+		MobyNamespace[] namespaces = p.getMobyNamespacesFromRDF();
+		for (int i = 0; i < namespaces.length; i++) {
+			System.out.println(namespaces[i]);
+		}
+   </code></pre><p>
+   This would output the following the name and description for each namespace in the document
  */
 public class NamespaceParser {
 
@@ -139,7 +153,18 @@
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
 		reader.read(model, new StringReader(getRdfAsString()), null);
-		// TODO start querying the model and creating namespace objects
+		// get all subjects in the document
+		ResIterator iterator = model.listSubjects();
+		while (iterator.hasNext()) {
+			Resource resource = iterator.nextResource();
+			// extract the name of the namespace
+			String name = resource.getLocalName();
+			MobyNamespace namespace = new MobyNamespace(name);
+			// extract the comment (a literal in the document)
+			String description = resource.getProperty(RDFS.comment).getLiteral().getString();
+			namespace.setDescription(description);
+			list.add(namespace);
+		}
 
 		// return the array
 		return (MobyNamespace[]) list.toArray(new MobyNamespace[list.size()]);
@@ -152,7 +177,6 @@
 	private String getRdfAsString() {
 		String s = null;
 		StringBuffer sb = new StringBuffer();
-		URL url = null;
 		try {
 			BufferedReader in = null;
 			in = new BufferedReader(new InputStreamReader(url.openStream()));
@@ -165,4 +189,14 @@
 		}
 		return sb.toString();
 	}
+	
+	
+	public static void main(String[] args) throws MobyException {
+		// show how to use this class
+		NamespaceParser p = new NamespaceParser("http://biomoby.org/RESOURCES/MOBY-S/Namespaces");
+		MobyNamespace[] namespaces = p.getMobyNamespacesFromRDF();
+		for (int i = 0; i < namespaces.length; i++) {
+			System.out.println(namespaces[i]);
+		}
+	}
 }




More information about the MOBY-guts mailing list