Example #1
0
  /**
   * Returns reflection of the given resource <code>r</code> into given domain <code>mDomain</code>.
   *
   * @param uri uri of the resource to be reflected
   * @param mDB is model, which contains statements about resource <code>uri</code>
   * @param mDomain domain model describing classes
   * @return <
   *     <UL>
   *       <LI><code>uri</code> if resource with this <code>uri</code> , i.e. this resource occurs
   *           as a subject of a any statement in <code>mDomain</code>.
   *       <LI>URI of <code>C</code>, if resource with this <code>uri</code> does NOT belong do
   *           <code>mDomain</code> and instance of resource (class) C, belonging do <code>mDomain
   *           </code>.
   *       <LI><code>null</code> -- otherwise.
   *     </UL>
   */
  public static Resource getReflection(Resource r, OntModel mDB, OntModel mDomain) {
    // TODO The idea of reflexion becomes illogical when the individual as
    // an instance of more then one type (class).

    if (mDomain.containsResource(r))
      // Associate resource with mDomain
      return (Resource) r.inModel(mDomain);

    // Check whether ontr is instance (individual) of some class...
    // Associate it for the test with mDB model
    r = (Resource) r.inModel(mDB);
    for (StmtIterator it = r.listProperties(RDF.type); it.hasNext(); ) {
      Resource clazz = it.nextStatement().getResource();
      // ...and this class belongs to domain ontology
      if (mDomain.containsResource(clazz)) {
        // Since clazz is object of rdf:type predicate, than it is
        // rdfs:Resource.
        // Associate it with mDomain.
        return (Resource) clazz.inModel(mDomain);
      }
    }

    // The value is undefined
    return null;
  }
Example #2
0
  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();
  }
Example #3
0
  /**
   * Answer the lowest common ancestor of two classes in a given ontology. This is the class that is
   * farthest from the root concept (defaulting to <code>owl:Thing</code> which is a super-class of
   * both <code>u</code> and <code>v</code>. The algorithm is based on <a
   * href="http://en.wikipedia.org/wiki/Tarjan's_off-line_least_common_ancestors_algorithm">Tarjan's
   * off-line LCA</a>. The current implementation expects that the given model:
   *
   * <ul>
   *   <li>is transitively closed over the <code>subClassOf</code> relation
   *   <li>can cheaply determine <em>direct sub-class</em> relations
   * </ul>
   *
   * <p>Both of these conditions are true of the built-in Jena OWL reasoners, such as {@link
   * OntModelSpec#OWL_MEM_MICRO_RULE_INF}, and external DL reasoners such as Pellet.
   *
   * @param m The ontology model being queried to find the LCA, which should conform to the reasoner
   *     capabilities described above
   * @param u An ontology class
   * @param v An ontology class
   * @return The LCA of <code>u</code> and <code>v</code>
   * @exception JenaException if the language profile of the given model does not define a top
   *     concept (e.g. <code>owl:Thing</code>)
   */
  public static OntClass getLCA(OntModel m, OntClass u, OntClass v) {
    Resource root = m.getProfile().THING();
    if (root == null) {
      throw new JenaException(
          "The given OntModel has a language profile that does not define a generic root class (such as owl:Thing)");
    }

    root = root.inModel(m);
    return getLCA(m, root.as(OntClass.class), u, v);
  }
 /** @see com.hp.hpl.jena.rdf.model.RDFNode#inModel(com.hp.hpl.jena.rdf.model.Model) */
 public RDFNode inModel(Model m) {
   return wrapped.inModel(m);
 }