当前位置: 首页>>代码示例>>Java>>正文


Java RDFWriter类代码示例

本文整理汇总了Java中org.eclipse.rdf4j.rio.RDFWriter的典型用法代码示例。如果您正苦于以下问题:Java RDFWriter类的具体用法?Java RDFWriter怎么用?Java RDFWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RDFWriter类属于org.eclipse.rdf4j.rio包,在下文中一共展示了RDFWriter类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mergeResourceWithPrefixes

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public static Model mergeResourceWithPrefixes(InputStream inputStreamPrefixes,
    InputStream inputStreamData) throws IOException {
  final Resource mergedDataResource =
      new InputStreamResource(new SequenceInputStream(inputStreamPrefixes, inputStreamData));
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

  RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);
  RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
  trigParser.setRDFHandler(turtleWriter);
  trigParser.parse(mergedDataResource.getInputStream(), "");

  Model result = Rio.parse(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "",
      RDFFormat.TURTLE);

  byteArrayOutputStream.close();
  inputStreamData.close();
  return result;
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:RdfModelTransformer.java

示例2: getString

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
/**
 * Convert Metadata object to RDF string
 *
 * @param <T>
 * @param metadata Subclass of metadata object
 * @param format RDF format
 * @return RDF string
 * @throws MetadataException
 */
public static <T extends Metadata> String getString(@Nonnull T metadata,
        @Nonnull RDFFormat format)
        throws MetadataException {
    Preconditions.checkNotNull(metadata,
            "Metadata object must not be null.");
    Preconditions.checkNotNull(format, "RDF format must not be null.");
    
    StringWriter sw = new StringWriter();
    RDFWriter writer = Rio.createWriter(format, sw);
    List<Statement> statement = getStatements(metadata);
    try {
        propagateToHandler(statement, writer);
    } catch (RepositoryException | RDFHandlerException ex) {
        LOGGER.error("Error reading RDF statements");
        throw (new MetadataException(ex.getMessage()));
    }
    return sw.toString();
}
 
开发者ID:DTL-FAIRData,项目名称:fairmetadata4j,代码行数:28,代码来源:MetadataUtils.java

示例3: getModel

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public static Model getModel(InputStream inputStream) throws IOException {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);

  RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
  trigParser.setRDFHandler(turtleWriter);
  trigParser.parse(inputStream, "");

  org.eclipse.rdf4j.model.Model result = Rio.parse(
      new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "", RDFFormat.TURTLE);

  byteArrayOutputStream.close();
  return result;
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:15,代码来源:RdfModelTransformer.java

示例4: testConstructQueryWithWriter

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
@Ignore
public void testConstructQueryWithWriter()
        throws Exception {
    RDFWriter writer = Rio.createWriter(RDFFormat.TURTLE, System.out);

    @SuppressWarnings("unused")
    String queryString = "PREFIX nn: <http://semanticbible.org/ns/2006/NTNames#>\n" +
            "PREFIX test: <http://marklogic.com#test>\n" +
            "\n" +
            "construct { ?s  test:test \"0\"} WHERE {?s nn:childOf nn:Eve . }";
    conn.prepareGraphQuery(QueryLanguage.SPARQL,
            "CONSTRUCT {?s ?p ?o } WHERE {?s ?p ?o } ").evaluate(writer);
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:14,代码来源:MarkLogicGraphQueryTest.java

示例5: write

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
/**
 * Write contents of RDF repository to N-Triples output
 * 
 * @param out
 * @param format RDF output format
 * @throws RepositoryException 
 */
public void write(Writer out, RDFFormat format) throws RepositoryException {
    RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, out);
    try {
        conn.export(writer);
    } catch (RDFHandlerException ex) {
        logger.warn("Error writing RDF");
    }
}
 
开发者ID:Fedict,项目名称:dcattools,代码行数:16,代码来源:Storage.java

