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


Java RDFDataMgr.write方法代码示例

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


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

示例1: writeTo

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Override
public void writeTo(Model t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
		MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
		throws IOException, WebApplicationException {
	
	Lang lang = null;
	
	if(mediaType.equals(KRFormat.N3_TYPE))
		lang = Lang.N3;
	else if(mediaType.equals(KRFormat.N_TRIPLE_TYPE))
		lang = Lang.NTRIPLES;
	else if(mediaType.equals(KRFormat.RDF_JSON_TYPE))
		lang = Lang.RDFJSON;
	else if(mediaType.equals(new MediaType("application", "json-ld")))
		lang = Lang.JSONLD;
	else lang = Lang.TURTLE;
	
	RDFDataMgr.write(entityStream, t, lang);
	
}
 
开发者ID:teamdigitale,项目名称:ontonethub,代码行数:21,代码来源:ModelWriter.java

示例2: main

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {

		File f = new File("/Users/rosenc/Documents/business/[2015]icbms/json_sample1.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		String line = null;
		String s = "";
		while ((line = br.readLine()) != null) {
			s = s + line + "\n";
		}

		System.out.println(s);
		Gson gson = new Gson();
		OneM2MContentInstanceDTO cont = gson.fromJson(s, OneM2MContentInstanceDTO.class);
		OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);

		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());
		System.out.println("content type ; " + mapper.getContentType());
		// 스트링 변환부분
		RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
		// System.out.println(mapper.getTypedContent("2k42kk"));
		// mapper.getTypedContent("2.4");

	}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:25,代码来源:OneM2MContentInstanceMapper.java

示例3: main

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void main(String[] args) {
	String sample = " {     \"_id\" : ObjectId(\"561e1e1e1ee82041fac258b6\"),     \"rn\" : \"SAE_0\",     \"ty\" : 2,     \"ri\" : \"SAE_0\",     \"pi\" : \"herit-in\",     \"lbl\" : [          \"home1\",          \"home_service\"     ],     \"et\" : \"20151203T122321\",     \"at\" : [          \"//onem2m.hubiss.com/cse1\",          \"//onem2m.hubiss.com/cse2\"     ],     \"aa\" : [          \"poa\",          \"apn\"     ],     \"apn\" : \"onem2mPlatformAdmin\",     \"api\" : \"NHeritAdmin\",     \"aei\" : \"/SAE_0\",     \"poa\" : [          \"10.101.101.111:8080\"     ],     \"rr\" : false,     \"_uri\" : \"/herit-in/herit-cse/SAE_0\",     \"ct\" : \"20151014T181926\",     \"lt\" : \"20151014T181926\" }";
	Gson gson = new Gson();
	OneM2MAEDTO cont = gson.fromJson(sample, OneM2MAEDTO.class);


	System.out.println(cont);
	
	OneM2MAEMapper mapper = new OneM2MAEMapper(cont);
	Model model = ModelFactory.createDefaultModel();
	model.add(mapper.from());
	
	//스트링 변환부분
	RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
	
	// gooper
	if(! model.isClosed()) {
		model.close();
	}
	if(model != null) {
		model = null;
	}

}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:25,代码来源:OneM2MAEDTO.java

示例4: main

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void main(String[] args) {
	String sample = "{     \"_id\" : ObjectId(\"560c9d741ee8203c53a63569\"),     \"rn\" : \"CONTENT_INST_5\",     \"ty\" : 4,     \"ri\" : \"CONTENT_INST_5\",     \"pi\" : \"CONTAINER_37\",     \"lbl\" : [          \"cnt-switch\"     ],     \"cr\" : \"C_AE-D-GASLOCK1004\",     \"cnf\" : \"text/plain:0\",     \"cs\" : 3,     \"con\" : \"Off\",     \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1004/cnt-switch/CONTENT_INST_5\",     \"ct\" : \"20151001T114156\",     \"lt\" : \"20151001T114156\" , \"or\":\"http://www.iotoasis.org/ontology/StateCondition\" }";
	Gson gson = new Gson();
	OneM2MContentInstanceDTO cont = gson.fromJson(sample, OneM2MContentInstanceDTO.class);
	System.out.println(cont);

	OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
	Model model = ModelFactory.createDefaultModel();
	model.add(mapper.from());

	// 스트링 변환부분
	RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
	
	// gooper
	if(! model.isClosed()) {
		model.close();
	}
	if(model != null) {
		model = null;
	}

}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:23,代码来源:OneM2MCSEBaseDTO.java

