Пример #1
0
 private void write(RDFResourceNode node) {
   if (!node.isAnonymous()) {
     write(node.getIRI());
   } else {
     pushTab();
     if (!isObjectList(node)) {
       render(node);
     } else {
       // List - special syntax
       List<RDFNode> list = new ArrayList<RDFNode>();
       toJavaList(node, list);
       pushTab();
       write("(");
       write(" ");
       pushTab();
       for (Iterator<RDFNode> it = list.iterator(); it.hasNext(); ) {
         write(it.next());
         if (it.hasNext()) {
           writeNewLine();
         }
       }
       popTab();
       writeNewLine();
       write(")");
       popTab();
     }
     popTab();
   }
 }
Пример #2
0
 public void writeNodeIDAttribute(RDFResourceNode node) throws IOException {
   writer.writeAttribute(Namespaces.RDF + "nodeID", node.toString());
 }
Пример #3
0
  /**
   * Renders the triples whose subject is the specified node
   *
   * @param node The node
   */
  @Override
  public void render(RDFResourceNode node) {
    level++;
    if (pending.contains(node)) {
      // We essentially remove all structure sharing during parsing - any cycles therefore indicate
      // a bug!
      throw new IllegalStateException(
          "Rendering cycle!  This indicates structure sharing and should not happen!");
    }
    pending.add(node);
    Set<RDFTriple> triples = new TreeSet<RDFTriple>(new TripleComparator());
    triples.addAll(getGraph().getTriplesForSubject(node));

    RDFResourceNode lastSubject = null;
    RDFResourceNode lastPredicate = null;
    boolean first = true;
    for (RDFTriple triple : triples) {
      RDFResourceNode subj = triple.getSubject();
      RDFResourceNode pred = triple.getProperty();
      if (lastSubject != null && (subj.equals(lastSubject) || subj.isAnonymous())) {
        if (lastPredicate != null && pred.equals(lastPredicate)) {
          // Only the object differs from previous triple
          // Just write the object
          write(" ,");
          writeNewLine();
          write(triple.getObject());
        } else {
          // The predicate, object differ from previous triple
          // Just write the predicate and object
          write(" ;");
          popTab();
          if (!subj.isAnonymous()) {
            writeNewLine();
          }
          writeNewLine();
          write(triple.getProperty());
          write(" ");
          pushTab();
          write(triple.getObject());
        }
      } else {
        if (!first) {
          popTab();
          popTab();
          writeNewLine();
        }
        // Subject, preficate and object are different from last triple
        if (!node.isAnonymous()) {
          write(triple.getSubject());
          write(" ");
        } else {
          pushTab();
          write("[");
          write(" ");
        }
        pushTab();
        write(triple.getProperty());
        write(" ");
        pushTab();
        write(triple.getObject());
      }
      lastSubject = subj;
      lastPredicate = pred;
      first = false;
    }

    if (node.isAnonymous()) {
      popTab();
      popTab();
      if (triples.isEmpty()) {
        write("[ ");
      } else {
        writeNewLine();
      }
      write("]");
      popTab();
    } else {
      popTab();
      popTab();
    }
    if (level == 1 && !triples.isEmpty()) {
      write(" .\n");
    }
    writer.flush();

    pending.remove(node);
    level--;
  }