예제 #1
0
  /**
   * Returns true if the description is consistent (i.e. if it is * possible for there to exist
   * models in which the extension of the class is non-empty.
   */
  public boolean isConsistent(OWLDescription d1) throws OWLException {
    checkStatus();
    StringWriter sw = new StringWriter();
    sw.write(
        "<asks xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">");

    sw.write("<satisfiable id=\"q\">");
    /* Add the rendered description here */
    renderer.reset();
    d1.accept(renderer);
    sw.write(renderer.result());
    sw.write("</satisfiable>");
    sw.write("</asks>");

    StringWriter response = new StringWriter();
    try {
      digReasoner.request(new StringReader(sw.toString()), response);
    } catch (Exception e) {
      throw new OWLException(e.getMessage());
    }

    uk.ac.man.cs.img.dig.helper.Response serverResponse =
        new uk.ac.man.cs.img.dig.helper.Response(response.toString());

    org.w3c.dom.Element r = serverResponse.extractResponse("q");
    return (r.getTagName().equals("true"));
  }
예제 #2
0
  /** Returns all the instances of the given class. */
  public Set instancesOf(OWLDescription d1) throws OWLException {
    Set result = new HashSet();

    try {
      checkStatus();
      StringWriter sw = new StringWriter();
      sw.write(
          "<asks xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">");

      sw.write("<instances id=\"q\">");
      /* Add the rendered description here */
      renderer.reset();
      d1.accept(renderer);
      sw.write(renderer.result());
      sw.write("</instances>");
      sw.write("</asks>");

      StringWriter response = new StringWriter();
      try {
        digReasoner.request(new StringReader(sw.toString()), response);
      } catch (Exception e) {
        throw new OWLException(e.getMessage());
      }

      uk.ac.man.cs.img.dig.helper.Response serverResponse =
          new uk.ac.man.cs.img.dig.helper.Response(response.toString());

      org.w3c.dom.Element r = serverResponse.extractResponse("q");

      List l = serverResponse.extractIndividuals(r);
      /* For some reason, RACER is returning duplicates */
      java.util.Set seen = new java.util.HashSet();
      for (int j = 0; j < l.size(); j++) {
        String name = (String) l.get(j);
        if (!seen.contains(name)) {
          /* As with the class, this is a little tricky. The
           * reasoner may return individuals that aren't
           * *in* the ontology it's working with, but are
           * defined elsewhere.*/
          OWLIndividual i = ontology.getOWLDataFactory().getOWLIndividual(new URI(name));
          // OWLIndividual i = ontology.getIndividual( new URI( name ) );
          result.add(i);
          seen.add(name);
        }
      }
    } catch (ExpressivenessOutOfScopeException ex) {
      throw new OWLException(ex.getMessage());
    } catch (Exception ex) {
      // System.out.println( ex.getMessage() );
      throw new OWLException(ex.getMessage());
    }
    return result;
  }
예제 #3
0
  /* Send the ontology off to the DIG reasoner */
  private void transmitOntology() throws OWLException {
    initialiseReasoner();
    try {
      /* Now tell the ontology to the reasoner. */
      Renderer renderer = new uk.ac.man.cs.img.owl.io.dig1_0.Renderer();
      StringWriter sw = new StringWriter();
      renderer.renderOntology(ontology, sw);

      StringWriter response = new StringWriter();
      digReasoner.request(new StringReader(sw.toString()), response);
    } catch (Exception e) {
      throw new OWLException(e.getMessage());
    }
  }
예제 #4
0
 public void tell(String str) throws OWLException {
   StringWriter sw = new StringWriter();
   sw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
   sw.write(
       "<tells xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">");
   sw.write(str);
   sw.write("</tells>");
   StringWriter response = new StringWriter();
   try {
     digReasoner.request(new StringReader(sw.toString()), response);
   } catch (Exception e) {
     throw new OWLException(e.getMessage());
   }
 }
예제 #5
0
  private Set getHierarchy(String queryTag, OWLDescription d) throws OWLException {
    StringWriter sw = new StringWriter();
    Set result = new HashSet();
    sw.write(
        "<asks xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">");

    sw.write("<" + queryTag + " id=\"q\">");
    /* Add the rendered description here */
    renderer.reset();
    d.accept(renderer);
    sw.write(renderer.result());
    sw.write("</" + queryTag + ">");
    sw.write("</asks>");

    StringWriter response = new StringWriter();
    try {
      digReasoner.request(new StringReader(sw.toString()), response);
    } catch (Exception e) {
      throw new OWLException(e.getMessage());
    }

    uk.ac.man.cs.img.dig.helper.Response serverResponse =
        new uk.ac.man.cs.img.dig.helper.Response(response.toString());

    org.w3c.dom.Element r = serverResponse.extractResponse("q");

    List syns = serverResponse.extractSynonymSets(r);
    for (Iterator it = syns.iterator(); it.hasNext(); ) {
      Set innerSet = new HashSet();
      List names = (List) it.next();
      for (Iterator nameIt = names.iterator(); nameIt.hasNext(); ) {
        uk.ac.man.cs.img.dig.helper.Response.Concept c =
            ((uk.ac.man.cs.img.dig.helper.Response.Concept) nameIt.next());
        OWLClass clazz = conceptToClass(c);
        if (clazz != null) {
          innerSet.add(clazz);
        }
      }
      result.add(innerSet);
    }
    return result;
  }