Examples of Ontology


Examples of com.hp.hpl.jena.ontology.Ontology

   
    // The new OntModel that will contain the pre-existing attributes (if any),
    // plus the new and updated attributes:
    final OntModel newOntModel = _createOntModel(model);
    final Ontology ont_ = newOntModel.createOntology(base_);
    log.info("New ontology created with namespace " + ns_ + " base " + base_);
    newOntModel.setNsPrefix("", ns_);
   
    // set preferred prefixes:
    Map<String, String> preferredPrefixMap = MdHelper.getPreferredPrefixMap();
    for ( String uri : preferredPrefixMap.keySet() ) {
      String prefix = preferredPrefixMap.get(uri);
      newOntModel.setNsPrefix(prefix, uri);
    }
   
   
    // Set internal attributes, which are updated in the newValues map itself
    // so we facilite the processing below:
    newValues.put(Omv.uri.getURI(), base_);
    newValues.put(Omv.version.getURI(), version);
   
    newValues.put(Omv.creationDate.getURI(), creationDate);


    //////////////////////////////////////////////////
    // transfer any preexisting attributes, and then remove all properties from
    // pre-existing ontRes so just the new OntModel gets added.
    if ( ontRes != null ) {
      for ( Statement st : prexistStatements ) {
        Property prd = st.getPredicate();

        //
        // Do not tranfer pre-existing/pre-assigned-above attributes
        //
        String newValue = newValues.get(prd.getURI());
        if ( newValue == null || newValue.trim().length() == 0 ) {
          log.info("  Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
          newOntModel.add(ont_, prd, st.getObject());
        }
        else {
          log.info(" Removing pre-existing values for predicate: " +prd+ " because of new value " +newValue);
          newOntModel.removeAll(ont_, prd, null);
        }
      } 
     
     
      if ( ! createOntologyResult.isPreserveOriginalBaseNamespace() ) {
       
        //
        // Only, when we're creating a new model, ie., per the new namespace, do the following removals.
        // (If we did this on a model with the same original namespace, we would remove the owl:Ontology
        // entry altogether and get an "rdf:Description" instead.
        //
       
        log.info("Removing original OWL.Ontology individual");
        ontRes.removeProperties();
        // TODO the following may be unnecesary but doesn't hurt:
        model.remove(ontRes, RDF.type, OWL.Ontology);
      }
    }

   
   
    ///////////////////////////////////////////////////////
    // Update attributes in model:

    Map<String, Property> uriPropMap = MdHelper.getUriPropMap();
    for ( String uri : newValues.keySet() ) {
      String value = newValues.get(uri).trim();
      if ( value.length() > 0 ) {
        Property prop = uriPropMap.get(uri);
        if ( prop == null ) {
          log.info("No property found for uri='" +uri+ "'");
          continue;
        }

        log.info(" Assigning: " +uri+ " = " +value);
        ont_.addProperty(prop, value);
      }
    }
   

View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

   * @param ontModel
   * @param prop Property
   * @return value of the property, or null if missing.
   */
  public static String getOntologyPropertyValue(OntModel ontModel, Property prop) {
    Ontology ontology = getOntology(ontModel);
    if ( ontology == null ) {
      return null;
    }
    RDFNode node = ontology.getPropertyValue(prop);
    if ( node == null ) {
      return null;
    }
    return node.toString();
  }
View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

  public static Ontology getOntology(OntModel ontModel) {
   
    OntModel mBase = ModelFactory.createOntologyModel(
                OntModelSpec.OWL_MEM, ontModel.getBaseModel() );

    Ontology ont = null;
   
    ExtendedIterator<Ontology> iter = mBase.listOntologies();
    try {
      if ( iter.hasNext() ) {
        ont = iter.next();
      }

      if ( log.isDebugEnabled() ) {
        if ( ont != null ) {
          if ( iter.hasNext() ) {
            Ontology ont2 = iter.next();
            log.debug("WARNING: more than one Ontology resource in OntModel. " +
                "Second one found (but ignored): " +ont2.getURI()
            );
          }
          log.debug("Returning Ontology with URI: " +ont.getURI());
        }
        else {
View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

   * @return the value of omv.version assigned to the ontology; null if no
   * assignment was performed.
   */
  // Method created as part of the fix to issue #252: "omv:version gone?".
  public static String setVersionFromCreationDateIfNecessary(OntModel ontModel) {
    Ontology ontology = getOntology(ontModel);
    if ( ontology == null ) {
      return null;
    }
    RDFNode node = ontology.getPropertyValue(Omv.version);
    if ( node != null ) {
      // already assigned; keep it:
      return null;
    }
    // omv.version not assigned; try to use omv.creationDate:
    node = ontology.getPropertyValue(Omv.creationDate);
    if ( node == null ) {
      // not available, return with no changes:
      return null;
    }
   
    String creationDate = node.toString();
    String version = _getVersionFromCreationDate(creationDate);
    if ( version != null ) {
      Literal versionLit = ResourceFactory.createPlainLiteral(version);
      ontology.setPropertyValue(Omv.version, versionLit);
      return version;
    }
    return null;
  }
View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

 
 
  private static OntModel setOrAddProperties(OntModel ontModel, boolean doSet, Map<String, String> values) {
    ExtendedIterator<Ontology> iter = ontModel.listOntologies();
    if ( iter.hasNext() ) {
      Ontology ont = (Ontology) iter.next();
      for ( String uri : values.keySet() ) {
        String value = values.get(uri);
        if ( value.trim().length() > 0 ) {
          Property prop = ResourceFactory.createProperty(uri);
          if ( doSet  &&  ont.getPropertyValue(prop) != null ) {
            ont.removeAll(prop);
          }
          ont.addProperty(prop, value.trim());
        }
      }
    }
    return ontModel;
  }
View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

      return;
    }

    List<Ontology> list = new ArrayList<Ontology>();
    while ( onts.hasNext() ) {
      Ontology ontology = onts.next();
      list.add(ontology);
    }
   
    if ( list.size() == 0 ) {
      return;
    }
   
    boolean includeOntUri = list.size() > 1 ;
    StringBuffer sb = new StringBuffer();
    for ( Ontology ontology : list ) {
      String ontUri = ontology.getURI();
      System.err.println("_prepareInfoAboutOntology: ontUri: " +ontUri);
      String versionFrom = null;
      String versionValue = null;
      RDFNode node = ontology.getPropertyValue(OMV_VERSION);
      if ( node != null ) {
        versionFrom = " (from omv:version)";
        if ( node.isLiteral() ) {
          versionValue = ((Literal) node).getLexicalForm();
        }
        else {
          versionValue = node.toString();
        }
      }
      else {
        versionValue = ontology.getVersionInfo();
        if ( versionValue != null ) {
          versionFrom = " (from owl:versionInfo)";
        }
      }
      if ( versionValue == null ) {
View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

   
    // The new OntModel that will contain the pre-existing attributes (if any),
    // plus the new and updated attributes:
    final OntModel newOntModel = _createOntModel(model);
    final Ontology ont_ = newOntModel.createOntology(base_);
    log.info("New ontology created with namespace " + ns_ + " base " + base_);
    newOntModel.setNsPrefix("", ns_);
   
    // set preferred prefixes:
    Map<String, String> preferredPrefixMap = MdHelper.getPreferredPrefixMap();
    for ( String uri : preferredPrefixMap.keySet() ) {
      String prefix = preferredPrefixMap.get(uri);
      newOntModel.setNsPrefix(prefix, uri);
    }
   
   
    // Set internal attributes, which are updated in the newValues map itself
    // so we facilite the processing below:
    newValues.put(Omv.version.getURI(), version);
   
    newValues.put(Omv.creationDate.getURI(), creationDate);
   
   
    // set some properties from the explicit values
    newValues.put(OmvMmi.origMaintainerCode.getURI(), orgAbbreviation);


    //////////////////////////////////////////////////
    // transfer any preexisting attributes, and then remove all properties from
    // pre-existing ontRes so just the new OntModel gets added.
    if ( ontRes != null ) {
      for ( Statement st : prexistStatements ) {
        Property prd = st.getPredicate();

        //
        // Do not tranfer pre-existing/pre-assigned-above attributes
        //
        String newValue = newValues.get(prd.getURI());
        if ( newValue == null || newValue.trim().length() == 0 ) {
          log.info("  Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
          newOntModel.add(ont_, prd, st.getObject());
        }
        else {
          log.info(" Removing pre-existing values for predicate: " +prd+ " because of new value " +newValue);
          newOntModel.removeAll(ont_, prd, null);
        }
      } 
     
     
      if ( ! createOntologyResult.isPreserveOriginalBaseNamespace() ) {
       
        //
        // Only, when we're creating a new model, ie., per the new namespace, do the following removals.
        // (If we did this on a model with the same original namespace, we would remove the owl:Ontology
        // entry altogether and get an "rdf:Description" instead.
        //
       
        log.info("Removing original OWL.Ontology individual");
        ontRes.removeProperties();
        // TODO the following may be unnecesary but doesn't hurt:
        model.remove(ontRes, RDF.type, OWL.Ontology);
      }
    }

   
   
    ///////////////////////////////////////////////////////
    // Update attributes in model:

    Map<String, Property> uriPropMap = MdHelper.getUriPropMap();
    for ( String uri : newValues.keySet() ) {
      String value = newValues.get(uri).trim();
      if ( value.length() > 0 ) {
        Property prop = uriPropMap.get(uri);
        if ( prop == null ) {
          log.info("No property found for uri='" +uri+ "'");
          continue;
        }

        log.info(" Assigning: " +uri+ " = " +value);
        ont_.addProperty(prop, value);
      }
    }
   

View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

   
    ////////////////////////////////////////////
    // load  model

    OntModel model;
    Ontology ont;
    String uriForEmpty;
    String newContentsFileName;

    if ( createOntologyResult.getFullPath() != null ) {
      //
      // new contents to check.
      // Get model from the new contents.
      //
      full_path = createOntologyResult.getFullPath();
      log.info("Loading model: " +full_path);

      File file = new File(full_path);
     
      try {
        model = Util2.loadModelWithCheckingUtf8(file, null);
      }
      catch ( Throwable ex ) {
        String error = "Unexpected error: " +ex.getClass().getName()+ " : " +ex.getMessage();
        log.info(error);
        createOntologyResult.setError(error);
        return createOntologyResult;
      }
     
      ont = JenaUtil2.getOntology(model);
     
      // get original namespace associated with the ontology, if any:
      uriForEmpty = Util2.getDefaultNamespace(model, file, createOntologyResult);
      // 2009-12-21: previously returning error if uriForEmpty==null. Not anymore; see below.
     
      newContentsFileName = file.getName();
    }
    else {
      // NO new contents.
      // Use contents from prior version.
      PriorOntologyInfo priorVersionInfo = createOntologyInfo.getPriorOntologyInfo();
     
      try {
        model = OntServiceUtil.retrieveModel(createOntologyInfo.getUri(), priorVersionInfo.getVersionNumber());
      }
      catch (Exception e) {
        String error = "error while retrieving registered ontology: " +e.getMessage();
        log.info(error, e);
        createOntologyResult.setError(error);
        return createOntologyResult;
      }
     
      ont = JenaUtil2.getOntology(model);
      if ( ont == null ) {
        // Shouldn't happen -- we're reading in an already registered version.
        String error = "error while getting Ontology resource a registered version. " +
            "Please report this bug.";
        log.info(error);
        createOntologyResult.setError(error);
        return createOntologyResult;
      }
      uriForEmpty = ont.getURI();

      // replace ':', '/', or '\' for '_'
      newContentsFileName = uriForEmpty.replaceAll(":|/|\\\\", "_");
    }

     
   
    final String original_base_ = uriForEmpty == null ? null : JenaUtil2.removeTrailingFragment(uriForEmpty);

    // and this is the info for the requested URI:
    final String ontUri = createOntologyInfo.getUri();
    final String ns_ = JenaUtil2.appendFragment(ontUri);
    final String base_ = JenaUtil2.removeTrailingFragment(ontUri);

    log.info("createOntologyReHosted: original namespace: " +original_base_);
    if ( original_base_ != null && ! original_base_.equals(base_) ) {
      // In this re-hosted case, we force the original URI and the new URI to be the same.
      // This may happen only in the case of a submission of a new version.
      String error = "The new base URI (" +base_+ ") is not equal to the registered " +
        "base URI (" +original_base_+ ") "
      ;
      log.debug(error);
      createOntologyResult.setError(error);
      return createOntologyResult;
    }
   
    /////////////////////////////////////////////////////////////////
    // If there is an pre-existing Ontology resource, get the associated statements:
    List<Statement> prexistStatements = null;
    if ( ont != null ) {
      prexistStatements = new ArrayList<Statement>();
      if ( log.isDebugEnabled() ) {
        log.debug("Getting pre-existing properties from Ontology: " +ont.getURI());
      }
      StmtIterator iter = ont.listProperties();
      while ( iter.hasNext() ) {
        Statement st = iter.nextStatement();
        prexistStatements.add(st);
     
    }

   
    // The new OntModel that will contain the pre-existing attributes (if any),
    // plus the new and updated attributes:
    final OntModel newOntModel = OntModelUtil.createOntModel(base_, model);
    final Ontology ont_ = JenaUtil2.getOntology(newOntModel);
    if ( log.isDebugEnabled() ) {
      log.debug("New ontology created with namespace " + ns_ + " base " + base_);
    }
   
    // Set internal attributes, which are updated in the newValues map itself
    // so we facilite the processing below:
    newValues.put(Omv.version.getURI(), version);
    newValues.put(Omv.creationDate.getURI(), creationDate);
   

    //////////////////////////////////////////////////
    // transfer any preexisting attributes, and then remove all properties from
    // pre-existing ont so just the new OntModel gets added.
    if ( prexistStatements != null ) {
      for ( Statement st : prexistStatements ) {
        Property prd = st.getPredicate();

        //
        // Do not tranfer pre-existing/pre-assigned-above attributes
        //
        String newValue = newValues.get(prd.getURI());
        if ( newValue == null || newValue.trim().length() == 0 ) {
          if ( log.isDebugEnabled() ) {
            log.debug("  Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
          }
          newOntModel.add(ont_, prd, st.getObject());
        }
        else {
          if ( log.isDebugEnabled() ) {
            log.debug(" Removing pre-existing values for predicate: " +prd+ " because of new value " +newValue);
          }
          newOntModel.removeAll(ont_, prd, null);
        }
      } 
     
    }

   
   
    ///////////////////////////////////////////////////////
    // Update attributes in model:

    Map<String, Property> uriPropMap = MdHelper.getUriPropMap();
    for ( String uri : newValues.keySet() ) {
      String value = newValues.get(uri);
      if ( value != null && value.trim().length() > 0 ) {
        Property prop = uriPropMap.get(uri);
        if ( prop == null ) {
          log.info("No property found for uri='" +uri+ "'");
          continue;
        }

        log.info(" Assigning: " +uri+ " = " +value);
        ont_.addProperty(prop, value);
      }
    }
   

View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

   
    // The new OntModel that will contain the pre-existing attributes (if any),
    // plus the new and updated attributes:
    final OntModel newOntModel = _createOntModel(model);
    final Ontology ont_ = newOntModel.createOntology(base_);
    log.info("New ontology created with namespace " + ns_ + " base " + base_);
    newOntModel.setNsPrefix("", ns_);
   
    // set preferred prefixes:
    Map<String, String> preferredPrefixMap = MdHelper.getPreferredPrefixMap();
    for ( String uri : preferredPrefixMap.keySet() ) {
      String prefix = preferredPrefixMap.get(uri);
      newOntModel.setNsPrefix(prefix, uri);
    }
   
   
    // Set internal attributes, which are updated in the newValues map itself
    // so we facilite the processing below:
    newValues.put(Omv.uri.getURI(), base_);
    newValues.put(Omv.version.getURI(), version);
   
    newValues.put(Omv.creationDate.getURI(), creationDate);


    //////////////////////////////////////////////////
    // transfer any preexisting attributes, and then remove all properties from
    // pre-existing ontRes so just the new OntModel gets added.
    if ( ontRes != null ) {
      for ( Statement st : prexistStatements ) {
        Property prd = st.getPredicate();

        //
        // Do not tranfer pre-existing/pre-assigned-above attributes
        //
        String newValue = newValues.get(prd.getURI());
        if ( newValue == null || newValue.trim().length() == 0 ) {
          log.info("  Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
          newOntModel.add(ont_, prd, st.getObject());
        }
        else {
          log.info(" Removing pre-existing values for predicate: " +prd+ " because of new value " +newValue);
          newOntModel.removeAll(ont_, prd, null);
        }
      } 
     
     
      if ( ! createOntologyResult.isPreserveOriginalBaseNamespace() ) {
       
        //
        // Only, when we're creating a new model, ie., per the new namespace, do the following removals.
        // (If we did this on a model with the same original namespace, we would remove the owl:Ontology
        // entry altogether and get an "rdf:Description" instead.
        //
       
        log.info("Removing original OWL.Ontology individual");
        ontRes.removeProperties();
        // TODO the following may be unnecesary but doesn't hurt:
        model.remove(ontRes, RDF.type, OWL.Ontology);
      }
    }

   
   
    ///////////////////////////////////////////////////////
    // Update attributes in model:

    Map<String, Property> uriPropMap = MdHelper.getUriPropMap();
    for ( String uri : newValues.keySet() ) {
      String value = newValues.get(uri).trim();
      if ( value.length() > 0 ) {
        Property prop = uriPropMap.get(uri);
        if ( prop == null ) {
          log.info("No property found for uri='" +uri+ "'");
          continue;
        }

        log.info(" Assigning: " +uri+ " = " +value);
        ont_.addProperty(prop, value);
      }
    }
   

View Full Code Here

Examples of com.hp.hpl.jena.ontology.Ontology

    for ( String uri : preferredPrefixMap.keySet() ) {
      String prefix = preferredPrefixMap.get(uri);
      newOntModel.setNsPrefix(prefix, uri);
    }
   
    Ontology ont = newOntModel.createOntology(base_);
    if ( log.isDebugEnabled() ) {
      log.debug("New ontology created with namespace " + ns_ + " base " + base_);
    }

    // Indicate VINE as the engineering tool:
    ont.addProperty(Omv.usedOntologyEngineeringTool, OmvMmi.vine);
   
    // add any desired owl:imports
    _addImports(ont);
   
    Map<String, Property> uriPropMap = MdHelper.getUriPropMap();
    for ( String uri : values.keySet() ) {
      String value = values.get(uri);
      if ( value.trim().length() > 0 ) {
        Property prop = uriPropMap.get(uri);
        if ( prop == null ) {
          log.warn("No property found for uri='" +uri+ "'");
          continue;
        }
        ont.addProperty(prop, value.trim());
      }
    }
   
    // set Omv.uri from final
    ont.addProperty(Omv.uri, finalUri);
   
    // TODO set Omv.acronym from something
    ont.addProperty(Omv.acronym, "ACRONYM");
   
   
    String fullTitle = values.get("fullTitle");
    if ( fullTitle != null ) {
      ont.addProperty(Omv.name, fullTitle);
    }
   
    String creator = values.get("creator");
    if ( creator != null ) {
      ont.addProperty(Omv.hasCreator, creator);
    }
   
    String briefDescription = values.get("briefDescription");
    if ( briefDescription != null ) {
      ont.addProperty(Omv.description, briefDescription);
    }
   
    if ( orgAbbreviation != null && orgAbbreviation.trim().length() > 0 ) {
      ont.addProperty(OmvMmi.origMaintainerCode, orgAbbreviation.trim());
    }
   
    createContents();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.