org.semanticweb.owlapi.model.OWLDataFactory Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLDataFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AssertInferenceTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #2
Source File: DescriptionTreeSimilarity.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * adds additional axioms specific to this method.
 * Creates a named LCS class equivalent to the generated expression
 * 
 * @param id
 * @param result
 * @param axioms
 */
@Override
protected void translateResultsToOWLAxioms(String id, OWLNamedIndividual result, Set<OWLAxiom> axioms) {
	OWLDataFactory df = graph.getDataFactory();
	
	// declare a named class for the LCS and make this equivalent to the anonymous expression
	OWLClass namedLCS = df.getOWLClass(IRI.create(id+"_LCS"));
	axioms.add(df.getOWLAnnotationAssertionAxiom(df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
			namedLCS.getIRI(), 
			df.getOWLLiteral("LCS of "+simEngine.label(a)+" and "+simEngine.label(b))));
	axioms.add(df.getOWLEquivalentClassesAxiom(namedLCS, lcs));

	// link the similarity object to the named LCS
	OWLAnnotationProperty lcsp = df.getOWLAnnotationProperty(annotationIRI("has_least_common_subsumer"));
	axioms.add(df.getOWLAnnotationAssertionAxiom(lcsp, result.getIRI(), namedLCS.getIRI()));
}
 
Example #3
Source File: BasicABox.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void translateBioentity(Bioentity e) {
	OWLDataFactory fac = graph.getDataFactory();
	Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
	IRI iri = graph.getIRIByIdentifier(e.getId());
	OWLNamedIndividual cls =  graph.getDataFactory().getOWLNamedIndividual(iri);
	emap.put(e.getId(), cls);

	// --label---
	axioms.add(fac.getOWLAnnotationAssertionAxiom(fac.getRDFSLabel(),
			cls.getIRI(),
			fac.getOWLLiteral(e.getSymbol())));

	/*
	// --taxon--
	OWLClass taxCls = getOWLClass(e.getNcbiTaxonId()); // todo - cache
	axioms.add(fac.getOWLSubClassOfAxiom(cls, 
			fac.getOWLObjectSomeValuesFrom(getGeneAnnotationObjectProperty(Vocab.IN_TAXON), 
					taxCls)));

	// TODO - other properties
	 */

	addAxioms(axioms);


}
 
Example #4
Source File: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void addImportsFromSupportOntologies() {
	OWLOntology sourceOntology = getSourceOntology();
	OWLDataFactory factory = getDataFactory();
	for (OWLOntology  o : getSupportOntologySet()) {
		Optional<IRI> ontologyIRI = o.getOntologyID().getOntologyIRI();
		if (ontologyIRI.isPresent()) {
			OWLImportsDeclaration importsDeclaration = factory.getOWLImportsDeclaration(ontologyIRI.get());
			AddImport ai = new AddImport(sourceOntology, importsDeclaration);
			LOG.info("Applying: "+ai);
			getManager().applyChange(ai);
		}
		else {
			String msg = "Could not add import due to missing ontology id: "+o;
			LOG.error(msg);
			throw new RuntimeException(msg);
		}
	}
	this.setSupportOntologySet(new HashSet<OWLOntology>());
}
 
