Package com.hp.hpl.jena.ontology

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


        assertTrue( nhr.contains( m_e ));
        assertTrue( nhr.contains( m_g ));
    }

    public void testNamedHierarchyRoots2() {
        OntClass anon0 = m_model.createClass();
        OntClass anon1 = m_model.createClass();
        anon0.addSubClass( m_a );
        anon0.addSubClass( m_e );
        anon0.addSubClass( anon1 );
        anon1.addSubClass( m_g );

        m_a.addSubClass( m_b );
        m_b.addSubClass( m_c );
        m_c.addSubClass( m_d );
        m_e.addSubClass( m_e );
View Full Code Here


        assertTrue( nhr.contains( m_g ));
    }

    /** Test for no dups in the returned list */
    public void testNamedHierarchyRoots3() {
        OntClass anon0 = m_model.createClass();
        OntClass anon1 = m_model.createClass();
        anon0.addSubClass( m_a );
        anon1.addSubClass( m_a );

        // only a is root
        m_a.addSubClass( m_b );
        m_a.addSubClass( m_c );
        m_a.addSubClass( m_d );
View Full Code Here

        assertTrue( nhr.contains( m_a ));
    }

    /** Test for indirect route to a non-root node */
    public void testNamedHierarchyRoots4() {
        OntClass anon0 = m_model.createClass();
        OntClass anon1 = m_model.createClass();
        anon0.addSubClass( m_a );
        anon1.addSubClass( m_b );

        // only a is root, because b is a subclass of a
        // even though b is a sub-class of an anon root
        m_a.addSubClass( m_b );
        m_a.addSubClass( m_c );
View Full Code Here

      UnionClass unionClass = ((OntClass) resource).asUnionClass();
      Iterator ops = unionClass.listOperands();

      // Iterate the members of this "union class"
      while (ops.hasNext()) {
        OntClass op = (OntClass) ops.next();

        // Find the union class that has this concept/class as a
        // member.
        if (op.getURI() == ontClass.getURI()) {

          // Get the properties binded with this "named class".
          Iterator ittt = unionClass.listDeclaredProperties(direct);
          while (ittt.hasNext()) {
            OntProperty ontProperty = (OntProperty) ittt.next();
View Full Code Here

      UnionClass unionClass = ((OntClass) resource).asUnionClass();
      Iterator ops = unionClass.listOperands();

      // Iterate the members of this "union class"
      while (ops.hasNext()) {
        OntClass op = (OntClass) ops.next();

        // Find the union class that has this concept/class as a
        // member.
        if (op.getURI() == ontClass.getURI()) {

          // Get the properties binded with this "named class".
          Iterator ittt = unionClass.listDeclaredProperties(direct);
          while (ittt.hasNext()) {
            OntProperty ontProperty = (OntProperty) ittt.next();
View Full Code Here

      UnionClass ucls = rcls.asUnionClass();
      Iterator operands = ucls.listOperands();

      while (operands.hasNext()) {
        OntClass operand = (OntClass) operands.next();
        addCompatibleSubClasses(operand, comps, false);
      }

    } else if (!rcls.isUnionClass() && !rcls.isComplementClass()
        && !rcls.isEnumeratedClass() && !rcls.isIntersectionClass()
        && !rcls.isRestriction()) {
      comps.add(rcls);

      Iterator subit = rcls.listSubClasses(true);
      while (subit.hasNext()) {

        OntClass sub = (OntClass) subit.next();
        addCompatibleSubClasses(sub, comps, false);
      }
    }
  }
View Full Code Here

      ObjectProperty op) {
    ArrayList<OntClass> declaredRanges = new ArrayList<OntClass>();
    Iterator it = op.listRange();

    while (it.hasNext()) {
      OntClass rcls = (OntClass) it.next();
      declaredRanges.addAll(getCompatibleSubClasses(rcls));
    }

    return declaredRanges;
  }
View Full Code Here

  public static ArrayList<OntClass> getCompatibleDeclaredDomains(OntProperty op){
    ArrayList<OntClass> declaredDomains = new ArrayList<OntClass>();
    Iterator it = op.listDomain();

    while (it.hasNext()) {
      OntClass rcls = (OntClass) it.next();
      declaredDomains.addAll(getCompatibleSubClasses(rcls));
    }

    return declaredDomains;
  }
View Full Code Here

            }

            docList.setText("");
            docList.append("��ʼ����\n");
            PrintUtil.registerPrefix("qa", prefix);
            OntClass hd_c = model.getOntClass(prefix + "�Ծ�����Ļش�");
            Individual zshd_i = hd_c.createIndividual(prefix
                + "�����Ļش�");
            Individual wt_i = model.getIndividual(prefix
                + "ͨ���������������Լ��Ĺ������");
            OntProperty wts_p = model.getOntProperty(prefix
                + "�Ծ�������");
            zshd_i.addProperty(wts_p, wt_i);

            OntProperty ydy_p = model.getObjectProperty(prefix
                + "Ҫ����");
            for (int i = 0; i < boxes.length; i++) {
              if (boxes[i].isSelected()) {
                Individual yd_i = model.getIndividual(prefix
                    + boxes[i].getLabel());
                zshd_i.addProperty(ydy_p, yd_i);
              }
            }

            String ruleSrc = "[rule1: (?key rdf:type qa:��׼��Ҫ��) "
                + " (?key qa:��ֵ ?points) "
                + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                + " (?question rdf:type qa:�Ծ�����) "
                + " (?standard rdf:type qa:��׼��) "
                + " (?answer qa:�Ծ������� ?question)"
                + " (?question qa:��׼���� ?standard) "
                + " (?standard qa:Ҫ���� ?key) "
                + " (?answer qa:Ҫ���� ?key) "
                + " noValue(?key qa:�÷�) " + " -> "
                + " (?key qa:�÷� ?points)" + "]";
            List rules = Rule.parseRules(ruleSrc);
            Reasoner reasoner = new GenericRuleReasoner(rules);
            InfModel inf = ModelFactory.createInfModel(reasoner,
                model);

            StmtIterator it = inf.getDeductionsModel()
                .listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t " + obj.getString() + "��ȫ�֣�\n");
            }

            ruleSrc = "[rule2: (?keya rdf:type qa:��׼��Ҫ��) "
                + " (?keyb rdf:type qa:��׼��Ҫ��) "
                + " (?keyb qa:��ֵ ?points) "
                + " (?keya ?p ?keyb)"
                + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                + " (?question rdf:type qa:�Ծ�����) "
                + " (?standard rdf:type qa:��׼��) "
                + " (?answer qa:�Ծ������� ?question)"
                + " (?question qa:��׼���� ?standard) "
                + " (?standard qa:Ҫ���� ?keya) "
                + " (?standard qa:Ҫ���� ?keyb) "
                + " (?answer qa:Ҫ���� ?keya) "
                + " noValue(?answer qa:Ҫ���� ?keyb) "
                + " product(?points, 0.5, ?wpoints ) " + " -> "
                + " (?keyb qa:�÷� ?wpoints) " + " ]";
            rules = Rule.parseRules(ruleSrc);
            reasoner = new GenericRuleReasoner(rules);
            InfModel inf2 = ModelFactory.createInfModel(reasoner,
                inf);
            it = inf2.getDeductionsModel().listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t" + obj.getString() + "����֣�\n");
            }

            ruleSrc = "[rule3: (?key rdf:type qa:��׼��Ҫ��) noValue(?key qa:�÷�) -> (?key qa:�÷� 0.0) ]";
            rules = Rule.parseRules(ruleSrc);
            reasoner = new GenericRuleReasoner(rules);
            InfModel inf3 = ModelFactory.createInfModel(reasoner,
                inf2);
            it = inf3.getDeductionsModel().listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t" + obj.getString() + "����֣�\n");
            }
            docList
                .append("------------------------------------------------------------\n");

            ruleSrc = "[rule4: (qa:�Ӱ� qa:�÷� ?jbpoints) "
                + " (qa:��������λ�� qa:�÷� ?wzpoints) "
                + " (qa:н�� qa:�÷� ?xcpoints) "
                + " (qa:�������� qa:�÷� ?hjpoints ) "
                + " sum(?jbpoints, ?wzpoints, ?temp1) "
                + " sum(?temp1, ?xcpoints, ?temp2) "
                + " sum(?temp2, ?hjpoints, ?score) "
                + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                + " (?question rdf:type qa:�Ծ�����) "
                + " (?standard rdf:type qa:��׼��) "
                + " (?answer qa:�Ծ������� ?question)"
                + " (?question qa:��׼���� ?standard) " + " -> "
                + " (?answer qa:�÷� ?score) " + "]";
            rules = Rule.parseRules(ruleSrc);
            reasoner = new GenericRuleReasoner(rules);
            InfModel inf4 = ModelFactory.createInfModel(reasoner,
                inf3);
            it = inf4.getDeductionsModel().listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t" + obj.getString() + "\n");
            }
            docList.append("�������");

          } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(frame,
                "�޷����ر���⣬��ȷ��qa.owl������ڵ�ǰĿ¼�¡�", "Error!",
                JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
          } catch (Exception ex) {
            JOptionPane.showMessageDialog(frame,
                "���������鿴error.log�ļ���", "Error!",
                JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
          }
        }
      }
    });

    run.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {

        new Thread() {
          public void run() {
            docList.setText("");
            docList.append("��ʼ����\n");
            OntModel model = ModelFactory
                .createOntologyModel(OntModelSpec.OWL_DL_MEM);
            try {
              model.read(new FileInputStream(new File("qa.owl")),
                  null);
              String prefix = "http://www.example.com/qa.owl#";
              PrintUtil.registerPrefix("qa", prefix);

              OntClass hd_c = model.getOntClass(prefix
                  + "�Ծ�����Ļش�");
              Individual zshd_i = hd_c.createIndividual(prefix
                  + "�����Ļش�");
              Individual wt_i = model.getIndividual(prefix
                  + "ͨ���������������Լ��Ĺ������");
              OntProperty wts_p = model.getOntProperty(prefix
                  + "�Ծ�������");
View Full Code Here

        if (notAlreadyExist) {
          newStart = i + 1;
        }
        break;
      } else {
        OntClass nounClass = model.getOntClass(prefix
            + pattern.get(patternStart));
        if (nounClass != null) {
          if (sentence.getTokens().get(i).getText().equals(
              nounClass.getLocalName())) {
            newStart = i + 1;
            break out;
          }

          ExtendedIterator<? extends OntResource> instances = nounClass
              .listInstances();
          while (instances.hasNext()) {
            String nounInstance = instances.next().getLocalName();
            if (sentence.getTokens().get(i).getText().equals(
                nounInstance)) {
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.