Package com.hp.hpl.jena.ontology

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


    OntResource r;
   
//    int count = 0;
    for (String propertyUri : this.objectProperties.keySet()) {

      OntProperty property = this.ontHandler.getOntModel().getOntProperty(propertyUri);
      if (property == null || !property.isURIResource())
        continue;
           
      directDomains = new HashSet<OntResource>();
      directDomainsUris = new HashSet<String>();
      indirectDomainsUris = new HashSet<String>();
      allDomains = new HashSet<OntResource>();
      allDomainsUris = new HashSet<String>();
      directRanges = new HashSet<OntResource>();
      directRangesUris = new HashSet<String>();
      indirectRangesUris = new HashSet<String>();
      allRanges = new HashSet<OntResource>();
      allRangesUris = new HashSet<String>();
     
//      count ++;
//      if (count % 1000 == 0)
//        System.gc();

     
      // direct domain
      ExtendedIterator<? extends OntResource> itrDomains = property.listDomain();
      while (itrDomains.hasNext()) {
        d = itrDomains.next();
        ontHandler.getMembers(d, directDomains, false);
      }
      directDomainsUris = ontHandler.getResourcesUris(directDomains);
     
//      if (directDomainsUris != null && directDomainsUris.contains(Uris.THING_URI))
//        directDomainsUris.remove(Uris.THING_URI);
     
      temp  = propertyDirectDomains.get(property.getURI());
      if (temp == null)
        propertyDirectDomains.put(property.getURI(), directDomainsUris);
      else
        temp.addAll(directDomainsUris);
     
      for (OntResource domain : directDomains) {
        temp = directOutObjectProperties.get(domain.getURI());
        if (temp == null) {
          temp = new HashSet<String>();
          directOutObjectProperties.put(domain.getURI(), temp);
        }
        temp.add(property.getURI());
      }

      // all domains
      if (directDomainsUris.contains(Uris.THING_URI))
        allDomainsUris = new HashSet<String>(this.classes.keySet());
      else {
        for (OntResource domain : directDomains) {
          allDomains.add(domain);
          ontHandler.getChildren(domain, allDomains, true);
        }
        allDomainsUris = ontHandler.getResourcesUris(allDomains);
      }

      // indirect domains
      for (String domainUri : allDomainsUris) {
        if (!directDomainsUris.contains(domainUri))
          indirectDomainsUris.add(domainUri);
      }

      temp  = propertyIndirectDomains.get(property.getURI());
      if (temp == null)
        propertyIndirectDomains.put(property.getURI(), indirectDomainsUris);
      else
        temp.addAll(indirectDomainsUris);
     
      for (String domainUri : indirectDomainsUris) {
        temp = indirectOutObjectProperties.get(domainUri);
        if (temp == null) {
          temp = new HashSet<String>();
          indirectOutObjectProperties.put(domainUri, temp);
        }
        temp.add(property.getURI());
      }
     
      // direct ranges
      ExtendedIterator<? extends OntResource> itrRanges = property.listRange();
      while (itrRanges.hasNext()) {
        r = itrRanges.next();
        ontHandler.getMembers(r, directRanges, false);
      }
      directRangesUris = ontHandler.getResourcesUris(directRanges);
     
//      if (directRangesUris != null && directRangesUris.contains(Uris.THING_URI))
//        directRangesUris.remove(Uris.THING_URI);

      temp  = propertyDirectRanges.get(property.getURI());
      if (temp == null)
        propertyDirectRanges.put(property.getURI(), directRangesUris);
      else
        temp.addAll(directRangesUris);
     
      for (OntResource range : directRanges) {
        temp = directInObjectProperties.get(range.getURI());
        if (temp == null) {
          temp = new HashSet<String>();
          directInObjectProperties.put(range.getURI(), temp);
        }
        temp.add(property.getURI());
      }
     
      // all ranges
      if (directRangesUris.contains(Uris.THING_URI))
        allRangesUris = new HashSet<String>(this.classes.keySet());
      else {
        for (OntResource range : directRanges) {
          allRanges.add(range);
          ontHandler.getChildren(range, allRanges, true);
        }
        allRangesUris = ontHandler.getResourcesUris(allRanges);
      }
     
      // indirect ranges
      for (String rangeUri : allRangesUris) {
        if (!directRangesUris.contains(rangeUri))
          indirectRangesUris.add(rangeUri);
      }
     
      temp  = propertyIndirectRanges.get(property.getURI());
      if (temp == null)
        propertyIndirectRanges.put(property.getURI(), indirectRangesUris);
      else
        temp.addAll(indirectRangesUris);
     
      for (String rangeUri : indirectRangesUris) {
        temp = indirectInObjectProperties.get(rangeUri);
        if (temp == null) {
          temp = new HashSet<String>();
          indirectInObjectProperties.put(rangeUri, temp);
        }
        temp.add(property.getURI());
      }
       
      for (String domain : directDomainsUris) {
        for (String range : directRangesUris) {
          temp =
            domainRangeToDirectProperties.get(domain + range);
          if (temp == null) {
            temp = new HashSet<String>();
            domainRangeToDirectProperties.put(domain + range, temp);
          }
          temp.add(property.getURI());
        }
      }

      for (String domain : allDomainsUris) {
        for (String range : allRangesUris) {
          if (directDomainsUris.contains(domain) && directRangesUris.contains(range)) continue;
          temp = domainRangeToIndirectProperties.get(domain + range);
          if (temp == null) {
            temp = new HashSet<String>();
            domainRangeToIndirectProperties.put(domain + range, temp);
          }
          temp.add(property.getURI());
        }
      }

    } 