示例5: replay

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
private Graph replay() {
    IO.close(bout);
    final boolean DEBUG = false;
    
    if ( DEBUG ) {
        System.out.println("== Graph ==");
        RDFDataMgr.write(System.out, baseGraph, Lang.NQ);
        System.out.println("== Replay ==");
        String x = StrUtils.fromUTF8bytes(bout.toByteArray());
        System.out.print(x);
        System.out.println("== ==");
    }
    
    // A completely separate graph (different dataset)
    Graph graph2 = txnGraph();
    
    try(ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray())) {
        RDFPatchOps.applyChange(graph2, bin);
        if ( DEBUG ) {
            System.out.println("== Graph outcome ==");
            RDFDataMgr.write(System.out, graph2, Lang.NT);
            System.out.println("== ==");
        }
        return graph2;
    } catch (IOException ex) { IO.exception(ex); return null; }
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:27,代码来源:TestRDFChangesGraph.java

示例6: run

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Override
public void run() {
	LOGGER.info("Starting extraction from \"" + endpointName + "\"...");
	SPARQLEndpointAnalyzer analyzer = new SPARQLEndpointAnalyzer(cacheDirectory);
	try {
		if (outputFile.exists()) {
			LOGGER.info("There already is a file for \"" + endpointName + "\". Jumping over this endpoint.");
		} else {
			Model voidModel = analyzer.extractVoidInfo(endpointCfg);
			if (voidModel != null) {
				voidModel.setNsPrefix("void", "http://rdfs.org/ns/void#");
				// NTripleWriter writer = new NTripleWriter();
				FileOutputStream fout = new FileOutputStream(outputFile);
				// writer.write(voidModel, fout, "");
				RDFDataMgr.write(fout, voidModel, RDFFormat.TURTLE_PRETTY);
				fout.close();
			} else {
				LOGGER.error("Error while requesting the void information of \"" + endpointName + "\".");
			}
		}
	} catch (Exception e) {
		LOGGER.error("Error while requesting and storing the void information of \"" + endpointName + "\".", e);
	} finally {
		LOGGER.info("Finished extraction from \"" + endpointName + "\"...");
	}
}
 
开发者ID:dice-group,项目名称:Tapioca,代码行数:27,代码来源:EndpointAnalyzingTask.java

示例7: serializeJenaSingleCompositeEvents

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
static public void serializeJenaSingleCompositeEvents (OutputStream stream,
                                                 HashMap<String, CompositeEvent> semEvents,
                                                 HashMap <String, SourceMeta> sourceMetaHashMap,
                                                       boolean ILIURI,
                                                       boolean VERBOSE_MENTIONS) {



    createModels();
    Set keySet = semEvents.keySet();
    Iterator<String> keys = keySet.iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        CompositeEvent semEvent = semEvents.get(key);
        if (semEvent!=null) {
            addJenaCompositeEvent(semEvent, sourceMetaHashMap, ILIURI, VERBOSE_MENTIONS);
        }
    }
    RDFDataMgr.write(stream, ds, RDFFormat.TRIG_PRETTY);
}
 
开发者ID:newsreader,项目名称:StreamEventCoreference,代码行数:21,代码来源:JenaSerialization.java

示例8: expand

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void expand() throws IOException {
    boolean combined = false ;
    String DIR = "testing/Inf" ;
    String DATA_FILE = "data.ttl" ;
    String VOCAB_FILE = "vocab.ttl" ;
    String RULES_FILE = DIR+"/rdfs-min.rules" ;

    Model vocab = RDFDataMgr.loadModel(VOCAB_FILE) ;
    Model data = RDFDataMgr.loadModel(DATA_FILE) ;
    
    String rules = FileUtils.readWholeFileAsUTF8(RULES_FILE) ;
    rules = rules.replaceAll("#[^\\n]*", "") ;

    InferenceSetupRDFS setup = new InferenceSetupRDFS(vocab, combined) ;
    
    Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
    InfModel m = ModelFactory.createInfModel(reasoner, vocab, data);
    
    // Expansion Graph
    Graph graphExpanded = Factory.createDefaultGraph() ;
    StreamRDF stream = StreamRDFLib.graph(graphExpanded) ;
    // Apply inferences.
    stream = new InferenceProcessorStreamRDF(stream, setup) ;
    sendToStream(data.getGraph(), stream) ;
    RDFDataMgr.write(System.out, graphExpanded, Lang.TTL) ;
}
 
