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


Java OWLOntologyManager類代碼示例

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


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

示例1: fromOntology

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * Returns a list of rules extracted from the given OWL-2 ontology document.
 * 
 * @param src an ontology document
 * @return a list of rules
 */
public static List<Rule> fromOntology(OWLOntologyDocumentSource src) {
	try {
		// use OWL-API to get a OWLOntology document from source
		OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
		manager.loadOntologyFromOntologyDocument(src);
		Set<OWLOntology> ontologies = manager.getOntologies();
		if (ontologies.isEmpty()) {
			return Collections.EMPTY_LIST;
		} else {
			// use first ontology from given source
			return fromOntology(ontologies.iterator().next());
		}
	} catch (OWLOntologyCreationException ex) {
		throw new IllegalArgumentException(
				"Loading ontology stream failed", ex);
	}
}
 
開發者ID:lszeremeta,項目名稱:neo4j-sparql-extension-yars,代碼行數:24,代碼來源:Rules.java

示例2: getOntologyFromName

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * Open the OWL ontology (from the ontology resources of CartAGen) whose name
 * is passed as parameter.
 * @param name
 * @return
 * @throws OWLOntologyCreationException
 */
public static OWLOntology getOntologyFromName(String name)
    throws OWLOntologyCreationException {
  // create the URI from the name and the CartAGen ontologies folder path
  String uri = FOLDER_PATH + "/" + name + ".owl";
  InputStream stream = OwlUtil.class.getResourceAsStream(uri);
  File file = new File(stream.toString());
  String path = file.getAbsolutePath().substring(0,
      file.getAbsolutePath().lastIndexOf('\\'));
  path = path.replaceAll(new String("\\\\"), new String("//"));
  path = path + "//src/main//resources//ontologies//" + name + ".owl";
  // create the ontology from the URI using an OWLOntologyManager
  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  IRI physicalURI = IRI.create(new File(path));
  OWLOntology ontology = manager
      .loadOntologyFromOntologyDocument(physicalURI);

  return ontology;
}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:26,代碼來源:OwlUtil.java

示例3: getOntology

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * @param filename
 * @return
 */
private static OWLOntology getOntology(String filename) {
	File file = new File(filename);
	
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();

	OWLOntology o;
	try {
		o = m.loadOntologyFromOntologyDocument(IRI.create(file.toURI()));
	} catch (OWLOntologyCreationException e) {
		fail("Cannot load ontology.");
		return null;
	}
	assertNotNull(o);

	return o;
}
 
開發者ID:AKSW,項目名稱:Resource2Vec,代碼行數:21,代碼來源:R2VManager.java

