예제 #1
0
  /**
   * Populates the namespaces map with default namespaces and namespaces used by the graph.
   *
   * @param graph Graph
   * @throws GraphException
   */
  protected void populateNamespaces(Graph graph) throws GraphException {

    // default namespaces
    namespaces = new HashMap<String, String>();
    namespaces.put(RDF_PREFIX, RDF.BASE_URI.toString());
    namespaces.put(RDFS_PREFIX, RDFS.BASE_URI.toString());
    namespaces.put("owl", "http://www.w3.org/2002/07/owl#");
    namespaces.put("dc", "http://purl.org/dc/elements/1.1/");

    // validate graph before reading
    if (graph == null) {
      throw new IllegalArgumentException("Graph argument is null.");
    }

    // get all statements
    ClosableIterator<Triple> tripleIter = graph.find(null, null, null);

    if (tripleIter != null) {

      while (tripleIter.hasNext()) {

        // get the next triple
        Triple triple = tripleIter.next();

        if (triple != null) {

          // evaluate subject
          SubjectNode subject = triple.getSubject();
          if (subject instanceof URIReference) {
            addNamespaceURI(((URIReference) subject).getURI());
          }

          // evaluate predicate (must be URIReference)
          PredicateNode predicate = triple.getPredicate();
          addNamespaceURI(((URIReference) predicate).getURI());

          // evaluate object
          ObjectNode object = triple.getObject();
          if (object instanceof URIReference) {
            addNamespaceURI(((URIReference) object).getURI());
          }
        }
      }

      // close the Iterator
      tripleIter.close();
    }
  }
예제 #2
0
 /** @see org.mulgara.resolver.spi.Statements#getObject() */
 @Override
 public long getObject() throws TuplesException {
   ObjectNode o = currentRow.getObject();
   try {
     return session.localize(o);
   } catch (LocalizeException e) {
     throw new TuplesException("Unable to localize object: " + o);
   }
 }
예제 #3
0
 /** @see org.mulgara.resolver.spi.Statements#getPredicate() */
 @Override
 public long getPredicate() throws TuplesException {
   PredicateNode p = currentRow.getPredicate();
   try {
     return session.localize(p);
   } catch (LocalizeException e) {
     throw new TuplesException("Unable to localize predicate: " + p);
   }
 }
예제 #4
0
 /** @see org.mulgara.resolver.spi.Statements#getSubject() */
 @Override
 public long getSubject() throws TuplesException {
   SubjectNode s = currentRow.getSubject();
   try {
     return session.localize(s);
   } catch (LocalizeException e) {
     throw new TuplesException("Unable to localize subject: " + s);
   }
 }