@Override
 public boolean accept(OntClass cls) {
   if (!cls.isAnon()) {
     return cls.getURI().startsWith(RDFS.getURI());
   }
   return false;
 }
示例#2
0
 private void unifyRDFSVersion(String ns) {
   for (Iterator it = Jena.cloneIt(model.listStatements()); it.hasNext(); ) {
     Statement s = (Statement) it.next();
     Resource newSubject = s.getSubject();
     Property newPredicate = s.getPredicate();
     RDFNode newObject = s.getObject();
     boolean changed = false;
     if (ns.equals(newSubject.getNameSpace())) {
       changed = true;
       newSubject = model.getResource(RDFS.getURI() + newSubject.getLocalName());
     }
     if (ns.equals(newPredicate.getNameSpace())) {
       changed = true;
       newPredicate = model.getProperty(RDFS.getURI() + newPredicate.getLocalName());
     }
     if (newObject.canAs(Resource.class)) {
       Resource oldResource = (Resource) newObject.as(Resource.class);
       if (ns.equals(oldResource.getNameSpace())) {
         changed = true;
         newObject = model.getResource(RDFS.getURI() + oldResource.getLocalName());
       }
     }
     if (changed) {
       model.add(newSubject, newPredicate, newObject);
       if (log.isLoggable(Level.FINE)) {
         log.fine(
             "Replaced deprecated triple "
                 + s
                 + " with "
                 + newSubject
                 + ", "
                 + newPredicate
                 + ", "
                 + newObject);
       }
       it.remove();
     }
   }
 }
  public void setSubPropertyOf(Properties Properties, OntModel ontologyModel) {

    Iterator<OntProperty> IteratorExtractedProperties =
        Properties.getExtractedProperty().iterator();
    while (IteratorExtractedProperties.hasNext()) {
      OntProperty property = (OntProperty) IteratorExtractedProperties.next();
      String URI = property.getURI();

      if (URI != null) {
        try {
          ExtendedIterator<OntProperty> itSup =
              (ExtendedIterator<OntProperty>) property.listSuperProperties(true);
          while (itSup.hasNext()) {
            OntProperty propertySup = itSup.next();
            String URISUP = propertySup.getURI();

            if (URISUP != null) {
              addSubPropertyOfRelation(property, propertySup);
            }
          }
        } catch (Exception e) {
          // SPARQL Query for SubProperties
          String queryString =
              "PREFIX rdfs:<"
                  + RDFS.getURI()
                  + ">"
                  + "PREFIX ont:<"
                  + property.getNameSpace()
                  + ">"
                  + "SELECT ?obj "
                  + "WHERE {"
                  + "      ont:"
                  + property.getLocalName()
                  + " rdfs:subPropertyOf ?obj"
                  + "      }";

          // Execute Query
          Query query = QueryFactory.create(queryString);
          QueryExecution qexec = QueryExecutionFactory.create(query, ontologyModel);

          try {

            ResultSet results = qexec.execSelect();

            // Temporary Model in Order to Construct Node for External Property
            OntModel ontologyTempModel =
                ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, null);

            // Extract Relation
            for (; results.hasNext(); ) {
              QuerySolution soln = results.nextSolution();

              Resource obj = soln.getResource("obj");
              String URIObj = obj.getURI();

              // Get SubPropertyOf all Property different from the current one
              if (URIObj != null && property.getURI() != URIObj) {
                OntProperty propertySup = ontologyTempModel.createOntProperty(URIObj);

                // Save SubPropertyOf Relation (property SubPropertyOf PropertySub)
                addSubPropertyOfRelation(property, propertySup);
              }
            }
          } finally {
            qexec.close();
          }
        }
      }
    }
  }