本文整理汇总了Java中org.semanticweb.owlapi.io.OWLParserFactory类的典型用法代码示例。如果您正苦于以下问题:Java OWLParserFactory类的具体用法?Java OWLParserFactory怎么用?Java OWLParserFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OWLParserFactory类属于org.semanticweb.owlapi.io包,在下文中一共展示了OWLParserFactory类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: silenceOboParser
import org.semanticweb.owlapi.io.OWLParserFactory; //导入依赖的package包/类
public static synchronized void silenceOboParser() {
if (silencedParser) {
return;
}
OWLManager.createOWLOntologyManager();
/* TODO: Why does this logging never become silent?
* Logger logger = Logger.getLogger("org.obolibrary");
logger.setLevel(java.util.logging.Level.SEVERE);
Handler[] handlers = logger.getHandlers();
for (Handler handler : handlers) {
handler.setLevel(Level.SEVERE);
}*/
// TODO: Why does this cause a concurrent modification exception if not synchronized
OWLParserFactoryRegistry registry = OWLParserFactoryRegistry.getInstance();
List<OWLParserFactory> factories = registry.getParserFactories();
for (OWLParserFactory factory : factories) {
if (factory instanceof OBOFormatParserFactory ||
factory instanceof OBO12ParserFactory) {
registry.unregisterParserFactory(factory);
}
}
silencedParser = true;
}
示例2: resetOBOParserFactories
import org.semanticweb.owlapi.io.OWLParserFactory; //导入依赖的package包/类
private static synchronized void resetOBOParserFactories(OWLOntologyManager m, Set<OWLParserFactory> factories) {
m.setOntologyParsers(factories);
}
示例3: importModel
import org.semanticweb.owlapi.io.OWLParserFactory; //导入依赖的package包/类
/**
* Try to load (or replace) a model with the given ontology. It is expected
* that the content is an A-Box ontology, which imports the T-BOX. Also the
* ontology ID is used to extract the modelId.<br>
* <br>
* This method will currently <b>NOT<b> work due to a bug in the OWL-API.
* The functional syntax parser does not properly report the exceptions and
* will return an ontology with an wrong ontology ID!
*
* @param modelData
* @return modelId
* @throws OWLOntologyCreationException
*/
public ModelContainer importModel(String modelData) throws OWLOntologyCreationException {
// load data from String
final OWLOntologyManager manager = graph.getManager();
final OWLOntologyDocumentSource documentSource = new StringDocumentSource(modelData);
OWLOntology modelOntology;
final Set<OWLParserFactory> originalFactories = removeOBOParserFactories(manager);
try {
modelOntology = manager.loadOntologyFromOntologyDocument(documentSource);
}
catch (OWLOntologyAlreadyExistsException e) {
// exception is thrown if there is an ontology with the same ID already in memory
OWLOntologyID id = e.getOntologyID();
IRI existingModelId = id.getOntologyIRI().orNull();
// remove the existing memory model
unlinkModel(existingModelId);
// try loading the import version (again)
modelOntology = manager.loadOntologyFromOntologyDocument(documentSource);
}
finally {
resetOBOParserFactories(manager, originalFactories);
}
// try to extract modelId
IRI modelId = null;
Optional<IRI> ontologyIRI = modelOntology.getOntologyID().getOntologyIRI();
if (ontologyIRI.isPresent()) {
modelId = ontologyIRI.get();
}
if (modelId == null) {
throw new OWLOntologyCreationException("Could not extract the modelId from the given model");
}
// paranoia check
ModelContainer existingModel = modelMap.get(modelId);
if (existingModel != null) {
unlinkModel(modelId);
}
// add to internal model
ModelContainer newModel = addModel(modelId, modelOntology);
// update imports
updateImports(newModel);
return newModel;
}
示例4: loadOntologyDocumentSource
import org.semanticweb.owlapi.io.OWLParserFactory; //导入依赖的package包/类
static OWLOntology loadOntologyDocumentSource(final OWLOntologyDocumentSource source, boolean minimal, OWLOntologyManager manager) throws OWLOntologyCreationException {
// silence the OBO parser in the OWL-API
java.util.logging.Logger.getLogger("org.obolibrary").setLevel(java.util.logging.Level.SEVERE);
final Set<OWLParserFactory> originalFactories = removeOBOParserFactories(manager);
try {
// load model from source
if (minimal == false) {
// add the obsolete imports to the ignored imports
OWLOntology abox = loadOWLOntologyDocumentSource(source, manager);
return abox;
}
else {
// only load the model, skip imports
// approach: return an empty ontology IRI for any IRI mapping request using.
final OWLOntologyManager m = OWLManager.createOWLOntologyManager();
final Set<IRI> emptyOntologies = new HashSet<IRI>();
m.getIRIMappers().add(new OWLOntologyIRIMapper() {
// generated
private static final long serialVersionUID = -8200679663396870351L;
@Override
public IRI getDocumentIRI(IRI ontologyIRI) {
// quick check:
// do nothing for the original IRI and known empty ontologies
if (source.getDocumentIRI().equals(ontologyIRI) || emptyOntologies.contains(ontologyIRI)) {
return null;
}
emptyOntologies.add(ontologyIRI);
try {
OWLOntology emptyOntology = m.createOntology(ontologyIRI);
return emptyOntology.getOntologyID().getDefaultDocumentIRI().orNull();
} catch (OWLOntologyCreationException e) {
throw new RuntimeException(e);
}
}
});
OWLOntology minimalAbox = loadOWLOntologyDocumentSource(source, m);
return minimalAbox;
}
} finally {
resetOBOParserFactories(manager, originalFactories);
}
}