本文整理汇总了Java中org.openrdf.rio.turtle.TurtleWriter类的典型用法代码示例。如果您正苦于以下问题:Java TurtleWriter类的具体用法?Java TurtleWriter怎么用?Java TurtleWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TurtleWriter类属于org.openrdf.rio.turtle包,在下文中一共展示了TurtleWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ttlToStdout
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
public static void ttlToStdout( Model model ) {
TurtleWriter tw = new TurtleWriter( System.out );
try {
tw.startRDF();
for ( Map.Entry<String, String> en : DEFAULTNAMESPACES.entrySet() ) {
tw.handleNamespace( en.getKey(), en.getValue() );
}
for ( Statement s : model ) {
tw.handleStatement( s );
}
tw.endRDF();
}
catch ( Exception e ) {
log.error( e, e );
}
}
示例2: loadSmallRdfObject
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@Test
public void loadSmallRdfObject() throws Exception {
rdfInput = env.createRdfInput("rdfInput", false);
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-small.ttl");
connection = rdfInput.getConnection();
URI graph = rdfInput.addNewDataGraph("test");
connection.add(inputStream, "", RDFFormat.TURTLE, graph);
ByteArrayOutputStream inputBos = new ByteArrayOutputStream();
connection.export(new TurtleWriter(inputBos), graph);
Assert.assertTrue(connection.size(graph) > 0);
config.setSparqlEndpoint("/sparql-auth");
config.setSetGraph(true);
config.setGraphUri("http://smallrdftest.org");
config.setInputType("RDF");
loader.configure((new ConfigurationBuilder()).setDpuConfiguration(config).toString());
env.run(loader);
}
示例3: loadLargeRdfObject
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@Test
public void loadLargeRdfObject() throws Exception {
rdfInput = env.createRdfInput("rdfInput", false);
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-large.nt");
connection = rdfInput.getConnection();
URI graph = rdfInput.addNewDataGraph("test");
connection.add(inputStream, "", RDFFormat.NTRIPLES, graph);
ByteArrayOutputStream inputBos = new ByteArrayOutputStream();
connection.export(new TurtleWriter(inputBos), graph);
Assert.assertTrue(connection.size(graph) > 0);
config.setSparqlEndpoint("/sparql-auth");
config.setSetGraph(true);
config.setGraphUri("http://largerdftest.org");
config.setInputType("RDF");
loader.configure((new ConfigurationBuilder()).setDpuConfiguration(config).toString());
env.run(loader);
}
示例4: formatChangeSet
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
private String formatChangeSet(Graph changeSet) {
StringWriter sw = new StringWriter();
TurtleWriter turtleWriter = new TurtleWriter(sw);
try {
turtleWriter.startRDF();
Iterator<Statement> statementIterator = changeSet.iterator();
while (statementIterator.hasNext()) {
turtleWriter.handleStatement(statementIterator.next());
}
turtleWriter.endRDF();
}
catch (RDFHandlerException e) {
return "Could not format changeset";
}
return sw.toString();
}
示例5: generateOutputFileIfPossible
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
public File generateOutputFileIfPossible() throws BridgeDBException, IOException{
try {
File parent = TransativeConfig.getTransativeDirectory();
File outputFile = new File(parent, getid());
Reporter.println("Writing transative to " + outputFile.getAbsolutePath());
FileWriter writer = new FileWriter(outputFile);
RDFWriter rdfWriter = new TurtleWriter(writer);
rdfWriter.startRDF();
writeHeader(rdfWriter);
boolean result = getSQL(rdfWriter);
rdfWriter.endRDF();
writer.flush();
writer.close();
if (result){
return outputFile;
} else {
return null;
}
} catch (RDFHandlerException ex) {
throw new BridgeDBException("Error writing to RDF ", ex);
}
}
示例6: getAvaiableWriters
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
public static Set<String> getAvaiableWriters(){
N3Writer n = null;
NTriplesWriter nt = null;
RDFXMLPrettyWriter x2 = null;
RDFXMLWriter x = null;
TriGWriter tr = null;
TriXWriter tw = null;
TurtleWriter t = null;
HashSet<String> results = new HashSet<String>();
StringWriter writer = new StringWriter();
for (RDFFormat rdfFormat:RDFFormat.values()){
RDFWriter rdfWriter = getWriterIfPossible(rdfFormat, writer);
if (rdfWriter != null){
results.add(rdfFormat.getName());
}
}
return results;
}
示例7: setUpClass
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
engine = InMemorySesameEngine.open();
engine.setBuilders( datab, UriBuilder.getBuilder( "http://os-em.com/ontologies/semtool/" ) );
RepositoryConnection rc = engine.getRawConnection();
rc.begin();
rc.add( LOADFILE, null, RDFFormat.NTRIPLES );
for ( URI extra : new URI[]{ YIGO, YUGO2, YUGO3 } ) {
rc.add( new StatementImpl( extra, RDF.TYPE, CAR ) );
rc.add( new StatementImpl( extra, RDFS.LABEL,
new LiteralImpl( extra.getLocalName() ) ) );
}
//rc.add( new StatementImpl( REL2, RDF.TYPE, REL ) );
rc.add( new StatementImpl( REL2, RDFS.LABEL, new LiteralImpl( "Yuri Purchased a Yigo" ) ) );
rc.add( new StatementImpl( REL2, RDFS.SUBPROPERTYOF, PURCHASE ) );
rc.add( new StatementImpl( REL2, new URIImpl( "http://os-em.com/ontologies/semtool/Price" ),
new LiteralImpl( "8000 USD" ) ) );
rc.remove( REL1, null, null );
rc.add( new StatementImpl( REL1, RDFS.LABEL, new LiteralImpl( "Yuri Purchased Yugo" ) ) );
rc.add( new StatementImpl( REL1, RDFS.SUBPROPERTYOF, PURCHASE ) );
rc.add( new StatementImpl( REL1, new URIImpl( "http://os-em.com/ontologies/semtool/Price" ),
new LiteralImpl( "3000 USD" ) ) );
rc.commit();
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
"ecctest.ttl" ) ) ) ) {
engine.getRawConnection().export( new TurtleWriter( w ) );
}
}
}
示例8: trace
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
private void trace( File f ) throws Exception {
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
File tracefile = new File( tmpdir, f.getName() );
try ( Writer w = new BufferedWriter( new FileWriter( tracefile ) ) ) {
engine.getRawConnection().export( new TurtleWriter( w ) );
}
}
}
示例9: compare
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
private static void compare( InMemorySesameEngine engine, File expected,
boolean doCountsOnly ) throws IOException, RepositoryException, RDFHandlerException {
// get rid of the random database id
engine.getRawConnection().remove( (Resource) null, RDF.TYPE, SEMTOOL.Database );
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
expected.getName() ) ) ) ) {
engine.getRawConnection().export( new TurtleWriter( w ) );
}
}
Model model = getExpectedGraph( expected, RDFFormat.TURTLE );
List<Statement> stmts = Iterations.asList( engine.getRawConnection()
.getStatements( null, null, null, false ) );
assertEquals( model.size(), stmts.size() );
if ( doCountsOnly ) {
// do counts instead of checking exact URIs
}
else {
for ( Statement s : stmts ) {
assertTrue( model.contains( s ) );
}
}
}
示例10: testCreateStatements
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@Test
public void testCreateStatements() throws Exception {
InsightManagerImpl imi = new InsightManagerImpl();
EngineUtil2.createInsightStatements( SRCFILE, imi );
Collection<Statement> stmts
= InsightManagerImpl.getModel( imi, new LocalUserImpl() );
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
SRCFILE.getName() ) ) ) ) {
TurtleWriter tw = new TurtleWriter( w );
tw.startRDF();
tw.handleNamespace( SEMPERS.PREFIX, SEMPERS.NAMESPACE );
tw.handleNamespace( SEMONTO.PREFIX, SEMONTO.NAMESPACE );
tw.handleNamespace( SEMCORE.PREFIX, SEMCORE.NAMESPACE );
tw.handleNamespace( SPIN.PREFIX, SPIN.NAMESPACE );
tw.handleNamespace( SP.PREFIX, SP.NAMESPACE );
tw.handleNamespace( UI.PREFIX, UI.NAMESPACE );
tw.handleNamespace( RDFS.PREFIX, RDFS.NAMESPACE );
tw.handleNamespace( RDF.PREFIX, RDF.NAMESPACE );
tw.handleNamespace( OWL.PREFIX, OWL.NAMESPACE );
tw.handleNamespace( OLO.PREFIX, OLO.NAMESPACE );
tw.handleNamespace( DCTERMS.PREFIX, DCTERMS.NAMESPACE );
tw.handleNamespace( XMLSchema.PREFIX, XMLSchema.NAMESPACE );
for ( Statement s : stmts ) {
tw.handleStatement( s );
}
tw.endRDF();
}
}
assertEquals(48, stmts.size() );
}
示例11: compare
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
private static void compare( InMemorySesameEngine engine, File expected,
boolean doCountsOnly ) throws IOException, RepositoryException, RDFHandlerException {
// get rid of the random database id
engine.getRawConnection().remove( (Resource) null, RDF.TYPE, SEMTOOL.Database );
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
expected.getName() ) ) ) ) {
engine.getRawConnection().export( new TurtleWriter( w ) );
}
}
Model model = getExpectedGraph( expected );
List<Statement> stmts = Iterations.asList( engine.getRawConnection()
.getStatements( null, null, null, false ) );
assertEquals( model.size(), stmts.size() );
if ( doCountsOnly ) {
// do counts instead of checking exact URIs
}
else {
for ( Statement s : stmts ) {
assertTrue( "not in model: " + s.getSubject()
+ "->" + s.getPredicate() + "->" + s.getObject().stringValue(),
model.contains( s ) );
}
}
}
示例12: testExporter
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@Test
public void testExporter() throws IOException {
Map<String, Class<?>> handlers = new HashMap<>();
handlers.put( "filename.ttl", TurtleWriter.class );
handlers.put( "filename.rdf", RDFXMLWriter.class );
handlers.put( "filename.x", NTriplesWriter.class );
for ( Map.Entry<String, Class<?>> en : handlers.entrySet() ) {
RDFHandler handler;
try ( StringWriter sw = new StringWriter() ) {
handler = Utility.getExporterFor( en.getKey(), sw );
}
assertEquals( en.getValue(), handler.getClass() );
}
}
示例13: extractConcepts
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@Test
public void extractConcepts() throws Exception {
extractor.configure((new ConfigurationBuilder()).setDpuConfiguration(config).toString());
env.run(extractor);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
connection.export(new TurtleWriter(outputStream), RDFHelper.getGraphsURIArray(output));
Assert.assertTrue(outputStream.size() > 0);
System.out.println(outputStream.toString());
}
示例14: before
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@BeforeClass
public static void before() throws Exception {
extractor = new ConceptExtractor();
env = new TestEnvironment();
input = env.createRdfInput("rdfInput", false);
output = env.createRdfOutput("rdfOutput", false);
failedExtractionOutput = env.createRdfOutput("failedExtractionOutput", false);
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.ttl");
connection = input.getConnection();
URI graph = input.addNewDataGraph("test");
connection.add(inputStream, "", RDFFormat.TURTLE, graph);
ByteArrayOutputStream inputBos = new ByteArrayOutputStream();
connection.export(new TurtleWriter(inputBos), graph);
Assert.assertTrue(connection.size(graph) > 0);
properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("target.properties"));
config = new ConceptExtractorConfig_V1();
config.setHost(properties.getProperty("host"));
config.setPort(properties.getProperty("port"));
config.setExtractorApi(properties.getProperty("extractorApi"));
config.setProjectId(properties.getProperty("projectId"));
config.setUsername(properties.getProperty("username"));
config.setPassword(properties.getProperty("password"));
config.setLanguage(properties.getProperty("en"));
List<String> options = new ArrayList<>();
options.add("useTransitiveBroaderConcepts");
options.add("useTransitiveBroaderTopConcepts");
options.add("useRelatedConcepts");
options.add("filterNestedConcepts");
options.add("tfidfScoring");
options.add("useTypes");
config.setBooleanParams(options);
}
示例15: extractConcepts
import org.openrdf.rio.turtle.TurtleWriter; //导入依赖的package包/类
@Test
public void extractConcepts() throws Exception {
extractor.configure((new ConfigurationBuilder()).setDpuConfiguration(config).toString());
env.run(extractor);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
connection.export(new TurtleWriter(outputStream), RDFHelper.getGraphsURIArray(output));
connection.export(new TurtleWriter(outputStream), RDFHelper.getGraphsURIArray(failedExtractionOutput));
Assert.assertTrue(outputStream.size() > 0);
System.out.println(outputStream.toString());
}