Example #5
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static  TaxonomyBuilder<OWLPropertyExpression> buildDataPropertyHierarchy(NormalizedOWLQLTbox tbox, Collection<? extends OWLPropertyExpression> additionalPropertyExpressions) {
	OWLOntology ont = tbox.getNormalizedOntology();
	OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory();
	Set< OWLPropertyExpression> props;
	if (additionalPropertyExpressions!=null) {
		props = new HashSet<OWLPropertyExpression>(additionalPropertyExpressions);
		props.addAll(ont.getDataPropertiesInSignature());
	} else {
		props = new HashSet<OWLPropertyExpression>( ont.getDataPropertiesInSignature());
	}
	SubPropertyComputation subcomp = new SubPropertyComputation(tbox);
	TaxonomyBuilder<OWLPropertyExpression> taxoBuilder = new TaxonomyBuilder<OWLPropertyExpression>(
			props, 
			fac.getOWLTopDataProperty(),
			fac.getOWLBottomDataProperty(),
			subcomp);
	taxoBuilder.build();
	logger.debug("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests);
	long size = props.size(); 
	logger.debug("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size);
	return taxoBuilder;
}
 
Example #6
Source File: OwlSimUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addElementLabels(OWLOntology ont, File file) throws IOException {
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLDataFactory df = m.getOWLDataFactory();
	List<String> lines = FileUtils.readLines(file);
	for (String line : lines) {
		if (line.startsWith("#"))
			continue;
		String[] colVals = line.split("\t");
		if (colVals.length != 2) {
			throw new IOException("Incorrect number of value: "+line);
		}
		IRI i = getIRIById(colVals[0]);
		OWLAnnotation ann = df.getOWLAnnotation(df.getRDFSLabel(), df.getOWLLiteral(colVals[1])); 
		m.addAxiom(ont, df.getOWLAnnotationAssertionAxiom(i, ann));
	}
}
 
Example #7
Source File: AbstractOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public OWLOntology cacheInformationContentInOntology() throws OWLOntologyCreationException, UnknownOWLClassException {
	OWLOntologyManager mgr = getSourceOntology().getOWLOntologyManager();
	OWLDataFactory df = mgr.getOWLDataFactory();
	OWLOntology o = mgr.createOntology();
	OWLAnnotationProperty p = df.getOWLAnnotationProperty(IRI.create(icIRIString));
	for (OWLClass c : getSourceOntology().getClassesInSignature()) {
		Double ic = getInformationContentForAttribute(c);
		if (ic != null) {
			mgr.addAxiom(o,
					df.getOWLAnnotationAssertionAxiom(p, 
							c.getIRI(), 
							df.getOWLLiteral(ic)));
		}

	}
	return o;
}
 
Example #8
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static  TaxonomyBuilder<OWLPropertyExpression> buildObjectPropertyHierarchy(NormalizedOWLQLTbox tbox, Collection<? extends OWLPropertyExpression> additionalPropertyExpressions) {
	OWLOntology ont = tbox.getNormalizedOntology();
	OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory();
	Set< OWLPropertyExpression> props;
	if (additionalPropertyExpressions!=null) {
		props = new HashSet<OWLPropertyExpression>(additionalPropertyExpressions);
		props.addAll(ont.getObjectPropertiesInSignature());
	} else {
		props = new HashSet<OWLPropertyExpression>( ont.getObjectPropertiesInSignature());
	}
	SubPropertyComputation subcomp = new SubPropertyComputation(tbox);
	TaxonomyBuilder<OWLPropertyExpression> taxoBuilder = new TaxonomyBuilder<OWLPropertyExpression>(
			props, 
			fac.getOWLTopObjectProperty(),
			fac.getOWLBottomObjectProperty(),
			subcomp);
	taxoBuilder.build();
	logger.debug("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests);
	long size = props.size(); 
	logger.debug("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size);
	return taxoBuilder;
}
 
Example #9
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static TaxonomyBuilder<OWLClassExpression>  buildClassHierarchy(NormalizedOWLQLTbox tbox, Collection<OWLClassExpression> additionalClassExpression) {
	OWLOntology ont = tbox.getNormalizedOntology();
	OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory();
	Set<OWLClassExpression> classes;
	if (additionalClassExpression!=null) {
		classes = new HashSet<OWLClassExpression>(additionalClassExpression);
		classes.addAll(ont.getClassesInSignature());
	} else {
		classes = new HashSet<OWLClassExpression>(ont.getClassesInSignature());
	}
	SubClassComputation subcomp = new SubClassComputation(tbox);
	TaxonomyBuilder<OWLClassExpression> taxoBuilder = new TaxonomyBuilder<OWLClassExpression>(
			classes, 
			fac.getOWLThing(),
			fac.getOWLNothing(),
			subcomp);
	taxoBuilder.build();
	logger.debug("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests);
	long size = classes.size();
	logger.debug("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size);
	return taxoBuilder;
}
 
Example #10
Source File: OWLSimReferenceBasedStatistics.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected DescriptiveStatistics computeDescriptiveStatistics(Set<OWLClass> attributes) throws UnknownOWLClassException  {
	DescriptiveStatistics statsPerAttSet = new DescriptiveStatistics();
	OWLDataFactory g = sourceOntology.getOWLOntologyManager().getOWLDataFactory();

	for (OWLClass c : attributes) {
		Double ic;
		try {
			ic = owlsim.getInformationContentForAttribute(c);
			if (ic == null) { 
				if (g.getOWLClass(c.getIRI()) != null) {
					ic = owlsim.getSummaryStatistics().max.getMax();
				} else {
					throw new UnknownOWLClassException(c); }
			}
			if (ic.isInfinite() || ic.isNaN()) {
				ic = owlsim.getSummaryStatistics().max.getMax();
			}
			statsPerAttSet.addValue(ic);	

		} catch (UnknownOWLClassException e) {
			LOG.info("Unknown class "+c.toStringID()+" submitted for summary stats. Removed from calculation.");
			continue;
		}
	}
	return statsPerAttSet;
}
 
Example #11
Source File: RoleAxiomOWLAPILowLevelIncrementalClassTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Override
void prepare() {
	final OWLDataFactory factory = new OWLDataFactoryImpl();
	A = factory.getOWLClass(IRI.create("A"));
	B = factory.getOWLClass(IRI.create("B"));
	OWLObjectProperty R = factory.getOWLObjectProperty(IRI.create("R"));
	OWLObjectProperty S = factory.getOWLObjectProperty(IRI.create("S"));
	OWLAxiom axExSsomeAsubB = factory.getOWLSubClassOfAxiom(
			factory.getOWLObjectSomeValuesFrom(S, A), B);
	OWLAxiom axReflR = factory.getOWLReflexiveObjectPropertyAxiom(R);
	axRsubS = factory.getOWLSubObjectPropertyOfAxiom(R, S);
	// from these three axioms it should follow A subclass B
	ontologyManager = TestOWLManager.createOWLOntologyManager();
	try {
		ont = ontologyManager.createOntology(new HashSet<OWLAxiom>(Arrays
				.asList(axExSsomeAsubB, axReflR, axRsubS)));
	} catch (OWLOntologyCreationException e) {
		fail(e.toString());
	}
}
 
Example #12
Source File: OCUtils.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static OWLOntology createOWLThingTypeDeclForIndividuals(OWLOntology ont) throws OWLOntologyCreationException, IOException  {
	OWLOntology ret = ont.getOntologyID()!=null && ont.getOntologyID().getOntologyIRI()!=null?
				ont.getOWLOntologyManager().createOntology(ont.getOntologyID().getOntologyIRI()):
				ont.getOWLOntologyManager().createOntology();
	
				OWLDataFactory fac = ret.getOWLOntologyManager().getOWLDataFactory();
	OWLClass owlThing = ret.getOWLOntologyManager().getOWLDataFactory().getOWLThing();
	for (OWLNamedIndividual ind: ont.getIndividualsInSignature()) {
		OWLNamedIndividual ni = fac.getOWLNamedIndividual(ind.getIRI());
		OWLAxiom ax = fac.getOWLClassAssertionAxiom(owlThing, ni);
		ret.getOWLOntologyManager().addAxiom(ret, ax);
	}
	return ret;
	
	
}
 
Example #13
Source File: DiffOperationTest.java    From robot with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Compare one ontology to a modified copy.
 *
 * @throws IOException on file problem
 * @throws OWLOntologyCreationException on ontology problem
 */
@Test
public void testCompareModified() throws IOException, OWLOntologyCreationException {
  OWLOntology simple = loadOntology("/simple.owl");
  Set<OWLOntology> onts = new HashSet<>();
  onts.add(simple);
  OWLOntologyManager manager = simple.getOWLOntologyManager();
  OWLDataFactory df = manager.getOWLDataFactory();
  OWLOntology simple1 = manager.createOntology(IRI.create(base + "simple1.owl"), onts);
  IRI test1 = IRI.create(base + "simple.owl#test1");
  manager.addAxiom(
      simple1,
      df.getOWLAnnotationAssertionAxiom(df.getRDFSLabel(), test1, df.getOWLLiteral("TEST #1")));

  StringWriter writer = new StringWriter();
  boolean actual = DiffOperation.compare(simple, simple1, writer);
  System.out.println(writer.toString());
  assertFalse(actual);
  String expected = IOUtils.toString(this.getClass().getResourceAsStream("/simple1.diff"));
  assertEquals(expected, writer.toString());
}
 
Example #14
Source File: OWLQLToNonRecursiveDatalogCompiler.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public OWLQLToNonRecursiveDatalogCompiler(OWLOntology originalOntTbox, Set<String> conceptURIsInAbox, Set<String> propertyURIsInAbox) {
	super();
	try {
		Set<OWLAxiom> tboxAxioms = NormalizedOWLQLTbox.getTboxRboxAxioms(originalOntTbox.getAxioms());
		/*if (completeTbox) {
			OWLOntology ontTbox = OWLManager.createOWLOntologyManager().createOntology();
			ontTbox.getOWLOntologyManager().addAxioms(ontTbox, tboxAxioms);
			PelletBasedTaxonomy.addImpliedTaxonomy(ontTbox);
			tboxAxioms = NormalizedOWLQLTbox.getTboxRboxAxioms(ontTbox.getAxioms());
		}*/
		tbox = new NormalizedOWLQLTbox(tboxAxioms);
		OWLDataFactory fac = tbox.getFactory();
		rename = new RuleRenaming(tbox);
		splitter = new Split(fac);
		taxo = new TaxonomyImpl(tbox);
		taxo.build();
		ejVarEliminator = new EliminateEJVar(tbox, taxo, fac);
		zeroArityAtomsEliminator = new DeleteRuleWithUnsatifiableAtoms(taxo,tbox);
		conceptsAndPropertiesNotInAboxEliminator = new DeleteRuleWithConceptOrPropertyNotInAbox(taxo, tbox, conceptURIsInAbox, propertyURIsInAbox);
		redundantAtomsEliminator = new DeleteRedundantAtoms(taxo, fac);
		unboundVarsEliminator = new DeleteUnboundVariables(fac);
		atomViewDef = new DefineAtomView(taxo, fac);
	} catch (OWLOntologyCreationException e) {
		throw new RuntimeException(e);
	}
}
 
Example #15
Source File: NCBI2OWLTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void testExactSynonym(OWLOntology ontology) {
	IRI iri = IRI.create("http://www.geneontology.org/formats/oboInOwl#hasExactSynonym");
	OWLDataFactory df = ontology.getOWLOntologyManager().
		getOWLDataFactory();
	OWLAnnotationProperty property = df.getOWLAnnotationProperty(iri);
	assertTrue("Exact Synonym property in signature",
		ontology.containsAnnotationPropertyInSignature(iri));
	
	// Check axioms
	Set<OWLAnnotationAxiom> axioms = ontology.getAxioms(property, Imports.EXCLUDED);
	assertEquals("Count class axioms", 0, axioms.size());

	// Check annotations
	List<String> values = new ArrayList<String>();
	values.add("AnnotationAssertion(rdfs:label <http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> \"has_exact_synonym\"^^xsd:string)");

	Set<OWLAnnotationAssertionAxiom> annotations = 
		ontology.getAnnotationAssertionAxioms(iri);
	assertEquals("Count annotations for Exact", 1, annotations.size());

	checkAnnotations(annotations, values);
}
 
Example #16
Source File: GAFOWLBridge.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void translateBioentity(Bioentity e) {
	OWLDataFactory fac = graph.getDataFactory();
	Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
	OWLClass cls = getOWLClass(e.getId());

	// --label---
	axioms.add(fac.getOWLAnnotationAssertionAxiom(fac.getRDFSLabel(),
			cls.getIRI(),
			fac.getOWLLiteral(e.getSymbol())));

	// --taxon--
	OWLClass taxCls = getOWLClass(e.getNcbiTaxonId()); // todo - cache
	axioms.add(fac.getOWLSubClassOfAxiom(cls, 
			fac.getOWLObjectSomeValuesFrom(getGeneAnnotationObjectProperty(Vocab.IN_TAXON), 
					taxCls)));

	// TODO - other properties

	addAxioms(axioms);


}
 
Example #17
Source File: NCBIConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a class for an NCBI Taxonomy ID and add it to the ontology.
 *
 * @param ontology the current ontology
 * @param id the NCBI Taxonomy ID, will be expanded into an IRI of the
 *	form http://purl.obolibrary.org/obo/NCBITaxon_1
 * @return the new class
 */
public static OWLClass createTaxon(OWLOntology ontology, String id) {
	IRI iri = createNCBIIRI(id);
	OWLDataFactory dataFactory = ontology.getOWLOntologyManager().
		getOWLDataFactory();
	OWLClass taxon = dataFactory.getOWLClass(iri);
	declare(ontology, taxon);
	annotate(ontology, taxon, "oio:hasOBONamespace",
		"ncbi_taxonomy");
	return taxon;
}
 
Example #18
Source File: OWLConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 typeCURIE a CURIE string for the type of synonym
 * @param propertyCURIE a CURIE string for the property
 * @param value the string value of the synonym
 * @return the axiom
 */
protected static OWLAnnotationAssertionAxiom synonym(
		OWLOntology ontology, OWLEntity subject,
		String typeCURIE, String propertyCURIE, String value) {
	OWLDataFactory dataFactory = ontology.getOWLOntologyManager().
		getOWLDataFactory();
	IRI type = format.getIRI(typeCURIE);
	OWLAnnotationProperty property =
		dataFactory.getOWLAnnotationProperty(
			format.getIRI(propertyCURIE));
	OWLLiteral literal = dataFactory.getOWLLiteral(value);
	return synonym(ontology, subject, type, property, literal);
}
 
Example #19
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Append xref annotations onto an existing axiom
 * 
 * @param axiom
 * @param xrefs
 * @param ontology
 * @return
 */
public static OWLAxiom appendXrefAnnotations(OWLAxiom axiom, Set<String> xrefs, OWLOntology ontology) {
    // filter existing
    Set<OWLAnnotation> newAnnotations = new HashSet<OWLAnnotation>(axiom.getAnnotations());
       final OWLOntologyManager manager = ontology.getOWLOntologyManager();
    final OWLDataFactory factory = manager.getOWLDataFactory();

    for (String x : xrefs) {
        OWLAnnotationProperty p = factory.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#hasDbXref"));
        OWLLiteral v = factory.getOWLLiteral(x);
        newAnnotations.add(factory.getOWLAnnotation(p, v));
    }
    final OWLAxiom newAxiom = changeAxiomAnnotations(axiom, newAnnotations, ontology);
    return newAxiom;
}
 
Example #20
Source File: InferenceBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Search for redundant axioms.
 * 
 * @param ontology
 * @param reasoner
 * @param dataFactory
 * @return set of all redundant axioms
 */
protected Set<OWLAxiom> getRedundantAxioms(OWLOntology ontology, OWLReasoner reasoner, OWLDataFactory dataFactory)
{
	Set<OWLAxiom> redundantAxioms = new HashSet<OWLAxiom>();
	for (OWLClass cls : ontology.getClassesInSignature()) {
		if (!doInferencesForClass(cls, ontology)) {
			continue;
		}
		updateRedundant(cls, ontology, redundantAxioms, reasoner, dataFactory);
	}
	return redundantAxioms;
}
 
Example #21
Source File: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, OWLReasoner r, String modelUrl, 
		Set<String> modelFilter, boolean skipDeprecatedModels, boolean skipTemplateModels) {
	super(server);
	this.model = model;
	this.reasoner = r;
	this.requiredModelStates = modelFilter;
	this.skipDeprecatedModels = skipDeprecatedModels;
	this.skipTemplateModels = skipTemplateModels;
	this.graph = new OWLGraphWrapper(model);
	this.modelUrl = modelUrl;
	current_doc_number = 0;
	OWLDataFactory df = graph.getDataFactory();
	partOf = OBOUpperVocabulary.BFO_part_of.getObjectProperty(df);
	occursIn = OBOUpperVocabulary.BFO_occurs_in.getObjectProperty(df);
	
	defaultClosureRelations = new ArrayList<String>(1);
	defaultClosureRelations.add(graph.getIdentifier(partOf));
	
	enabledBy = OBOUpperVocabulary.GOREL_enabled_by.getObjectProperty(df);
	
	title = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/title"));
	source = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/source"));
	contributor = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/contributor"));
	date = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/date"));
	evidence = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence"));
	modelState = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/modelstate"));
	comment = df.getRDFSComment();
	with = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence-with"));
	layoutHintX = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/hint/layout/x"));
	layoutHintY = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/hint/layout/y"));
	templatestate = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/templatestate"));
	
	displayLabelProp = df.getRDFSLabel();
	shortIdProp = df.getOWLAnnotationProperty(IRI.create(Obo2OWLConstants.OIOVOCAB_IRI_PREFIX+"id"));
	
	jsonProp = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/json-model"));
	
	bpSet = getAspect(graph, "biological_process");
}
 
Example #22
Source File: InferenceBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update the set of redundant axioms for the given {@link OWLClass} cls.
 * 
 * @param cls
 * @param ontology
 * @param redundantAxioms
 * @param reasoner
 * @param dataFactory
 */
protected static void updateRedundant(OWLClass cls, OWLOntology ontology, Set<OWLAxiom> redundantAxioms, 
		OWLReasoner reasoner, OWLDataFactory dataFactory)
{
	final OWLClass owlThing = dataFactory.getOWLThing();
	
	// get all direct super classes
	final Set<OWLClass> direct = reasoner.getSuperClasses(cls, true).getFlattened();
	direct.remove(owlThing);

	// get all super classes (includes direct ones)
	final Set<OWLClass> indirect = reasoner.getSuperClasses(cls, false).getFlattened();
	indirect.remove(owlThing);

	// remove direct super classes from all -> redundant super classes
	indirect.removeAll(direct);
	// rename
	final Set<OWLClass> redundant = indirect;

	// filter
	// subclass of axioms, which have a super class in the redundant set
	Set<OWLSubClassOfAxiom> axioms = ontology.getSubClassAxiomsForSubClass(cls);
	for (OWLSubClassOfAxiom subClassOfAxiom : axioms) {
		OWLClassExpression ce = subClassOfAxiom.getSuperClass();
		if (!ce.isAnonymous()) {
			OWLClass superClass = ce.asOWLClass();
			if (redundant.contains(superClass)) {
				redundantAxioms.add(subClassOfAxiom);
			}
		}
	}
}
 
Example #23
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * For every pair X DisjointWith Y, generate an axiom
 * A and Y = Nothing
 * 
 * (may become deprecated after Elk supports disjoints)
 * 
 * @param ont
 * @param manager
 * @param dataFactory
 */
public static void translateDisjointsToEquivalents(OWLOntology ont, OWLOntologyManager manager, OWLDataFactory dataFactory) {
	for (OWLDisjointClassesAxiom dca : ont.getAxioms(AxiomType.DISJOINT_CLASSES, Imports.INCLUDED)) {
		for (OWLClassExpression ce1 : dca.getClassExpressions()) {
			for (OWLClassExpression ce2 : dca.getClassExpressions()) {
				if (ce1.compareTo(ce2) <= 0)
					continue;
				OWLEquivalentClassesAxiom eca = dataFactory.getOWLEquivalentClassesAxiom(dataFactory.getOWLNothing(),
						dataFactory.getOWLObjectIntersectionOf(ce1, ce2));
				manager.addAxiom(ont, eca);
				// TODO - remove if requested
			}
		}
	}
}
 
Example #24
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Mooncat(OWLOntologyManager manager, OWLDataFactory dataFactory,
		OWLOntology ontology) {
	super();
	this.manager = manager;
	this.dataFactory = dataFactory;
	//this.ontology = ontology;
}
 
Example #25
Source File: DLQueryTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Execute the DL query on the given ontology graph. Uses the factory to create 
 * the {@link OWLReasoner} for an internal query ontology.
 * 
 * @param dlQuery
 * @param graph
 * @param reasonerFactory
 * @return set of {@link OWLClass} which 
 * @throws OWLParserException
 * @throws OWLOntologyCreationException
 */
public static Set<OWLClass> executeDLQuery(String dlQuery, OWLGraphWrapper graph, 
		OWLReasonerFactory reasonerFactory) throws OWLParserException, OWLOntologyCreationException 
{
	// create parser and parse DL query string
	ManchesterSyntaxTool parser = null;
	
	OWLClassExpression ce;
	try {
		parser = new ManchesterSyntaxTool(graph.getSourceOntology(), graph.getSupportOntologySet());
		ce = parser.parseManchesterExpression(dlQuery);
	} finally {
		// always dispose parser to avoid a memory leak
		if (parser != null) {
			parser.dispose();
		}
	}
	
	// create query ontology
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLOntology queryOntology = m.createOntology(IRI.generateDocumentIRI(), graph.getAllOntologies());
	OWLDataFactory f = m.getOWLDataFactory();
	OWLClass qc = f.getOWLClass(IRI.create("http://owltools.org/Q"));
	OWLEquivalentClassesAxiom ax = f.getOWLEquivalentClassesAxiom(ce, qc);
	m.addAxiom(queryOntology, ax);
	
	Set<OWLClass> subset = executeQuery(ce, queryOntology, reasonerFactory);
	if(subset.isEmpty()) {
		LOG.warn("No classes found for query subclass of:"+dlQuery);
	}
	return subset;
}
 
Example #26
Source File: AbstractOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setInformationContentFromOntology(OWLOntology o) {
	OWLOntologyManager mgr = getSourceOntology().getOWLOntologyManager();
	OWLDataFactory df = mgr.getOWLDataFactory();
	clearInformationContentCache();
	for (OWLAnnotationAssertionAxiom ax : o.getAxioms(AxiomType.ANNOTATION_ASSERTION)) {
		if (ax.getProperty().getIRI().toString().equals(icIRIString)) {
			OWLLiteral lit = (OWLLiteral) ax.getValue();
			OWLClass c = df.getOWLClass((IRI) ax.getSubject());
			Double v = lit.parseDouble();
			setInformtionContectForAttribute(c, v);
		}
	}
	assignDefaultInformationContentForAllClasses();
}
 
Example #27
Source File: ABoxUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a "fake" individual for every class.
 * 
 * ABox IRI = TBox IRI + suffix
 * 
 * if suffix == null, then we are punning
 * 
 * @param srcOnt
 * @param iriSuffix
 * @throws OWLOntologyCreationException
 */
public static void makeDefaultIndividuals(OWLOntology srcOnt, String iriSuffix) throws OWLOntologyCreationException {
	OWLOntologyManager m = srcOnt.getOWLOntologyManager();
	OWLDataFactory df = m.getOWLDataFactory();
	for (OWLClass c : srcOnt.getClassesInSignature(Imports.INCLUDED)) {
		IRI iri;
		if (iriSuffix == null || iriSuffix.equals(""))
		  iri = c.getIRI();
		else
			iri = IRI.create(c.getIRI().toString()+iriSuffix);
		OWLNamedIndividual ind = df.getOWLNamedIndividual(iri);
		m.addAxiom(srcOnt, df.getOWLDeclarationAxiom(ind));
		m.addAxiom(srcOnt, df.getOWLClassAssertionAxiom(c, ind));
	}
}
 
Example #28
Source File: PropertyViewOntologyBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param owlDataFactory
 * @param owlOntologyManager
 * @param sourceOntology
 * @param unitsOntology
 * @param viewProperty
 */
public PropertyViewOntologyBuilder(OWLDataFactory owlDataFactory,
		OWLOntologyManager owlOntologyManager, OWLOntology sourceOntology,
		OWLOntology unitsOntology, OWLObjectProperty viewProperty) {
	super();
	this.owlDataFactory = owlDataFactory;
	this.owlOntologyManager = owlOntologyManager;
	this.sourceOntology = sourceOntology;
	this.elementsOntology = unitsOntology;
	this.viewProperty = viewProperty;
	init();
}
 
Example #29
Source File: TransformationUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Names all inner ObjectSomeValuesFrom expressions
 * 
 * @param srcOntology
 * @param tgtOntology
 * @param qmap
 * @param isAddLabels
 * @return
 */
public static Map<OWLClass, OWLClassExpression> nameObjectSomeValuesFrom(OWLOntology srcOntology,
		OWLOntology tgtOntology,
		Map<OWLClass,OWLClassExpression> qmap,
		boolean isAddLabels) {

	if (qmap == null) 
		qmap = new HashMap<OWLClass, OWLClassExpression>();
	OWLOntologyManager mgr = srcOntology.getOWLOntologyManager();
	OWLDataFactory df = mgr.getOWLDataFactory();
	for (OWLOntology ont : srcOntology.getImportsClosure()) {
		for (OWLAxiom ax : srcOntology.getAxioms()) {
			for (OWLClassExpression x : ax.getNestedClassExpressions()) {
				if (x instanceof OWLObjectSomeValuesFrom) {
					OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)x;
					OWLClass filler = (OWLClass) svf.getFiller();
					OWLObjectProperty p = (OWLObjectProperty) svf.getProperty();
					IRI iri = getSkolemIRI(filler, p);
					OWLClass c = df.getOWLClass(iri);
					mgr.addAxiom(tgtOntology, df.getOWLEquivalentClassesAxiom(c, svf));
					qmap.put(c, svf);
					if (isAddLabels) {
						Set<OWLAnnotation> anns = OwlHelper.getAnnotations(filler, df.getRDFSLabel(), ont);
						for (OWLAnnotation ann : anns) {
							mgr.addAxiom(tgtOntology, df.getOWLAnnotationAssertionAxiom(c.getIRI(), ann));
						}
					}
				}
			}
		}
	}
	return qmap;

}
 
Example #30
Source File: TransformationUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addLabel(OWLNamedIndividual i, OWLGraphWrapper g, OWLReasoner reasoner) {
	OWLOntology ontology = g.getSourceOntology();
	Set<OWLClass> types = new HashSet<>();
	if (reasoner == null) {
		for (OWLClassExpression x : OwlHelper.getTypes(i, ontology)) {
			if (!x.isAnonymous()) {
				types.add((OWLClass) x);
			}
		}
	}
	else {
		 types = reasoner.getTypes(i, true).getFlattened();
	}
	StringBuffer iLabel = null;
	for (OWLClass type : types) {
		String label = g.getLabel(type);
		if (iLabel == null)
			iLabel = new StringBuffer("a");
		else
			iLabel.append(" & ");
		iLabel.append(" "+label);
	}
	OWLDataFactory df = g.getDataFactory();
	OWLAxiom ax =
			df.getOWLAnnotationAssertionAxiom(df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
			i.getIRI(), 
			df.getOWLLiteral(iLabel.toString()));
	g.getManager().addAxiom(ontology,
			ax);
}