コード例 #1
0
  @Test
  public void triplesTest() throws IOException, JsonLdError {
    final InputStream in =
        getClass().getClassLoader().getResourceAsStream("testfiles/product.jsonld");
    final Object input = JSONUtils.fromInputStream(in);

    final ClerezzaTripleCallback callback = new ClerezzaTripleCallback();

    final MGraph graph = (MGraph) JsonLdProcessor.toRDF(input, callback);

    for (final Triple t : graph) {
      System.out.println(t);
    }
    assertEquals("Graph size", 13, graph.size());
  }
コード例 #2
0
  @Override
  public void read(
      InputStream in, String baseURI, ContentType ct, final StreamRDF output, Context context) {
    try {
      Object jsonObject = JSONUtils.fromInputStream(in);
      JSONLDTripleCallback callback =
          new JSONLDTripleCallback() {

            @Override
            // public Object call(Map<String, Object> dataset) {
            public Object call(RDFDataset dataset) {
              for (String gn : dataset.keySet()) {
                Object x = dataset.get(gn);
                if ("@default".equals(gn)) {
                  @SuppressWarnings("unchecked")
                  List<Map<String, Object>> triples = (List<Map<String, Object>>) x;
                  for (Map<String, Object> t : triples) {
                    Node s = createNode(t, "subject");
                    Node p = createNode(t, "predicate");
                    Node o = createNode(t, "object");
                    Triple triple = Triple.create(s, p, o);
                    output.triple(triple);
                  }
                } else {
                  @SuppressWarnings("unchecked")
                  List<Map<String, Object>> quads = (List<Map<String, Object>>) x;
                  Node g = NodeFactory.createURI(gn); // Bnodes?
                  for (Map<String, Object> q : quads) {
                    Node s = createNode(q, "subject");
                    Node p = createNode(q, "subject");
                    Node o = createNode(q, "object");
                    output.triple(Triple.create(s, p, o));
                  }
                }
              }
              return null;
            }
          };

      JSONLD.toRDF(jsonObject, callback);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (JSONLDProcessingError e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
  @Test
  public void curiesInContextTest() throws IOException, JsonLdError {
    final InputStream in =
        getClass().getClassLoader().getResourceAsStream("testfiles/curies-in-context.jsonld");
    final Object input = JSONUtils.fromInputStream(in);

    final ClerezzaTripleCallback callback = new ClerezzaTripleCallback();

    final MGraph graph = (MGraph) JsonLdProcessor.toRDF(input, callback);

    for (final Triple t : graph) {
      System.out.println(t);
      assertTrue(
          "Predicate got fully expanded", t.getPredicate().getUnicodeString().startsWith("http"));
    }
    assertEquals("Graph size", 3, graph.size());
  }