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


Java RDFFormat类代码示例

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


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

示例1: writeJsonLd

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
private void writeJsonLd(final OutputStream output, final DatasetGraph graph, final IRI... profiles) {
    final String profile = getCustomJsonLdProfile(profiles);
    final RDFFormat format = nonNull(profile) && nonNull(cache) ? JSONLD_COMPACT_FLAT : getJsonLdProfile(profiles);
    final WriterDatasetRIOT writer = RDFDataMgr.createDatasetWriter(format);
    final PrefixMap pm = RiotLib.prefixMap(graph);
    final String base = null;
    final JsonLDWriteContext ctx = new JsonLDWriteContext();
    if (nonNull(profile) && nonNull(cache)) {
        LOGGER.debug("Setting JSON-LD context with profile: {}", profile);
        final String c = cache.get(profile, p -> {
            try (final TypedInputStream res = HttpOp.execHttpGet(profile)) {
                return IOUtils.toString(res.getInputStream(), UTF_8);
            } catch (final IOException | HttpException ex) {
                LOGGER.warn("Error fetching profile {}: {}", p, ex.getMessage());
                return null;
            }
        });
        if (nonNull(c)) {
            ctx.setJsonLDContext(c);
            ctx.setJsonLDContextSubstitution("\"" + profile + "\"");
        }
    }
    writer.write(output, graph, pm, base, ctx);
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:25,代码来源:JenaIOService.java

示例2: main

import org.apache.jena.riot.RDFFormat; //导入依赖的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.RDFFormat; //导入依赖的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.RDFFormat; //导入依赖的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: exportJenaModelToRdfFile

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
public static void exportJenaModelToRdfFile(Model model, String filePath, RDFFormat format, boolean gzip) throws IOException {
	String fileExtension = RdfVocabulary.getRdfFileExtension(format);
	if (gzip) {
		fileExtension += ".gz";
	}
			
	String filePathWithExtension = FileManager.createFileNameWithExtension(filePath, fileExtension);
	

	logger.info(String.format("Exporting graph to file '%s' with format '%s'", filePathWithExtension, format));
	File file = FileManager.createFile(filePathWithExtension);
	OutputStream out = new FileOutputStream(file);
	if (gzip) {
		out = new GZIPOutputStream(out);
	}
	try {
		RDFDataMgr.write(out, model, format);
	}
	finally {
		out.close();
	}
	logger.info(String.format("Exporting graph to file is completed, file size: %s", FileManager.getReadableFileSize(file.length())));
}
 
开发者ID:Web-of-Building-Data,项目名称:Ifc2Rdf,代码行数:24,代码来源:RdfUtils.java

示例6: exportSchema

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
/**
 * Exports schema
 * @param outputSchemaJenaModelFactory
 * @param schema
 * @param outputSchemaFilePath
 * @param outputFileFormat
 * @param gzipOutputFile 
 * @throws Exception
 */
private static Model exportSchema(
		JenaModelFactoryBase outputSchemaJenaModelFactory,
		IfcSchema schema,
		String outputSchemaFilePath,
		RDFFormat outputFileFormat,
		boolean gzipOutputFile)
		throws Exception {
	// export model to RDF graph
	logger.info("Exporting schema to RDF graph");
	Model schemaGraph = outputSchemaJenaModelFactory.createModel();
	if (schemaGraph.supportsTransactions()) {
		schemaGraph.begin();				
	}
	Ifc2RdfExportUtil.exportSchemaToJenaModel(schemaGraph, schema, null);
	if (schemaGraph.supportsTransactions()) {
		schemaGraph.commit();
	}
	logger.info("Exporting schema RDF graph is completed");
	
	// export model to RDF file
	if (!StringUtils.isEmptyOrNull(outputSchemaFilePath)) {
		RdfUtils.exportJenaModelToRdfFile(schemaGraph, outputSchemaFilePath, outputFileFormat, gzipOutputFile);
	}
	return schemaGraph;
}
 
开发者ID:Web-of-Building-Data,项目名称:Ifc2Rdf,代码行数:35,代码来源:Ifc2RdfExporter.java

示例7: testWriteableView

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
@Test
public void testWriteableView() {
    MarkLogicDatasetGraph dsg = getMarkLogicDatasetGraph("testdata/smallfile.nt");
    Graph defaultGraph = dsg.getDefaultGraph();
    RDFDataMgr.write(System.out, defaultGraph, RDFFormat.TURTLE);

    Triple newTriple = Triple.create(NodeFactory.createURI("http://a"),
            NodeFactory.createURI("http://b"),
            NodeFactory.createLiteral("1", XSDint));

    defaultGraph.add(newTriple);

    QueryExecution qe = QueryExecutionFactory.create(
            "prefix xsd: <http://www.w3.org/2001/XMLSchema#>  ask where { <http://a> ?p  \"1\"^^xsd:int .}", dsg.toDataset());
    assertTrue(qe.execAsk());
    defaultGraph.remove(newTriple.getSubject(), newTriple.getPredicate(), newTriple.getObject());
    qe = QueryExecutionFactory.create(
            "prefix xsd: <http://www.w3.org/2001/XMLSchema#>  ask where { <http://a> ?p  \"1\"^^xsd:int .}", dsg.toDataset());
    assertFalse(qe.execAsk());
}
 
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:21,代码来源:MarkLogicDatasetGraphTest.java

示例8: serializeJenaSingleCompositeEvents

import org.apache.jena.riot.RDFFormat; //导入依赖的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

示例9: testSomeMethod2

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
@Test
public void testSomeMethod2() throws Exception {
  Dataset ds = TDBFactory.createDataset("/scratch/WORK2/jena/dataset2/");
  
  OntModel model1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym1"));
  OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym2"));
  OntClass thing = model1.createClass("http://www.w3.org/2002/07/owl#Thing");
  model1.createIndividual("http://example.com/onto1#VijayRaj", thing);
  model2.createIndividual("http://example.;cegilovcom/onto2#VijayRaj", thing);
  Model m = model1.union(model2);
  
  FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/mergetestds.xml");
  RDFDataMgr.write(fw, ds, RDFFormat.NQUADS_UTF8);
  

}
 
开发者ID:vijayrajak,项目名称:JenaKBClient,代码行数:17,代码来源:KBIndividualImplTest.java

示例10: testRule

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
@Test
public void testRule() throws Exception {
  Node var = NodeFactory.createAnon();
  
  System.out.println("Node: " + var);
  
  KBCollection varCol = new KBCollectionImpl("http://www.w3.org/2007/rif#var");
  RDFNode varRdf = KBObjectImpl.getBaseContextModel().asRDFNode(var);
  System.out.println("RDF Node: " + varRdf);

  Resource varRes = varRdf.asResource();
  System.out.println("Resource: " + varRes.getLocalName() + ", " + varRes.getNameSpace() + ", " + varRes.getURI());
  // Individual varInd = ((KBCollectionImpl)varCol).getCore().createIndividual();//.createIndividual(varRes.getURI());
  // KBObjectImpl.getBaseContextModel().createIndividual(((KBCollectionImpl)varCol).getCore());
  
  Variable v = new VariableImpl("vijayvar");
  System.out.println("Var Name: " + v.getName());
  FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/test4.xml");
  RDFDataMgr.write(fw, KBObjectImpl.getDataset(), RDFFormat.NQUADS);
  
}
 
开发者ID:vijayrajak,项目名称:JenaKBClient,代码行数:22,代码来源:KBIndividualImplTest.java

示例11: testStatements

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
@Test
public void testStatements() throws Exception {
  String bio_ns = "http://example.com/biology#";
  KBCollection human = new KBCollectionImpl(bio_ns + "human");
  Variable v = new VariableImpl ("person");
  
  KBObjectImpl.getBaseContextModel().createList(new RDFNode[] {((Resource)human.getCore()), ((Resource)v.getCore())});
  FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/test5.xml");
  
  
  KBPredicate father = new KBPredicateImpl(Constants.CYC_TBOX_NS.concat("father"));
  
  Statement s;
  s = KBObjectImpl.getBaseContextModel().createStatement(((KBCollectionImpl)Constants.owlThing()).getCore(), (OntProperty)((KBPredicateImpl)father).getCore(), ((VariableImpl)v).getCore());
  KBObjectImpl.getBaseContextModel().add(s);
  
  KBObjectImpl.getBaseContextModel().createReifiedStatement(s);
  
  RDFDataMgr.write(fw, KBObjectImpl.getDataset(), RDFFormat.NQUADS);
}
 
开发者ID:vijayrajak,项目名称:JenaKBClient,代码行数:21,代码来源:KBIndividualImplTest.java

示例12: getRdfFormatFromFilePath

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
public static RDFFormat getRdfFormatFromFilePath(String filePath) {
	filePath = filePath.toLowerCase();
	if (filePath.endsWith(".gzip")) {
		filePath = filePath.substring(0, filePath.length() - 5);
	} else if (filePath.endsWith(".gz")) {
		filePath = filePath.substring(0, filePath.length() - 3);			
	}
	
	if (filePath.endsWith("ttl")) {
		return RDFFormat.TURTLE;
	} else if (filePath.endsWith("nt")) {
		return RDFFormat.NTRIPLES;
	} else if (filePath.endsWith("nq")) {
		return RDFFormat.NQUADS;
	} else if (filePath.endsWith("jsonld")) {
		return RDFFormat.JSONLD;
	} else if (filePath.endsWith("trig")) {
		return RDFFormat.TRIG;
	} else {
		return RDFFormat.RDFXML;
	}
}
 
开发者ID:Web-of-Building-Data,项目名称:drumbeat-ifc2ld,代码行数:23,代码来源:RdfIOUtils.java

示例13: exportJenaModelToRdfFile

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
@Deprecated
	public static String exportJenaModelToRdfFile(Model model, String baseUri, String filePath, RDFFormat format, boolean gzip) throws IOException {
		
		String filePathWithExtension = formatRdfFileName(filePath, format, gzip);		

		logger.info(String.format("Exporting graph to file '%s' with format '%s'", filePathWithExtension, format));
		File file = FileManager.createFile(filePathWithExtension);
		OutputStream out = new FileOutputStream(file);
		if (gzip) {
			out = new GZIPOutputStream(out);
		}
		try {
			String lang = format.getLang().getName();
//			RDFDataMgr.write(out, model, format);
			model.write(out, lang, baseUri);
		}
		finally {
			out.close();
		}
		logger.info(String.format("Exporting graph to file is completed, file size: %s", FileManager.getReadableFileSize(file.length())));
		
		return filePathWithExtension;
	}
 
开发者ID:Web-of-Building-Data,项目名称:drumbeat-ifc2ld,代码行数:24,代码来源:RdfUtils.java

示例14: getRdfFormatMap

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
@Deprecated
public static Map<String, RDFFormat> getRdfFormatMap() {
	
	if (rdfFormats == null) {
		rdfFormats = new TreeMap<>();
		Field[] declaredFields = RDFFormat.class.getDeclaredFields();
		for (Field field : declaredFields) {
		    if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(RDFFormat.class)) {			    	
		    	try {
					rdfFormats.put(field.getName(), (RDFFormat)field.get(null));
				} catch (Exception e) {
					throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
				}
		    }
		}			
	}
	
	return rdfFormats;
	
}
 
