コード例 #1
0
ファイル: ErrorPages.java プロジェクト: sparkling/elda
  public static String RenderTemplatePage(Bindings b, String templateName) throws IOException {

    MediaType mt = MediaType.TEXT_HTML;
    Resource config = model.createResource("eh:/root");
    Mode prefixMode = Mode.PreferPrefixes;
    ShortnameService sns = new StandardShortnameService();

    List<Resource> noResults = CollectionUtils.list(root.inModel(model));
    Graph resultGraph = graphModel.getGraph();

    resultGraph.getPrefixMapping().setNsPrefix("api", API.NS);
    resultGraph.add(Triple.create(root.asNode(), API.items.asNode(), RDF.nil.asNode()));

    APIResultSet rs = new APIResultSet(resultGraph, noResults, true, true, "details", View.ALL);
    VelocityRenderer vr = new VelocityRenderer(mt, null, config, prefixMode, sns);

    VelocityRendering vx = new VelocityRendering(b, rs, vr);

    VelocityEngine ve = vx.createVelocityEngine();
    VelocityContext vc = vx.createVelocityContext(b);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Writer w = new OutputStreamWriter(bos, "UTF-8");
    Template t = ve.getTemplate(templateName);

    t.merge(vc, w);
    w.close();

    return bos.toString();
  }
コード例 #2
0
  /**
   * Query SPARQL endpoint with a SELECT query
   *
   * @param qExec QueryExecution encapsulating the query
   * @return model retrieved by querying the endpoint
   */
  private Model getSelectModel(QueryExecution qExec) {
    Model model = ModelFactory.createDefaultModel();
    Graph graph = model.getGraph();
    ResultSet results = qExec.execSelect();

    while (results.hasNext()) {
      QuerySolution sol = results.next();
      String subject;
      String predicate;
      RDFNode object;

      try {
        subject = sol.getResource("s").toString();
        predicate = sol.getResource("p").toString();
        object = sol.get("o");
      } catch (NoSuchElementException e) {
        logger.error("SELECT query does not return a (?s ?p ?o) Triple");
        continue;
      }

      Node objNode;
      if (object.isLiteral()) {
        Literal obj = object.asLiteral();
        objNode = NodeFactory.createLiteral(obj.getString(), obj.getDatatype());
      } else {
        objNode = NodeFactory.createLiteral(object.toString());
      }

      graph.add(
          new Triple(NodeFactory.createURI(subject), NodeFactory.createURI(predicate), objNode));
    }

    return model;
  }
コード例 #3
0
 @Override
 public void add(List<Triple> arg0) {
   Graph g = GraphFactory.createPlainGraph();
   for (Triple t : arg0) {
     g.add(t);
   }
   add(g);
 }
コード例 #4
0
 @Override
 public void add(Triple[] arg0) {
   Graph g = GraphFactory.createPlainGraph();
   for (int i = 0; i < arg0.length; i++) {
     g.add(arg0[i]);
   }
   add(g);
 }
コード例 #5
0
 @Override
 public void add(Iterator<Triple> arg0) {
   Graph g = GraphFactory.createPlainGraph();
   while (arg0.hasNext()) {
     Triple t = arg0.next();
     g.add(t);
   }
   add(g);
 }
コード例 #6
0
 @Override
 public void add(Quad quad) {
   Graph graph;
   if (quad.isDefaultGraph()) {
     graph = getDefaultGraph();
   } else {
     graph = getGraph(quad.getGraph());
   }
   if (graph != null) {
     graph.add(quad.asTriple());
   }
 }
コード例 #7
0
 /**
  * Adds a set of precomputed triples to the deductions store. These do not, themselves, fire any
  * rules but provide additional axioms that might enable future rule firing when real data is
  * added. Used to implement bindSchema processing in the parent Reasoner.
  *
  * @return return true if the rule set has also been loaded
  */
 protected boolean preloadDeductions(Graph preloadIn) {
   Graph d = fdeductions.getGraph();
   BasicForwardRuleInfGraph preload = (BasicForwardRuleInfGraph) preloadIn;
   // If the rule set is the same we can reuse those as well
   if (preload.rules == rules) {
     // Load raw deductions
     for (Iterator<Triple> i = preload.find(null, null, null); i.hasNext(); ) {
       d.add(i.next());
     }
     engine.setRuleStore(preload.engine.getRuleStore());
     return true;
   } else {
     return false;
   }
 }
コード例 #8
0
ファイル: Renamer.java プロジェクト: jimmy0415/CIMTool
 public OntModel applyRenamings() {
   OntModel result = ModelFactory.createMem();
   Graph graph = result.getGraph();
   Iterator it = model.getGraph().find(Triple.ANY);
   while (it.hasNext()) {
     Triple t = (Triple) it.next();
     Node s = t.getSubject().isURI() ? rename(t.getSubject()) : null;
     Node o = t.getObject().isURI() ? rename(t.getObject()) : null;
     if (s != null || o != null)
       t =
           Triple.create(
               s != null ? s : t.getSubject(), t.getPredicate(), o != null ? o : t.getObject());
     graph.add(t);
   }
   return result;
 }