@Test
  public void directDataLinkToQuads() throws IOException {
    // first make a file of quads to load later
    final Model model = createDefaultModel();
    final Path quads = createTempFile("quadExample", ".nq");
    final Resource quadsURI = model.createResource(quads.toFile().toURI().toString());
    final Resource simpleExample = model.createResource("test:simpleExample");
    simpleExample.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
    simpleExample.addProperty(data, quadsURI);

    final DatasetGraph dsg = createTxnMem().asDatasetGraph();
    model
        .listStatements()
        .mapWith(Statement::asTriple)
        .mapWith(t -> new Quad(quadsURI.asNode(), t))
        .forEachRemaining(dsg::add);
    try (OutputStream out = new FileOutputStream(quads.toFile())) {
      write(out, dsg, NQUADS);
    }

    final Dataset dataset = assemble(simpleExample);
    final Model assembledDefaultModel = dataset.getDefaultModel();
    final Model assembledNamedModel = dataset.getNamedModel(quadsURI.getURI());
    assertTrue(assembledDefaultModel.isEmpty());
    assertTrue(
        assembledNamedModel.contains(
            assembledNamedModel.createStatement(simpleExample, data, quadsURI)));
  }
 private Model JoinMap(Model map) {
   Model newMap = ModelFactory.createDefaultModel();
   StmtIterator stmts = map.listStatements();
   while (stmts.hasNext()) {
     Statement s = stmts.next();
     if (s.getSubject().isURIResource() || s.getObject().isURIResource()) {
       s =
           newMap.createStatement(
               checkUri(s.getSubject().asNode(), newMap).asResource(),
               s.getPredicate(),
               checkUri(s.getObject().asNode(), newMap));
     }
     newMap.add(s);
   }
   return newMap;
 }
Exemple #3
0
  @Override
  public List<Statement> from() {
    initResource();
    // Container type
    Statement stmtType =
        model.createStatement(
            applicationEntity, RDF.type, model.createResource(baseuri + "/m2m/ApplicationEntity"));
    slist.add(stmtType);

    // Ontology Reference Type
    if (dto.getOr() != null) {
      Statement stmtType2 =
          model.createStatement(
              applicationEntity, RDF.type, model.createResource(ontologyReference));
      slist.add(stmtType2);
    }

    // name
    Statement stmtName =
        model.createStatement(
            applicationEntity, model.createProperty(baseuri + "/m2m/resourceName"), resourceName);
    slist.add(stmtName);

    // parent resource
    Statement stmtParentResource =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/hasParentResource"),
            parentResource);
    slist.add(stmtParentResource);

    // parent isResourceOf
    Statement stmtIsAEOf =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/isApplicationEntityOf"),
            parentResource);
    slist.add(stmtIsAEOf);

    // parent resource
    Statement stmtResourceOf =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/isApplicationEntityOf"),
            parentResource);
    slist.add(stmtResourceOf);

    // label
    Statement stmtLabel = model.createStatement(applicationEntity, RDFS.label, label);
    slist.add(stmtLabel);

    // createtime xsd datetime
    SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Calendar cal1 = Calendar.getInstance();
    try {
      cal1.setTime(sd.parse(StrUtils.makeXsdDateFromOnem2mDate(this.dto.getCt())));
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Statement stmtCreateTime =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/hasCreateDate"),
            model.createTypedLiteral(cal1));
    slist.add(stmtCreateTime);

    // last modified time
    Calendar cal2 = Calendar.getInstance();
    try {
      cal2.setTime(sd.parse(StrUtils.makeXsdDateFromOnem2mDate(this.dto.getLt())));
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Statement stmtLastModifiedTime =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/hasLastModifiedDate"),
            model.createTypedLiteral(cal2));
    slist.add(stmtLastModifiedTime);

    // resourceid
    Statement stmtResourceId =
        model.createStatement(
            applicationEntity, model.createProperty(baseuri + "/m2m/hasResourceId"), resourceId);
    slist.add(stmtResourceId);

    // pointofaccess
    if (dto.getPoa().length != 0) {
      for (int i = 0; i < dto.getPoa().length; i++) {
        slist.add(
            model.createStatement(
                applicationEntity,
                model.createProperty(baseuri + "/m2m/hasPointOfAccess"),
                model.createResource(dto.getPoa()[i])));
      }
    }

    // announce attribute
    if (dto.getAa().length != 0) {
      for (int i = 0; i < dto.getAa().length; i++) {
        slist.add(
            model.createStatement(
                applicationEntity,
                model.createProperty(baseuri + "/m2m/hasAnnounceTo"),
                model.createResource(dto.getAa()[i])));
      }
    }
    // announce to
    if (dto.getAt().length != 0) {
      for (int i = 0; i < dto.getAt().length; i++) {
        slist.add(
            model.createStatement(
                applicationEntity,
                model.createProperty(baseuri + "/m2m/hasAnnounceAttribute"),
                model.createResource(dto.getAt()[i])));
      }
    }

    // appname
    Statement appname =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/resourceName"),
            model.createResource(dto.getApn()));
    slist.add(appname);
    // appid
    Statement appid =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/hasAppID"),
            model.createResource(dto.getApi()));
    slist.add(appid);

    // aeid
    Statement aeid =
        model.createStatement(
            applicationEntity,
            model.createProperty(baseuri + "/m2m/hasApplicationEntityID"),
            model.createResource(dto.getApi()));
    slist.add(aeid);

    slist.add(stmtResourceId);
    return slist;
  }