开发者ID:afs,项目名称:jena-inf-engine,代码行数:27,代码来源:DevRDFS.java

示例9: generateResultString

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
 * Generate result string
 * @param mostSimilarDatasets datasets as collection
 * @return String
 */
protected String generateResultString(TopDoubleObjectCollection<String> mostSimilarDatasets) {
    Model rdfModel = ModelFactory.createDefaultModel();
    Property simProperty = rdfModel.createProperty(TAPIOCA_SIMILARITY_URI);
    Resource datasetResource;
    for (int i = 0; i < mostSimilarDatasets.values.length; ++i) {
        datasetResource = rdfModel.createResource((String) mostSimilarDatasets.objects[i]);
        rdfModel.addLiteral(datasetResource, simProperty, mostSimilarDatasets.values[i]);
        if (rdfMetaDataModel.containsResource(datasetResource)) {
            rdfModel.add(rdfMetaDataModel.listStatements(datasetResource, null, (RDFNode) null));
        } else {
            LOGGER.warn("Got a dataset that does not occur inside the meta data model (URI=\""
                    + datasetResource.getURI() + "\").");
        }
    }

    StringWriter stringWriter = new StringWriter();
    RDFDataMgr.write(stringWriter, rdfModel, RDFFormat.JSONLD);
    String result = stringWriter.toString();
    IOUtils.closeQuietly(stringWriter);
    return result;
}
 
开发者ID:dice-group,项目名称:Tapioca,代码行数:27,代码来源:AbstractEngine.java

示例10: write

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
private static void write(final RdfStream rdfStream,
                   final OutputStream output,
                   final Lang dataFormat,
                   final MediaType dataMediaType) throws IOException {

    final RDFFormat format = defaultSerialization(dataFormat);

    // For formats that can be block-streamed (n-triples, turtle)
    if (format != null) {
        LOGGER.debug("Stream-based serialization of {}", dataFormat.toString());
        final StreamRDF stream = getWriterStream(output, format);
        stream.start();
        rdfStream.forEach(stream::triple);
        stream.finish();

    // For formats that require analysis of the entire model and cannot be streamed directly (rdfxml, n3)
    } else {
        LOGGER.debug("Non-stream serialization of {}", dataFormat.toString());
        final Model model = rdfStream.collect(toModel());
        // use block output streaming for RDFXML
        if (RDFXML.equals(dataFormat)) {
            RDFDataMgr.write(output, model.getGraph(), RDFXML_PLAIN);
        } else if (JSONLD.equals(dataFormat)) {
            final RDFFormat jsonldFormat = getFormatFromMediaType(dataMediaType);
            RDFDataMgr.write(output, model.getGraph(), jsonldFormat);
        } else {
            RDFDataMgr.write(output, model.getGraph(), dataFormat);
        }
    }
}
 
开发者ID:duraspace,项目名称:lambdora,代码行数:31,代码来源:RdfStreamStreamingOutput.java

