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


Java OntModel.read方法代码示例

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


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

示例1: map

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Override
public void map(List<DIF> pojoList, Properties props) {
  // create the base model
  OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
  ontModel.setNsPrefix("dif_v9.8.2", MUDROD_GCMD_DIF_9_8_2);
  ontModel.setNsPrefix("geo", "http://www.opengis.net/ont/geosparql#");
  ontModel.read(SWEET_REPR_DATA_PRODUCT, null, "TURTLE");

  // get the https://sweetontology.net/reprDataProduct/Dataset class reference
  Resource dataset = ontModel.getResource(SWEET_REPR_DATA_PRODUCT_NS + "Dataset");
  // create the https://sweetontology.net/reprDataProduct/PODAACDataset class
  // reference
  OntClass podaacDataset = ontModel.createClass(PODAAC_DATASET + "PODAACDataset");
  // make PODAACDataset a subclass of Dataset
  podaacDataset.addSuperClass(dataset);
  // create an individual for each DIF POJO
  for (DIF dif : pojoList) {
    Individual gcmdDif = podaacDataset.createIndividual(PODAAC_DATASET + dif.getEntryID());
    buildIndividual(ontModel, dif, gcmdDif);
  }
  writeOntologyModel(ontModel, props);
}
 
开发者ID:ESIPFed,项目名称:eskg,代码行数:23,代码来源:PODAACOntologyMapper.java

示例2: loadOntologyFromClasspath

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
protected OntModel loadOntologyFromClasspath(String classPathUri, String uri) {
    
    OntModel ontModel = ModelFactory.createOntologyModel();

    // Load from classpath
    InputStream inStream = getClass().getResourceAsStream(classPathUri);
    if (inStream == null) {
        throw new IllegalArgumentException("Can't load " + classPathUri);
    }
    // Ontology ontology = ontModel.createOntology(uri);
    if (classPathUri.endsWith(".ttl")) {
        ontModel.read(inStream, uri, "TURTLE");
    } else {
        ontModel.read(inStream, uri);
    }
    return ontModel;
}
 
开发者ID:apache,项目名称:incubator-taverna-engine,代码行数:18,代码来源:ProvModel.java

