Examples of KR2RMLMapping


Examples of edu.isi.karma.kr2rml.mapping.KR2RMLMapping

        Worksheet worksheet = generateWorksheet(sourceName, new BufferedInputStream(data), dataType,
          workspace, maxNumLines);
     
     
      //Generate mappping data for the worksheet using the model parser
      KR2RMLMapping mapping = modelParser.parse();
     
      applyHistoryToWorksheet(workspace, worksheet, mapping);
      SuperSelection selection = SuperSelectionManager.DEFAULT_SELECTION;
      if (selectionName != null && !selectionName.trim().isEmpty())
        selection = worksheet.getSuperSelectionManager().getSuperSelection(selectionName);
View Full Code Here

Examples of edu.isi.karma.kr2rml.mapping.KR2RMLMapping

    {
      logger.error("Error occured while generating RDF!", e);
      return new UpdateContainer(new ErrorUpdate("Error occured while generating RDF: " + e.getMessage()));
    }

    KR2RMLMapping mapping = mappingGen.getKR2RMLMapping();
    if (url != null && !url.trim().isEmpty() && modelContext != null && !modelContext.trim().isEmpty() && generateBloomFilters && utilObj.testURIExists(modelRepoUrl, "", url)) {
      try {
        File tmp = new File("tmp");
        PrintWriter pw = new PrintWriter(tmp);
        pw.println(utilObj.getMappingFromTripleStore(modelRepoUrl, modelContext, url));
        pw.close();
        Model model = WorksheetR2RMLJenaModelParser.loadSourceModelIntoJenaModel(tmp.toURI().toURL());
        tmp.delete();
        R2RMLMappingIdentifier identifier = new R2RMLMappingIdentifier(mapping.getId().getName(), new URL(url));
        WorksheetR2RMLJenaModelParser parser = new WorksheetR2RMLJenaModelParser(model, identifier);
        mapping = parser.parse();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    logger.debug(mapping.toString());

    StringWriter sw = new StringWriter();
    // Generate the RDF using KR2RML data structures
    long start = 0;
    try {
      List<KR2RMLRDFWriter> writers = new ArrayList<KR2RMLRDFWriter>();
      File f = new File(rdfFileLocalPath);
      File parentDir = f.getParentFile();
      parentDir.mkdirs();
      BufferedWriter bw = new BufferedWriter(
          new OutputStreamWriter(new FileOutputStream(f),"UTF-8"));
      N3KR2RMLRDFWriter writer = new N3KR2RMLRDFWriter(new URIFormatter(workspace.getOntologyManager(), errorReport), new PrintWriter (bw));
      writer.setBaseURI(rdfSourceNamespace);
      writers.add(writer);
      if (generateBloomFilters && utilObj.testURIExists(modelRepoUrl, "", url)) {
        BloomFilterKR2RMLRDFWriter bfWriter = new BloomFilterKR2RMLRDFWriter(new PrintWriter(sw), false, this.rdfSourceNamespace);
        writers.add(bfWriter);
        bfWriter.setR2RMLMappingIdentifier(mapping.getId());
      }
      KR2RMLWorksheetRDFGenerator rdfGen = new KR2RMLWorksheetRDFGenerator(worksheet,
          workspace.getFactory(), workspace.getOntologyManager(),
          writers, false, mapping, errorReport, selection);
View Full Code Here

Examples of edu.isi.karma.kr2rml.mapping.KR2RMLMapping

    } catch (KarmaException e)
    {
      logger.error("Error occured while generating RDF!", e);
      return new UpdateContainer(new ErrorUpdate("Error occured while generating RDF: " + e.getMessage()));
    }
    KR2RMLMapping mapping = mappingGen.getKR2RMLMapping();

    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));
    }
    final String avroFileName = workspace.getCommandPreferencesId() + worksheetId + "-" +
        worksheet.getTitle().replaceAll("\\.", "_") "-export"+".avro";
    final String avroFileLocalPath = ServletContextParameterMap.getParameterValue(ContextParameter.AVRO_PUBLISH_DIR)
        avroFileName;
   
    try {
      FileOutputStream fos = new FileOutputStream(new File(avroFileLocalPath));
      AvroKR2RMLRDFWriter writer = new AvroKR2RMLRDFWriter(fos);
      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);
View Full Code Here

Examples of edu.isi.karma.kr2rml.mapping.KR2RMLMapping

    } catch (KarmaException e)
    {
      logger.error("Error occured while generating RDF!", e);
      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

Examples of edu.isi.karma.kr2rml.mapping.KR2RMLMapping

      throws RepositoryException, RDFParseException, IOException, JSONException, KarmaException {

    Worksheet ws = workspace.getFactory().getWorksheet(worksheetId);
    R2RMLMappingIdentifier id = new R2RMLMappingIdentifier(ws.getTitle(), r2rmlModelFile.toURI().toURL());
    WorksheetR2RMLJenaModelParser parser = new WorksheetR2RMLJenaModelParser(id);
    KR2RMLMapping mapping = parser.parse();
    KR2RMLVersion version = mapping.getVersion();
    if(version.compareTo(KR2RMLVersion.current) < 0)
    {
      uc.add(new InfoUpdate("Model version is " + version.toString() + ".  Current version is " + KR2RMLVersion.current.toString() + ".  Please publish it again."));
    }
    return mapping.getWorksheetHistory();

  }
View Full Code Here

Examples of edu.isi.karma.kr2rml.mapping.KR2RMLMapping

  private void generateRDF(String wkname, String query, List<KR2RMLRDFWriter> writers, R2RMLMappingIdentifier id, String baseURI)
      throws IOException, JSONException, KarmaException, SQLException, ClassNotFoundException{
    logger.debug("Generating RDF...");

    WorksheetR2RMLJenaModelParser parserTest = new WorksheetR2RMLJenaModelParser(id);
    KR2RMLMapping mapping = parserTest.parse();
    for (KR2RMLRDFWriter writer : writers) {
      if (writer instanceof BloomFilterKR2RMLRDFWriter) {
        BloomFilterKR2RMLRDFWriter t = (BloomFilterKR2RMLRDFWriter)writer;
        t.setR2RMLMappingIdentifier(id);
      }
View Full Code Here

Examples of edu.isi.karma.kr2rml.mapping.KR2RMLMapping

    {
      logger.error("Error occured while exporting CSV!", e);
      return new UpdateContainer(new ErrorUpdate("Error occured while exporting CSV: " + e.getMessage()));
    }
       
    KR2RMLMapping mapping = mappingGen.getKR2RMLMapping();
    logger.debug(mapping.toString());
   
   
    // Generate the RDF using KR2RML data structures
    try {
      KR2RMLWorksheetRDFGenerator rdfGen = new KR2RMLWorksheetRDFGenerator(worksheet,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.