Package edu.isi.karma.kr2rml

Examples of edu.isi.karma.kr2rml.KR2RMLMappingWriter


    File f = new File(modelFileLocalPath);
    File parentDir = f.getParentFile();
    parentDir.mkdirs();
    PrintWriter writer = new PrintWriter(f, "UTF-8");

    KR2RMLMappingWriter mappingWriter = new KR2RMLMappingWriter();
    mappingWriter.addR2RMLMapping(mappingGen.getKR2RMLMapping(), worksheet, workspace);
    mappingWriter.writeR2RMLMapping(writer);
    mappingWriter.close();
    writer.flush();
    writer.close();
  }
View Full Code Here


      return new UpdateContainer(new ErrorUpdate("Error occured while generating RDF: " + e.getMessage()));
    }
    KR2RMLMapping mapping = mappingGen.getKR2RMLMapping();
    //    TriplesMap triplesMap = mapping.getTriplesMapIndex().get(alignmentNodeId);
    if (contextFromModel) {
      KR2RMLMappingWriter writer;
      try {
        StringWriter string = new StringWriter();
        PrintWriter pw = new PrintWriter(string);
        writer = new KR2RMLMappingWriter();
        writer.addR2RMLMapping(mapping, worksheet, workspace);
        writer.writeR2RMLMapping(pw);
        writer.close();
        pw.flush();
        pw.close();
        Model model = ModelFactory.createDefaultModel();
        InputStream s = new ReaderInputStream(new StringReader(string.toString()));
        model.read(s, null, "TURTLE");
        contextJSON = new ContextGenerator(model, true).generateContext().toString();

      } catch (Exception e) {

      }

    }
    logger.debug(mapping.toString());

    //****************************************************************************************************/
    //*** Extract list of TripleMaps *************************************************************************************************/
    List<TriplesMap> triplesMapList = mapping.getTriplesMapList();


    String rootTriplesMapId = null;
    for(TriplesMap map: triplesMapList)
    {
      if(map.getSubject().getId().compareTo(alignmentNodeId) == 0)
      {
        rootTriplesMapId = map.getId();
        break;
      }
    }
    if(null == rootTriplesMapId)
    {
      String errmsg ="Invalid alignment id " + alignmentNodeId;
      logger.error(errmsg);
      return new UpdateContainer(new ErrorUpdate("Error occured while searching for root for JSON: " +errmsg));
    }
    // create JSONKR2RMLRDFWriter
    final String jsonFileName = workspace.getCommandPreferencesId() + worksheetId + "-" +
        worksheet.getTitle().replaceAll("\\.", "_") "-export"+".json";
    final String jsonFileLocalPath = ServletContextParameterMap.getParameterValue(ContextParameter.JSON_PUBLISH_DIR)
        jsonFileName;
    final String contextName = workspace.getCommandPreferencesId() + worksheetId + "-" + worksheet.getTitle().replaceAll("\\.", "_") "-context.json";
    final String jsonContextFileLocalPath = ServletContextParameterMap.getParameterValue(ContextParameter.JSON_PUBLISH_DIR) + contextName;
    PrintWriter printWriter;
    try {
      printWriter = new PrintWriter(jsonFileLocalPath);
      String baseURI = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.baseURI);
      JSONKR2RMLRDFWriter writer = new JSONKR2RMLRDFWriter(printWriter, baseURI);
      if (contextJSON != null && !contextJSON.isEmpty()) {
        JSONObject context = new JSONObject();
        try {
          context = new JSONObject(this.contextJSON);
        }catch(Exception e)
        {

        }

        PrintWriter pw = new PrintWriter(jsonContextFileLocalPath);
        pw.println(context.toString(4));
        pw.close();
        StringBuilder url = new StringBuilder();
        url.append(ServletContextParameterMap.getParameterValue(ContextParameter.JETTY_HOST));
        url.append(":");
        url.append(ServletContextParameterMap.getParameterValue(ContextParameter.JETTY_PORT));
        url.append("/");
        url.append(ServletContextParameterMap.getParameterValue(ContextParameter.JSON_PUBLISH_RELATIVE_DIR));
        url.append(contextName);
        writer.setGlobalContext(context, new ContextIdentifier(context.toString(), new URL(url.toString())));
      }
      writer.addPrefixes(mapping.getPrefixes());
      RootStrategy strategy = new UserSpecifiedRootStrategy(rootTriplesMapId, new SteinerTreeRootStrategy(new WorksheetDepthRootStrategy()));
      KR2RMLWorksheetRDFGenerator generator = new KR2RMLWorksheetRDFGenerator(worksheet, f, ontMgr, writer, false, strategy, mapping, errorReport, selection);
      try {
        generator.generateRDF(true);
        logger.info("RDF written to file.");
View Full Code Here

TOP

Related Classes of edu.isi.karma.kr2rml.KR2RMLMappingWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.