Ejemplo n.º 1
0
  /** Prints out the inferred classes of the aligned ontology */
  public void printInfClasses(Model model) {
    ExtendedIterator<OntClass> classes = ((OntModel) model).listClasses();
    while (classes.hasNext()) {
      OntClass thisClass = (OntClass) classes.next();
      if (thisClass.getLocalName() != null) {
        System.out.println("Found class: " + thisClass.getLocalName());

        ExtendedIterator inst = thisClass.listInstances();
        while (inst.hasNext()) {
          Individual thisInstance = (Individual) inst.next();
          System.out.println("\tFound instance: " + thisInstance.getLocalName());
        }
      }
    }
  } // printInfClasses
Ejemplo n.º 2
0
  /**
   * Returns a collection of RDFStatements that match the described subject
   *
   * @param subject Subject
   * @return collection of RDFStatements
   */
  public Collection<RDFStatement> getStatements(String subject) {

    if (subject == null || subject.isEmpty()) {
      return null;
    }
    List<RDFStatement> statement = null;

    try {
      // define a describe query
      String query = String.format("DESCRIBE %s FROM < %s >", subject, this.graphName);

      logger.debug("Query: \n{}", query);
      Query sparqlQuery = QueryFactory.create(query);
      VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create(sparqlQuery, this.graph);
      // execute the query and get the graph
      Model model = vqe.execDescribe();
      Graph queriedGraph = model.getGraph();
      // itreate over the retrieved triples, and place them inside a list
      ExtendedIterator<Triple> iter = queriedGraph.find(Node.ANY, Node.ANY, Node.ANY);
      statement = new ArrayList<>();
      while (iter.hasNext()) {
        Triple t = (Triple) iter.next();
        RDFStatement stmt =
            new RDFStatement(
                t.getSubject().toString(), t.getPredicate().toString(), t.getObject().toString());
        statement.add(stmt);
      }
    } catch (Exception ex) {
      logger.error("Exception occured while querying for statements", ex);
    }
    return statement;
  }
 /**
  * List of all subproperties of the predicate parameter
  *
  * @param prop prefix namespace : name of the propoety
  * @return list<prefix:prop_name>
  */
 public List<String> listSubProp(String prop) {
   List<String> l = new ArrayList<String>();
   ExtendedIterator<OntProperty> listAllOntProperties = ontologie.listAllOntProperties();
   while (listAllOntProperties.hasNext()) {
     OntProperty next = listAllOntProperties.next();
     if (next.getLocalName().equals(prop.split(":")[1])
         && next.getNameSpace().equals(prop.split(":")[0])) {
       ExtendedIterator<? extends OntProperty> listSubProperties = next.listSubProperties();
       while (listSubProperties.hasNext()) {
         OntProperty next2 = listSubProperties.next();
         l.add(next2.getNameSpace() + ":" + next2.getLocalName());
       }
     }
   }
   return l;
 }