示例3: loadOntologyFromClasspath

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
protected OntModel loadOntologyFromClasspath(String classPathUri, String uri) {
	OntModel ontModel = createOntologyModel();

	// Load from classpath
	InputStream inStream = getClass().getResourceAsStream(classPathUri);
	if (inStream == null)
		throw new IllegalArgumentException("Can't load " + classPathUri);
	// Ontology ontology = ontModel.createOntology(uri);
	ontModel.read(inStream, uri);
	try {
		inStream.close();
	} catch (IOException e) {
		// Shouldn't happen
	}
	return ontModel;
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:17,代码来源:RDFToManifest.java

示例4: workflowUUIDs

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Test
public void workflowUUIDs() throws Exception {
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	roEvo.workflowHistory(helloWorld.getMainWorkflow(), os);
	System.out.write(os.toByteArray());
	assertTrue(500 < os.size());
	String ttl = os.toString("UTF-8");
	assertTrue(ttl.contains("01348671-5aaa-4cc2-84cc-477329b70b0d"));
	assertTrue(ttl.contains("VersionableResource"));
	assertTrue(ttl.contains("Entity"));
	
	OntModel m = ModelFactory.createOntologyModel();
	m.read(new ByteArrayInputStream(os.toByteArray()), "http://example.com/", "Turtle");
	Resource mainWf = m.getResource(helloWorld.getMainWorkflow().getIdentifier().toASCIIString());		
	Resource older = mainWf.getProperty(Prov_o.wasRevisionOf).getResource();
	Resource oldest = older.getProperty(Prov_o.wasRevisionOf).getResource();
	assertNull(oldest.getProperty(Prov_o.wasRevisionOf));
	
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:20,代码来源:TestRoEvoSerializer.java

示例5: getDataModel

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
protected Model getDataModel(String[] args) throws IOException {
	for(int i = 0; i < args.length - 1; i++) {
		if(DATA_FILE.equals(args[i])) {
			String dataFileName = args[i + 1];
			OntModel dataModel = ModelFactory.createOntologyModel(spec);
			File dataFile = new File(dataFileName);
			dataModel.read(new FileInputStream(dataFile), "urn:x-base", FileUtils.langTurtle);
			return dataModel;
		}
	}
	System.err.println("Missing -datafile, e.g.: -datafile myfile.ttl");
	System.exit(0);
	return null;
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:15,代码来源:AbstractTool.java

示例6: getShapesModel

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
protected Model getShapesModel(String[] args) throws IOException {
	for(int i = 0; i < args.length - 1; i++) {
		if(SHAPES_FILE.equals(args[i])) {
			String fileName = args[i + 1];
			OntModel model = ModelFactory.createOntologyModel(spec);
			File dataFile = new File(fileName);
			model.read(new FileInputStream(dataFile), "urn:x-base", FileUtils.langTurtle);
			return model;
		}
	}
	return null;
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:13,代码来源:AbstractTool.java

示例7: post

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Override
public RESTResource post(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
	
	String data = "";
	String ontologyUri = null;
	try {
		data = ThingDescriptionUtils.streamToString(payload);
		ontologyUri = new URI(data).toString();
		data = null;
	} catch (IOException e1) {
		e1.printStackTrace();
		throw new BadRequestException();
	} catch (URISyntaxException e2) {
		// do nothing
	}
	
	Dataset dataset = ThingDirectory.get().dataset;
	dataset.begin(ReadWrite.WRITE);
	try {
		String rootId = null;
		
		OntModel ontology = ModelFactory.createOntologyModel();
		if (data == null) {
			ontology.read(ontologyUri.toString(), "Turtle");
		} else {
			ontologyUri = "http://example.org/"; // TODO
			ontology.read(new ByteArrayInputStream(data.getBytes("UTF-8")), ontologyUri, "Turtle");
		}

		Model tdb = dataset.getDefaultModel();
		
		ExtendedIterator<Ontology> it = ontology.listOntologies();
		if (!it.hasNext()) {
				throw new BadRequestException();
		}
		while (it.hasNext()) {
			Ontology o = it.next();
			
			String prefix = ontology.getNsURIPrefix(o.getURI());
			// if no prefix found, generates id
			String id = (prefix != null && !prefix.isEmpty()) ? prefix : generateID();
			URI resourceUri = URI.create(normalize(uri) + "/" + id);
			
			OntModel axioms;
			if (isRootOntology(o.getURI(), ontology)) {
				rootId = id;
				axioms = ontology;
			} else {
				axioms = ontology.getImportedModel(o.getURI());
			}
			
			// TODO Check if the vocab isn't already registered in the dataset
			dataset.addNamedModel(resourceUri.toString(), axioms);
			
			Date currentDate = new Date(System.currentTimeMillis());
			DateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			tdb.getResource(resourceUri.toString()).addProperty(DCTerms.source, ontologyUri);
			tdb.getResource(resourceUri.toString()).addProperty(DCTerms.created, f.format(currentDate));

			addToAll("/vocab/" + id, new VocabularyHandler(id, instances));

			ThingDirectory.LOG.info(String.format("Registered RDFS/OWL vocabulary %s (id: %s)", o.getURI(), id));
		}
		
		dataset.commit();
		
		RESTResource resource = new RESTResource("/vocab/" + rootId, new VocabularyHandler(rootId, instances));
		return resource;

	} catch (Exception e) {
		e.printStackTrace();
		throw new RESTException();
	} finally {
		dataset.end();
	}
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:77,代码来源:VocabularyCollectionHandler.java

示例8: post

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Override
public RESTResource post(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
	
	String data = "";
	String ontologyUri = null;
	try {
		data = ThingDescriptionUtils.streamToString(payload);
		ontologyUri = new URI(data).toString();
		data = null;
	} catch (IOException e1) {
		e1.printStackTrace();
		throw new BadRequestException();
	} catch (URISyntaxException e2) {
		// do nothing
	}
	
	Dataset dataset = Repository.get().dataset;
	dataset.begin(ReadWrite.WRITE);
	try {
		String rootId = null;
		
		OntModel ontology = ModelFactory.createOntologyModel();
		if (data == null) {
			ontology.read(ontologyUri.toString(), "Turtle");
		} else {
			ontologyUri = "http://example.org/"; // TODO
			ontology.read(new ByteArrayInputStream(data.getBytes("UTF-8")), ontologyUri, "Turtle");
		}

		Model tdb = dataset.getDefaultModel();
		
		ExtendedIterator<Ontology> it = ontology.listOntologies();
		if (!it.hasNext()) {
				throw new BadRequestException();
		}
		while (it.hasNext()) {
			Ontology o = it.next();
			
			String prefix = ontology.getNsURIPrefix(o.getURI());
			// if no prefix found, generates id
			String id = (prefix != null && !prefix.isEmpty()) ? prefix : generateID();
			URI resourceUri = URI.create(normalize(uri) + "/" + id);
			
			OntModel axioms;
			if (isRootOntology(o.getURI(), ontology)) {
				rootId = id;
				axioms = ontology;
			} else {
				axioms = ontology.getImportedModel(o.getURI());
			}
			
			// TODO Check if the vocab isn't already registered in the dataset
			dataset.addNamedModel(resourceUri.toString(), axioms);
			
			Date currentDate = new Date(System.currentTimeMillis());
			DateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			tdb.getResource(resourceUri.toString()).addProperty(DCTerms.source, ontologyUri);
			tdb.getResource(resourceUri.toString()).addProperty(DCTerms.created, f.format(currentDate));

			addToAll("/vocab/" + id, new VocabularyHandler(id, instances));

			Repository.LOG.info(String.format("Registered RDFS/OWL vocabulary %s (id: %s)", o.getURI(), id));
		}
		
		dataset.commit();
		
		RESTResource resource = new RESTResource("/vocab/" + rootId, new VocabularyHandler(rootId, instances));
		return resource;

	} catch (Exception e) {
		e.printStackTrace();
		throw new RESTException();
	} finally {
		dataset.end();
	}
}
 
开发者ID:thingweb,项目名称:thingweb-repository,代码行数:77,代码来源:VocabularyCollectionHandler.java


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