示例4: isEdgeEntailed

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
public boolean isEdgeEntailed(OWLEdge e, OWLOntology currentOntology, OWLReasoner reasoner) {
	OWLOntologyManager m = getManager();

	Set<OWLSubClassOfAxiom> scas = currentOntology.getSubClassAxiomsForSubClass(e.c);
	Set<OWLSubClassOfAxiom> rmAxioms = new HashSet<OWLSubClassOfAxiom>();
	for (OWLSubClassOfAxiom sca : scas) {
		if (sca.getSuperClass().equals(e.p)) {
			LOG.info("REMOVING: "+sca);
			rmAxioms.add(sca);
		}
	}
	boolean isEdgeAsserted = rmAxioms.size() > 0;
	if (isEdgeAsserted) {
		m.removeAxioms(currentOntology, rmAxioms);
		reasoner.flush();
	}
	boolean isEntailed;
	isEntailed = reasoner.getSuperClasses(e.c, false).containsEntity(e.p);
	if (isEdgeAsserted) {
		m.addAxioms(currentOntology, rmAxioms);
		reasoner.flush();
	}

	return isEntailed;
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:26,代碼來源:ProvenanceReasonerWrapper.java

示例5: translate

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * Translate the given {@link GafDocument} into an OWL representation of the LEGO model.
 * 
 * @param gaf
 * @return lego ontology
 * @throws OWLException
 * @throws UnknownIdentifierException 
 */
public OWLOntology translate(GafDocument gaf) throws OWLException, UnknownIdentifierException {
	final OWLOntologyManager m = graph.getManager();
	OWLOntology lego = m.createOntology(IRI.generateDocumentIRI());
	OWLOntology sourceOntology = graph.getSourceOntology();
	OWLOntologyID ontologyID = sourceOntology.getOntologyID();
	if (ontologyID != null) {
		Optional<IRI> ontologyIRI = ontologyID.getOntologyIRI();
		if (ontologyIRI.isPresent()) {
			OWLDataFactory f = m.getOWLDataFactory();
			OWLImportsDeclaration importDeclaration = f.getOWLImportsDeclaration(ontologyIRI.get());
			m.applyChange(new AddImport(lego, importDeclaration ));
		}
	}
	translate(gaf.getGeneAnnotations(), lego);
	return lego;
}
 
開發者ID:geneontology,項目名稱:minerva,代碼行數:25,代碼來源:GafToLegoIndividualTranslator.java

示例6: addBioEntity

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
private void addBioEntity(OWLClass pr, OWLOntology lego, Bioentity bioentity) {
	Set<OWLDeclarationAxiom> declarationAxioms = lego.getDeclarationAxioms(pr);
	if (declarationAxioms == null || declarationAxioms.isEmpty()) {
		// add class declaration and add label
		OWLOntologyManager m = lego.getOWLOntologyManager();
		OWLDataFactory f = m.getOWLDataFactory();
		
		Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
		axioms.add(f.getOWLDeclarationAxiom(pr));
		
		String label = bioentity.getSymbol()+" - "+bioentity.getFullName();
		
		axioms.add(f.getOWLAnnotationAssertionAxiom(f.getRDFSLabel(), pr.getIRI(), f.getOWLLiteral(label)));
		
		m.addAxioms(lego, axioms);
	}
}
 
開發者ID:geneontology,項目名稱:minerva,代碼行數:18,代碼來源:GafToLegoTranslator.java

示例7: minimizedTranslate

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * Translate the given {@link GafDocument} into an OWL representation of the LEGO model.
 * Additionally minimize the lego model and imports into one ontology module.
 * 
 * @param gaf
 * @return minimized lego ontology
 */
public OWLOntology minimizedTranslate(GafDocument gaf) {
	OWLOntology all = translate(gaf);
	final OWLOntologyManager m = all.getOWLOntologyManager();
	
	SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, all, ModuleType.BOT);
	Set<OWLEntity> sig = new HashSet<OWLEntity>(all.getIndividualsInSignature());
	Set<OWLAxiom> moduleAxioms = sme.extract(sig);
	
	try {
		OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
		m.addAxioms(module, moduleAxioms);
		return module;
	} catch (OWLException e) {
		throw new RuntimeException("Could not create minimized lego model.", e);
	}
}
 
開發者ID:geneontology,項目名稱:minerva,代碼行數:24,代碼來源:GafToLegoTranslator.java