开发者ID:Web-of-Building-Data,项目名称:drumbeat-ifc2ld,代码行数:21,代码来源:RdfUtils.java

示例15: exportSchema

import org.apache.jena.riot.RDFFormat; //导入依赖的package包/类
public static File exportSchema(String name, RDFFormat rdfFormat, boolean gzip) throws Exception {
	
	IfcSchema schema = IfcSchemaPool.getSchema(name);		
	AbstractJenaProvider outputSchemaJenaProvider = new MemoryJenaProvider();
	
	String outputSchemaFilePath = IFC_SCHEMA_OUTPUT_DIR_PATH + name;
	
	Ifc2RdfConversionContext conversionContext = Ifc2RdfConversionContextLoader.loadFromConfigurationDocument(
			ConfigurationDocument.getDefault(),
			DEFAULT_CONVERSION_CONTEXT_NAME);		
	
	Ifc2RdfExporter.exportSchema(
			outputSchemaJenaProvider,
			schema,
			conversionContext,
			outputSchemaFilePath,
			rdfFormat,
			gzip);
	
	outputSchemaFilePath = RdfUtils.formatRdfFileName(outputSchemaFilePath, rdfFormat, gzip);
	
	return new File(outputSchemaFilePath);
}
 
开发者ID:Web-of-Building-Data,项目名称:drumbeat-ifc2ld,代码行数:24,代码来源:IfcApplication.java


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