private float execute(OntClass c1, OntClass c2) {
    int max = 0, min = 0;
    Collection<OntProperty> listaProps2 = OntologyCache.getOrAddListProperties(c2);

    for (Iterator i = OntologyCache.getOrAddListProperties(c1).iterator(); i.hasNext(); ) {
      OntProperty p1 = (OntProperty) i.next();
      if (p1.isDatatypeProperty()) {
        max += 1;
        for (OntProperty p2 : listaProps2) {
          if (p2.isDatatypeProperty()) {
            SimilarityVO similarityVO = new SimilarityVO();
            similarityVO.setElementA(p1);
            similarityVO.setElementB(p2);
            similarityVO.setSimilarity(
                strategyEditDistance.compute(p1.getLocalName(), p2.getLocalName()));
            similaridade.add(similarityVO);
          }
        }
      }
    }
    // Loop para pegar o numero de datatypeproperty de c2
    for (OntProperty p2 : listaProps2) if (p2.isDatatypeProperty()) min += 1;

    similaridade = strategyCalculation.explore(similaridade);
    return averageWithPenalty(sumSimilarities(), max, min);
  }
  /**
   * If @param superClassUri is a superclass of @param subClassUri, it returns true; otherwise,
   * false. If third parameter is set to true, it also considers indirect superclasses.
   *
   * @param superClassUri
   * @param subClassUri
   * @param recursive
   * @return
   */
  public boolean isSubClass(String subClassUri, String superClassUri, boolean recursive) {

    if (ontCache.getDirectSubClassCheck().contains(subClassUri + superClassUri)) return true;
    else if (recursive)
      return ontCache.getIndirectSubClassCheck().contains(subClassUri + superClassUri);

    return false;
  }
  /**
   * This function takes a class uri and returns the object properties who have this class in their
   * domain. If second parameter set to True, it also returns the object properties inherited from
   * parents of the given class.
   *
   * @param domainUri
   * @param inheritance
   * @return
   */
  public HashSet<String> getObjectPropertiesOfClass(String domainUri, boolean inheritance) {

    HashSet<String> direct = ontCache.getDirectOutObjectProperties().get(domainUri);
    if (!inheritance) return direct;

    HashSet<String> all = new HashSet<String>();
    HashSet<String> indirect = ontCache.getIndirectOutObjectProperties().get(domainUri);
    if (direct != null) all.addAll(direct);
    if (indirect != null) all.addAll(indirect);
    return all;
  }
  /**
   * returns URIs of all super-properties of @param propertyUri
   *
   * @param propertyUri
   * @param recursive
   * @return
   */
  public HashMap<String, Label> getSuperProperties(String propertyUri, boolean recursive) {

    HashMap<String, Label> direct = ontCache.getDirectSuperProperties().get(propertyUri);
    if (!recursive) return direct;

    HashMap<String, Label> all = new HashMap<String, Label>();
    HashMap<String, Label> indirect = ontCache.getIndirectSuperProperties().get(propertyUri);
    if (direct != null) all.putAll(direct);
    if (indirect != null) all.putAll(indirect);
    return all;
  }
  /**
   * This method takes a property URI and returns ranges of that property. If @param recursive is
   * true, it also returns the children of the domains.
   *
   * @param propertyUri
   * @param recursive
   * @return
   */
  public HashSet<String> getRangesOfProperty(String propertyUri, boolean recursive) {

    HashSet<String> results = new HashSet<String>();
    HashSet<String> direct = null;
    HashSet<String> indirect = null;

    direct = ontCache.getPropertyDirectRanges().get(propertyUri);
    if (direct != null) results.addAll(direct);
    if (recursive) indirect = ontCache.getPropertyIndirectRanges().get(propertyUri);
    if (indirect != null) results.addAll(indirect);

    return results;
  }
  public boolean doImportAndUpdateCache(File sourceFile, String encoding) {

    if (sourceFile == null) {
      logger.debug("input file is null.");
      return false;
    }

    logger.debug("Importing " + sourceFile.getName() + " OWL Ontology ...");

    if (!sourceFile.exists()) {
      logger.error("file does not exist  " + sourceFile.getAbsolutePath());
      return false;
    }

    try {
      InputStreamReader s = EncodingDetector.getInputStreamReader(sourceFile, encoding);
      ontHandler.getOntModel().read(s, null);
    } catch (Throwable t) {
      logger.error("Error reading the OWL ontology file!", t);
      return false;
    }

    // update the cache
    ontCache = new OntologyCache(ontHandler);
    ontCache.init();

    // notify listeners
    this.notifyListeners();

    logger.debug("done.");
    return true;
  }
  public Map<String, Label> getDataPropertiesByDomain(String domainUri, boolean recursive) {

    HashSet<String> dataProperties = ontCache.getDirectOutDataProperties().get(domainUri);
    if (recursive) {
      HashSet<String> propRecursive = ontCache.getIndirectOutDataProperties().get(domainUri);
      if (propRecursive != null) dataProperties.addAll(propRecursive);
    }
    HashMap<String, Label> results = new HashMap<String, Label>();

    if (dataProperties == null) return results;

    for (String op : dataProperties) {
      results.put(op, ontCache.getPropertyLabel(op));
    }

    return results;
  }
  public Map<String, Label> getObjectPropertiesByRange(String rangeUri, boolean recursive) {

    HashSet<String> objectProperties = ontCache.getDirectInObjectProperties().get(rangeUri);
    if (recursive) {
      HashSet<String> propRecursive = ontCache.getIndirectInObjectProperties().get(rangeUri);
      if (propRecursive != null) objectProperties.addAll(propRecursive);
    }
    HashMap<String, Label> results = new HashMap<String, Label>();

    if (objectProperties == null) return results;

    for (String op : objectProperties) {
      results.put(op, ontCache.getPropertyLabel(op));
    }

    return results;
  }
  /**
   * This method takes @param rangeClassUri and for object properties whose ranges includes this
   * parameter, returns all of their domains. If @param recursive is true, it also returns the
   * children of the domains.
   *
   * @param rangeUri
   * @param recursive
   * @return
   */
  public HashSet<String> getDomainsGivenRange(String rangeUri, boolean recursive) {

    HashSet<String> objectProperties = ontCache.getDirectInObjectProperties().get(rangeUri);
    HashSet<String> results = new HashSet<String>();
    HashSet<String> direct = null;
    HashSet<String> indirect = null;

    if (objectProperties == null) return results;

    for (String op : objectProperties) {
      direct = ontCache.getPropertyDirectDomains().get(op);
      if (direct != null) results.addAll(direct);
      if (recursive) indirect = ontCache.getPropertyIndirectDomains().get(op);
      if (indirect != null) results.addAll(indirect);
    }

    return results;
  }
