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


Java OntModelSpec類代碼示例

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


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

示例1: createModel

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
/**
 * Create a model with a reasoner set based on the chosen reasoning level.
 * 
 * @param reasoningLevel
 *          The reasoning level for this model
 * 
 * @return The created ontology model
 */
private OntModel createModel(String reasoningLevel) {
  OntModel model;
  int reasoningLevelIndex;

  model = null;

  reasoningLevelIndex = getReasoningLevelIndex(reasoningLevel);

  if (reasoningLevelIndex == 0) { // None
    model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
  } else if (reasoningLevelIndex == 1) { // RDFS
    model = ModelFactory
        .createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
  } else if (reasoningLevelIndex == 2) { // OWL
    final Reasoner reasoner = PelletReasonerFactory.theInstance().create();
    final Model infModel = ModelFactory.createInfModel(reasoner,
        ModelFactory.createDefaultModel());
    model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,
        infModel);
  }

  return model;
}
 
開發者ID:DaveRead,項目名稱:BasicQuery,代碼行數:32,代碼來源:RdbToRdf.java

示例2: readOwlFile

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
static void readOwlFile (String pathToOwlFile) {
        OntModel ontologyModel =
                ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
        ontologyModel.read(pathToOwlFile, "RDF/XML-ABBREV");
       // OntClass myClass = ontologyModel.getOntClass("namespace+className");

        OntClass myClass = ontologyModel.getOntClass(ResourcesUri.nwr+"domain-ontology#Motion");
        System.out.println("myClass.toString() = " + myClass.toString());
        System.out.println("myClass.getSuperClass().toString() = " + myClass.getSuperClass().toString());

        //List list =
              //  namedHierarchyRoots(ontologyModel);


       Iterator i = ontologyModel.listHierarchyRootClasses()
                .filterDrop( new Filter() {
                    public boolean accept( Object o ) {
                        return ((Resource) o).isAnon();
                    }} ); ///get all top nodes and excludes anonymous classes

       // Iterator i = ontologyModel.listHierarchyRootClasses();
        while (i.hasNext()) {
            System.out.println(i.next().toString());
/*            OntClass ontClass = ontologyModel.getOntClass(i.next().toString());
            if (ontClass.hasSubClass()) {

            }*/
        }

        String q = createSparql("event", "<http://www.newsreader-project.eu/domain-ontology#Motion>");
        System.out.println("q = " + q);
        QueryExecution qe = QueryExecutionFactory.create(q,
                ontologyModel);
        for (ResultSet rs = qe.execSelect() ; rs.hasNext() ; ) {
            QuerySolution binding = rs.nextSolution();
            System.out.println("binding = " + binding.toString());
            System.out.println("Event: " + binding.get("event"));
        }

        ontologyModel.close();
    }
 
開發者ID:newsreader,項目名稱:StreamEventCoreference,代碼行數:42,代碼來源:OwlReader.java

示例3: testSomeMethod2

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的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

示例4: CSVSToRDFConverter

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
public CSVSToRDFConverter(String sourceFilesDir, String className, String baseNameSpace, String separator,
		String textFieldSeparator, int keyColIndex) {

	nsTBox = baseNameSpace + "model#";
	nsABox = baseNameSpace + "data#";

	this.sourceFilesDir = sourceFilesDir;
	this.className = className;
	this.separator = separator;
	this.textFieldSeparator = textFieldSeparator;

	tboxModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
	aboxModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);

	pathSeparator = System.getProperty("file.separator");
	this.keyColIndex = keyColIndex;
}
 
開發者ID:sll-mdilab,項目名稱:t5-doc,代碼行數:18,代碼來源:CSVSToRDFConverter.java

示例5: writeUserEntries

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
/**
 * Writes the user entities to rdf
 */
