private void outputQuad(Quad quad) {
      String qs = FmtUtils.stringForQuad(quad, sCxt.getPrefixMapping());

      if (quad.getGraph() != null) {
        String g = FmtUtils.stringForNode(quad.getGraph(), sCxt);
        out.print(g);
        out.print(" ");
      }
      outputTripleOfQuad(quad);
      out.println(" .");
    }
    private void outputTripleOfQuad(Quad quad) {
      String s = FmtUtils.stringForNode(quad.getSubject(), sCxt);
      String p = FmtUtils.stringForNode(quad.getPredicate(), sCxt);
      String o = FmtUtils.stringForNode(quad.getObject(), sCxt);

      out.print(s);
      out.print(" ");
      out.print(p);
      out.print(" ");
      out.print(o);
    }
 // c.f. FmtUtils.stringForURI
 // Uses PrefixMap, not PrefixMapping
 static String stringForURI(String uri, String base, PrefixMap mapping) {
   if (mapping != null) {
     String pname = mapping.abbreviate(uri);
     if (pname != null) return pname;
   }
   if (base != null) {
     String x = FmtUtils.abbrevByBase(uri, base);
     if (x != null) return "<" + x + ">";
   }
   return FmtUtils.stringForURI(uri);
 }
  /** Encoding of a node so it can be reconstructed */
  public static String serialize(Node n, String base, PrefixMap prefixMap) {
    // See also Nodec.
    // See also OutputLangUtils - merge and this is a buffering call.

    if (n == null) return "<<null>>";

    if (n.isBlank()) {
      String str = n.getBlankNodeLabel();
      // c.f. OutputLangUtils
      if (onlySafeBNodeLabels) str = safeBNodeLabel(str);
      return "_:" + str;
    }

    if (n.isLiteral()) return FmtUtils.stringForLiteral((Node_Literal) n, null);

    if (n.isURI()) {
      String uri = n.getURI();
      return stringForURI(uri, base, prefixMap);
    }

    // Safe name?
    if (n.isVariable()) return "?" + n.getName();
    //
    //        if ( n.equals(Node.ANY) )
    //            return "ANY" ;

    throw new TDBException("Failed to turn a node into a string: " + n);
    // return null ;
  }
  public static void printPrefixes(Prologue prologue, IndentedWriter out) {
    if (prologue.getPrefixMapping() == null) return;

    Map<String, String> pmap = null;

    if (prologue.getPrefixMapping() instanceof PrefixMapping2) {
      PrefixMapping2 pm2 = (PrefixMapping2) prologue.getPrefixMapping();
      pmap = pm2.getNsPrefixMap(false);
    } else {
      Map<String, String> _pmap = prologue.getPrefixMapping().getNsPrefixMap();
      pmap = _pmap;
    }

    if (pmap.size() > 0) {
      // boolean first = true ;
      for (String k : pmap.keySet()) {
        String v = pmap.get(k);
        out.print("PREFIX  ");
        out.print(k);
        out.print(':');
        out.print(' ', 4 - k.length());
        // Include at least one space
        out.print(' ');
        out.print(FmtUtils.stringForURI(v));
        out.newline();
      }
    }
  }
    public void visit(UpdateCreate update) {
      out.ensureStartOfLine();
      out.print("CREATE");
      out.print(" ");
      if (update.isSilent()) out.print("SILENT ");

      String s = FmtUtils.stringForNode(update.getGraph(), sCxt);
      out.print(s);
    }
  public static String lang(Node node) {
    if (!node.isLiteral())
      NodeValue.raise(
          new ExprTypeException("lang: Not a literal: " + FmtUtils.stringForNode(node)));

    String s = node.getLiteralLanguage();
    if (s == null) s = "";
    return s;
  }
Exemple #8
0
 @Override
 public String asSparqlTerm(PrefixLogger pl) {
   String lang = (language.equals("none") ? "" : language);
   RDFDatatype dt =
       datatype.length() == 0 ? null : TypeMapper.getInstance().getSafeTypeByName(datatype);
   Node n = NodeFactory.createLiteral(spelling, lang, dt);
   if (datatype.length() > 0) pl.present(datatype);
   String lf = FmtUtils.stringForNode(n, RDFUtils.noPrefixes);
   return lf;
 }
 public static void output(IndentedWriter out, List<Node> nodeList, SerializationContext naming) {
   out.print("(");
   boolean first = true;
   for (Node node : nodeList) {
     if (!first) out.print(" ");
     out.print(FmtUtils.stringForNode(node, naming));
     first = false;
   }
   out.print(")");
 }
 private void printTargetUpdate2(Target target) {
   if (target.isDefault()) {
     out.print("DEFAULT");
   } else if (target.isOneNamedGraph()) {
     // out.print("GRAPH ") ;
     String s = FmtUtils.stringForNode(target.getGraph(), sCxt);
     out.print(s);
   } else {
     out.print("Target BROKEN / Update2");
     throw new ARQException("Malformed Target / Update2");
   }
 }
 private void printTarget(Target target) {
   if (target.isAll()) {
     out.print("ALL");
   } else if (target.isAllNamed()) {
     out.print("NAMED");
   } else if (target.isDefault()) {
     out.print("DEFAULT");
   } else if (target.isOneNamedGraph()) {
     out.print("GRAPH ");
     String s = FmtUtils.stringForNode(target.getGraph(), sCxt);
     out.print(s);
   } else {
     out.print("Target BROKEN");
     throw new ARQException("Malformed Target");
   }
 }
 public static String displayStr(Triple t, PrefixMapping prefixMapping) {
   return FmtUtils.stringForTriple(t, prefixMapping);
 }
 public static String displayStr(RDFNode obj) {
   return FmtUtils.stringForRDFNode(obj);
 }
 public static String displayStr(Node n) {
   return FmtUtils.stringForNode(n);
 }
 private void output(Node node) {
   String $ = FmtUtils.stringForNode(node, sCxt);
   out.print($);
 }
 private void outputStringAsURI(String uriStr) {
   String x = FmtUtils.stringForURI(uriStr, sCxt);
   out.print(x);
 }
 public static void output(IndentedWriter out, Node node, SerializationContext naming) {
   out.print(FmtUtils.stringForNode(node, naming));
 }