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


Java Rio类代码示例

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


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

示例1: RDF4JSchemaGeneratorCore

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
public RDF4JSchemaGeneratorCore(String filename, RDFFormat format) throws IOException, RDFParseException {
    Path file = Paths.get(filename);
    if (!Files.exists(file)) throw new FileNotFoundException(filename);

    if (format == null) {
        format = Rio.getParserFormatForFileName(filename).orElse(null);
        log.trace("detected input format from filename {}: {}", filename, format);
    }

    try (final InputStream inputStream = Files.newInputStream(file)) {
        log.trace("Loading input file");
        model = Rio.parse(inputStream, "", format);
    }

    //import
    Set<Resource> owlOntologies = model.filter(null, RDF.TYPE, OWL.ONTOLOGY).subjects();
    if (!owlOntologies.isEmpty()) {
        setPrefix(owlOntologies.iterator().next().stringValue());
    }
}
 
开发者ID:ansell,项目名称:rdf4j-schema-generator,代码行数:21,代码来源:RDF4JSchemaGeneratorCore.java

示例2: data

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
@Parameters(name = "{0}")
public static Collection<Object[]> data() {
    Collection<Object[]> result = new ArrayList<>();
    for (RDFFormat nextParserFormat : RDFParserRegistry.getInstance().getKeys()) {
        try {
            // Try to create a writer, as not all formats (RDFa for example) have writers,
            // and we can't automatically test those formats like this
            OutputStream out = new ByteArrayOutputStream();
            Rio.createWriter(nextParserFormat, out);
            // If the writer creation did not throw an exception, add it to the list
            result.add(new Object[]{nextParserFormat});
        } catch(UnsupportedRDFormatException e) {
            // Ignore to drop this format from the list
        }
    }
    assertFalse("No RDFFormats found with RDFParser and RDFWriter implementations on classpath", result.isEmpty());
    return result;
}
 
开发者ID:ansell,项目名称:rdf4j-schema-generator,代码行数:19,代码来源:SchemaGeneratorTest.java

示例3: mergeResourceWithPrefixes

import org.eclipse.rdf4j.rio.Rio; //导入依赖的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

示例4: addFile

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
private void addFile(final InputStream in,
                     final RDFFormat format) throws Exception {
    Preconditions.checkNotNull(in);

    try {
        try (SailConnection sc = getConnection()) {
            RDFHandler h = new SailAdder(sc);
            RDFParser p = Rio.createParser(format);
            p.setRDFHandler(h);
            p.parse(in, "http://example.org/bogusBaseIRI/");
            commit(sc);
        }
    } finally {
        in.close();
    }
}
 
开发者ID:joshsh,项目名称:graphsail,代码行数:17,代码来源:SailTest.java

示例5: convertStmtListToRDF

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
/**
 * Convert Model of RMap object to an OutputStream of RDF.
 *
 * @param model Model of RMap object to be converted
 * @param rdfType RDF Format for serialization
 * @return OutputStream containing RDF serialization of RMap object
 * @throws RMapException the r map exception
 */
