Package com.hp.hpl.jena.ontology

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


        queue.offer(t);
      }
      String uri = this.tree.getOntModel().expandPrefix(
          ":" + nextToken.term());
      if (type.equals(OntologyElementTree.ONTCLASS)) {
        OntClass cls = this.tree.getOntModel().getOntClass(uri);
        ExtendedIterator it = cls.listSuperClasses();
        while (it.hasNext()) {
          offer(nextToken, ((OntClass) it.next()).getLocalName(),
              tree.getActualWeight(Weights.ONTCLASS_SUPERCLASS));
        }

        it = cls.listSubClasses();
        while (it.hasNext()) {
          offer(nextToken, ((OntClass) it.next()).getLocalName(),
              tree.getActualWeight(Weights.ONTCLASS_SUBCLASS));
        }
        for (DatatypeProperty dp : JenaUtil.getDatatypeProperties(cls,
            false)) {
          offer(
              nextToken,
              dp.getLocalName(),
              tree
                  .getActualWeight(Weights.ONTCLASS_DECLARED_PROPERTY));
        }
        for (ObjectProperty op : JenaUtil.getObjectProperties(cls,
            false)) {
          offer(
              nextToken,
              op.getLocalName(),
              tree
                  .getActualWeight(Weights.ONTCLASS_DECLARED_PROPERTY));
        }

      } else if (type.equals(OntologyElementTree.INDIVIDUAL)) {
        Individual ind = this.tree.getOntModel().getIndividual(uri);
        ExtendedIterator it = ind.listOntClasses(true);
        while (it.hasNext()) {
          OntClass cls = (OntClass) it.next();

          offer(nextToken, cls.getLocalName(), tree
              .getActualWeight(Weights.INDIVIDUAL_CLASS));

          for (DatatypeProperty dp : JenaUtil.getDatatypeProperties(
              cls, false)) {

            StmtIterator sit = ind.listProperties(dp);
            if (sit.hasNext()) {
              offer(
                  nextToken,
                  dp.getLocalName(),
                  tree
                      .getActualWeight(Weights.INDIVIDUAL_DECLARED_PROPERTY));
            }
            while (sit.hasNext()) {
              offer(nextToken, sit.nextStatement().getLiteral()
                  .getString(), tree
                  .getActualWeight(Weights.INDIVIDUAL_OBJECT));

            }

          }
          for (ObjectProperty op : JenaUtil.getObjectProperties(cls,
              false)) {

            StmtIterator sit = ind.listProperties(op);
            if (sit.hasNext()) {
              offer(
                  nextToken,
                  op.getLocalName(),
                  tree
                      .getActualWeight(Weights.INDIVIDUAL_DECLARED_PROPERTY));
            }
            while (sit.hasNext()) {
              offer(nextToken, ((Resource) sit.nextStatement()
                  .getObject()).getLocalName(), tree
                  .getActualWeight(Weights.INDIVIDUAL_OBJECT));

            }
          }

        }
        ResIterator rit = this.tree.getOntModel()
            .listResourcesWithProperty(null, ind);
        while (rit.hasNext()) {
          offer(nextToken, rit.nextResource().getLocalName(), tree
              .getActualWeight(Weights.INDIVIDUAL_SUBJECT));
        }

      } else if (type.equals(OntologyElementTree.OBJECTPROPERTY)) {
        ObjectProperty op = this.tree.getOntModel().getObjectProperty(
            uri);
        for (OntClass cls : JenaUtil.getCompatibleDeclaredDomains(op)) {
          offer(nextToken, cls.getLocalName(), tree
              .getActualWeight(Weights.OBJECTPROPERTY_DOMAIN));
        }
        for (OntClass cls : JenaUtil.getCompatibleDeclaredRanges(op)) {
          offer(nextToken, cls.getLocalName(), tree
              .getActualWeight(Weights.OBJECTPROPERTY_RANGE));
        }

      } else if (type.equals(OntologyElementTree.DATATYPEPROPERTY)) {
        DatatypeProperty dp = this.tree.getOntModel()
            .getDatatypeProperty(uri);
        for (OntClass cls : JenaUtil.getCompatibleDeclaredDomains(dp)) {
          offer(nextToken, cls.getLocalName(), tree
              .getActualWeight(Weights.OBJECTPROPERTY_DOMAIN));
        }
      }
    }
