Implementation Details

From NCBO Wiki
Revision as of 16:49, 13 October 2008 by Noy (talk | contribs)
Jump to navigation Jump to search

Note: These notes are for BioPortal developers only and are not critical in understanding the BioPortal approach to metadata representation.

This page provides pseudo code for using the Protege API to access and edit the metadata instances.

Dealing with instance data

Currently, BioPortal represents the class information in a ClassBean.You will probably need an InstanceBean, similar to the ClassBean, to pass around information about the instances. In fact, you can simply have a ResourceBean that does just that (unless there is special handling of superclass relation in the ClassBean). Perhaps, we will also need an AnnotationBean to encapsulate information about a particular marginal note or review.

Initializing variables that refer directly to BioPortal Metadata Ontology

At the time the server starts up, we should initialize variables of types OWLModel, OWLClass and RDFProperty corresponding to the BioPortal Metadata ontology and classes and properties in the Metadata ontology. Implementations of most API calls will refer to these variables and having them cached will speed up the queries significantly. Any time a metadata ontology is updated (doesn’t happen often of course), these will need to be re-initialized. The classes and properties that we initialize are the only ones that developers must keep intact when they custom-tailor metadata in their own BioPortal installation.

Accessing BioPortal Metadata Ontology

The knowledge base variable bioportalMetadataOntology that points to the Metadata ontology (with its instances). We create all new metadata instances in this ontology.

OWLModel bioportalMetadataOntology = new JenaOWLModel …  // however you initialize an OWL Model in BP

Classes to access ontology metadata

OWLClass virtualOntologyClass = bioportalMetadataOntology.getOWLNamedClass (“VirtualOntology”); // the class "Virtual Ontology"
RDFProperty currentVersionProperty = bioportalMetadataOntology.getRDFProperty("currentVersion"); // the property pointing to the latest version of the ontology (attached to the individuals of the VirtualOntology class)
RDFProperty virtualURIProperty = bioportalMetadataOntology.getRDFProperty("virtualURI"); // the property "virtualURI" at the "Virtual Ontology" class

We need to list the core properties somewhere and access them. This list can be represented somewhere in the ontology, but for now, we can have it initialized statically in the code:

    public static final String [] CORE_PROPERTY_NAMES = new String [] {
          "OMV:name",
          "OMV:acronym",
          "OMV:creationDate",
          "OMV:description",
          "OMV:documentation",
          "OMV:endorsedBy",
          "OMV:domain",
          "OMV:ontologyLanguage",
          "OMV:keyClasses",
          "OMV:keywords"
    };
     public static final String [] SUMMARY_PROPERTY_NAMES = new String [] {
          "OMV:name",
          "OMV:creationDate"
    };

We can then use these lists to initialize the ordered list of RDFProperty objects to go through:

     coreProperties = new ArrayList<RDFProperty> ();
     for (int i = CORE_PROPERTY_NAMES.length - 1; i >= 0; i--) {
            String nextName = CORE_PROPERTY_NAMES [i];
            RDFProperty nextProperty = bioportalMetadataOntology.getRDFProperty(nextName);
            coreProperties.add (nextProperty);
     }

The same for summaryProperties

The properties versionsProperty and viewsProperty provide access from the instance of a VirtualOntology class to the instances representing its versions and views, respectively:

versionsProperty = bioportalMetadataOntology.getRDFProperty("hasVerisons"); viewsProperty = bioportalMetadataOntology.getRDFProperty("hasViews");


Specifications for the API calls

For each call below, we provide the user cases, input, output, and pseudo-code for the implementation.

Calls for ontology metadata

Get the list of all virtual ontologies

Use cases: We need to access the list of all virtual ontologies in any place where we show the list of available ontologies in BioPortal: the main table on the “Browse” page; Search screen; ontology selection when defining a project.

Input: none

Output: a collection of OWL individuals, with each individual describing one virtual ontology (e.g., “BRO”)

Implementation: simply get a list of instances of the VirtualOntology class:

 virtualOntologyClass.getInstances(true)

Get the current (latest) version for a particular ontology

Use cases: providing the information about the ontology, for example, on the metadata page or to fill out the corresponding row in the table for the “Browse” page. This call will give you the URL for that version and you can then call the next service to get the details about that version.

Input: virtualOntologyURI: the name of the virtual ontology (or the Java object);

Output: the URL (name) for the instance representing the current version (or the Java object)

Implementation: There are two methods, depending on whether we have a Java object for the virtual ontology instance or its virtual URI.

/*
  * @param:   virtualOntologyURI  a virtual URI for the ontology
  */
public static OWLIndividual getCurrentVersion (URI virtualOntologyURI) throws Exception  {
         OWLIndividual virtualOntologyInstance = Util.getVirtualOntologyFromURI (virtualOntologyURI); // returns a virtual ontology instance correpsonding to this virtual URI
         return (OWLIndividual) virtualOntologyInstance.getPropertyValue(currentVersionProperty);
}
/*
  * @param:   virtualOntologyIndividual  an OWL individual representig a virtual ontology
  */	
public static OWLIndividual getCurrentVersion (OWLIndividual virtualOntologyInstance)  {
          return (OWLIndividual) virtualOntologyInstance.getPropertyValue(currentVersionProperty);
}


Get the latest metadata for the current ontology

Use cases: Provide either the limited metadata for the table on the “Browse” page; or the complete metadata for the “Ontology metadata” page. Another version of this call returns only summary properties – the ones that appear in the Browse table (summaryProperties collection)

Input: virtualOntologyURI: URI for the latest version (or the Java object)

Output: a list of property-value pairs for the core metadata properties

Implementation:

/*
  * @param:   virtualOntologyURI  a virtual URI for the ontology
  */
public static Collection<PropertyValue> getCoreMetadata (URI virtualOntologyURI) {
         OWLIndividual virtualOntologyInstance = Util.getVirtualOntologyFromURI (virtualOntologyURI); // returns a virtual ontology instance correpsonding to this virtual URI
         Collection<PropertyValue> result = new ArrayList<PropertyValue> ();
         for (Iterator i = Constants.coreProperties.iterator(); i.hasNext(); ) {
                       RDFProperty nextCoreProperty = (RDFProperty)i.next();
                       PropertyValue nextPair = new PropertyValue ();
                       nextPair.property = nextCoreProperty.toString();
                       nextPair.value = virtualOntologyInstance.getPropertyValue(nextCoreProperty).toString();
                       result.add(nextPair);
         }
         return result;
}