Ejemplo n.º 1
0
  public void addHash(Quad quad) throws IOException {
    // TODO 1. we should ignore blank nodes
    // TODO 2. we should ignore certain triples

    String subjectHash = "";
    if (!(quad.getSubject().isBlank())) {
      subjectHash = quad.getSubject().toString();
    }

    String propertyHash = quad.getPredicate().toString();

    String objectHash = "";
    if (!(quad.getObject().isBlank())) {
      objectHash = quad.getObject().toString();
    }

    String graphHash = "";
    if (quad.getGraph() != null) {
      graphHash = quad.getGraph().toString();
    }

    this.hashSet.add(this.fastHashing(subjectHash + propertyHash + objectHash + graphHash));

    //	this.hashSet.add(DigestUtils.md5Hex(subjectHash+propertyHash+objectHash+graphHash));
  }
Ejemplo n.º 2
0
    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(" .");
    }
  @Override
  public void send(Quad quad) {
    try {
      byte[] s = tdbloader3.serialize(quad.getSubject()).getBytes("UTF-8");
      byte[] p = tdbloader3.serialize(quad.getPredicate()).getBytes("UTF-8");
      byte[] o = tdbloader3.serialize(quad.getObject()).getBytes("UTF-8");
      byte[] g = null;
      // Union graph?!
      if (!quad.isTriple() && !quad.isDefaultGraph())
        g = tdbloader3.serialize(quad.getGraph()).getBytes("UTF-8");

      digest.reset();
      digest.update(s); // TODO: should we do something better here?
      digest.update(p);
      digest.update(o);
      if (g != null) digest.update(g.toString().getBytes("UTF-8"));

      String md5 = new String(Hex.encodeHex(digest.digest()));
      sdb01.add(new Pair<byte[], byte[]>(s, (md5 + "|s").getBytes("UTF-8")));
      sdb01.add(new Pair<byte[], byte[]>(p, (md5 + "|p").getBytes("UTF-8")));
      sdb01.add(new Pair<byte[], byte[]>(o, (md5 + "|o").getBytes("UTF-8")));
      if (g != null) sdb01.add(new Pair<byte[], byte[]>(g, (md5 + "|g").getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
      throw new AtlasException(e);
    }

    monitor.tick();
  }
Ejemplo n.º 4
0
 public static void outputPlain(IndentedWriter out, Quad qp, SerializationContext naming) {
   output(out, qp.getGraph(), naming);
   out.print(" ");
   output(out, qp.getSubject(), naming);
   out.print(" ");
   output(out, qp.getPredicate(), naming);
   out.print(" ");
   output(out, qp.getObject(), naming);
 }
Ejemplo n.º 5
0
 public static String str(Quad q) {
   return serialize(q.getGraph())
       + " "
       + serialize(q.getSubject())
       + " "
       + serialize(q.getPredicate())
       + " "
       + serialize(q.getObject());
 }
 @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());
   }
 }
Ejemplo n.º 7
0
    private void outputQuads(List<Quad> quads) {
      out.incIndent(BLOCK_INDENT);
      Node g = Quad.tripleInQuad;
      boolean inBlock = false;
      for (Quad q : quads) {
        if (q.getGraph() != g) {
          // New graph (default or named)
          if (inBlock) {
            // In named - end it.
            out.decIndent(BLOCK_INDENT);
            out.println("}");
            inBlock = false;
          }

          g = q.getGraph();

          // Start new block.
          // Two cases for no braces:
          // Quad.tripleInQuad and Quad.defaultGraphNodeGenerated ;
          if (!q.isTriple() && !q.isDefaultGraphGenerated()) {
            out.print("GRAPH ");
            output(g);
            out.println(" {");
            out.incIndent(BLOCK_INDENT);
            inBlock = true;
          }
        }

        outputTripleOfQuad(q);
        out.println(" .");
      }

      if (inBlock) {
        out.decIndent(BLOCK_INDENT);
        out.println("}");
        inBlock = false;
      }
      out.decIndent(BLOCK_INDENT);
    }
Ejemplo n.º 8
0
  public static Quad substitute(Quad quad, Binding binding) {
    if (isNotNeeded(binding)) return quad;

    Node g = quad.getGraph();
    Node s = quad.getSubject();
    Node p = quad.getPredicate();
    Node o = quad.getObject();

    Node g1 = substitute(g, binding);
    Node s1 = substitute(s, binding);
    Node p1 = substitute(p, binding);
    Node o1 = substitute(o, binding);

    Quad q = quad;
    if (s1 != s || p1 != p || o1 != o || g1 != g) q = new Quad(g1, s1, p1, o1);
    return q;
  }
Ejemplo n.º 9
0
 @Override
 public Iterator<Quad> find(Quad arg0) {
   return find(arg0.getSubject(), arg0.getPredicate(), arg0.getObject(), arg0.getGraph());
 }
Ejemplo n.º 10
0
 private Graph getGraphFor(Quad q) {
   return getGraphFor(q.getGraph());
 }