示例#10
0
  /**
   * This method takes @param domainUri and rangeClassUri and for returns all links/properties with
   * this domain & range If @param recursive is true, it also returns the children of the domains.
   *
   * @param domainUri
   * @param rangeUri
   * @param recursive
   * @return
   */
  public Map<String, Label> getObjectPropertiesByDomainRange(
      String domainUri, String rangeUri, boolean recursive) {

    if (domainUri == null || domainUri.length() == 0)
      return this.getObjectPropertiesByRange(rangeUri, recursive);

    if (rangeUri == null || rangeUri.length() == 0)
      return this.getObjectPropertiesByDomain(domainUri, recursive);

    HashSet<String> objectProperties = ontCache.getDirectInObjectProperties().get(rangeUri);
    if (recursive) {
      HashSet<String> propRecursive = ontCache.getIndirectInObjectProperties().get(rangeUri);
      if (propRecursive != null) objectProperties.addAll(propRecursive);
    }
    HashMap<String, Label> results = new HashMap<String, Label>();
    HashSet<String> direct = null;
    HashSet<String> indirect = null;

    if (objectProperties == null) return results;

    for (String op : objectProperties) {
      boolean propAdded = false;
      direct = ontCache.getPropertyDirectDomains().get(op);
      if (direct != null) {
        for (String directDomain : direct) {
          if (directDomain.equals(domainUri)) {
            results.put(op, ontCache.getPropertyLabel(op));
            propAdded = true;
            break;
          }
        }
        // results.addAll(direct);
      }
      if (propAdded) continue;
      if (recursive) indirect = ontCache.getPropertyIndirectDomains().get(op);
      if (indirect != null) {
        // results.addAll(indirect);
        for (String indirectDomain : indirect) {
          if (indirectDomain.equals(domainUri)) {
            results.put(op, ontCache.getPropertyLabel(op));
            propAdded = true;
            break;
          }
        }
      }
    }

    return results;
  }
示例#11
0
 public void updateCache() {
   ontCache = new OntologyCache(ontHandler);
   ontCache.init();
 }