当前位置: 首页>>代码示例>>Java>>正文


Java OWLOntology.getAnnotations方法代码示例

本文整理汇总了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));
	}
}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:20,代码来源:OntologyMetadata.java

示例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));
		}
	}
}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:21,代码来源:Mooncat.java

示例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;
}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:20,代码来源:OWLGraphWrapperExtended.java

示例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;
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:31,代码来源:GroupingTranslator.java

示例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();
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:19,代码来源:OwlLoaderAlgorithm.java

示例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;
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:17,代码来源:OwlLoaderAlgorithm.java

示例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;
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:45,代码来源:BeforeSaveModelValidator.java

示例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));
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:51,代码来源:ModelDecorationTest.java

示例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;
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:55,代码来源:OwlLoaderAlgorithm.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:81,代码来源:SolrCommandRunner.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:77,代码来源:SolrCommandRunner.java

示例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();
	}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:54,代码来源:OntologyMetadataMarkdownWriter.java


注:本文中的org.semanticweb.owlapi.model.OWLOntology.getAnnotations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。