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


Java Rio.createParser方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: getModel

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

示例7: parseTriple

import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
 * Parses the RMapTriple out of the supplied solr document
 *
 * @param doc
 * @return
 * @throws IOException
 */
private RMapTriple parseTriple(DiscoSolrDocument doc) throws IOException {
    Collection<Statement> statements = new HashSet<>();
    RDFParser parser = Rio.createParser(RDFFormat.NQUADS);
    parser.setRDFHandler(new StatementCollector(statements));
    parser.parse(new ByteArrayInputStream(doc.getDiscoRelatedStatements().get(0).getBytes()), "");
    assertEquals(1, statements.size());

    return rdf4jStatement2RMapTriple(statements.iterator().next());
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:17,代码来源:SimpleDiscoMapperTest.java

示例8: convertRDFToStmtList

import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
 * Deserialize RDF InputStream into a list of Statements.
 *
 * @param rdfIn InputStream of RDF
 * @param rdfType Format of RDF in InputStream
 * @param baseUri  String with base URI of any relative URI in InputStream.
 * @return List of Statements created from RDF InputStsream
 * @throws RMapException if null parameters, or invalid rdfType, or error parsing stream
 */
public Set <Statement> convertRDFToStmtList(InputStream rdfIn, RDFType rdfType, String baseUri) 
		throws RMapException	{
	if (rdfIn==null){
		throw new RMapException("Null rdf input stream");
	}
	if (rdfType==null){
		throw new RMapException("Null rdf type");
	}
	Set <Statement> stmts = new HashSet<Statement>();
	RDFFormat rdfFormat = null;
	try {
		rdfFormat = this.getRDFFormatConstant(rdfType);
	} catch (Exception e1) {
		throw new RMapException("Unable to match rdfType: " + rdfType, e1);
	}
	RDFParser rdfParser = Rio.createParser(rdfFormat);	
	StatementCollector collector = new StatementCollector(stmts);		
	rdfParser.setRDFHandler(collector);
	try {
		rdfParser.parse(rdfIn, baseUri);
	} catch (RDFParseException | RDFHandlerException | IOException e) {
		throw new RMapException("Unable to parse input RDF: " + e.getMessage(), e);
	}		
	
	//Need to do last check to make sure IRIs are compatible with java.net.URI format. 
	//IRI is less restrictive and will allow e.g. /n in URIs.
	for (Statement stmt:stmts){
		if (!ORAdapter.isRdf4jStmtUriCompatible(stmt)){
			throw new RMapException("A statement in the RDF contains an invalid URI: " + stmt.toString());
		}
	}
	
	return stmts;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:44,代码来源:RioRDFHandler.java

示例9: testStatsTarget

import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Test
public void testStatsTarget() throws Exception {
    HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "statsTable", true, -1, true, 0, null, null);
    sail.initialize();
    ValueFactory vf = SimpleValueFactory.getInstance();
    for (int i = 0; i < 1000; i++) {
        sail.addStatement((i % 13 == 0) ? vf.createBNode("id_"+i % 150) : vf.createIRI("http://whatever/subj" + (i % 150)), vf.createIRI("http://whatever/pred" + (i % 11)),  (i % 9 == 0) ? vf.createBNode("id_"+i % 100) : vf.createLiteral("whatever value " + i), i < 200 ? null : vf.createIRI("http://whatever/graph" + (i % 2)));
        sail.addStatement((i % 13 == 0) ? vf.createBNode("id_"+i % 150) : vf.createIRI("http://whatever/subj" + (i % 150)), RDF.TYPE,  vf.createIRI("http://whatever/type" + i), i < 200 ? null : vf.createIRI("http://whatever/graph" + (i % 2)));
    }
    Resource bNode = vf.createBNode("bnodeid");
    Value val = vf.createLiteral(42);
    IRI iri = vf.createIRI("http://frequent/iri");
    IRI graph0 = vf.createIRI("http://whatever/graph0");
    IRI graph1 = vf.createIRI("http://whatever/graph1");
    for (int i=0; i < 100; i++) {
        IRI iri2 = vf.createIRI("http://frequent/iri"+i);
        sail.addStatement(bNode, iri2, val);
        sail.addStatement(bNode, iri2, iri, graph0);
        sail.addStatement(iri, iri2, bNode, graph1);
    }
    sail.commit();
    sail.close();

    File root = File.createTempFile("test_stats", "");
    root.delete();
    root.mkdirs();

    assertEquals(0, ToolRunner.run(HBaseServerTestInstance.getInstanceConfig(), new HalyardStats(),
            new String[]{ "-D" + HalyardStats.SUBSET_THRESHOLD + "=100", "-s", "statsTable", "-t", root.toURI().toURL().toString() + "stats{0}.trig"}));

    File f = new File(root, "stats0.trig");
    assertTrue(f.isFile());
    System.out.println(f.getAbsolutePath());
    String content =new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8);
    try (FileInputStream in = new FileInputStream(f)) {
        final Model m = Rio.parse(in, "", RDFFormat.TRIG, new ParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true), SimpleValueFactory.getInstance(), new ParseErrorLogger());
        try (InputStream ref = HalyardStatsTest.class.getResourceAsStream("testStatsTarget.ttl")) {
            RDFParser p = Rio.createParser(RDFFormat.TRIG);
            p.setPreserveBNodeIDs(true);
            p.setRDFHandler(new AbstractRDFHandler() {
                @Override
                public void handleStatement(Statement st) throws RDFHandlerException {
                    if (!m.contains(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())) {
                        fail(MessageFormat.format("Expected {0} in:\n{1}\n", st, content));
                    }
                }
            }).parse(ref, "");
        }
    }
}
 
开发者ID:Merck,项目名称:Halyard,代码行数:51,代码来源:HalyardStatsTest.java


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