public OutputStream convertStmtListToRDF(Model model, RDFType rdfType) 
throws RMapException	{
	if (model==null){
		throw new RMapException("Null or empty Statement model");
	}
	if (rdfType==null){
		throw new RMapException("RDF format name null");
	}	
	RDFFormat rdfFormat = null;
	OutputStream bOut = new ByteArrayOutputStream();
	try {
		rdfFormat = this.getRDFFormatConstant(rdfType);
		Rio.write(model, bOut, rdfFormat);
	} catch (Exception e) {
		throw new RMapException("Exception thrown creating RDF from statement list",e);
	}
	return bOut;		
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:27,代码来源:RioRDFHandler.java

示例6: triple2Rdf

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
public OutputStream triple2Rdf(RMapTriple triple, RDFType rdfType) throws RMapException, RMapDefectiveArgumentException {
	if (triple == null){
		throw new RMapException("Null triple");
	}
	if (rdfType==null){
		throw new RMapException("null rdf format name");
	}
	Statement stmt = ORAdapter.rmapTriple2Rdf4jStatement(triple);

	RDFFormat rdfFormat = null;
	OutputStream bOut = new ByteArrayOutputStream();
	try {
		rdfFormat = this.getRDFFormatConstant(rdfType);
		Rio.write(stmt, bOut, rdfFormat);
	} catch (Exception e) {
		throw new RMapException("Exception thrown creating RDF from statement",e);
	}
	return bOut;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:20,代码来源:RioRDFHandler.java

示例7: init

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
/**
 * Initialize repository and load triples
 * 
 * @throws IOException 
 */
public void init() throws IOException {
    LOG.debug("Initialize repository");
    repo = new SailRepository(new MemoryStore());
    repo.initialize();
    
    Optional<RDFFormat> fmt = Rio.getParserFormatForFileName(path.toString());
    if (!fmt.isPresent()) {
        throw new IOException("Could not determine file type");
    }
    
    LOG.debug("Adding triples");
    BufferedReader r = Files.newBufferedReader(path);
    
    Date start = new Date();
    RepositoryConnection con = repo.getConnection();
    try {
        con.add(r, BASE_URI, fmt.get());
    } catch (RepositoryException cve) {
        LOG.error("Error adding triples", cve);
    }
    LOG.info("{} triples loaded in {} ms", 
            con.size(), new Date().getTime() - start.getTime());
            
    if(con.isEmpty()) {
        LOG.error("No statements loaded");
        close();
    }
}
 
开发者ID:Fedict,项目名称:rdfvalidator,代码行数:34,代码来源:Validator.java

示例8: getTriplesCount

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
private static int getTriplesCount(String uri, String compression, RDFFormat format) throws Exception {
    InputStream in = FileSystem.get(URI.create(uri), HBaseServerTestInstance.getInstanceConfig()).open(new Path(uri));
    try {
        if (compression != null) {
            in = new CompressorStreamFactory().createCompressorInputStream(compression, in);
        }
        RDFParser parser = Rio.createParser(format);
        final AtomicInteger i = new AtomicInteger();
        parser.setRDFHandler(new AbstractRDFHandler(){
            @Override
            public void handleStatement(Statement st) throws RDFHandlerException {
                i.incrementAndGet();
            }
        });
        parser.parse(in, uri);
        return i.get();
    } finally {
        in.close();
    }
}
 
开发者ID:Merck,项目名称:Halyard,代码行数:21,代码来源:HalyardExportTest.java

示例9: getFileContentAsStatements

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
/**
 * Method to read the content of a turtle file
 * 
 * @param fileName Turtle file name
 * @param baseURI
 * @return File content as a string
 */
public static List<Statement> getFileContentAsStatements(String fileName, 
        String baseURI)  {        
    List<Statement> statements = null;  
    try {
        String content = getFileContentAsString(fileName);
        StringReader reader = new StringReader(content);
        Model model;
        model = Rio.parse(reader, baseURI, FILE_FORMAT);
        Iterator<Statement> it = model.iterator();
        statements =  Lists.newArrayList(it);
    } catch (IOException | RDFParseException | 
            UnsupportedRDFormatException ex) {
        LOGGER.error("Error getting turle file",ex);          
    }         
    return statements;
}
 
开发者ID:DTL-FAIRData,项目名称:FAIRDataPoint,代码行数:24,代码来源:ExampleFilesUtils.java

示例10: getString

import org.eclipse.rdf4j.rio.Rio; //导入依赖的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

示例11: getStatements

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
/**
 * Create List<Statements> from rdf string
 * 
 * @param rdfString     RDF string
 * @param baseUri       Base uri
 * @param format        RDF format
 * @return
 * @throws MetadataParserException 
 */
public static List<Statement> getStatements(String rdfString, IRI baseUri,
        RDFFormat format) throws MetadataParserException {
    String uri;
    if (baseUri == null) {
        uri = "http://example.com/dummyResource";
    } else {
        uri = baseUri.stringValue();
    }
    try {
        Model model = Rio.parse(new StringReader(rdfString), uri , format);
        Iterator<Statement> it = model.iterator();
        List<Statement> statements = ImmutableList.copyOf(it);
        return statements;
    } catch (RDFParseException | UnsupportedRDFormatException | 
            IOException ex) {
        String errMsg = "Error reading dataset metadata content"
                + ex.getMessage();
        LOGGER.error(errMsg);
        throw (new MetadataParserException(errMsg));
    }
}
 
开发者ID:DTL-FAIRData,项目名称:fairmetadata4j,代码行数:31,代码来源:RDFUtils.java

示例12: getFileContentAsStatements

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
/**
 * Method to read the content of a turtle file
 * 
 * @param fileName Turtle file name
 * @param baseURI RDF content's base uri
 * @return File content as a string
 */
public static List<Statement> getFileContentAsStatements(String fileName, 
        String baseURI)  {        
    List<Statement> statements = null;  
    try {
        String content = getFileContentAsString(fileName);
        StringReader reader = new StringReader(content);
        Model model;
        model = Rio.parse(reader, baseURI, FILE_FORMAT);
        Iterator<Statement> it = model.iterator();
        statements =  Lists.newArrayList(it);
    } catch (IOException | RDFParseException | 
            UnsupportedRDFormatException ex) {
        LOGGER.error("Error getting turle file",ex);          
    }         
    return statements;
}
 
开发者ID:DTL-FAIRData,项目名称:fairmetadata4j,代码行数:24,代码来源:ExampleFilesUtils.java

示例13: parseConfig

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
private Model parseConfig(File file) throws SailConfigException, IOException
{
    RDFFormat format = Rio.getParserFormatForFileName(file.getAbsolutePath()).get();
    if (format==null)
        throw new SailConfigException("Unsupported file format: " + file.getAbsolutePath());
    RDFParser parser = Rio.createParser(format);
    Model model = new LinkedHashModel();
    parser.setRDFHandler(new StatementCollector(model));
    InputStream stream = new FileInputStream(file);

    try {
        parser.parse(stream, file.getAbsolutePath());
    } catch (Exception e) {
        throw new SailConfigException("Error parsing file!");
    }

    stream.close();
    return model;
}
 
开发者ID:semagrow,项目名称:semagrow,代码行数:20,代码来源:SemagrowRepositoryResolver.java

示例14: startUp

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
@PostConstruct
public void startUp() throws IOException, RDFParseException, RDFHandlerException  {
    if(this.sparqlSamplesFile!=null){
        HashMapHandler handler = new HashMapHandler();
        RDFParser parser = Rio.createParser(RDFFormat.TURTLE);
        parser.setRDFHandler(handler);
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(this.sparqlSamplesFile);
            parser.parse(fis, "");
            this.samplesData = handler.getSamplesData();
        } finally {
            if(fis!=null){
                fis.close();
            }
        }            
    }
}
 
开发者ID:semagrow,项目名称:semagrow,代码行数:19,代码来源:SparqlSamplesController.java

示例15: parseQueryLog

import org.eclipse.rdf4j.rio.Rio; //导入依赖的package包/类
@Override
public void parseQueryLog(InputStream in) throws IOException, QueryLogException {
    if (handler == null)
        throw new QueryLogException("No query log handler defined");

    try {
        model = Rio.parse(in, "", RDFFormat.NTRIPLES);
    } catch (Exception e) {
        throw new QueryLogException(e);
    }

    Model queryRecords = model.filter(null, RDF.TYPE, QFR.QUERYRECORD);

    for (Resource qr : queryRecords.subjects()) {
        QueryLogRecord record = parseQueryRecord(qr,model);
        handler.handleQueryRecord(record);
    }
}
 
开发者ID:semagrow,项目名称:semagrow,代码行数:19,代码来源:RDFQueryLogParser.java


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