View Full Code Here


   */
  public Label getInverseProperty(String uri) {
    ObjectProperty op = ontModel.getObjectProperty(uri);
    if (op == null)
      return null;
    OntProperty inverseProp = null;
    try {
      inverseProp = op.getInverse();
    } catch (ConversionException e) {
      logger.error(e.getMessage());
    }
    if (inverseProp != null) {
      return getUriLabel(inverseProp.getURI());
    }
    else
      return null;
  }
View Full Code Here

   */
  public Label getInverseOfProperty(String uri) {
    ObjectProperty op = ontModel.getObjectProperty(uri);
    if (op == null)
      return null;
    OntProperty inverseOfProp = null;
    try {
      inverseOfProp = op.getInverse();
    } catch (ConversionException e) {
      logger.error(e.getMessage());
    }
    if (inverseOfProp != null) {
      return getUriLabel(inverseOfProp.getURI());
    }
    else
      return null;
  }
View Full Code Here

   * @param recursive
   */
  public void getParents(OntResource r, HashSet<OntResource> resources, boolean recursive) {
   
    OntClass c = null;
    OntProperty p = null;
   
    if (resources == null)
      resources = new HashSet<OntResource>();

    if (r == null)
      return;
   
    if (r.isClass())
      c = r.asClass();
    else if  (r.isProperty())
      p = r.asProperty();
    else
      return;
   
    if (c != null) { // && c.hasSuperClass()) {
      ExtendedIterator<OntClass> i = null;
      try {
//        if (recursive)
//          i = c.listSuperClasses(false);
//        else
          i = c.listSuperClasses(true);
      } catch (ConversionException e) {
        logger.debug(e.getMessage());
      }
            for (; i != null && i.hasNext();) {
                OntClass superC = (OntClass) i.next();
                if (superC.isURIResource()) {
                  resources.add(superC);
                  if (recursive)
                    getParents(superC, resources, recursive);
                } else {
                  HashSet<OntResource> members = new HashSet<OntResource>();
                  getMembers(superC, members, false);
                  for (OntResource or : members) {
                    resources.add(or);
                    if (recursive)
                      getParents(or, resources, recursive);
                  }
                }
            }
    }

    if (p != null) {
      ExtendedIterator<? extends OntProperty> i = null;
      try {
  //      if (recursive)
  //        i = p.listSuperProperties(false);
  //      else
          i = p.listSuperProperties(true);
      } catch (ConversionException e) {
        logger.debug(e.getMessage());
      }
            for (; i != null && i.hasNext();) {
               
View Full Code Here

   * @param recursive
   */
  public void getChildren(OntResource r, HashSet<OntResource> resources, boolean recursive) {
   
    OntClass c = null;
    OntProperty p = null;
   
    if (resources == null)
      resources = new HashSet<OntResource>();

    if (r == null)
      return;

    if (r.isClass())
      c = r.asClass();
    else if  (r.isProperty())
      p = r.asProperty();
    else
      return;
   
    if (c != null) {
      ExtendedIterator<OntClass> i = null;
      try {
//        if (recursive)
//          i = c.listSubClasses(false);
//        else
          i = c.listSubClasses(true);
      } catch (ConversionException e) {
        logger.debug(e.getMessage());
      }
            for (; i != null && i.hasNext();) {
                OntClass subC = (OntClass) i.next();
                if (subC.isURIResource()) {
                  resources.add(subC);
                  if (recursive)
                    getChildren(subC, resources, recursive);
                } else {
                  HashSet<OntResource> members = new HashSet<OntResource>();
                  getMembers(subC, members, false);
                  for (OntResource or : members) {
                    resources.add(or);
                    if (recursive)
                      getChildren(or, resources, recursive);
                  }
                }
            }
    }

    if (p != null) {
      ExtendedIterator<? extends OntProperty> i = null;
      try {
//        if (recursive)
//          i = p.listSubProperties(false);
//        else
          i = p.listSubProperties(true);
      } catch (ConversionException e) {
        logger.debug(e.getMessage());
      }
            for (; i != null && i.hasNext();) {
                OntProperty subP = (OntProperty) i.next();
                if (subP.isURIResource()) {
                  resources.add(subP);
                  if (recursive)
                    getChildren(subP, resources, recursive);
                }
//                else {
View Full Code Here

    ArrayList<DatatypeProperty> list = new ArrayList<DatatypeProperty>();

    // First get the properties binded with this "named class".
    Iterator it = ontClass.listDeclaredProperties(direct);
    while (it.hasNext()) {
      OntProperty ontProperty = (OntProperty) it.next();
      if (ontProperty != null) {
        if (ontProperty.getDomain() == null
            || ontProperty.getDomain() == OWL.Thing)
          continue;
        if (ontProperty.isDatatypeProperty())
          list.add(ontProperty.asDatatypeProperty());
      }
    }
    // Then get the properties binded with "union classes" that contains
    // this concept/class.
    Iterator unionClasses = ontClass.getOntModel().listUnionClasses();

    // Iterate all "union classes"
    while (unionClasses.hasNext()) {

      Resource resource = (Resource) unionClasses.next();
      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();
            if (ontProperty != null) {
              if (ontProperty.getDomain() == null
                  || ontProperty.getDomain() == OWL.Thing)
                continue;

              if (ontProperty.isDatatypeProperty())
                list.add(ontProperty.asDatatypeProperty());
            }
          }

        }
View Full Code Here

    ArrayList<ObjectProperty> list = new ArrayList<ObjectProperty>();

    // First get the properties bound with this "named class".
    Iterator it = ontClass.listDeclaredProperties(direct);
    while (it.hasNext()) {
      OntProperty ontProperty = (OntProperty) it.next();
      if (ontProperty != null) {
        if (ontProperty.getDomain() == null
            || ontProperty.getDomain() == OWL.Thing)
          continue;
        if (ontProperty.isObjectProperty())
          list.add(ontProperty.asObjectProperty());
      }
    }
    // Then get the properties bound with "union classes" that contains
    // this concept/class.
    Iterator unionClasses = ontClass.getOntModel().listUnionClasses();

    // Iterate all "union classes"
    while (unionClasses.hasNext()) {

      Resource resource = (Resource) unionClasses.next();
      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();
            if (ontProperty != null) {
              if (ontProperty.getDomain() == null
                  || ontProperty.getDomain() == OWL.Thing)
                continue;

              if (ontProperty.isObjectProperty())
                list.add(ontProperty.asObjectProperty());
            }
          }

        }
View Full Code Here

              .createOntologyModel(OntModelSpec.OWL_DL_MEM);
          try {
            model.read(new FileInputStream(new File("qa.owl")),
                null);
            String prefix = "http://www.example.com/qa.owl#";
            OntProperty gjc = model.getOntProperty(prefix + "�ؼ���");

            for (int i = 0; i < boxes.length; i++) {
              boxes[i].setSelected(false);
              Individual yd_i = model.getIndividual(prefix
                  + boxes[i].getLabel());
              Iterator it = yd_i.listPropertyValues(gjc);
              while (it.hasNext()) {
                Literal lt = (Literal) it.next();
               
                String[] literal_tokens = seg.split(lt.getString()).getFinalResult().split("/\\w+ ");

                boolean contain= false;
                for (int j=0;j<text_tokens.length-literal_tokens.length;j++){
                  int k=0;
                  for (; k<literal_tokens.length;k++){
                    if (!text_tokens[j+k].equals(literal_tokens[k])){
                      break;
                    }
                  }

                  if (k ==literal_tokens.length){
                    contain = true;
                    break;
                  }
                }

                if (contain) {
                  boxes[i].setSelected(true);
                }
              }
            }

            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
                  + "�Ծ�������");
              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
View Full Code Here

        predicateIndex = i;
        break;
      }
    }

    OntProperty predicate = model.getOntProperty(prefix
        + pattern.get(predicateIndex));
    ExtendedIterator<? extends OntProperty> subPredicates = predicate
        .listSubProperties();

    boolean match = false;
    while (subPredicates.hasNext()) {
      String subPredicate = subPredicates.next().getLocalName();
View Full Code Here

    }
   
    //�������ԵĶ�����
    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));
          }
        }
        return qr;
      }
      return null;
    }
   
    //��������ı���
    Individual s_i = this.getOntModel().getIndividual(subject);
    if (s_i != null) {
      OntProperty p_p = this.getOntModel().getOntProperty(predicate);
      if (p_p != null) {
        QueryResult qr;
        if (p_p.isObjectProperty()) {
          qr = new QueryResult(OntologyElement.INDIVIDUAL);
        } else if (p_p.isDatatypeProperty()) {
          qr = new QueryResult(OntologyElement.LITERAL);
        } else {
          return null;
        }
View Full Code Here

TOP

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

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.