Revision: 14941
          http://gate.svn.sourceforge.net/gate/?rev=14941&view=rev
Author:   markagreenwood
Date:     2012-01-09 10:54:30 +0000 (Mon, 09 Jan 2012)
Log Message:
-----------
we now pass in a loaded ontology instance rather than a URL to give us more 
flexibility on how the ontology is loaded

Modified Paths:
--------------
    gate/trunk/plugins/Ontology_BDM_Computation/creole.xml
    
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/BDMCompMain.java
    
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/TestBDMCompPlugin.java

Modified: gate/trunk/plugins/Ontology_BDM_Computation/creole.xml
===================================================================
--- gate/trunk/plugins/Ontology_BDM_Computation/creole.xml      2012-01-09 
10:43:38 UTC (rev 14940)
+++ gate/trunk/plugins/Ontology_BDM_Computation/creole.xml      2012-01-09 
10:54:30 UTC (rev 14941)
@@ -11,9 +11,9 @@
       <CLASS>gate.bdmComp.BDMCompMain</CLASS>
       <JAR>BDMCompMain.jar</JAR>
 
-      <PARAMETER NAME="ontologyURL"
-        COMMENT="The URL storing the ontology used for BDM computing" 
RUNTIME="true"
-        OPTIONAL="false">java.net.URL</PARAMETER>
+      <PARAMETER NAME="ontology"
+        COMMENT="The ontology used for BDM computing" RUNTIME="true"
+        OPTIONAL="false">gate.creole.ontology.Ontology</PARAMETER>
 
        <PARAMETER NAME="outputBDMFile"
         COMMENT="The URL storing the BDM scores" RUNTIME="true"

Modified: 
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/BDMCompMain.java
===================================================================
--- 
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/BDMCompMain.java   
    2012-01-09 10:43:38 UTC (rev 14940)
+++ 
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/BDMCompMain.java   
    2012-01-09 10:54:30 UTC (rev 14941)
@@ -14,6 +14,14 @@
 
 package gate.bdmComp;
 
+import gate.Factory;
+import gate.ProcessingResource;
+import gate.creole.AbstractLanguageAnalyser;
+import gate.creole.ExecutionException;
+import gate.creole.ResourceInstantiationException;
+import gate.creole.ontology.OClass;
+import gate.creole.ontology.Ontology;
+
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -21,23 +29,12 @@
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
 