Ejemplo n.º 4
0
  private void fillMap(
      Resource s, Model model, Map<Resource, SortedSet<Statement>> resource2Statements) {

    // get all statements with subject s
    ExtendedIterator<Statement> it = model.listStatements(s, null, (RDFNode) null);

    // filter statement if necessary
    if (!dropFilters.isEmpty()) {
      Iterator<Filter<Statement>> iter = dropFilters.iterator();
      Filter<Statement> keepFilter = iter.next();
      it = it.filterKeep(keepFilter);
      while (iter.hasNext()) {
        it = it.filterKeep(iter.next());
        //				keepFilter = keepFilter.and(iter.next());
      }
      //			it = it.filterKeep(keepFilter);
    }

    SortedSet<Statement> statements = resource2Statements.get(s);
    if (statements == null) {
      statements = new TreeSet<Statement>(comparator);
      resource2Statements.put(s, statements);
    }

    while (it.hasNext()) {
      Statement st = it.next();
      statements.add(st);
      if ((st.getObject().isResource()) && !resource2Statements.containsKey(st.getObject())) {
        fillMap(st.getObject().asResource(), model, resource2Statements);
      }
    }
  }
  public SPDXChecksum(Model spdxModel, Node checksumNode) throws InvalidSPDXAnalysisException {
    this.model = spdxModel;
    this.checksumNode = checksumNode;
    if (checksumNode.isBlank()) {
      checksumResource = model.createResource(checksumNode.getBlankNodeId());
    } else if (checksumNode.isURI()) {
      checksumResource = model.createResource(checksumNode.getURI());
    } else {
      throw (new InvalidSPDXAnalysisException("Checksum node can not be a literal"));
    }
    // Algorithm
    Node p =
        spdxModel
            .getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_ALGORITHM)
            .asNode();
    Triple m = Triple.createMatch(checksumNode, p, null);
    ExtendedIterator<Triple> tripleIter = spdxModel.getGraph().find(m);
    while (tripleIter.hasNext()) {
      Triple t = tripleIter.next();
      if (t.getObject().isLiteral()) {
        // The following is for compatibility with rdf generated with older
        // versions of the tool
        this.algorithm = t.getObject().toString(false);
      } else if (t.getObject().isURI()) {
        this.algorithm = URI_TO_ALGORITHM.get(t.getObject().getURI());
        if (this.algorithm == null) {
          this.algorithm = "UNKNOWN";
        }
      } else {
        throw (new InvalidSPDXAnalysisException(
            "Invalid checksum algorithm - must be one of the defined algorithms supported by SPDX."));
      }
    }

    // value
    p =
        spdxModel
            .getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE)
            .asNode();
    m = Triple.createMatch(checksumNode, p, null);
    tripleIter = spdxModel.getGraph().find(m);
    while (tripleIter.hasNext()) {
      Triple t = tripleIter.next();
      this.value = t.getObject().toString(false);
    }
  }
 /**
  * Find the next result triple and bind the result vars appropriately.
  *
  * @param interpreter the calling interpreter whose trail should be used
  * @return false if there are no more matches in the iterator.
  */
 public boolean nextMatch(LPInterpreter interpreter) {
   if (matchIterator.hasNext()) {
     lastMatch = matchIterator.next();
     return true;
   } else {
     return false;
   }
 }
 /**
  * @param ontology - OntModel to extract all OntClasses.
  * @return
  */
 public static ArrayList<OntClass> getAllOWLClasses(final OntModel ontology) {
   ExtendedIterator<OntClass> owlClasses = ontology.listClasses();
   ArrayList<OntClass> ontologyClasses = new ArrayList<OntClass>();
   while (owlClasses.hasNext()) {
     ontologyClasses.add(owlClasses.next());
   }
   return ontologyClasses;
 }
 @Override
 public void addGraph(Node gn, Graph g) {
   // Convert to quads.
   // super.addGraph(gn, g) ;
   ExtendedIterator<Triple> iter = g.find(Node.ANY, Node.ANY, Node.ANY);
   for (; iter.hasNext(); ) {
     Triple t = iter.next();
     add(gn, t.getSubject(), t.getPredicate(), t.getObject());
   }
 }
Ejemplo n.º 9
0
 public static void removeAll(Graph g, Node s, Node p, Node o) {
   ExtendedIterator<Triple> it = g.find(s, p, o);
   try {
     while (it.hasNext()) {
       Triple t = it.next();
       g.delete(t);
       it.remove();
     }
   } finally {
     it.close();
   }
 }
Ejemplo n.º 10
0
  public static void main(String args[]) {
    String filename = "example6.rdf";

    // Create an empty model
    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);

    // Use the FileManager to find the input file
    InputStream in = FileManager.get().open(filename);

    if (in == null) throw new IllegalArgumentException("File: " + filename + " not found");

    // Read the RDF/XML file
    model.read(in, null);
    // model.write(System.out,"Turtle");

    ExtendedIterator<? extends OntResource> iterator;
    // ** TASK 7.1: List all individuals of "Person" **
    OntClass person = model.getOntClass(ns + "Person");

    iterator = person.listInstances();
    System.out.println("Individuals");
    System.out.println("------------------------------------");
    while (iterator.hasNext()) {
      OntResource r = iterator.next();
      System.out.println(r.getURI());
    }
    System.out.println("------------------------------------");
    // ** TASK 7.2: List all subclasses of "Person" **
    iterator = person.listSubClasses();
    System.out.println("Sublcasses");
    System.out.println("------------------------------------");
    while (iterator.hasNext()) {
      OntResource r = iterator.next();
      System.out.println(r.getURI());
    }
    System.out.println("------------------------------------");
    // ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses.
    // TIP: you need some inference... **

  }