View Full Code Here


      }
      return null;
    }
    //������ĸ���
    else if (RDFS.subClassOf.getURI().equals(predicate) || "����".equals(p)) {
      OntClass s_c = this.getOntModel().getOntClass(subject);
      if (s_c != null) {
        QueryResult qr = new QueryResult(OntologyElement.ONTCLASS);
        OntClass sp = s_c.getSuperClass();
        if (sp != null)
          qr.add(wrap(sp));
        return qr;
      }
      return null;
    }
    //�����������
    else if ("����".equals(p)) {

      OntClass s_c = this.getOntModel().getOntClass(subject);
      if (s_c != null) {
        QueryResult qr = new QueryResult(OntologyElement.ONTCLASS);
        Iterator it = s_c.listSubClasses();
        while (it.hasNext()) {
          OntClass sp = (OntClass) it.next();
          if (sp != null) {
            qr.add(wrap(sp));
          }
        }
        return qr;
      }
      return null;
    }
   
    //�������ԵĶ�����
    else if (RDFS.domain.getURI().equals(predicate) || "������".equals(p)
        || "domain".equals(p)) {
      OntProperty s_p = this.getOntModel().getOntProperty(subject);
      if (s_p != null) {
        QueryResult qr = new QueryResult(OntologyElement.ONTCLASS);
        qr.add(wrap(s_p.getDomain().asClass()));
        return qr;
      }
      return null;
    }
   
    //�������Ե�ֵ��
    else if (RDFS.range.getURI().equals(predicate) || "ֵ��".equals(p)
        || "range".equals(p)) {
      OntProperty s_p = this.getOntModel().getOntProperty(subject);
      if (s_p != null) {
        QueryResult qr = new QueryResult(OntologyElement.ONTCLASS);
        OntResource range = s_p.getRange();
        if (range != null) {
          qr.add(wrap(range.asClass()));
          return qr;
        }
        return null;
      }
      return null;
    }
   
    //�������ʵ��
    else if ("ʵ��".equals(p)) {
      OntClass s_c = this.getOntModel().getOntClass(subject);
      if (s_c != null) {
        QueryResult qr = new QueryResult(OntologyElement.INDIVIDUAL);
        Iterator it = s_c.listInstances();
        while (it.hasNext()) {
          Individual ind = (Individual) it.next();
          if (ind != null) {
            qr.add(wrap(ind));
          }
View Full Code Here

  }

  //��װһ���࣬���丸��
  private OntClassOE wrap(OntClass cls, boolean withSuperClass) {
    OntClassOE wp = new OntClassOE(cls.getURI(), cls.getLocalName());
    OntClass sp = cls.getSuperClass();
    if (withSuperClass && sp != null) {
      wp.setSuperClass(wrap(sp, false));
    }
    return wp;
  }
View Full Code Here

    private void doTestConcurrency(final OntModel model) throws InterruptedException {
        // initialize the model
        final String NS = PrintUtil.egNS;
       
        model.enterCriticalSection(Lock.WRITE);
        final OntClass Top = model.createClass(NS + "Top");
        for (int i = 0; i < MODEL_SIZE; i++) {
            OntClass C = model.createClass(NS + "C" + i);
            Top.addSubClass(C);
            model.createIndividual(NS + "i" + i, C);
        }
        model.leaveCriticalSection();
View Full Code Here

  /**
   * parse owl ontology files using jena
   */
  public void parse(OntModel m) {
    for (Iterator i = rootClasses( m );  i.hasNext()) {
      OntClass c = (OntClass) i.next();

      //dont deal with anonymous classes
      if (c.isAnon()) {
        continue;
      }

      parseClass( c,  new ArrayList(), 0 );
    }
View Full Code Here

    // recurse to the next level down
    if (cls.canAs( OntClass.class &&  !occurs.contains( cls )) {
      //list subclasses
      for (Iterator i = cls.listSubClasses( true );  i.hasNext(); ) {
        OntClass sub = (OntClass) i.next();

        // we push this expression on the occurs list before we recurse
        occurs.add( cls );
        parseClass(sub, occurs, depth+1);
        occurs.remove( cls );
View Full Code Here

  public Iterator rootClasses( OntModel m ) {
    List roots = new ArrayList();
   
    for (Iterator i = m.listClasses();  i.hasNext(); ) {
      OntClass c = (OntClass) i.next();
       
      try {
      // too confusing to list all the restrictions as root classes
        if (c.isAnon()) {
          continue;
        }
   
        if (c.hasSuperClass( m.getProfile().THING(), true ) ) {
          // this class is directly descended from Thing
          roots.add( c );
        } else if (c.getCardinality( m.getProfile().SUB_CLASS_OF() ) == 0 ) {
          // this class has no super-classes
          // (can occur if we're not using the reasoner)
          roots.add( c );
        }
      } catch (Exception e) {
View Full Code Here

        }
      } else if (resource instanceof OntClass) {
        //list equivalent classes
        for (Iterator i=((OntClass)resource).listEquivalentClasses();
          i.hasNext();) {
          OntClass equivClass = (OntClass) i.next();
          //add labels
          for (Iterator j=equivClass.listLabels(null); j.hasNext();) {
            Literal l = (Literal) j.next();
            synonyms.put(l.toString(), "1");
          }
        }
      }
View Full Code Here

    out.println();
 
    // recurse to the next level down
    if (cls.canAs( OntClass.class ) && !occurs.contains( cls )) {
      for (Iterator i = cls.listSubClasses( true ); i.hasNext(); ) {
        OntClass sub = (OntClass) i.next();

        // we push this expression on the occurs list before we recurse
        occurs.add( cls );
        renderHierarchy( out, sub, occurs, depth + 1 );
        occurs.remove( cls );
View Full Code Here

   
    for (Iterator i = getParser().rootClasses( getModel() );
      i.hasNext(); ) {
   
      //print class
      OntClass c = (OntClass) i.next();

      renderHierarchy(System.out, c, new LinkedList(), 0);
    }

    String[] terms =
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.ontology.OntClass

Copyright © 2018 www.massapicom. 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.