當前位置: 首頁>>代碼示例>>Java>>正文


Java Lang類代碼示例

本文整理匯總了Java中org.apache.jena.riot.Lang的典型用法代碼示例。如果您正苦於以下問題:Java Lang類的具體用法?Java Lang怎麽用?Java Lang使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Lang類屬於org.apache.jena.riot包,在下文中一共展示了Lang類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createModel

import org.apache.jena.riot.Lang; //導入依賴的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

示例2: DBpediaGenderDictionary

import org.apache.jena.riot.Lang; //導入依賴的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

示例3: writeTo

import org.apache.jena.riot.Lang; //導入依賴的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

示例4: analyze

import org.apache.jena.riot.Lang; //導入依賴的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

示例5: nextStreamingKeyValue

import org.apache.jena.riot.Lang; //導入依賴的package包/類
public boolean nextStreamingKeyValue() throws IOException, InterruptedException {
    if(rdfIter == null) return false;
    if (!rdfIter.hasNext() && collectionHash.size() == 0) {
        if(compressed) {
            hasNext = false;
            return false;
        } else {
            if (iterator!=null && iterator.hasNext()) {
                close();
                initStream(iterator.next());
            } else {
                hasNext = false;
                return false;
            }
        }
    }

    if (lang == Lang.NQUADS || lang == Lang.TRIG) {
        return nextStramingQuadKeyValue();
    } else {
        return nextStreamingTripleKeyValue();
    }
}
 
開發者ID:marklogic,項目名稱:marklogic-contentpump,代碼行數:24,代碼來源:RDFReader.java

示例6: buildAll

import org.apache.jena.riot.Lang; //導入依賴的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

示例7: DBpediaGenderDictionary

import org.apache.jena.riot.Lang; //導入依賴的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

示例8: replay

import org.apache.jena.riot.Lang; //導入依賴的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

示例9: buildServletContext

import org.apache.jena.riot.Lang; //導入依賴的package包/類
/** Build a ServletContextHandler. */
private static ServletContextHandler buildServletContext(String contextPath) {
    if ( contextPath == null || contextPath.isEmpty() )
        contextPath = "/" ;
    else if ( !contextPath.startsWith("/") )
        contextPath = "/" + contextPath ;
    ServletContextHandler context = new ServletContextHandler() ;
    context.setDisplayName("PatchLogServer") ;
    MimeTypes mt = new MimeTypes();
    addMimeType(mt, Lang.TTL);
    addMimeType(mt, Lang.NT);
    addMimeType(mt, Lang.TRIG);
    addMimeType(mt, Lang.NQ);
    addMimeType(mt, Lang.RDFXML);
    context.setMimeTypes(mt);
    ErrorHandler eh = new HttpErrorHandler();
    context.setErrorHandler(eh) ;
    return context ;
}
 
開發者ID:afs,項目名稱:rdf-delta,代碼行數:20,代碼來源:PatchLogServer.java

示例10: TestBase

import org.apache.jena.riot.Lang; //導入依賴的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

示例11: readRDF

import org.apache.jena.riot.Lang; //導入依賴的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

示例12: toRdf

import org.apache.jena.riot.Lang; //導入依賴的package包/類
/**
 * Convert a PhenoPacket to RDF triples using the JSON-LD context
 * 
 * @param packet
 * @param base
 *            URI base for generated RDF; if `null` a UUID-based base will
 *            be used
 * @return model containing RDF triples
 * @throws JsonLdError
 * @throws JsonProcessingException
 */
public static Model toRdf(PhenoPacket packet, String base)
		throws JsonLdError, JsonProcessingException {
	PhenoPacket packetWithContext;
	if (packet.getContext() == null) {
		packetWithContext = PhenoPacket.newBuilder(packet)
                           .context(ContextUtil.defaultContextURI)
                           .build();
	} else {
		packetWithContext = packet;
	}
	Model rdfModel = ModelFactory.createDefaultModel();
	StringReader reader = new StringReader(
			JsonGenerator.render(packetWithContext));
	String baseToUse;
	if (base != null) {
		baseToUse = base;
	} else {
		String uuid = UUID.randomUUID().toString();
		baseToUse = "http://phenopackets.org/local/" + uuid + "/";
	}
	RDFDataMgr.read(rdfModel, reader, baseToUse, Lang.JSONLD);
	return rdfModel;
}
 
開發者ID:phenopackets,項目名稱:phenopacket-reference-implementation,代碼行數:35,代碼來源:RdfGenerator.java

示例13: getBaseFromFile

import org.apache.jena.riot.Lang; //導入依賴的package包/類
/**
 * Gets the {@link JenaBase} from the given {@link IFile}.
 * 
 * @param file
 *            the {@link IFile}
 * @return the {@link JenaBase} from the given {@link IFile} if nay, <code>null</code> otherwise
 */
private JenaBase getBaseFromFile(IFile file) {
	JenaBase res = null;

	final Lang lang = EXTENSION_TO_LANG.get(file.getFileExtension());
	if (lang != null) {
		try {
			final Model model = RDFDataMgr.loadModel(file.getLocation().toFile().getAbsolutePath(), lang);
			if (!model.isEmpty()) {
				res = new JenaBase(model, file.getFullPath().toString());
			}
			// CHECKSTYLE:OFF
		} catch (Exception e) {
			// CHECKSTYLE:ON
			Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID,
					UNABLE_TO_LOAD_SEMANTIC_BASE_FROM + file.getLocation().toString(), e));
		}
	}

	return res;
}
 
開發者ID:ModelWriter,項目名稱:Source,代碼行數:28,代碼來源:SemanticBaseListener.java

示例14: readFrom

import org.apache.jena.riot.Lang; //導入依賴的package包/類
@Override
   public Model readFrom(Class<Model> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException
   {
if (log.isTraceEnabled()) log.trace("Reading Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType);

Model model = ModelFactory.createDefaultModel();	

       MediaType formatType = new MediaType(mediaType.getType(), mediaType.getSubtype()); // discard charset param        
       Lang lang = RDFLanguages.contentTypeToLang(formatType.toString());
       if (lang == null)
       {
           if (log.isErrorEnabled()) log.error("MediaType '{}' not supported by Jena", formatType);
           throw new NoReaderForLangException("MediaType not supported: " + formatType);
       }
if (log.isDebugEnabled()) log.debug("RDF language used to read Model: {}", lang);
       
       return read(model, entityStream, lang, getUriInfo().getBaseUri().toString());
   }
 
開發者ID:AtomGraph,項目名稱:Processor,代碼行數:19,代碼來源:BasedModelProvider.java

示例15: writeTo

import org.apache.jena.riot.Lang; //導入依賴的package包/類
@Override
   public void writeTo(Model model, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException
   {
if (log.isTraceEnabled()) log.trace("Writing Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType);

       MediaType formatType = new MediaType(mediaType.getType(), mediaType.getSubtype()); // discard charset param        
       Lang lang = RDFLanguages.contentTypeToLang(formatType.toString());
       if (lang == null)
       {
           if (log.isErrorEnabled()) log.error("MediaType '{}' not supported by Jena", formatType);
           throw new NoWriterForLangException("MediaType not supported: " + formatType);
       }
if (log.isDebugEnabled()) log.debug("RDF language used to read Model: {}", lang);
       
write(model, entityStream, lang, getUriInfo().getBaseUri().toString());
   }
 
開發者ID:AtomGraph,項目名稱:Processor,代碼行數:17,代碼來源:BasedModelProvider.java


注:本文中的org.apache.jena.riot.Lang類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。