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


Java RDFDataMgr类代码示例

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


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

示例1: writeJsonLd

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

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
public static PipedRDFIterator<Triple> parse(String dump){
    PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
    final String d=dump;
    System.out.println(d);
    final PipedRDFStream<Triple> inputStream = new PipedTriplesStream(iter);
    // PipedRDFStream and PipedRDFIterator need to be on different threads
    ExecutorService executor = Executors.newSingleThreadExecutor();
    // Create a runnable for our parser thread
    Runnable parser = new Runnable() {
        @Override
        public void run() {
            // Call the parsing process.
            RDFDataMgr.parse(inputStream, d);
        }
    };

    // Start the parser on another thread
    executor.submit(parser);
    return iter;
}
 
开发者ID:WDAqua,项目名称:PageRankRDF,代码行数:21,代码来源:Parser.java

示例3: createModel

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
private Model createModel(Logger logger) throws IOException {
		LoggingUtils.configureSilentLog4J();
		Model model = ModelFactory.createDefaultModel();
		model.setNsPrefixes(PrefixMapping.Standard);
		model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
		model.setNsPrefix("skos", "http://www.w3.org/2004/02/skos/core#");
		model.setNsPrefix("oboInOwl", "http://www.geneontology.org/formats/oboInOwl#");
		model.setNsPrefixes(prefixes);
		for (InputStream is : Iterators.loop(source.getInputStreams())) {
			logger.info("loading model from: " + source.getStreamName(is));
//			System.err.println("is = " + is);
//			model.read(is, null, Lang.RDFXML.toString());
			RDFDataMgr.read(model, is, Lang.RDFXML);
		}
		return model;
	}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:17,代码来源:RDFProjector.java

示例4: DBpediaGenderDictionary

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
public DBpediaGenderDictionary() {
	Model model = ModelFactory.createDefaultModel();

	Literal maleLit = model.createLiteral(VALUE_MALE, "en");
	Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");

	RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
	StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
	while(iter.hasNext()) {
		Statement st = iter.next();
		Literal lit = st.getObject().asLiteral();
		if(lit.equals(maleLit)) {
			male.add(st.getSubject().getURI());
		} else if(lit.equals(femaleLit)){
			female.add(st.getSubject().getURI());
		}
	}
}
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:19,代码来源:DBpediaGenderDictionary.java

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

示例6: analyze

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
@Override
public Iterator<byte[]> analyze(CrawleableUri curi, File data, Sink sink) {
    FileInputStream fin = null;
    try {
        // First, try to get the language of the data
        Lang lang = null;
        String contentType = (String) curi.getData(HttpHeaders.CONTENT_TYPE);
        if (contentType != null) {
            lang = RDFLanguages.contentTypeToLang(contentType);
        } else {
            lang = RDFLanguages.filenameToLang(data.getName(), null);
        }
        FilterSinkRDF filtered = new FilterSinkRDF(curi, sink);
        RDFDataMgr.parse(filtered, data.getAbsolutePath(), lang);
    } catch (Exception e) {
        LOGGER.error("Exception while analyzing. Aborting.");
    } finally {
        IOUtils.closeQuietly(fin);
    }
    return collector.getUris(curi);
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:22,代码来源:RDFAnalyzer.java

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

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

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

示例10: buildAll

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
/**
 * Build all properties for each class contained in a specification file.<br>
 * <br>
 * Specification file contains tab-separated rows as:<br>
 * [ClassName][TAB][JSON example URL]
 * 
 * @param specFile
 * @param outFile
 * @throws IOException 
 * @throws JSONException 
 */
public void buildAll(String specFile, String inFile, String outFile) throws JSONException, IOException {
	logger.info("Started.");
	String base = System.getProperty("user.dir") + "/";
	FileOutputStream file = new FileOutputStream(new File(base + outFile));
	logger.info("user.dir = "+base);
	logger.info("Opening RDF file: "+base + inFile);
	Model m = RDFDataMgr.loadModel(base + inFile, Lang.RDFXML);
	Scanner in = new Scanner(new File(specFile));
	while (in.hasNextLine()) {
		String[] line = in.nextLine().split("\t");
		build(line[0], line[1], m);
	}
	in.close();
	logger.info("Writing to file "+outFile+ "...");
	
	m.write(file);
	
	file.close();
	logger.info("Done.");
}
 
开发者ID:ML-Schema,项目名称:openml-rdf,代码行数:32,代码来源:VocabularyBuilder.java

示例11: DBpediaGenderDictionary

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
public DBpediaGenderDictionary() {
	Model model = ModelFactory.createDefaultModel();

	Literal maleLit = model.createLiteral(VALUE_MALE, "en");
	Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");

	RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
	StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
	while (iter.hasNext()) {
		Statement st = iter.next();
		Literal lit = st.getObject().asLiteral();
		if (lit.equals(maleLit)) {
			male.add(st.getSubject().getURI());
		} else if (lit.equals(femaleLit)) {
			female.add(st.getSubject().getURI());
		}
	}
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:19,代码来源:DBpediaGenderDictionary.java

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

示例13: main

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
public static void main(String ...args) {
    // -- Base dataset 
    DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem();

    // -- Destination for changes.
    // Text form of output.  
    OutputStream out = System.out;
    // Create an RDFChanges that writes to "out".
    RDFChanges changeLog = RDFPatchOps.textWriter(out);

    // Combined datasetgraph and changes. 
    DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog);

    // Wrap in the Dataset API
    Dataset ds = DatasetFactory.wrap(dsg);

    // --------
    // Do something. Read in data.ttl inside a transaction.
    // (data.ttl is in src/main/resources/)
    Txn.executeWrite(ds,
        ()->RDFDataMgr.read(dsg, "data.ttl")
        );
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:24,代码来源:DeltaEx1_DatasetWithPatchLog.java

示例14: TestBase

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
public TestBase(Logger log, File exampleDir, String name) {
    this.log = log;
    this.exampleDir = exampleDir;

    log.info("constructing with " + exampleDir);

    SPARQLGenerate.init();
            
    // read location-mapping
    Model conf = ModelFactory.createDefaultModel();
    conf.add(RDFDataMgr.loadModel(new File(exampleDir, "queryset/configuration.ttl").toString(), Lang.TTL));
    conf.add(RDFDataMgr.loadModel(new File(exampleDir, "documentset/configuration.ttl").toString(), Lang.TTL));

    // initialize stream manager
    SPARQLGenerateStreamManager sm = SPARQLGenerateStreamManager.makeStreamManager(new LocatorFileAccept(exampleDir.toURI().getPath()));
    sm.setLocationMapper(conf);
    SPARQLGenerate.setStreamManager(sm);
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:19,代码来源:TestBase.java

示例15: readRDF

import org.apache.jena.riot.RDFDataMgr; //导入依赖的package包/类
private static Model readRDF(String s) {
        Model model = ModelFactory.createDefaultModel();

        if (isPath(s)) {
//            System.out.println("Parsing file " + s);
            model.read(s);
        } else {
            try {
//                System.out.println("Parsing RDF string " + s);
                RDFDataMgr.read(model, new ByteArrayInputStream(s.getBytes("UTF-8")), Lang.TTL);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return model;
    }
 
开发者ID:xgfd,项目名称:ASPG,代码行数:17,代码来源:viz.java


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