示例8: parseRow

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
private void parseRow(String[] row) {
	OWLDataFactory df = graph.getDataFactory();
	OWLOntologyManager mgr = graph.getManager();
	String geneSetId = row[0];
	IRI geneSetIRI = IRI.create(prefix + geneSetId);
	String desc = row[1];
	OWLClass geneSetCls = df.getOWLClass(geneSetIRI);
	OWLAxiom ax = df.getOWLAnnotationAssertionAxiom(df.getRDFSLabel(),geneSetIRI, literal(desc));
	mgr.addAxiom(graph.getSourceOntology(), ax);
			
	// assume each value is an entity, e.g. gene
	for (int i=2; i < row.length; i++) {
		OWLNamedIndividual individual = df.getOWLNamedIndividual(IRI.create(prefix + row[i]));
		mgr.addAxiom(graph.getSourceOntology(), df.getOWLClassAssertionAxiom(geneSetCls, individual));
	}
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:17,代碼來源:GMTParser.java

示例9: saveModel

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * Save a model to the database.
 * 
 * @param m
 * @param annotations
 * @param metadata
 *
 * @throws OWLOntologyStorageException
 * @throws OWLOntologyCreationException
 * @throws IOException
 * @throws RepositoryException 
 * @throws UnknownIdentifierException 
 */
public void saveModel(ModelContainer m,
		Set<OWLAnnotation> annotations, METADATA metadata)
				throws OWLOntologyStorageException, OWLOntologyCreationException,
				IOException, RepositoryException, UnknownIdentifierException {
	IRI modelId = m.getModelId();
	final OWLOntology ont = m.getAboxOntology();
	final OWLOntologyManager manager = ont.getOWLOntologyManager();
	List<OWLOntologyChange> changes = preSaveFileHandler(ont);
	synchronized(ont) {
		try {
			this.writeModelToDatabase(ont, modelId);
			// reset modified flag for abox after successful save
			m.setAboxModified(false);
		} finally {
			if (changes != null) {
				List<OWLOntologyChange> invertedChanges = ReverseChangeGenerator
						.invertChanges(changes);
				if (invertedChanges != null && !invertedChanges.isEmpty()) {
					manager.applyChanges(invertedChanges);
				}
			}
		}
	}
}
 
開發者ID:geneontology,項目名稱:minerva,代碼行數:38,代碼來源:BlazegraphMolecularModelManager.java

示例10: handleSupportOntologies

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
private static List<OWLOntologyChange> handleSupportOntologies(OWLGraphWrapper graph)
{
	OWLOntology ontology = graph.getSourceOntology();
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory factory = manager.getOWLDataFactory();
	
	List<OWLOntologyChange> removeImportChanges = new ArrayList<OWLOntologyChange>();
	Set<OWLOntology> supportOntologySet = graph.getSupportOntologySet();
	for (OWLOntology support : supportOntologySet) {
		Optional<IRI> supportIRI = support.getOntologyID().getOntologyIRI();
		if(supportIRI.isPresent()) {
			IRI ontologyIRI = supportIRI.get();
			OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(ontologyIRI);
			ChangeApplied status = manager.applyChange(new AddImport(ontology, importDeclaration));
			if (ChangeApplied.SUCCESSFULLY == status) {
				// the change was successful, create remove import for later
				removeImportChanges.add(new RemoveImport(ontology, importDeclaration));
			}
		}
	}
	return removeImportChanges;
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:23,代碼來源:AssertInferenceTool.java

示例11: addAutoGeneratedClassNames

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
private void addAutoGeneratedClassNames(OWLOntologyManager manager,
										OWLOntology ontology,
										Map<String, OWLClassExpression> nameMap) {
	
	OWLDataFactory factory = manager.getOWLDataFactory();
	List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
	
	for (Map.Entry<String, OWLClassExpression> entry : nameMap.entrySet()) {
		
		OWLClass subClass = factory.getOWLClass( IRI.create(entry.getKey()) );
		OWLAxiom declAxiom = factory.getOWLEquivalentClassesAxiom( subClass, entry.getValue() );
		
		changes.addAll( manager.addAxiom( ontology, declAxiom ) );
	}
	
	manager.applyChanges( changes );
}
 
開發者ID:klinovp,項目名稱:pronto,代碼行數:18,代碼來源:KBStandaloneLoader.java

示例12: synonym

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * Add an synonym annotation, plus an annotation on that annotation
 * that specified the type of synonym. The second annotation has the
 * property oio:hasSynonymType.
 *
 * @param ontology the current ontology
 * @param subject the subject of the annotation
 * @param type the IRI of the type of synonym
 * @param property the IRI of the annotation property.
 * @param value the literal value of the synonym
 * @return the synonym annotation axiom
 */
protected static OWLAnnotationAssertionAxiom synonym(
		OWLOntology ontology, OWLEntity subject, 
		OWLAnnotationValue type,
		OWLAnnotationProperty property, 
		OWLAnnotationValue value) {
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory dataFactory = manager.getOWLDataFactory();
	OWLAnnotationProperty hasSynonymType =
		dataFactory.getOWLAnnotationProperty(
			format.getIRI("oio:hasSynonymType"));
	OWLAnnotation annotation = 
		dataFactory.getOWLAnnotation(hasSynonymType, type);
	Set<OWLAnnotation> annotations = new HashSet<OWLAnnotation>();
	annotations.add(annotation);
	OWLAnnotationAssertionAxiom axiom =
		dataFactory.getOWLAnnotationAssertionAxiom(
			property, subject.getIRI(), value,
			annotations);
	manager.addAxiom(ontology, axiom);
	return axiom;
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:34,代碼來源:OWLConverter.java

示例13: loadOWLOntology

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
public OWLOntology loadOWLOntology(String phy_iri_onto) throws OWLOntologyCreationException{		

		try {
			
			OWLOntologyManager managerOnto;
			managerOnto = SynchronizedOWLManager.createOWLOntologyManager();			
			managerOnto.setSilentMissingImportsHandling(true);									
			return managerOnto.loadOntology(IRI.create(phy_iri_onto));
			
						
		}
		catch(Exception e){
			System.err.println("Error loading OWL ontology: " + e.getMessage());
			//e.printStackTrace();
			throw new OWLOntologyCreationException();
		}
	}
 
開發者ID:ernestojimenezruiz,項目名稱:logmap-matcher,代碼行數:18,代碼來源:BasicMultiplePartitioning.java

示例14: checkEntailment

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
/**
 * Classifies a given ontology and checks whether another ontology is
 * entailed by the former.
 *
 * @param premiseFile
 *            ontology file to be classified and used as premise
 * @param conclusionFile
 *            file with the conclusion
 * @throws FileNotFoundException
 *             if the file was not found
 * @throws OWLOntologyCreationException
 *             if the ontology could not be created
 * @throws OWLRendererException
 *             if a renderer error occurs
 * @return <code>true</code> if and only if the premise ontology entails the
 *         conclusion ontology
 */
public boolean checkEntailment(File premiseFile, File conclusionFile)
		throws OWLOntologyCreationException, OWLRendererException, FileNotFoundException {
	Objects.requireNonNull(premiseFile);
	Objects.requireNonNull(conclusionFile);
	logger.fine("starting jcel console ...");

	OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

	logger.fine("loading premise ontology using the OWL API ...");
	OWLOntology premiseOntology = manager.loadOntologyFromOntologyDocument(premiseFile);

	logger.fine("loading conclusion ontology using the OWL API ...");
	OWLOntology conclusionOntology = manager.loadOntologyFromOntologyDocument(conclusionFile);

	logger.fine("starting reasoner ...");
	JcelReasoner reasoner = new JcelReasoner(premiseOntology, false);

	logger.fine("precomputing inferences ...");
	reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	boolean ret = conclusionOntology.getAxioms().stream().allMatch(axiom -> reasoner.isEntailed(axiom));

	logger.fine("jcel console finished.");
	return ret;
}
 
開發者ID:julianmendez,項目名稱:jcel,代碼行數:43,代碼來源:ConsoleStarter.java

示例15: createModule

import org.semanticweb.owlapi.model.OWLOntologyManager; //導入依賴的package包/類
private static void createModule(String moduleName, Set<OWLEntity> signature, OWLOntology ont)
		throws OWLOntologyCreationException, IOException, OWLOntologyStorageException 
{
	// create a new manager avoid unnecessary change events
	final OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	
	// extract module
	SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, ont, ModuleType.BOT);
	Set<OWLAxiom> moduleAxioms = sme.extract(signature);
	
	OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
	m.addAxioms(module, moduleAxioms);
	
	// save module
	OutputStream moduleOutputStream = null;
	try {
		moduleOutputStream = new FileOutputStream(getModuleFile(moduleName));
		m.saveOntology(module, moduleOutputStream);
	}
	finally {
		IOUtils.closeQuietly(moduleOutputStream);
	}
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:24,代碼來源:AssertInferenceTool.java


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