private static OntModel writeUserEntries() {
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	try {
		thewebsemantic.Bean2RDF writer = new Bean2RDF(model);
		InitialContext ic = new InitialContext();
		UserService userService = (UserService) ic.lookup("java:module/UserService");
		List<User> users = userService.getAll();
		for (User u : users) {
			writer.save(u);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return model;
}
 
開發者ID:U-QASAR,項目名稱:u-qasar.platform,代碼行數:19,代碼來源:UQasarUtil.java

示例6: writeProjectEntries

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
/**
 * Writes the project entities to rdf
 */
private static OntModel writeProjectEntries() {
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	try {
		thewebsemantic.Bean2RDF writer = new Bean2RDF(model);
		InitialContext ic = new InitialContext();
		TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
		List<Project> projects = treeNodeService.getAllProjects();
		for (Project proj : projects) {
			writer.save(proj);
		}

	} catch (Exception e) {
		e.printStackTrace();
	}
	return model;
}
 
開發者ID:U-QASAR,項目名稱:u-qasar.platform,代碼行數:20,代碼來源:UQasarUtil.java

示例7: readSemanticModelFiles

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
/**
	 * Read the RDF model from files.
	 */
	public static void readSemanticModelFiles() {
		logger.debug("Reading the model from a file");
		// Read the model to an existing model
		String dataDir = UQasarUtil.getDataDirPath();
		String modelPath = "file:///" + dataDir + ONTOLOGYFILE;
//		String modelPath = "file:///C:/nyrhinen/Programme/jboss-as-7.1.1.Final/standalone/data/uq-ontology-model.rdf";

		OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
		RDFDataMgr.read(model, modelPath);
		// Test output to standard output
		//		RDFDataMgr.write(System.out, uqModel, RDFFormat.RDFXML_PRETTY);
		logger.debug("Model read from file " +modelPath);
		UQasarUtil.setUqModel(model);
		System.out.println("Reading done.");
	}
 
開發者ID:U-QASAR,項目名稱:u-qasar.platform,代碼行數:19,代碼來源:UQasarUtil.java

示例8: SadlJenaModelGetter

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
/**
 * This constructor should be called when the repository format is not known
 * @param _tdbFolder
 */
public SadlJenaModelGetter(IConfigurationManager configMgr, String _tdbFolder) {
	configurationManager = configMgr;
	File tdbFile = new File(_tdbFolder);
	if (tdbFile.exists()) {
		setFormat(IConfigurationManager.JENA_TDB);	// if the caller doesn't tell us the format
													// and the TDB folder exists, use it
	}
	else {
		setFormat(IConfigurationManager.RDF_XML_ABBREV_FORMAT);
	}
	setTdbFolder(_tdbFolder);
 	if (originalModelGetter == null) {
		// save original (file-based) importModelGetter
		originalModelGetter = OntModelSpec.getDefaultSpec(OWL.getURI()).getImportModelGetter();
	}
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:21,代碼來源:SadlJenaModelGetter.java

示例9: loadOntModel

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
@Override
public OntModel loadOntModel(String owlFilename) {
	try {
		FileInputStream is = new FileInputStream(new File(owlFilename));
		return initOntModel(is, getOwlFormatFromFile(owlFilename));
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	boolean savePI = ontModel.getDocumentManager().getProcessImports();
	ontModel.getDocumentManager().setProcessImports(false);
	try {
		ontModel.read(owlFilename, getOwlFormatFromFile(owlFilename));
	}
	finally {
		ontModel.getDocumentManager().setProcessImports(savePI);
	}
	return ontModel;
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:21,代碼來源:ConfigurationManagerForIDE.java

示例10: SadlJenaModelGetter

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
/**
 * This constructor should be called when the repository format is not known
 * @param _tdbFolder
 * @throws ConfigurationException 
 */
public SadlJenaModelGetter(OntModelSpec spec, String modelFolder) throws ConfigurationException {
	this.modelFolder = modelFolder;
	File modelFolderFile = new File(modelFolder);
	if (!modelFolderFile.exists()) {
		throw new ConfigurationException("Invalid model folder (" + modelFolder + ")passed to SadlJenaModelGetter");
	}
	modelSpec = spec;
	File tdbFile = new File(getTdbFolder());
	if (tdbFile.exists()) {
		setFormat(JENA_TDB);	// if the caller doesn't tell us the format
													// and the TDB folder exists, use it
	}
	else {
		setFormat(RDF_XML_ABBREV_FORMAT);
	}
 	if (originalModelGetter == null) {
		// save original (file-based) importModelGetter
		originalModelGetter = spec.getImportModelGetter();
	}
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:26,代碼來源:SadlJenaModelGetter.java

示例11: MetricsProcessor

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
public MetricsProcessor(String uri, org.eclipse.emf.ecore.resource.Resource resource, IConfigurationManagerForIDE configMgr, SadlModelProcessor modelProcessor) throws JenaProcessorException, ConfigurationException {
	if (resource == null) {
		throw new JenaProcessorException("MetricsProcessor constructor called with null resource");
	}
	this.modelProcessor = modelProcessor;
	String modelFolder = getModelFolderPath(resource);
	if (modelFolder != null) {
		// for JUnit tests, this will be null
		String fn = modelFolder + "/" + resource.getURI().segment(resource.getURI().segmentCount() - 1);
		baseUri = uri + ".metrics";
		filename = fn + ".metrics.owl";
		setTheJenaModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM));
		this.configMgr = configMgr;
		modelOntology = getTheJenaModel().createOntology(baseUri);
		modelOntology.addComment("SADL model metrics", "en");
	}
	else {
		throw new ConfigurationException("Model folder not found");
	}
}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:21,代碼來源:MetricsProcessor.java

示例12: buscarUsuarioRdf

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
public OutputStream buscarUsuarioRdf(Long id, String urlBase){
	OutputStream ret = new ByteArrayOutputStream();
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	model.setNsPrefix( "trires", Constantes.ONTO_URI );
	
	Usuario usuario = entityManager.find(Usuario.class, id);
	if (usuario != null){
		Resource recurso = model.createResource(Constantes.USUARIO_URI + usuario.getId().toString());
		recurso.addProperty(RDF.type, VocabularioMembro.RDF_TYPE_CLASS);
		recurso.addProperty(VocabularioMembro.ID, usuario.getId().toString());
		recurso.addProperty(VocabularioMembro.DESCRICAO, usuario.getDescricao());
		recurso.addProperty(VocabularioMembro.EMAIL, usuario.getEmail());
		recurso.addProperty(VocabularioMembro.INSTITUICAO, usuario.getInstituicao());
		recurso.addProperty(VocabularioMembro.LINK_LATTES, usuario.getLinkLattes());
		recurso.addProperty(VocabularioMembro.NOME, usuario.getNome());
	}
	
	model.write(ret, "RDF/XML");
	model.close();
	return ret;
}
 
開發者ID:dwws-ufes,項目名稱:2014-trires,代碼行數:22,代碼來源:UsuariosService.java

示例13: listarTodosRdf

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
public OutputStream listarTodosRdf(String urlBase){
	OutputStream ret = new ByteArrayOutputStream();
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
	model.setNsPrefix( "trires", Constantes.ONTO_URI );
	
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<Usuario> criteriaQuery = criteriaBuilder.createQuery(Usuario.class);
	Root<Usuario> from = criteriaQuery.from(Usuario.class);
	criteriaQuery.select(from);
	List<Usuario> gruposTrabalho = entityManager.createQuery(criteriaQuery).getResultList();
	for (Usuario usuario : gruposTrabalho) {
		Resource recurso = model.createResource(Constantes.USUARIO_URI + usuario.getId().toString());
		recurso.addProperty(RDF.type, VocabularioMembro.RDF_TYPE_CLASS);
		recurso.addProperty(VocabularioMembro.ID, usuario.getId().toString());
		recurso.addProperty(VocabularioMembro.DESCRICAO, usuario.getDescricao());
		recurso.addProperty(VocabularioMembro.EMAIL, usuario.getEmail());
		recurso.addProperty(VocabularioMembro.INSTITUICAO, usuario.getInstituicao());
		recurso.addProperty(VocabularioMembro.LINK_LATTES, usuario.getLinkLattes());
		recurso.addProperty(VocabularioMembro.NOME, usuario.getNome());
	}
	model.write(ret, "RDF/XML");
	model.close();
	return ret;
}
 
開發者ID:dwws-ufes,項目名稱:2014-trires,代碼行數:25,代碼來源:UsuariosService.java

示例14: ConcreteOntology

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
public ConcreteOntology(InputStream is) {
  this.model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
  model.read(is, null);

  this.defaultNamespace = this.model.getNsPrefixURI("");
  this.commTypes = new HashSet<String>();
  this.commTypes.addAll(this.loadViaOntology("Communication"));

  this.sectionTypes = new HashSet<>();
  this.sectionTypes.addAll(this.loadViaOntology("Section"));

  this.nerTags = new HashSet<>();
  this.nerTags.addAll(this.loadViaOntology("NamedEntityRecognitionTag"));

  this.posTags = new HashSet<>();
  this.posTags.addAll(this.loadViaOntology("PartOfSpeechTag"));
}
 
開發者ID:hltcoe,項目名稱:concrete-java,代碼行數:18,代碼來源:ConcreteOntology.java

示例15: readIFC

import com.hp.hpl.jena.ontology.OntModelSpec; //導入依賴的package包/類
public OntModel readIFC(String filename,String path) throws IOException {
	File file = new File("C:\\M\\xlokia.txt");
	if (!file.exists()) {
		file.createNewFile();
	}

	FileWriter fw = new FileWriter(file.getAbsoluteFile());
	BufferedWriter logfile = new BufferedWriter(fw);

	ByteArrayOutputStream strout = new ByteArrayOutputStream();
	BufferedWriter log = new BufferedWriter(new OutputStreamWriter(strout));
	ExpressReader er = new ExpressReader("c:\\jo\\IFC2X3_Final.exp");
	er.outputRDFS(log);
	IFC_ClassModel m1 = new IFC_ClassModel(filename,
			er.getEntities(), er.getTypes(), "r1");
	m1.listRDF(log, path);

	InputStream is = new ByteArrayInputStream(strout.toString().getBytes());

	OntModel model = ModelFactory
			.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
	model.read(is, null, "N3");
	return model;

}
 
開發者ID:jyrkio,項目名稱:Open-IFC-to-RDF-converter,代碼行數:26,代碼來源:IFC2Jena.java


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