本文整理汇总了Java中org.semanticweb.owlapi.model.OWLOntologyCreationException类的典型用法代码示例。如果您正苦于以下问题:Java OWLOntologyCreationException类的具体用法?Java OWLOntologyCreationException怎么用?Java OWLOntologyCreationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OWLOntologyCreationException类属于org.semanticweb.owlapi.model包,在下文中一共展示了OWLOntologyCreationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromOntology
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的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);
}
}
示例2: getOntologyFromName
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的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;
}
示例3: getOntology
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的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;
}
示例4: buildConceptMapperDictionary
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
/**
* Creates a dictionary for use by the ConceptMapper that includes GO terms
* from the namespaces defined in the namespacesToInclude set.
*
* @param namespacesToInclude
* @param workDirectory
* @param cleanWorkDirectory
* @param synonymType
* @return
* @throws IOException
* @throws OWLOntologyCreationException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws OBOParseException
*/
public static File buildConceptMapperDictionary(EnumSet<GoNamespace> namespacesToInclude, File workDirectory,
CleanDirectory cleanWorkDirectory, SynonymType synonymType) throws IOException, IllegalArgumentException,
IllegalAccessException, OWLOntologyCreationException {
if (namespacesToInclude.isEmpty())
return null;
boolean doClean = cleanWorkDirectory.equals(CleanDirectory.YES);
GeneOntologyClassIterator goIter = new GeneOntologyClassIterator(workDirectory, doClean);
File geneOntologyOboFile = goIter.getGeneOntologyOboFile();
goIter.close();
return buildConceptMapperDictionary(namespacesToInclude, workDirectory, geneOntologyOboFile, doClean,
synonymType);
}
示例5: testExactSynonymOnly_SO_OBO
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
@Test
public void testExactSynonymOnly_SO_OBO() throws IOException, OWLOntologyCreationException {
File oboFile = ClassPathUtil.copyClasspathResourceToDirectory(getClass(), SAMPLE_SO_OBO_FILE_NAME,
folder.newFolder("input"));
OntologyUtil ontUtil = new OntologyUtil(oboFile);
File outputFile = folder.newFile("dict.xml");
OboToDictionary.buildDictionary(outputFile, ontUtil, null, SynonymType.EXACT);
/* @formatter:off */
List<String> expectedLines = CollectionsUtil.createList(
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>",
"<synonym>",
"<token id=\"http://purl.obolibrary.org/obo/SO_0000012\" canonical=\"scRNA_primary_transcript\">",
"<variant base=\"scRNA_primary_transcript\"/>",
"<variant base=\"scRNA primary transcript\"/>",
"<variant base=\"scRNA primary transcript\"/>", // this entry ends up in there twice due to underscore removal
"<variant base=\"scRNA transcript\"/>",
"<variant base=\"small cytoplasmic RNA transcript\"/>",
"</token>",
"</synonym>");
/* @formatter:on */
assertTrue(FileComparisonUtil.hasExpectedLines(outputFile, CharacterEncoding.UTF_8, expectedLines, null,
LineOrder.ANY_ORDER, ColumnOrder.AS_IN_FILE, LineTrim.ON, ShowWhiteSpace.ON));
}
示例6: initialize
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
super.initialize(context);
try {
ontUtil = new OntologyUtil(ontologyFile);
/*
* check that the term to remove is in the ontology -- if it is not,
* it could be a format issue
*/
OWLClass cls = ontUtil.getOWLClassFromId(termIdToRemove);
if (cls == null) {
String errorMessage = "Ontology term ID selected for removal is not in the given ontology. "
+ "This could be a formatting issue. Term selected for removal: " + termIdToRemove
+ " Example term ID from the ontology: " + ontUtil.getClassIterator().next().toStringID();
throw new ResourceInitializationException(new IllegalArgumentException(errorMessage));
}
} catch (OWLOntologyCreationException e) {
throw new ResourceInitializationException(e);
}
annotationDataExtractor = (AnnotationDataExtractor) ConstructorUtil
.invokeConstructor(annotationDataExtractorClassName);
}
示例7: create
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
@Override
public InferenceProvider create(final ModelContainer model) throws OWLOntologyCreationException, InterruptedException {
synchronized (model.getAboxOntology()) {
InferenceProvider inferenceProvider = inferenceCache.get(model);
if (inferenceProvider == null) {
addMiss();
inferenceProvider = super.create(model);
model.registerListener(new ModelChangeListenerImplementation(model));
inferenceCache.put(model, inferenceProvider);
}
else {
addHit();
}
return inferenceProvider;
}
}
示例8: deleteFactCommand
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
@Deprecated
public void deleteFactCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
if (isHelp()) {
info("generates ClassAssertion");
return;
}
OWLOntology ont = resolveOntology(Param.ontology);
OWLIndividual i = resolveIndividual(Param.individualId);
OWLIndividual j = resolveIndividual(Param.fillerId);
OWLObjectProperty p = resolveObjectProperty(Param.propertyId);
for (OWLObjectPropertyAssertionAxiom ax : ont.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) {
if (ax.getSubject().equals(i)) {
if (p == null || ax.getProperty().equals(p)) {
if (j == null || ax.getObject().equals(j)) {
removeAxiom(ont, graph.getDataFactory().getOWLObjectPropertyAssertionAxiom(p, i, j));
}
}
}
}
String jsonStr = "";
response.getWriter().write(jsonStr);
}
示例9: testUnion
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
@Test
public void testUnion() throws OWLOntologyCreationException, IOException, FrameMergeException {
OWLObject cls = gw.getOWLObjectByIdentifier("NCBITaxon:6239"); // C elegans
OWLObject uc = gw.getOWLObjectByIdentifier("NCBITaxon_Union:0000005"); // C elegans
Set<OWLGraphEdge> edges = gw.getOutgoingEdgesClosure(cls);
// TODO - test includes union
boolean ok = false;
for (OWLGraphEdge e : edges) {
System.out.println(e);
OWLObject t = e.getTarget();
String tid = gw.getIdentifier(t);
System.out.println(" "+tid);
// Nematoda or Protostomia
if ("NCBITaxon_Union:0000005".equals(tid)) {
ok = true;
}
}
assertTrue(ok);
assertTrue(gw.getAncestorsReflexive(cls).contains(uc));
}
示例10: mergeSpecificImport
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
/**
* Merge a specific ontology from the import closure into the main ontology.
* Removes the import statement.
*
* @param ontologyIRI id of the ontology to merge
* @throws OWLOntologyCreationException
*/
public void mergeSpecificImport(IRI ontologyIRI) throws OWLOntologyCreationException {
OWLOntologyManager manager = getManager();
Set<OWLOntology> imports = sourceOntology.getImportsClosure();
for (OWLOntology o : imports) {
if (o.equals(sourceOntology))
continue;
Optional<IRI> currentIRI = o.getOntologyID().getOntologyIRI();
if (currentIRI.isPresent() && currentIRI.get().equals(ontologyIRI)) {
String comment = "Includes "+summarizeOntology(o);
LOG.info(comment);
addCommentToOntology(sourceOntology, comment);
manager.addAxioms(sourceOntology, o.getAxioms());
}
}
Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
for (OWLImportsDeclaration oid : oids) {
if (ontologyIRI.equals(oid.getIRI())) {
RemoveImport ri = new RemoveImport(sourceOntology, oid);
getManager().applyChange(ri);
}
}
}
示例11: convertToOWL
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
/**
* Read a data file, create an OWL representation, and save an OWL file.
* Create alternate identifiers from the merge.dmp file information
*
* @param inputPath the path to the input data file (e.g. taxonomy.dat)
* @param outputPath the path to the output OWL file
* (e.g. ncbi_taxonomy.owl).
* @param mergeInfo the input stream of the merged information
* @param citationInfo the input stream of the citation information
* @param uniqueNames
* @return OWL ontology
* @throws IOException if the paths do not resolve
* @throws OWLOntologyCreationException if OWLAPI fails to create an
* empty ontology
* @throws OWLOntologyStorageException if OWLAPI can't save the file
*/
public static OWLOntology convertToOWL(String inputPath,
String outputPath, InputStream mergeInfo,
InputStream citationInfo,
Map<String, String> uniqueNames) throws IOException,
OWLOntologyCreationException,
OWLOntologyStorageException {
File outputFile = new File(outputPath);
IRI outputIRI = IRI.create(outputFile);
OWLOntology ontology = convertToOWL(inputPath, uniqueNames);
if (mergeInfo != null) {
addAltIds(ontology, mergeInfo);
}
if (citationInfo != null) {
addCitationInfo(ontology, citationInfo);
}
logger.debug("Saving ontology...");
ontology.getOWLOntologyManager().saveOntology(
ontology, outputIRI);
return ontology;
}
示例12: checkEntailment
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的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;
}
示例13: testDiffInCommon
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
@Test
public void testDiffInCommon() throws OWLOntologyCreationException {
ParserWrapper pw = new ParserWrapper();
OWLOntology ont1 = pw.parseOWL(getResourceIRIString("difftest1.obo"));
OWLOntology ont2 = pw.parseOWL(getResourceIRIString("difftest2.obo"));
Diff diff = new Diff();
diff.ontology1 = ont1;
diff.ontology2 = ont2;
diff.isCompareClassesInCommon = true;
DiffUtil.getDiff(diff);
System.out.println(diff.ontology1remaining.getAxioms());
System.out.println(diff.ontology2remaining.getAxioms());
System.out.println(diff.intersectionOntology.getAxioms());
assertEquals(4, diff.intersectionOntology.getAxiomCount());
assertEquals(5, diff.ontology1remaining.getAxiomCount());
assertEquals(6, diff.ontology2remaining.getAxiomCount());
}
示例14: getOntologyAndNetworkFiles
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
/**
* Returns a list of example configurations based on a list of files.
*
* @param list
* list of files
* @return a list of example configurations based on a list of files
* @throws IOException
* if something goes wrong with I/O
* @throws OWLOntologyCreationException
* if something goes wrong with the creation of the ontologies
*/
public List<ExampleConfiguration> getOntologyAndNetworkFiles(List<String> list)
throws IOException, OWLOntologyCreationException {
Objects.requireNonNull(list);
List<ExampleConfiguration> ret = new ArrayList<>();
List<String> owlFiles = getFilesWithExtension(list, OWL_EXTENSION);
for (String fileName : owlFiles) {
String fileNamePrefix = fileName.substring(0, fileName.length() - OWL_EXTENSION.length());
String bayesianNetworkFileName = fileNamePrefix + NETWORK_EXTENSION;
String queryFileName = fileNamePrefix + QUERY_EXTENSION;
String owlOntologyName = fileName;
OWLOntology owlOntology = readOntology(getInputStreamForFile(owlOntologyName));
String bayesianNetwork = getFile(getInputStreamForFile(bayesianNetworkFileName));
String query = getFile(getInputStreamForFile(queryFileName));
ExampleConfiguration exampleConf = new ExampleConfigurationImpl(getFileName(fileNamePrefix),
owlOntologyName, owlOntology, bayesianNetworkFileName, bayesianNetwork, query);
ret.add(exampleConf);
}
return ret;
}
示例15: main
import org.semanticweb.owlapi.model.OWLOntologyCreationException; //导入依赖的package包/类
public static void main(String[] args) throws OWLOntologyCreationException {
// Creation of a new Querier = Motor running the query
System.out.println("Initialization of the querier...");
QueryingWithNamedClasses querier = new QueryingWithNamedClasses();
// Actual query:
// "In our ontology, what are the subclasses of the named class MeatEater?"
// It will work only if you use a reference to a class already present
// in your ontology (named class).
Set<OWLClass> results = querier.getSubClasses("MeatEater");
// The result is the set of classes satisfying the query.
for (OWLClass owlClass : results) {
// Just iterates over it and print the name of the class
System.out.println("Subclass: "
+ querier.shortFormProvider.getShortForm(owlClass));
}
}