Ejemplo n.º 11
0
 public static synchronized boolean isSingleValued(
     OntClass cls, OntProperty prop, String rngString) {
   if (prop.isFunctionalProperty()) {
     return true;
   }
   if (cls != null) {
     ExtendedIterator<OntClass> eitr = cls.listSuperClasses(false);
     while (eitr.hasNext()) {
       OntClass supercls = eitr.next();
       if (supercls.isRestriction()) {
         Restriction rstrct = supercls.asRestriction();
         if (rstrct.isMaxCardinalityRestriction()) {
           MaxCardinalityRestriction mxcr = rstrct.asMaxCardinalityRestriction();
           if (mxcr.getOnProperty().equals(prop) && mxcr.getMaxCardinality() == 1) {
             return true;
           }
         } else if (rstrct.isCardinalityRestriction()) {
           if (rstrct.isCardinalityRestriction()) {
             CardinalityRestriction cr = rstrct.asCardinalityRestriction();
             if (cr.getOnProperty().equals(prop) && cr.getCardinality() == 1) {
               return true;
             }
           }
         } else {
           if (rstrct.hasProperty(OWL2.maxQualifiedCardinality)) {
             if (rstrct.getOnProperty().equals(prop)
                 && rstrct.getProperty(OWL2.maxQualifiedCardinality).getInt() == 1) {
               // check class
               if (rstrct.getProperty(OWL2.onClass).getResource().toString().equals(rngString)) {
                 return true;
               }
             }
           } else if (rstrct.hasProperty(OWL2.qualifiedCardinality)) {
             if (rstrct.getOnProperty().equals(prop)
                 && rstrct.getProperty(OWL2.qualifiedCardinality).getInt() == 1) {
               // check class
               if (rstrct.getProperty(OWL2.onClass).getResource().toString().equals(rngString)) {
                 return true;
               }
             }
           }
           //						StmtIterator siter = rstrct.listProperties();
           //						while (siter.hasNext()) {
           //							System.out.println(siter.nextStatement().toString());
           //						}
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 12
0
  private Node walkTree(
      Model model,
      Dataset oldDataset,
      Node node,
      Node predicate,
      Query query,
      QuerySolution initialBinding,
      Set<Node> reached) {
    QuerySolutionMap localBinding = new QuerySolutionMap();
    localBinding.addAll(initialBinding);
    localBinding.add("arg1", model.asRDFNode(node));
    Dataset dataset = new DatasetWithDifferentDefaultModel(model, oldDataset);
    QueryExecution qexec = ARQFactory.get().createQueryExecution(query, dataset, localBinding);
    ResultSet rs = qexec.execSelect();
    try {
      if (rs.hasNext()) {
        List<String> resultVars = rs.getResultVars();
        String varName = resultVars.get(0);
        RDFNode resultNode = rs.next().get(varName);
        if (resultNode != null) {
          return resultNode.asNode();
        }
      }
    } finally {
      qexec.close();
    }

    // Recurse into parents
    ExtendedIterator<Triple> it = createIterator(model.getGraph(), node, predicate);
    try {
      while (it.hasNext()) {
        Node next = getNext(it.next());
        if ((next.isBlank() || next.isURI()) && !reached.contains(next)) {
          reached.add(next);
          Node nextResult =
              walkTree(model, oldDataset, next, predicate, query, initialBinding, reached);
          if (nextResult != null) {
            return nextResult;
          }
        }
      }
    } finally {
      it.close();
    }

    return null;
  }
Ejemplo n.º 13
0
  public static void removeAll(Graph g) {
    ExtendedIterator<Triple> it = GraphUtil.findAll(g);
    try {
      while (it.hasNext()) {
        Triple t = it.next();
        g.delete(t);
        it.remove();
      }
    } finally {
      it.close();
    }

    // get rid of remaining blank nodes using a SPARQL DELETE
    if (g instanceof SparqlGraph) {
      ((SparqlGraph) g).removeAll();
    }
  }
Ejemplo n.º 14
0
  public Search(
      final java.awt.Frame parent,
      boolean modal,
      final OntClass ontClass,
      final OntProperty ontTarget,
      final JTextField txtField) {
    super(parent, modal);
    initComponents();
    this.parent = (SaveImage) parent;
    this.ontClass = ontClass;
    individuals = new ArrayList<>();
    all_individuals = new ArrayList<>();
    for (NodeIterator i =
            ontClass.listPropertyValues(
                Ontology.getOntModel().getProperty(Ontology.getNameSpace() + "lbl_netbeans"));
        i.hasNext(); ) {
      title_class.setText(i.next().toString());
    }
    this.txtField = txtField;
    model = new InstancesTable();
    tbl_individuals.setModel(model);
    for (ExtendedIterator<? extends OntResource> i = ontClass.listInstances(); i.hasNext(); ) {
      Individual inst = (Individual) i.next();
      if (inst.getNameSpace() != null) {
        individuals.add(inst);
        all_individuals.add(inst);
      }
    }

    tbl_individuals.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              JTable target = (JTable) e.getSource();
              int row = target.getSelectedRow();
              temp = ((SaveImage) parent).getContentFields().get(ontTarget.toString());
              temp.setIndividual(individuals.get(row));
              temp.getField().setText(individuals.get(row).getLocalName());
            }
          }
        });
  }
  public static Collection<Node> containerMembers(Graph graph, Node container, Node containerType) {
    if (!isContainer(graph, container, containerType)) return null;

    ExtendedIterator<Triple> iter = graph.find(container, Node.ANY, Node.ANY);

    SortedMap<Integer, Node> triples = new TreeMap<Integer, Node>(order);
    try {
      for (; iter.hasNext(); ) {
        Triple t = iter.next();
        int index = getIndex(t);
        if (index == NOT_FOUND) continue;
        // Insert
        triples.put(new Integer(index), t.getObject());
      }
    } finally {
      iter.close();
    }
    return triples.values();
  }
Ejemplo n.º 16
0
  public static void showShows() {
    OntModel model = PersistentOntology.getOntModel();
    model.write(System.out, "N-TRIPLES");
    OntClass show = model.getOntClass(PersistentOntology.NS + "TVShow");

    ExtendedIterator it = show.listInstances();

    while (it.hasNext()) {
      System.out.println("TVSHOW:");
      Individual ind = (Individual) it.next();
      Statement p = ind.getProperty(PersistentOntology.name);
      if (p != null)
        System.out.println(" - name: " + ind.getProperty(PersistentOntology.name).getString());

      p = ind.getProperty(PersistentOntology.status);
      if (p != null)
        System.out.println(" - status: " + ind.getProperty(PersistentOntology.status).getString());

      p = ind.getProperty(PersistentOntology.airDay);
      if (p != null) System.out.println(" - dates: " + p.getString());
      System.out.println();
    }
  }
  private static int countContainerMember(
      Graph graph, Node container, Node containerType, Node member, boolean stopEarly) {
    if (graph == null) {
      Log.warn(GraphContainerUtils.class, "containerMember called with null graph");
      return 0;
    }

    if (container == null) {
      Log.warn(GraphContainerUtils.class, "containerMember called with null list");
      return 0;
    }
    if (member == null) {
      Log.warn(GraphContainerUtils.class, "containerMember called with null member");
      return 0;
    }

    if (!isContainer(graph, container, containerType)) return 0;

    int count = 0;
    ExtendedIterator<Triple> iter = graph.find(container, Node.ANY, member);
    try {
      for (; iter.hasNext(); ) {
        Triple t = iter.next();
        Node p = t.getPredicate();
        String u = p.getURI();

        if (u.matches(membershipPattern)) {
          count++;
          if (stopEarly) return count;
        }
      }
    } finally {
      iter.close();
    }
    return count;
  }
  public void createJenaModel(RegisterContextRequest rcr) {

    OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    Model entityOnt = FileManager.get().loadModel(ONT_FILE);
    ontModel.addSubModel(entityOnt);
    ontModel.setNsPrefixes(entityOnt.getNsPrefixMap());
    //        ontModel.loadImports();

    ExtendedIterator<OntProperty> iter = ontModel.listAllOntProperties();
    while (iter.hasNext()) {
      OntProperty ontProp = iter.next();
      System.out.println(ontProp.getLocalName());
      //            if (formParams.containsKey(ontProp.getLocalName())) {
      //                regIndividual.addProperty(ontProp,
      // ontModel.getcreateTypedLiteral(formParams.get(ontProp.getLocalName())[0]));
      //            }
    }

    //         OntClass regClass = ontModel.getOntClass(ONT_URL + "iotReg");
    //         OntClass entClass = ontModel.createOntClass(ONT_URL + "entity");
    //        OntClass regClass = (OntClass) ontModel.createOntResource(OntClass.class,
    // null,ONT_URL+"Registration" );
    //        OntClass regClass = (OntClass) ontModel.createClass(ONT_URL + "Registration");
    //        OntClass entityClass = (OntClass) ontModel.createClass(ONT_URL + "Entity");
    OntClass entityGroup = (OntClass) ontModel.getOntClass(ONT_URL + "EntityGroup");
    OntClass entity = (OntClass) ontModel.getOntClass(ONT_URL + "Entity");
    OntClass attribute = (OntClass) ontModel.getOntClass(ONT_URL + "Attribute");
    OntClass metadata = (OntClass) ontModel.getOntClass(ONT_URL + "Metadata");
    OntClass location = (OntClass) ontModel.getOntClass(entityOnt.getNsPrefixURI("geo") + "Point");

    //         System.out.println("Class type is: " + regClass.getLocalName());
    String ngsiValue = "";
    ngsiValue = rcr.getRegistrationId();
    Individual entityGroupIndiv = ontModel.createIndividual(ONT_URL + ngsiValue, entityGroup);
    entityGroupIndiv.setPropertyValue(
        ontModel.getProperty(ONT_URL + "registrationId"), ontModel.createLiteral(ngsiValue));
    ngsiValue = rcr.getTimestamp().toString();
    entityGroupIndiv.setPropertyValue(
        ontModel.getProperty(ONT_URL + "regTimeStamp"), ontModel.createLiteral(ngsiValue));
    ngsiValue = rcr.getDuration();
    entityGroupIndiv.setPropertyValue(
        ontModel.getProperty(ONT_URL + "duration"), ontModel.createLiteral(ngsiValue));

    ngsiValue = rcr.getContextRegistration().get(0).getEntityId().get(0).getId();
    Individual entity1 = ontModel.createIndividual(ONT_URL + ngsiValue, entity);
    entityGroupIndiv.setPropertyValue(ontModel.getProperty(ONT_URL + "hasEntity"), entity1);
    ngsiValue = rcr.getContextRegistration().get(0).getEntityId().get(0).getId();
    entity1.setPropertyValue(
        ontModel.getProperty(ONT_URL + "id"), ontModel.createLiteral(ngsiValue));
    ngsiValue = rcr.getContextRegistration().get(0).getEntityId().get(0).getType();
    entity1.setPropertyValue(
        ontModel.getProperty(ONT_URL + "type"), ontModel.createLiteral(ngsiValue));

    ngsiValue =
        rcr.getContextRegistration().get(0).getContextRegistrationAttribute().get(0).getName();
    Individual attribute1 = ontModel.createIndividual(ONT_URL + ngsiValue, attribute);
    entity1.setPropertyValue(ontModel.getProperty(ONT_URL + "hasAttribute"), attribute1);

    ngsiValue =
        rcr.getContextRegistration().get(0).getContextRegistrationAttribute().get(0).getType();
    attribute1.setPropertyValue(
        ontModel.getProperty(ONT_URL + "type"), ontModel.createLiteral(ngsiValue));

    ngsiValue =
        rcr.getContextRegistration()
            .get(0)
            .getContextRegistrationAttribute()
            .get(0)
            .getContextMetadata()
            .get(0)
            .getName();
    Individual metadata1 = ontModel.createIndividual(ONT_URL + ngsiValue, metadata);
    attribute1.setPropertyValue(ontModel.getProperty(ONT_URL + "hasMetadata"), metadata1);

    ngsiValue =
        rcr.getContextRegistration()
            .get(0)
            .getContextRegistrationAttribute()
            .get(0)
            .getContextMetadata()
            .get(0)
            .getType();
    metadata1.setPropertyValue(
        ontModel.getProperty(ONT_URL + "type"), ontModel.createLiteral(ngsiValue));
    ngsiValue =
        rcr.getContextRegistration()
            .get(0)
            .getContextRegistrationAttribute()
            .get(0)
            .getContextMetadata()
            .get(0)
            .getValue()
            .toString();
    metadata1.setPropertyValue(
        ontModel.getProperty(ONT_URL + "value"), ontModel.createLiteral(ngsiValue));

    ngsiValue =
        rcr.getContextRegistration()
            .get(0)
            .getContextRegistrationAttribute()
            .get(0)
            .getContextMetadata()
            .get(1)
            .getName();
    Individual metadata2 = ontModel.createIndividual(ONT_URL + ngsiValue, metadata);
    attribute1.addProperty(ontModel.getProperty(ONT_URL + "hasMetadata"), metadata2);

    ngsiValue =
        rcr.getContextRegistration()
            .get(0)
            .getContextRegistrationAttribute()
            .get(0)
            .getContextMetadata()
            .get(1)
            .getType();
    metadata2.setPropertyValue(
        ontModel.getProperty(ONT_URL + "type"), ontModel.createLiteral(ngsiValue));
    ngsiValue =
        rcr.getContextRegistration()
            .get(0)
            .getContextRegistrationAttribute()
            .get(0)
            .getContextMetadata()
            .get(1)
            .getValue()
            .toString();
    metadata2.setPropertyValue(
        ontModel.getProperty(ONT_URL + "value"), ontModel.createLiteral(ngsiValue));

    //        ngsiValue =
    // rcr.getContextRegistration().get(0).getContextRegistrationAttribute().get(0).getContextMetadata().get(2).getName();
    //        Individual metadata3 = ontModel.createIndividual(ONT_URL + ngsiValue, metadata);
    //        attribute1.addProperty(ontModel.getProperty(ONT_URL + "hasMetadata"), metadata3);
    //
    //        ngsiValue =
    // rcr.getContextRegistration().get(0).getContextRegistrationAttribute().get(0).getContextMetadata().get(2).getType();
    //        metadata3.setPropertyValue(ontModel.getProperty(ONT_URL + "type"),
    // ontModel.createLiteral(ngsiValue));
    //        ngsiValue =
    // rcr.getContextRegistration().get(0).getContextRegistrationAttribute().get(0).getContextMetadata().get(2).getValue().toString();
    //        metadata3.setPropertyValue(ontModel.getProperty(ONT_URL + "value"),
    // ontModel.createLiteral(ngsiValue));

    //        System.out.println("has propertry
    // \"expiry\":"+entityIndiv.hasProperty(ontModel.getProperty(ONT_URL, "expiry")));

    ontModel.write(System.out, "TURTLE");
    //        ontModel.write(System.out, "RDF/XML");
    //          ontModel.write(System.out, "JSON-LD");

  }
  @Override
  public UpdateContainer doIt(VWorkspace vWorkspace) throws CommandException {
    OntologyManager ontMgr = vWorkspace.getWorkspace().getOntologyManager();
    JSONArray classesList = new JSONArray();
    JSONArray classesMap = new JSONArray();
    JSONArray propertiesList = new JSONArray();
    JSONArray propertiesMap = new JSONArray();

    Map<String, String> prefixMap = vWorkspace.getWorkspace().getOntologyManager().getPrefixMap();

    ExtendedIterator<OntClass> iter = ontMgr.getOntModel().listNamedClasses();
    //		ExtendedIterator<DatatypeProperty> propsIter = ontMgr.getOntModel()
    //				.listDatatypeProperties();
    ExtendedIterator<OntProperty> propsIter = ontMgr.getOntModel().listAllOntProperties();
    final JSONObject outputObj = new JSONObject();

    try {
      while (iter.hasNext()) {
        OntClass cls = iter.next();

        String pr = prefixMap.get(cls.getNameSpace());
        String classLabel = cls.getLocalName();
        //				if (cls.getLabel(null) != null && !cls.getLabel(null).equals(""))
        //					classLabel = cls.getLabel(null);
        String clsStr = (pr != null && !pr.equals("")) ? pr + ":" + classLabel : classLabel;

        classesList.put(clsStr);
        JSONObject classKey = new JSONObject();
        classKey.put(clsStr, cls.getURI());
        classesMap.put(classKey);
      }

      while (propsIter.hasNext()) {
        //				DatatypeProperty prop = propsIter.next();
        OntProperty prop = propsIter.next();

        if (prop.isObjectProperty() && !prop.isDatatypeProperty()) continue;

        String pr = prefixMap.get(prop.getNameSpace());
        String propLabel = prop.getLocalName();
        //				if (prop.getLabel(null) != null && !prop.getLabel(null).equals(""))
        //					propLabel = prop.getLabel(null);
        String propStr = (pr != null && !pr.equals("")) ? pr + ":" + propLabel : propLabel;

        propertiesList.put(propStr);
        JSONObject propKey = new JSONObject();
        propKey.put(propStr, prop.getURI());
        propertiesMap.put(propKey);
      }

      // Populate the JSON object that will hold everything in output
      outputObj.put(JsonKeys.classList.name(), classesList);
      outputObj.put(JsonKeys.classMap.name(), classesMap);
      outputObj.put(JsonKeys.propertyList.name(), propertiesList);
      outputObj.put(JsonKeys.propertyMap.name(), propertiesMap);

    } catch (JSONException e) {
      logger.error("Error populating JSON!");
    }

    UpdateContainer upd =
        new UpdateContainer(
            new AbstractUpdate() {
              @Override
              public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) {
                pw.print(outputObj.toString());
              }
            });
    return upd;
  }
  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();
          }
        }
      }
    }
  }