コード例 #1
0
 /**
  * Example the conclusions graph for introduction of restrictions which require a comprehension
  * rewrite and declare new (anon) classes for those restrictions.
  */
 public void comprehensionAxioms(Model premises, Model conclusions) {
   // Comprehend all restriction declarations and note them in a map
   Map<Resource, Resource> comprehension = new HashMap<>();
   StmtIterator ri = conclusions.listStatements(null, RDF.type, OWL.Restriction);
   while (ri.hasNext()) {
     Resource restriction = ri.nextStatement().getSubject();
     StmtIterator pi = restriction.listProperties(OWL.onProperty);
     while (pi.hasNext()) {
       Resource prop = (Resource) pi.nextStatement().getObject();
       StmtIterator vi = restriction.listProperties();
       while (vi.hasNext()) {
         Statement rs = vi.nextStatement();
         if (!rs.getPredicate().equals(OWL.onProperty)) {
           // Have a restriction on(prop) of type rs in the conclusions
           // So assert a premise that such a restriction could exisit
           Resource comp =
               premises
                   .createResource()
                   .addProperty(RDF.type, OWL.Restriction)
                   .addProperty(OWL.onProperty, prop)
                   .addProperty(rs.getPredicate(), rs.getObject());
           comprehension.put(restriction, comp);
         }
       }
     }
   }
   // Comprehend any intersectionOf lists. Introduce anon class which has the form
   // of the intersection expression.
   // Rewrite queries of the form (X intersectionOf Y) to the form
   //   (X equivalentClass ?CC) (?CC intersectionOf Y)
   StmtIterator ii = conclusions.listStatements(null, OWL.intersectionOf, (RDFNode) null);
   List<Statement> intersections = new ArrayList<>();
   while (ii.hasNext()) {
     intersections.add(ii.nextStatement());
   }
   for (Statement is : intersections) {
     // Declare in the premises that such an intersection exists
     Resource comp =
         premises
             .createResource()
             .addProperty(RDF.type, OWL.Class)
             .addProperty(
                 OWL.intersectionOf, mapList(premises, (Resource) is.getObject(), comprehension));
     // Rewrite the conclusions to be a test for equivalence between the class being
     // queried and the comprehended interesection
     conclusions.remove(is);
     conclusions.add(is.getSubject(), OWL.equivalentClass, comp);
   }
   // Comprehend any oneOf lists
   StmtIterator io = conclusions.listStatements(null, OWL.oneOf, (RDFNode) null);
   while (io.hasNext()) {
     Statement s = io.nextStatement();
     Resource comp = premises.createResource().addProperty(OWL.oneOf, s.getObject());
   }
 }
コード例 #2
0
 /** Return a list of all tests of the given type, according to the current filters */
 public List<Resource> findTestsOfType(Resource testType) {
   ArrayList<Resource> result = new ArrayList<>();
   StmtIterator si = testDefinitions.listStatements(null, RDF.type, testType);
   while (si.hasNext()) {
     Resource test = si.nextStatement().getSubject();
     boolean accept = true;
     // Check test status
     Literal status = (Literal) test.getProperty(RDFTest.status).getObject();
     if (approvedOnly) {
       accept = status.getString().equals(STATUS_FLAGS[0]);
     } else {
       accept = false;
       for (String STATUS_FLAG : STATUS_FLAGS) {
         if (status.getString().equals(STATUS_FLAG)) {
           accept = true;
           break;
         }
       }
     }
     // Check for blocked tests
     for (String BLOCKED_TEST : BLOCKED_TESTS) {
       if (BLOCKED_TEST.equals(test.toString())) {
         accept = false;
       }
     }
     // End of filter tests
     if (accept) {
       result.add(test);
     }
   }
   return result;
 }
コード例 #3
0
ファイル: ModelServlet.java プロジェクト: Ferada/mate
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String path = request.getPathInfo();
    boolean htmlOutput = true;
    String language = null;
    String contentType = "text/html; charset='utf-8'";

    if (path != null) {
      if (path.endsWith(".rdf")) {
        contentType = "application/rdf+xml; charset='utf-8'";
        htmlOutput = false;
        language = "RDF/XML";
      } else if (path.endsWith(".xml")) {
        contentType = "application/xml; charset='utf-8'";
        htmlOutput = false;
        language = "RDF/XML";
      } else if (path.endsWith(".n3")) {
        contentType = "text/n3; charset='utf-8'";
        htmlOutput = false;
        language = "N3";
      }
    }

    response.setContentType(contentType);
    response.setStatus(HttpServletResponse.SC_OK);

    Writer writer = response.getWriter();

    synchronized (board) {
      if (htmlOutput) {
        writer.write(
            "<!DOCTYPE html>\n"
                + "<html lang='en'>"
                + "<head><meta charset='utf-8'/><title>MATe model</title></head>"
                + "<body><ul>");
        StmtIterator it = model.listStatements();
        /* TODO: well, this could be prettier */
        while (it.hasNext()) writer.write("<li>" + it.nextStatement() + "</li>");
        writer.write("<ul></body></html>");
      } else model.write(writer, language);
    }
  }
  public static void main(String[] args) {

    List<String> obj = new ArrayList<String>();

    Scanner input = new Scanner(System.in);

    System.out.print("Enter URI: ");

    String userIn = input.nextLine();

    // create an empty Model
    Model model = ModelFactory.createDefaultModel();

    // read the RDF/XML file
    model.read(userIn);

    // write it to standard out
    // model.write(System.out);

    // list the statements in the Model
    StmtIterator iter = model.listStatements();

    System.out.println();

    // print out the predicate, subject and object of each statement
    while (iter.hasNext()) {
      Statement stmt = iter.nextStatement(); // get next statement
      Resource subject = stmt.getSubject(); // get the subject
      Property predicate = stmt.getPredicate(); // get the predicate
      RDFNode object = stmt.getObject(); // get the object

      System.out.print(subject.toString());
      System.out.print(" -> " + predicate.toString() + " -> ");
      if (object instanceof Resource) {
        System.out.print(object.toString() + "\n");
      } else {
        // object is a literal
        System.out.print(" \"" + object.toString() + "\"\n");
      }
    }

    /* for(int i = 0; i < (obj.size()); i++){

    	String sparqlQueryString1=
    								"SELECT ?s ?o "+
    								"WHERE {"+
    								"?s ?p ?o ."+
    								"?o <bif:contains> \""+obj.get(i)+"\" ."+
    								"}"+
    								"limit 10";

    		      Query query = QueryFactory.create(sparqlQueryString1);
    		      QueryExecution qexec = QueryExecutionFactory.sparqlService("http://pubmed.bio2rdf.org/sparql", query);

    		      ResultSet results = qexec.execSelect();
    		      System.out.println("Query: "+obj.get(i));
    		      ResultSetFormatter.out(System.out, results, query);

    		     qexec.close() ;
    } */

  }