-import gate.Factory;
-import gate.FeatureMap;
-import gate.Gate;
-import gate.ProcessingResource;
-import gate.creole.AbstractLanguageAnalyser;
-import gate.creole.ExecutionException;
-import gate.creole.ResourceInstantiationException;
-import gate.creole.ontology.OClass;
-import gate.creole.ontology.Ontology;
-
 /**
  * TODO: the output file is always growing for each run of the PR
  * it's like if the local variables are not reset for each run so it
@@ -45,10 +42,8 @@
  */
 public class BDMCompMain extends AbstractLanguageAnalyser implements
 ProcessingResource {
-  /** File name or URL storing the ontology. */
-  URL ontologyURL = null;
   /** The ontology used. */
-  Ontology ontologyUsed = null;
+  Ontology ontology = null;
   /** The file storing the BDM score. */
   URL outputBDMFile = null;
   /** store the BDM information for each pair of concepts. */
@@ -87,38 +82,26 @@
     
          /** load the ontology. */ 
          //if(ontologyUsed == null || ontologyUsed.toString().trim() == "") {
-           if(ontologyURL == null || ontologyURL.toString().trim() == "") {
+           if(ontology == null) {
         throw new ExecutionException("No ontology: neither using a loaded 
ontology nor giving the ontology URL!");
-           } else { 
+           }
+           /*else { 
              // step 3: set the parameters 
-             FeatureMap fm = Factory.newFeatureMap(); 
-             fm.put("rdfXmlURL", ontologyURL);
              
-             String baseURI=ontologyURL.toURI().toString();
-             baseURI = baseURI.substring(0,baseURI.lastIndexOf('/')+1);        
      
-             fm.put("baseURI", baseURI);
-             
-             // step 4: finally create an instance of ontology 
-             try {
-          ontologyUsed = 
(Ontology)Factory.createResource("gate.creole.ontology.impl.sesame.OWLIMOntology",
 fm);
-        }
-        catch(ResourceInstantiationException e) {
-          e.printStackTrace();
-        } 
-           }
+           }*/
          //}
            //write the header of the bdm score file
            if(isExistingResultFile) {
              bdmResultsWriter.append("##The following are the BDM scores for 
");
-             bdmResultsWriter.append("each pair of concepts in the ontology 
named "+ontologyUsed.getName()+".\n");
+             bdmResultsWriter.append("each pair of concepts in the ontology 
named "+ontology.getName()+".\n");
            }
            // retrieving a list of top classes 
-           Set<OClass> topClasses = ontologyUsed.getOClasses(true);
+           Set<OClass> topClasses = ontology.getOClasses(true);
            if(topClasses.size()>1) {
              System.out.println("The ontology has "+topClasses.size() +" top 
classes!!");
            }
            // retrieving a list of all classes 
-      Set<OClass> allConcepts = ontologyUsed.getOClasses(false);
+      Set<OClass> allConcepts = ontology.getOClasses(false);
       //assign a number id to each class
       
       HashMap<Integer,OClass> id2concept= new HashMap<Integer,OClass>();
@@ -130,7 +113,7 @@
         ++num;
       }
       
-      System.out.println("ontology "+ontologyUsed.getName()+", 
allConcepts="+allConcepts.size());
+      System.out.println("ontology "+ontology.getName()+", 
allConcepts="+allConcepts.size());
       
       //for each concept, get the chain from it to the top class
       HashMap<OClass,String> concept2chain = new HashMap<OClass,String>();
@@ -354,7 +337,7 @@
         }
       }
       // unload the ontology
-      if (ontologyUsed != null) Factory.deleteResource(ontologyUsed);
+      if (ontology != null) Factory.deleteResource(ontology);
     }
       
          
@@ -377,19 +360,19 @@
             // System.out.println("****** curCon="+curCon.getName()+"*"+", 
num="+superCons.size());
            //}
            for(OClass oneCon:superCons) {
-             oneCon = (OClass) 
ontologyUsed.getOResourceByName(oneCon.getName());
+             oneCon = (OClass) ontology.getOResourceByName(oneCon.getName());
              chainNow +=  obtainAChain(oneCon, chainSofar);
            }
          }
         return chainNow;
        }
        
-       public void setOntologyURL(URL ontoU) {
-    this.ontologyURL = ontoU;
+       public void setOntology(Ontology ontology) {
+    this.ontology = ontology;
   }
 
-  public URL getOntologyURL() {
-    return this.ontologyURL;
+  public Ontology getOntology() {
+    return this.ontology;
   }
   public void setOutputBDMFile(URL ontoU) {
     this.outputBDMFile = ontoU;

Modified: 
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/TestBDMCompPlugin.java
===================================================================
--- 
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/TestBDMCompPlugin.java
 2012-01-09 10:43:38 UTC (rev 14940)
+++ 
gate/trunk/plugins/Ontology_BDM_Computation/src/gate/bdmComp/TestBDMCompPlugin.java
 2012-01-09 10:54:30 UTC (rev 14941)
@@ -5,6 +5,7 @@
 import gate.FeatureMap;
 import gate.Gate;
 import gate.GateConstants;
+import gate.creole.ontology.Ontology;
 import gate.util.GateException;
 
 import java.io.File;
@@ -98,7 +99,18 @@
       File testOnto = new File(corpusDirName, "protont.owl");
       File bdmFile = new File(corpusDirName, "protont-bdm.txt");
      
-      bdmM.setOntologyURL(testOnto.toURI().toURL()); //("ann1;ann2;ann3");
+      FeatureMap fm = Factory.newFeatureMap(); 
+      fm.put("rdfXmlURL", testOnto.toURI().toURL());
+      
+      String baseURI=testOnto.getParentFile().toURI().toString();
+      baseURI = baseURI.substring(0,baseURI.lastIndexOf('/')+1);        
+      fm.put("baseURI", baseURI);
+      
+      fm.put("loadImports", Boolean.FALSE);
+      
+      Ontology ontology = 
(Ontology)Factory.createResource("gate.creole.ontology.impl.sesame.OWLIMOntology",
 fm);
+             
+      bdmM.setOntology(ontology); //("ann1;ann2;ann3");
       bdmM.setOutputBDMFile(bdmFile.toURI().toURL());
       //bdmM.setAnnTypesAndFeats("Os;sent->Op");
       //bdmM.setVerbosity("0");

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to