示例11: write

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Override
public void write(final Stream<? extends Triple> triples, final OutputStream output, final RDFSyntax syntax,
        final IRI... profiles) {
    requireNonNull(triples, "The triples stream may not be null!");
    requireNonNull(output, "The output stream may not be null!");
    requireNonNull(syntax, "The RDF syntax value may not be null!");

    try {
        if (RDFA.equals(syntax)) {
            htmlSerializer.write(output, triples, profiles.length > 0 ? profiles[0] : null);
        } else {
            final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
                    new RuntimeTrellisException("Invalid content type: " + syntax.mediaType()));

            final RDFFormat format = defaultSerialization(lang);

            if (nonNull(format)) {
                LOGGER.debug("Writing stream-based RDF: {}", format);
                final StreamRDF stream = getWriterStream(output, format);
                stream.start();
                ofNullable(nsService).ifPresent(svc -> svc.getNamespaces().forEach(stream::prefix));
                triples.map(rdf::asJenaTriple).forEachOrdered(stream::triple);
                stream.finish();
            } else {
                LOGGER.debug("Writing buffered RDF: {}", lang);
                final org.apache.jena.graph.Graph graph = createDefaultGraph();
                ofNullable(nsService).map(NamespaceService::getNamespaces)
                    .ifPresent(graph.getPrefixMapping()::setNsPrefixes);
                triples.map(rdf::asJenaTriple).forEachOrdered(graph::add);
                if (JSONLD.equals(lang)) {
                    writeJsonLd(output, DatasetGraphFactory.create(graph), profiles);
                } else {
                    RDFDataMgr.write(output, graph, lang);
                }
            }
        }
    } catch (final AtlasException ex) {
        throw new RuntimeTrellisException(ex);
    }
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:41,代码来源:JenaIOService.java

示例12: write

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Override
public void write(final Stream<? extends Triple> triples, final OutputStream output, final RDFSyntax syntax,
        final IRI... profiles) {
    requireNonNull(triples, "The triples stream may not be null!");
    requireNonNull(output, "The output stream may not be null!");
    requireNonNull(syntax, "The RDF syntax value may not be null!");

    try {
        if (RDFA_HTML.equals(syntax)) {
            htmlSerializer.write(output, triples, profiles.length > 0 ? profiles[0] : null);
        } else {
            final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
                    new RuntimeRepositoryException("Invalid content type: " + syntax.mediaType));

            final RDFFormat format = defaultSerialization(lang);

            if (nonNull(format)) {
                LOGGER.debug("Writing stream-based RDF: {}", format);
                final StreamRDF stream = getWriterStream(output, format);
                stream.start();
                ofNullable(nsService).ifPresent(svc -> svc.getNamespaces().forEach(stream::prefix));
                triples.map(rdf::asJenaTriple).forEachOrdered(stream::triple);
                stream.finish();
            } else {
                LOGGER.debug("Writing buffered RDF: {}", lang);
                final org.apache.jena.graph.Graph graph = createDefaultGraph();
                ofNullable(nsService).map(NamespaceService::getNamespaces)
                    .ifPresent(graph.getPrefixMapping()::setNsPrefixes);
                triples.map(rdf::asJenaTriple).forEachOrdered(graph::add);
                if (JSONLD.equals(lang)) {
                    writeJsonLd(output, DatasetGraphFactory.create(graph), profiles);
                } else {
                    RDFDataMgr.write(output, graph, lang);
                }
            }
        }
    } catch (final AtlasException ex) {
        throw new RuntimeRepositoryException(ex);
    }
}
 
开发者ID:trellis-ldp-archive,项目名称:trellis-io-jena,代码行数:41,代码来源:JenaIOService.java