示例6: renderInternal

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
protected void renderInternal(Map model, HttpServletRequest request, HttpServletResponse response) throws IOException {
    RDFWriterFactory rdfWriterFactory = (RDFWriterFactory)model.get("factory");
    RDFFormat rdfFormat = rdfWriterFactory.getRDFFormat();
    response.setStatus(200);
    this.setContentType(response, rdfFormat);
    this.setContentDisposition(model, response, rdfFormat);
    boolean headersOnly = ((Boolean)model.get("headersOnly")).booleanValue();
    if(!headersOnly) {
        ServletOutputStream out = response.getOutputStream();

        try {
            RDFWriter e = rdfWriterFactory.getWriter(out);
            GraphQuery graphQuery = (GraphQuery)model.get("queryResult");
            graphQuery.evaluate(e);
        } catch (QueryInterruptedException var15) {
            this.logger.error("Query interrupted", var15);
            response.sendError(503, "Query evaluation took too long");
        } catch (QueryEvaluationException var16) {
            this.logger.error("Query evaluation error", var16);
            response.sendError(500, "Query evaluation error: " + var16.getMessage());
        } catch (RDFHandlerException var17) {
            this.logger.error("Serialization error", var17);
            response.sendError(500, "Serialization error: " + var17.getMessage());
        } finally {
            out.close();
        }
    }

    this.logEndOfRequest(request);
}
 
开发者ID:semagrow,项目名称:semagrow,代码行数:31,代码来源:GraphQueryResultView.java

示例7: getQueryRecordLogger

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
private QueryLogWriter getQueryRecordLogger(RDFWriterFactory writerFactory, OutputStream out) {

        RDFWriter writer = writerFactory.getWriter(out);

        QueryLogWriter handler = new RDFQueryLogWriter(writer);

        try {
            handler.startQueryLog();
        } catch (QueryLogException e) {
            e.printStackTrace();
        }
        return handler;
    }
 
开发者ID:semagrow,项目名称:semagrow,代码行数:14,代码来源:RDFQueryLogFactory.java

示例8: writeTo

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
@Override
public void writeTo(OutputStream stream, Syntax syntax) throws
		// interface allows it
		IOException, ModelRuntimeException {
	RDFWriter rdfWriter = Rio.createWriter(getRDFFormat(syntax), stream);
	writeTo(rdfWriter);
}
 
开发者ID:semweb4j,项目名称:semweb4j,代码行数:8,代码来源:RepositoryModel.java

示例9: writeTo

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
private void writeTo(RDFWriter writer) throws ModelRuntimeException {
	this.assertModel();
	try {
		this.connection.export(writer);
	} catch(RDF4JException e) {
		throw new ModelRuntimeException(e);
	}
}
 
开发者ID:semweb4j,项目名称:semweb4j,代码行数:9,代码来源:RepositoryModelSet.java

