Beispiel #1
0
  public String shortForm(OWLNamedObject ono) throws OWLException {
    /* If it's an anonymous one, create a new name for it. */
    if (ono instanceof OWLIndividual) {
      OWLIndividual oi = (OWLIndividual) ono;
      if (oi.isAnonymous()) {
        if (!anonymousIndividuals.containsKey(oi)) {

          String newName = "|_" + sdf.format(new Date()) + "-" + random.nextInt(1000) + "|";
          anonymousIndividuals.put(oi, newName);
        }
        return (String) anonymousIndividuals.get(oi);
      }
    }
    URI uri = ono.getURI();
    if (uri == null) {
      return "|_|";
    }
    try {
      if (uri.getFragment() == null) {
        /* It's not of the form http://xyz/path#frag */
        return "|" + uri.toString() + "|";
      }
      /* It's of the form http://xyz/path#frag */
      String ssp = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null).toString();
      if (!ssp.endsWith("#")) {
        ssp = ssp + "#";
      }
      if (known.keySet().contains(ssp)) {
        return "|" + (String) known.get(ssp) + ":" + uri.getFragment() + "|";
      }
      if (shortNames.contains(ssp)) {
        if ((shortNames.indexOf(ssp)) < names.length) {
          return "|" + (names[shortNames.indexOf(ssp)]) + ":" + uri.getFragment() + "|";
        }
        /* We can't shorten it -- there are too many...*/
        return "|" + uri.toString() + "|";
      }
    } catch (URISyntaxException ex) {
    }
    return "|" + uri.toString() + "|";
  }
  /** Gather togther all the URIs that are used by this ontology. */
  private void gatherURIs() throws OWLException {
    /* Initialise the collections. */
    this.classURIs = new HashSet();
    this.individualURIs = new HashSet();
    this.objectPropertyURIs = new HashSet();
    this.dataPropertyURIs = new HashSet();
    this.annotationPropertyURIs = new HashSet();
    this.datatypeURIs = new HashSet();
    this.allURIs = new HashSet();

    /* Collect together all the URIs */
    for (Iterator it = allOntologies.iterator(); it.hasNext(); ) {
      OWLOntology onto = (OWLOntology) it.next();
      for (Iterator cit = onto.getClasses().iterator(); cit.hasNext(); ) {
        OWLNamedObject entity = (OWLNamedObject) cit.next();
        classURIs.add(entity.getURI());
        allURIs.add(entity.getURI());
      }
      for (Iterator cit = onto.getIndividuals().iterator(); cit.hasNext(); ) {
        OWLNamedObject entity = (OWLNamedObject) cit.next();
        individualURIs.add(entity.getURI());
        allURIs.add(entity.getURI());
      }
      for (Iterator cit = onto.getObjectProperties().iterator(); cit.hasNext(); ) {
        OWLNamedObject entity = (OWLNamedObject) cit.next();
        objectPropertyURIs.add(entity.getURI());
        allURIs.add(entity.getURI());
      }
      for (Iterator cit = onto.getDataProperties().iterator(); cit.hasNext(); ) {
        OWLNamedObject entity = (OWLNamedObject) cit.next();
        dataPropertyURIs.add(entity.getURI());
        allURIs.add(entity.getURI());
      }
      for (Iterator cit = onto.getAnnotationProperties().iterator(); cit.hasNext(); ) {
        OWLNamedObject entity = (OWLNamedObject) cit.next();
        annotationPropertyURIs.add(entity.getURI());
        allURIs.add(entity.getURI());
      }
      for (Iterator cit = onto.getDatatypes().iterator(); cit.hasNext(); ) {
        OWLDataType entity = (OWLDataType) cit.next();
        datatypeURIs.add(entity.getURI());
        allURIs.add(entity.getURI());
      }
    }
  }