示例13: main

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void main(String[] args) {
	String sample = " {     \"_id\" : ObjectId(\"561e1e1e1ee82041fac258b6\"),     \"rn\" : \"SAE_0\",     \"ty\" : 2,     \"ri\" : \"SAE_0\",     \"pi\" : \"herit-in\",     \"lbl\" : [          \"home1\",          \"home_service\"     ],     \"et\" : \"20151203T122321\",     \"at\" : [          \"//onem2m.hubiss.com/cse1\",          \"//onem2m.hubiss.com/cse2\"     ],     \"aa\" : [          \"poa\",          \"apn\"     ],     \"apn\" : \"onem2mPlatformAdmin\",     \"api\" : \"NHeritAdmin\",     \"aei\" : \"/SAE_0\",     \"poa\" : [          \"10.101.101.111:8080\"     ],     \"rr\" : false,     \"_uri\" : \"/herit-in/herit-cse/SAE_0\",     \"ct\" : \"20151014T181926\",     \"lt\" : \"20151014T181926\" }";
	Gson gson = new Gson();
	OneM2MAEDTO cont = gson.fromJson(sample, OneM2MAEDTO.class);


	System.out.println(cont);
	
	OneM2MAEMapper mapper = new OneM2MAEMapper(cont);
	Model model = ModelFactory.createDefaultModel();
	model.add(mapper.from());
	
	//스트링 변환부분
	RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:16,代码来源:OneM2MAEDTO.java

示例14: main

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void main(String[] args) {
		String sample = "{     \"_id\" : ObjectId(\"561f27831ee8202c5e307d37\"),     \"rn\" : \"CONTAINER_268\",     \"ty\" : 3,     \"ri\" : \"CONTAINER_268\",     \"pi\" : \"SAE_0\",     \"lbl\" : [          \"switch\",          \"key1\",          \"key2\"     ],     \"et\" : \"20151203T122321\",     \"cr\" : \"//onem2m.herit.net/herit-cse/SAE_5\",     \"mni\" : 100,     \"mbs\" : 1.024e+006,     \"mia\" : 36000,     \"cni\" : 1,     \"cbs\" : 2,     \"_uri\" : \"/herit-in/herit-cse/SAE_0/CONTAINER_268\",     \"ct\" : \"20151015T131147\",     \"lt\" : \"20151015T131147\", \"or\":\"http://www.pineone.com/m2m/SwitchStatusSensor\" }";
		Gson gson = new Gson();
		OneM2MContainerDTO cont = gson.fromJson(sample, OneM2MContainerDTO.class);


		System.out.println(cont);
		
		OneM2MContainerMapper mapper = new OneM2MContainerMapper(cont);
		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());
		
		//스트링 변환부분
		RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);

		//스트링 변환부분
//		String serviceURI = "http://219.248.137.7:13030/icbms";
//
//		DatasetAccessor	accessor = DatasetAccessorFactory.createHTTP(serviceURI);
//		accessor.deleteDefault();
//		accessor.add(model);
//		
//		
//		QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI	,"select * {?s ?p ?o}"	);
//		ResultSet rs = q.execSelect();
//		ResultSetFormatter.out(rs);;
		
//		model = DatasetAccessorFactory.createHTTP(serviceURI).getModel();
//		System.out.println(model.size());

	}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:32,代码来源:OneM2MContainerDTO.java

示例15: main

import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void main(String[] args) {
//		String sample = "{     \"_id\" : ObjectId(\"560c9d741ee8203c53a63569\"),     \"rn\" : \"CONTENT_INST_5\",     \"ty\" : 4,     \"ri\" : \"CONTENT_INST_5\",     \"pi\" : \"CONTAINER_37\",     \"lbl\" : [          \"cnt-switch\"     ],     \"cr\" : \"C_AE-D-GASLOCK1004\",     \"cnf\" : \"text/plain:0\",     \"cs\" : 3,     \"con\" : \"Off\",     \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1004/cnt-switch/CONTENT_INST_5\",     \"ct\" : \"20151001T114156\",     \"lt\" : \"20151001T114156\" , \"or\":\"http://www.pineone.com/campus/StateCondition\" }";
		String sample = 
				"{ "+
				"	    \"_id\" : ObjectId(\"560c9b1e1ee8203c53a63554\"),"+
				"	    \"rn\" : \"CONTENT_INST_0\","+
				"	    \"ty\" : 4,"+
				"	    \"ri\" : \"CONTENT_INST_0\","+
				"	    \"pi\" : \"CONTAINER_15\","+
				"	    \"lbl\" : [ "+
				"	        \"cnt-temperature\""+
				"	    ],"+
				"	    \"cr\" : \"C_AE-D-GASLOCK1001\","+
				"	    \"cnf\" : \"text/plain:0\","+
				"	    \"cs\" : 2,"+
				"	    \"con\" : \"13\","+
				"	    \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1001/cnt-temperature/CONTENT_INST_0\","+
				"	    \"ct\" : \"20151001T113158\","+
				"	    \"lt\" : \"20151001T113158\" "+
				"	} " ;
		Gson gson = new Gson();
		OneM2MContentInstanceDTO cont = gson.fromJson(sample, OneM2MContentInstanceDTO.class);
		System.out.println(cont);


		OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
		mapper = new OneM2MContentInstanceMapper(cont);
		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());

		// 스트링 변환부분
		RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
	}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:34,代码来源:OneM2MContentInstanceDTO.java


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