示例10: export

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public static void export(final Connection connection, final Path path)
        throws SQLException, IOException, RDFHandlerException {

    final Map<Long, String> screenNames = loadScreenNames(connection, path);

    connection.setAutoCommit(false);

    final ValueFactory vf = SimpleValueFactory.getInstance();

    try (Writer writer = new OutputStreamWriter(
            new GZIPOutputStream(new FileOutputStream(path.toFile())), Charsets.UTF_8)) {

        final RDFWriter out = Rio.createWriter(RDFFormat.NTRIPLES, writer);
        out.startRDF();

        int counter = 0;
        try (PreparedStatement stmt = connection.prepareStatement("" //
                + "SELECT resource_id, uid, score, is_alignment\n" //
                + "FROM alignments\n" //
                + "WHERE version=2\n" //
                + "ORDER BY resource_id ASC, score DESC")) {
            stmt.setFetchSize(1000);
            try (ResultSet rs = stmt.executeQuery()) {
                IRI lastEntity = null;
                int rank = 1;
                while (rs.next()) {
                    final long uid = rs.getLong("uid");
                    final String screenName = screenNames.get(uid);
                    Preconditions.checkState(screenName != null);
                    final IRI entity = vf.createIRI(rs.getString("resource_id"));
                    final IRI account = vf.createIRI(
                            "http://twitter.com/" + screenName.replaceAll("\\s", "+"));
                    final BNode candidate = vf.createBNode();
                    final float score = rs.getFloat("score");
                    final boolean align = rs.getBoolean("is_alignment");
                    rank = entity.equals(lastEntity) ? rank + 1 : 1;
                    lastEntity = entity;
                    LOGGER.debug("Processing candidate {} {} {} {}", entity, candidate, score,
                            align);
                    if (align) {
                        emit(out, entity, FOAF.ACCOUNT, account);
                    }
                    emit(out, entity, OWL.SAMEAS, entity);
                    emit(out, entity, SL.CANDIDATE_PROPERTY, candidate);
                    emit(out, candidate, SL.RANK, vf.createLiteral(rank));
                    emit(out, candidate, SL.CONFIDENCE, vf.createLiteral(score));
                    emit(out, candidate, SL.ACCOUNT, account);
                    emit(out, account, DCTERMS.IDENTIFIER, vf.createLiteral(uid));
                    emit(out, account, FOAF.ACCOUNT_NAME, vf.createLiteral(screenName));
                    if (++counter % 10000 == 0) {
                        LOGGER.info("{} candidates processed", counter);
                    }
                }
            }
        }

        out.endRDF();
    }
}
 
开发者ID:Remper,项目名称:sociallink,代码行数:60,代码来源:RDFExporter.java

示例11: main

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
/**
   * Main program
   * 
   * @param args 
   */
  public static void main(String[] args) {
      logger.info("-- START --");
      if (args.length < 2) {
          logger.error("No input or output file");
          System.exit(-1);
      }
      
      Optional<RDFFormat> fmtin = Rio.getParserFormatForFileName(args[0]);
      if(!fmtin.isPresent()) {
          logger.error("No parser for input {}", args[0]);
          System.exit(-2);
      }
      
      Optional<RDFFormat> fmtout = Rio.getWriterFormatForFileName(args[1]);
      if(!fmtout.isPresent()) {
          logger.error("No parser for output {}", args[1]);
          System.exit(-3);            
      }
      
      int code = 0;
      Repository repo = new SailRepository(new MemoryStore());
repo.initialize();
      
      try (RepositoryConnection con = repo.getConnection()) {
          con.add(new File(args[0]), "http://data.gov.be", fmtin.get());
	// Various namespace prefixes
          con.setNamespace(DCAT.PREFIX, DCAT.NAMESPACE);
	con.setNamespace(DCTERMS.PREFIX, DCTERMS.NAMESPACE);
	con.setNamespace(FOAF.PREFIX, FOAF.NAMESPACE);
	con.setNamespace("vcard", "http://www.w3.org/2006/vcard/ns#");
	con.setNamespace("locn", "http://www.w3.org/ns/locn#");

	FileOutputStream fout = new FileOutputStream(new File(args[1]));
	
	RDFWriter writer;
	if (fmtout.get().equals(RDFFormat.RDFXML)) {
		writer = new RDFXMLPrettyWriterFactory().getWriter(fout);
	} else {
		writer = Rio.createWriter(fmtout.get(), fout);
	}

	logger.info("Using writer {}", writer.getClass().getCanonicalName());
	
          con.export(writer);
      } catch (IOException ex) {
          logger.error("Error converting", ex);
          code = -1;
      }
      
      repo.shutDown();
      
      System.exit(code);
  }
 
开发者ID:Fedict,项目名称:dcattools,代码行数:59,代码来源:Converter.java

示例12: RDFQueryLogWriter

import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public RDFQueryLogWriter(RDFWriter handler) {
    this.handler = handler;
}
 
开发者ID:semagrow,项目名称:semagrow,代码行数:4,代码来源:RDFQueryLogWriter.java


注:本文中的org.eclipse.rdf4j.rio.RDFWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。