本文整理匯總了Java中org.semanticweb.owlapi.model.OWLOntology.getAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLOntology.getAnnotations方法的具體用法?Java OWLOntology.getAnnotations怎麽用?Java OWLOntology.getAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.semanticweb.owlapi.model.OWLOntology
的用法示例。
在下文中一共展示了OWLOntology.getAnnotations方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: OntologyMetadata
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
public OntologyMetadata(OWLOntology ont) {
super();
OWLOntologyID id = ont.getOntologyID();
if (id.getOntologyIRI().isPresent())
ontologyIRI = id.getOntologyIRI().get().toString();
if (id.getVersionIRI().isPresent())
versionIRI = id.getVersionIRI().get().toString();
importDirectives = new HashSet<String>();
for (OWLImportsDeclaration oid : ont.getImportsDeclarations()) {
importDirectives.add(oid.getIRI().toString());
}
classCount = ont.getClassesInSignature().size();
namedIndividualCount = ont.getIndividualsInSignature().size();
axiomCount = ont.getAxiomCount();
annotations = new HashSet<OntologyAnnotation>();
for (OWLAnnotation ann : ont.getAnnotations()) {
annotations.add(new OntologyAnnotation(ann));
}
}
示例2: removeDirectives
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
private void removeDirectives() {
// TODO decide: move the set of directives into a constant/static collection?
Set<IRI> directivesIRIs = new HashSet<IRI>();
directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation.getIRI());
directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsEquivalent.getIRI());
directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsGenusDifferentia.getIRI());
directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsHasSubClass.getIRI());
directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsIsA.getIRI());
directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsRelationship.getIRI());
directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsReverseGenusDifferentia.getIRI());
OWLOntology o = graph.getSourceOntology();
for(OWLAnnotation ann : o.getAnnotations()) {
final OWLAnnotationProperty property = ann.getProperty();
if (directivesIRIs.contains(property.getIRI())) {
manager.applyChange(new RemoveOntologyAnnotation(o, ann));
}
}
}
示例3: getOntologyAnnotationValue
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
private String getOntologyAnnotationValue(OWLOntology o, OboFormatTag tag) {
IRI dateTagIRI = Obo2Owl.trTagToIRI(tag.getTag());
Set<OWLAnnotation> annotations = o.getAnnotations();
for (OWLAnnotation annotation : annotations) {
OWLAnnotationProperty property = annotation.getProperty();
if(dateTagIRI.equals(property.getIRI())) {
OWLAnnotationValue value = annotation.getValue();
if (value != null) {
if (value instanceof IRI) {
return ((IRI) value).toString();
}
else if (value instanceof OWLLiteral) {
return ((OWLLiteral) value).getLiteral();
}
}
}
}
return null;
}
示例4: getModelState
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
public static String getModelState(OWLOntology model, String defaultValue) {
String modelState = defaultValue;
Set<OWLAnnotation> modelAnnotations = model.getAnnotations();
for (OWLAnnotation modelAnnotation : modelAnnotations) {
IRI propIRI = modelAnnotation.getProperty().getIRI();
if (AnnotationShorthand.modelstate.getAnnotationProperty().equals(propIRI)) {
String value = modelAnnotation.getValue().accept(new OWLAnnotationValueVisitorEx<String>() {
@Override
public String visit(IRI iri) {
return null;
}
@Override
public String visit(OWLAnonymousIndividual individual) {
return null;
}
@Override
public String visit(OWLLiteral literal) {
return literal.getLiteral();
}
});
if (value != null) {
modelState = value;
}
}
}
return modelState;
}
示例5: getRootTerminologyPreferredName
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Returns the terminology preferred name.
*
* @param ontology the ontology
* @return the terminology preferred name
* @throws Exception the exception
*/
private String getRootTerminologyPreferredName(OWLOntology ontology)
throws Exception {
// Get the rdfs:label property of the ontology itself
for (final OWLAnnotation annotation : ontology.getAnnotations()) {
if (annotation.getProperty().isLabel()) {
return getValue(annotation);
}
}
// otherwise, just use the terminology name
return getTerminology();
}
示例6: getComment
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Returns the comment.
*
* @param ontology the ontology
* @return the comment
* @throws Exception the exception
*/
private String getComment(OWLOntology ontology) throws Exception {
for (final OWLAnnotation annotation : ontology.getAnnotations()) {
if (annotation.getProperty().isComment()) {
return getValue(annotation);
}
}
return null;
}
示例7: validateBeforeSave
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
public List<String> validateBeforeSave(ModelContainer model) throws OWLOntologyCreationException {
// get model
List<String> errors = new ArrayList<String>(3);
// check that model has required meta data
OWLOntology aboxOntology = model.getAboxOntology();
boolean hasTitle = false;
boolean hasContributor = false;
// get ontology annotations
Set<OWLAnnotation> annotations = aboxOntology.getAnnotations();
for (OWLAnnotation annotation : annotations) {
OWLAnnotationProperty p = annotation.getProperty();
AnnotationShorthand legoType = AnnotationShorthand.getShorthand(p.getIRI());
if (legoType != null) {
// check for title
if (AnnotationShorthand.title.equals(legoType)) {
hasTitle = true;
}
// check for contributor
else if (AnnotationShorthand.contributor.equals(legoType)) {
hasContributor = true;
}
}
}
if (hasTitle == false) {
errors.add("The model has no title. All models must have a human readable title.");
}
if (hasContributor == false) {
errors.add("The model has no contributors. All models must have an association with their contributors.");
}
// require at least one declared instance
Set<OWLNamedIndividual> individuals = aboxOntology.getIndividualsInSignature();
if (individuals.isEmpty()) {
errors.add("The model has no individuals. Empty models should not be saved.");
}
// avoid returning empty list
if (errors.isEmpty()) {
errors = null;
}
return errors;
}
示例8: testDecorate1
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
@Test
public void testDecorate1() throws Exception {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLDataFactory f = m.getOWLDataFactory();
CurieMappings defaultMappings = DefaultCurieHandler.loadDefaultMappings();
CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap("http://testmodel.geneontology.org/","testmodel"));
CurieHandler curieHandler = new MappedCurieHandler(defaultMappings, localMappings);
OWLOntology model = m.createOntology(IRI.create("http://testmodel.geneontology.org/0001"));
// add class without a label or id
IRI cIRI = IRI.create("http://purl.obolibrary.org/obo/GO_0001");
OWLClass c = f.getOWLClass(cIRI);
m.addAxiom(model, f.getOWLDeclarationAxiom(c));
// add individual using the class as type
OWLNamedIndividual i = f.getOWLNamedIndividual(IRI.create("http://testmodel.geneontology.org/0001/0001"));
m.addAxiom(model, f.getOWLDeclarationAxiom(i));
m.addAxiom(model, f.getOWLClassAssertionAxiom(c, i));
List<LookupEntry> testEntries = new ArrayList<LookupEntry>();
testEntries.add(new LookupEntry(cIRI, "TEST CLASS 1", "Class", null));
ExternalLookupService lookup = new TableLookupService(testEntries);
int originalAxiomCount = model.getAxiomCount();
int originalAnnotationCount = model.getAnnotations().size();
ModelWriterHelper w = new ModelWriterHelper(curieHandler, lookup);
List<OWLOntologyChange> changes = w.handle(model);
// model annotations
// id, label for cls
assertEquals(6, changes.size()); // 3 + 3 declarations
assertEquals(5+originalAxiomCount, model.getAxiomCount());
final Set<OWLAnnotation> modelAnnotationsAfter = model.getAnnotations();
assertEquals(1+originalAnnotationCount, modelAnnotationsAfter.size());
//System.out.println(render(model));
ModelReaderHelper.INSTANCE.filter(model);
assertEquals(originalAxiomCount+3, model.getAxiomCount()); // declarations are fine
assertEquals(originalAnnotationCount, model.getAnnotations().size());
//System.out.println(render(model));
}
示例9: getReleaseVersion
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Returns the version.
*
* @param ontology the ontology
* @return the version
* @throws Exception the exception
*/
private String getReleaseVersion(OWLOntology ontology) throws Exception {
String version = null;
if (ontology.getOntologyID().getVersionIRI() != null) {
version = ontology.getOntologyID().getVersionIRI().toString();
} else {
// check versionInfo
for (final OWLAnnotation annotation : ontology.getAnnotations()) {
if (getTerminologyId(annotation.getProperty().getIRI())
.equals("versionInfo")) {
version = getValue(annotation);
}
}
}
logInfo(" release version = " + version);
// This is the list of available patterns for extracting a date.
// Try each one
String[] patterns = new String[] {
// e.g.
// http://snomed.info/sct/900000000000207008/version/20150131
".*\\/(\\d{8})$",
// e.g.
// http://purl.obolibrary.org/obo/go/releases/2015-07-28/go.owl
".*\\/(\\d\\d\\d\\d-\\d\\d-\\d\\d)$",
".*\\/(\\d\\d\\d\\d-\\d\\d-\\d\\d\\/)$"
};
// Iterate through patterns
for (final String pattern : patterns) {
final Pattern pattern2 = Pattern.compile(pattern);
final Matcher matcher = pattern2.matcher(version);
// Assume if it matches, the pattern has a group 1, extract and
// prepare it.
if (matcher.matches()) {
String parsedVersion = matcher.group(1);
// Remove dashes
parsedVersion = parsedVersion.replaceAll("-", "");
Logger.getLogger(getClass())
.info(" parsed version = " + parsedVersion);
return parsedVersion;
}
}
// else return null
return null;
}
示例10: experimentalLoadComplexAnnotationSolr
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Experimental method for trying out the loading of complex_annotation doc type
*
* @param opts
* @throws Exception
*/
@CLIMethod("--solr-load-complex-annotations")
public void experimentalLoadComplexAnnotationSolr(Opts opts) throws Exception {
// Check to see if the global url has been set.
String url = sortOutSolrURL(globalSolrURL);
// Only proceed if our environment was well-defined.
if( legoCatalogs == null || legoFiles == null || legoCatalogs.isEmpty() || legoFiles.isEmpty() ){
LOG.warn("Lego environment not well defined--skipping.");
}else{
// Ready the environment for every pass.
ParserWrapper pw = new ParserWrapper();
// Add all of the catalogs.
for( File legoCatalog : legoCatalogs ){
pw.addIRIMapper(new CatalogXmlIRIMapper(legoCatalog));
}
OWLOntologyManager manager = pw.getManager();
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
// Actual loading--iterate over our list and load individually.
for( File legoFile : legoFiles ){
String fname = legoFile.getName();
OWLReasoner currentReasoner = null;
OWLOntology ontology = null;
// TODO: Temp cover for missing group labels and IDs.
//String agID = legoFile.getCanonicalPath();
String agLabel = StringUtils.removeEnd(fname, ".owl");
String agID = new String(agLabel);
try {
ontology = pw.parseOWL(IRI.create(legoFile));
currentReasoner = reasonerFactory.createReasoner(ontology);
// Some sanity checks--some of the genereated ones are problematic.
boolean consistent = currentReasoner.isConsistent();
if( consistent == false ){
LOG.info("Skip since inconsistent: " + fname);
continue;
}
Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom();
// TODO - make configurable to allow fail fast
if (unsatisfiable.isEmpty() == false) {
LOG.info("Skip since unsatisfiable: " + fname);
continue;
}
Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
Set<OWLAnnotation> modelAnnotations = ontology.getAnnotations();
OWLGraphWrapper currentGraph = new OWLGraphWrapper(ontology);
try {
LOG.info("Trying complex annotation load of: " + fname);
ComplexAnnotationSolrDocumentLoader loader =
new ComplexAnnotationSolrDocumentLoader(url, currentGraph, currentReasoner, individuals, modelAnnotations, agID, agLabel, fname);
loader.load();
} catch (SolrServerException e) {
LOG.info("Complex annotation load of " + fname + " at " + url + " failed!");
e.printStackTrace();
System.exit(1);
}
} finally {
// Cleanup reasoner and ontology.
if (currentReasoner != null) {
currentReasoner.dispose();
}
if (ontology != null) {
manager.removeOntology(ontology);
}
}
}
}
}
示例11: loadComplexAnnotationSolr
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Experimental method for trying out the loading of complex_annotation doc type.
* Works with --read-ca-list <file>.
*
* @param opts
* @throws Exception
*/
@CLIMethod("--solr-load-complex-exp")
public void loadComplexAnnotationSolr(Opts opts) throws Exception {
// Check to see if the global url has been set.
String url = sortOutSolrURL(globalSolrURL);
// Only proceed if our environment was well-defined.
if( caFiles == null || caFiles.isEmpty() ){
LOG.warn("LEGO environment not well defined--will skip loading LEGO/CA.");
}else{
// NOTE: These two lines are remainders from old code, and I'm not sure of their place in this world of ours.
// I wish there was an arcitecture diagram somehwere...
OWLOntologyManager manager = pw.getManager();
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
// Actual loading--iterate over our list and load individually.
for( String fname : caFiles ){
OWLReasoner currentReasoner = null;
OWLOntology ontology = null;
// TODO: Temp cover for missing group labels and IDs.
//String agID = legoFile.getCanonicalPath();
String pretmp = StringUtils.removeEnd(fname, ".owl");
String[] bits = StringUtils.split(pretmp, "/");
String agID = bits[bits.length -1];
String agLabel = new String(StringUtils.replaceOnce(agID, ":", "_"));
try {
ontology = pw.parseOWL(IRI.create(fname));
currentReasoner = reasonerFactory.createReasoner(ontology);
// Some sanity checks--some of the genereated ones are problematic.
boolean consistent = currentReasoner.isConsistent();
if( consistent == false ){
LOG.info("Skip since inconsistent: " + fname);
continue;
}
Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom();
if (unsatisfiable.isEmpty() == false) {
LOG.info("Skip since unsatisfiable: " + fname);
continue;
}
Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
Set<OWLAnnotation> modelAnnotations = ontology.getAnnotations();
OWLGraphWrapper currentGraph = new OWLGraphWrapper(ontology);
try {
LOG.info("Trying complex annotation load of: " + fname);
ComplexAnnotationSolrDocumentLoader loader =
new ComplexAnnotationSolrDocumentLoader(url, currentGraph, currentReasoner, individuals, modelAnnotations, agID, agLabel, fname);
loader.load();
} catch (SolrServerException e) {
LOG.info("Complex annotation load of " + fname + " at " + url + " failed!");
e.printStackTrace();
System.exit(1);
}
} finally {
// Cleanup reasoner and ontology.
if (currentReasoner != null) {
currentReasoner.dispose();
}
if (ontology != null) {
manager.removeOntology(ontology);
}
}
}
}
}
示例12: renderMarkdown
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
public static String renderMarkdown(OWLGraphWrapper g, String baseDir, boolean isIncludeImage) {
OWLOntology ont = g.getSourceOntology();
StringBuilder out = new StringBuilder();
String ontId = g.getOntologyId();
Set<OWLAnnotation> oAnns = ont.getAnnotations();
System.err.println("NUM1:"+oAnns.size());
String title = getVal("title", oAnns);
out.append("## Ontology: "+title+"\n\n");
out.append("IRI: "+rurl(ont)+"\n\n");
String desc = getVal("description", oAnns);
out.append("### Description\n\n");
out.append(desc+"\n\n");
Set<OWLOntology> imports = ont.getImports();
if (imports.size() > 0) {
out.append("### Imports\n\n");
for (OWLOntology im : imports) {
out.append(" * "+rurl(im)+"\n");
}
}
if (isIncludeImage) {
String imgFn = baseDir + "/" + ontId + ".png";
out.append("![]("+imgFn+")\n\n");
}
System.err.println("NUM:"+oAnns.size());
if (oAnns.size() > 0) {
out.append("### Annotations:\n\n");
for (OWLAnnotation ann : oAnns) {
String annLabel = g.getLabelOrDisplayId(ann.getProperty());
OWLAnnotationValue v = ann.getValue();
String dv = v.toString();
if (v instanceof OWLLiteral) {
OWLLiteral lv = ((OWLLiteral)v);
dv = lv.getLiteral();
IRI dt = lv.getDatatype().getIRI();
//System.out.println("DT = "+dt);
if (dt.equals(OWL2Datatype.XSD_ANY_URI.getIRI())) {
dv = href(lv.getLiteral());
}
}
out.append(" * "+href(ann.getProperty().getIRI().toString(),annLabel)+" : "+dv+"\n");
}
}
return out.toString();
}