org.semanticweb.owlapi.model.OWLClass Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLClass. 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: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Try to extract an id space from an {@link OWLObject}.
 * Currently it is only defined for an {@link OWLClass}, 
 * otherwise the result is null.
 * 
 * @param obj
 * @return id space or null
 */
public String getIdSpace(OWLObject obj) {
	String idSpace = obj.accept(new OWLObjectVisitorExAdapter<String>(null){

		@Override
		public String visit(final OWLClass cls) {
			// id space only makes sense for classes
			String identifier = getIdentifier(cls.getIRI());
			Matcher matcher = ID_SPACE_PATTERN.matcher(identifier);
			if (matcher.matches()) {
				return matcher.group(1);
			}
			return null;
		}

	});
	return idSpace;
}
 
Example #2
Source File: PhenoSimHQEPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addPhenoAxioms() {
	OWLClass qualityCls = getOWLClassViaOBOSuffix(QUALITY);
	OWLClass abnormalCls = getOWLClassViaOBOSuffix(ABNORMAL);

	// Quality SubClassOf qualifier SOME abnormal
	// (not globally true, approximation for analysis)
	addAxiomToOutput(getOWLDataFactory().getOWLSubClassOfAxiom(qualityCls,
			getOWLDataFactory().getOWLObjectSomeValuesFrom(getOWLObjectPropertyViaOBOSuffix(QUALIFIER), 
					abnormalCls)),
					false);

	// Quality EquivalentTo inheres_in some Thing
	// (not globally true, approximation for analysis)
	addAxiomToOutput(getOWLDataFactory().getOWLEquivalentClassesAxiom(qualityCls,
			getOWLDataFactory().getOWLObjectSomeValuesFrom(getOWLObjectPropertyViaOBOSuffix(INHERES_IN), 
					getOWLDataFactory().getOWLThing())),
					false);

	// Relational Qualities
	// towards/depends_on SubProp of inheres_in
	// TEMPORARY
	addAxiomToOutput(getOWLDataFactory().getOWLSubObjectPropertyOfAxiom(getOWLObjectPropertyViaOBOSuffix(DEPENDS_ON),
			getOWLObjectPropertyViaOBOSuffix(INHERES_IN)),
			false);

}
 
Example #3
Source File: PhenoSimHQEPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @return 'E' classes
 */
protected Set<OWLClass> getPhenotypeEntityClasses() {
	Set<OWLClass> entityClasses = new HashSet<OWLClass>();

	// add all that are NOT excluded
	for (OWLClass c : inputOntology.getClassesInSignature(Imports.INCLUDED)) {
		if (!isVerbotenEntity(c)) {
			entityClasses.add(c);
			continue;
		}
		else {
			LOG.info("Excluding from entity set:"+c);
		}
	}

	// exclude all qualities
	entityClasses.removeAll(getQualityClasses());

	entityClasses.removeAll(classesToSkip);


	return entityClasses;
}
 
Example #4
Source File: Sim2CommandRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@CLIMethod("--learn-class-differentia")
public void learnClassDifferentia(Opts opts) throws Exception {
	OWLPrettyPrinter owlpp = getPrettyPrinter();
	if (owlsim == null) {
		owlsim = getOwlSimFactory().createOwlSim(g.getSourceOntology());
		owlsim.createElementAttributeMapFromOntology();
	}
	EnrichmentConfig ec = new EnrichmentConfig();
	while (opts.hasOpts()) {
		if (opts.nextEq("-p")) {
			ec.pValueCorrectedCutoff = Double.parseDouble(opts.nextOpt());
		} else if (opts.nextEq("-i")) {
			ec.attributeInformationContentCutoff = Double.parseDouble(opts
					.nextOpt());
		} else
			break;
	}
	owlsim.setEnrichmentConfig(ec);
	OWLClass baseClass = this.resolveClass(opts.nextOpt());
	OWLClass rootDifferentia = this.resolveClass(opts.nextOpt());
	ClassDifferentiaLearner cdl = new ClassDifferentiaLearner(owlsim);
	cdl.compute(baseClass, rootDifferentia);
	System.out.println(cdl.render(owlpp));
}
 
Example #5
Source File: ChEBIParser.java    From act with GNU General Public License v3.0 6 votes vote down vote up
private HashMap<OWLClass, P<OWLClass, HashMap<String, EntryTypes>>>
  getAllElementsWithParentsIn(Set<OWLClass> parentCategories) throws OWLException {
  HashMap<OWLClass, P<OWLClass, HashMap<String, EntryTypes>>> selected;
  selected = new HashMap<OWLClass, P<OWLClass, HashMap<String, EntryTypes>>>();
  for (OWLClass cl : ontology.getClassesInSignature()) {
    Set<OWLClass> parents = get_has_role_parents(cl);
    HashMap<String, EntryTypes> data = getData(cl);

    for (OWLClass p : parents) {
      if (parentCategories.contains(p)) {
        // this class has a parent within the set we are looking for.
        // so it qualifies as a class to be returned.. add it to map
        P<OWLClass, HashMap<String, EntryTypes>> p_data;
        p_data = new P<OWLClass, HashMap<String, EntryTypes>>(p, data);
        selected.put(cl, p_data);
      }
    }
  }
  return selected;
}
 
Example #6
Source File: SimpleOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Set<Node<OWLClass>> getInferredAttributes(OWLNamedIndividual a) {
	// TODO - refactor this method - in previous versions of Elk it was
	// not possible to ask for the types an instance instantiates, now
	// with Elk 0.4 it is
	if (elementToInferredAttributesMap.containsKey(a))
		return new HashSet<Node<OWLClass>>(elementToInferredAttributesMap.get(a));
	Set<Node<OWLClass>> nodes = new HashSet<Node<OWLClass>>();
	for (OWLClass c : getAttributesForElement(a)) {
		// if nodes contains c, it also contains all subsumers of c
		if (nodes.contains(c)) continue;
		nodes.addAll(getNamedReflexiveSubsumers(c));
		// nodes.addAll(getReasoner().getSuperClasses(c, false).getNodes());
	}
	elementToInferredAttributesMap.put(a, nodes);
	return new HashSet<Node<OWLClass>>(nodes);
}
 
Example #7
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public ScoreAttributeSetPair getSimilarityMaxIC(OWLNamedIndividual i,
		OWLNamedIndividual j) throws UnknownOWLClassException {

	Set<Node<OWLClass>> atts = getNamedCommonSubsumers(i,j);

	ScoreAttributeSetPair best = new ScoreAttributeSetPair(0.0);
	for (Node<OWLClass> n : atts) {
		OWLClass c = getDeterministicRepresentative(n);
		Double ic = getInformationContentForAttribute(c);
		if (Math.abs(ic - best.score) < 0.000001) {
			// tie for best attribute
			best.addAttributeClass(c);
		}
		if (ic > best.score) {
			best = new ScoreAttributeSetPair(ic, c);
		}
	}
	return best;
}
 
Example #8
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Set<ObjectProperty> getAllClassObjectProperties(IRI iri) {
    org.semanticweb.owlapi.model.IRI classIRI = SimpleOntologyValues.owlapiIRI(iri);
    if (owlOntology.containsClassInSignature(classIRI)) {
        OWLClass owlClass = owlManager.getOWLDataFactory().getOWLClass(classIRI);
        Node<OWLClass> equivalentClasses = owlReasoner.getEquivalentClasses(owlClass);
        NodeSet<OWLClass> superClasses = owlReasoner.getSuperClasses(owlClass);
        return owlOntology.objectPropertiesInSignature(Imports.INCLUDED)
                .filter(property -> {
                    Set<OWLObjectPropertyDomainAxiom> domains = owlOntology.axioms(
                            OWLObjectPropertyDomainAxiom.class, OWLObjectPropertyExpression.class, property,
                            Imports.INCLUDED, Navigation.IN_SUB_POSITION).collect(Collectors.toSet());
                    return hasClassAsDomain(domains.stream(), classIRI, equivalentClasses, superClasses)
                            || hasNoDomain(domains.stream());
                })
                .map(SimpleOntologyValues::mobiObjectProperty)
                .collect(Collectors.toSet());
    }
    throw new IllegalArgumentException("Class not found in ontology");
}
 
Example #9
Source File: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static Set<OWLClass> getAspect(OWLGraphWrapper graph, String aspect) {
	Set<OWLClass> result = new HashSet<OWLClass>();
	for(OWLClass cls : graph.getAllOWLClasses()) {
		if (cls.isBuiltIn()) {
			continue;
		}
		String id = graph.getIdentifier(cls);
		if (id.startsWith("GO:") == false) {
			continue;
		}
		String namespace = graph.getNamespace(cls);
		if (namespace != null && namespace.equals(aspect)) {
			result.add(cls);
		}
	}
	return result;
}
 
Example #10
Source File: OWLGraphWrapperEdgesExtendedTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test {@link OWLGraphWrapperEdgesExtended#getOntologyLeaves()}
 */
@Test
public void shouldGetOntologyLeaves()
{
    //the ontology has 9 leaves, FOO:0100, FOO:0003, FOO:0005, FOO:0010, FOO:0011, 
    //FOO:0012, FOO:0013, FOO:0014 and FOO:0015, an the taxon due to GCIs
    Set<OWLClass> leaves = wrapper.getOntologyLeaves();
    assertTrue("Incorrect leaves returned: " + leaves, 
            leaves.size() == 9 && 
            leaves.contains(wrapper.getOWLClassByIdentifier("FOO:0100")) && 
            leaves.contains(wrapper.getOWLClassByIdentifier("FOO:0003")) && 
            leaves.contains(wrapper.getOWLClassByIdentifier("FOO:0005")) && 
            leaves.contains(wrapper.getOWLClassByIdentifier("FOO:0010")) &&  
            leaves.contains(wrapper.getOWLClassByIdentifier("FOO:0014")) && 
            leaves.contains(wrapper.getOWLClassByIdentifier("FOO:0015")) && 
            leaves.contains(wrapper.getOWLClassByIdentifier("NCBITaxon:9606")) && 
            leaves.contains(wrapper.getOWLClassByIdentifier("NCBITaxon:10090")) && 
            leaves.contains(wrapper.getOWLClassByIdentifier("NCBITaxon:7743")));
}
 
Example #11
Source File: SimSpeedTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void axa(Set<OWLClass> cset, Set<OWLClass> dset, Method m) {
	if (m.equals(Method.EFFICIENT))
		axaEfficient(cset, dset);
	double total = 0;
	int n = 0;
	for (OWLClass c : cset) {
		//msg("Attr(c)="+c);
		for (OWLClass d : cset) {
			double s = jaccard(c,d,m);				
			//msg(" "+c+" , "+d+" = "+s);
			total += s;
			
			//Set<Node<OWLClass>> lcs = getNamedCommonSubsumers(c, d);
			//msg(" "+c+" , "+d+" = "+lcs);
			n++;
		}
	}
	msg("AVG: "+total / (double) n);
}
 
Example #12
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
public boolean reason() {
  if (config.isRemoveUnsatisfiableClasses()) {
    removeUnsatisfiableClasses();
  }
  if (!shouldReason()) {
    return false;
  }

  List<OWLOntologyChange> changes = new ArrayList<>();

  for (OWLClass ce: ont.getClassesInSignature(true)) {
    if (config.isAddInferredEquivalences()) {
      changes.add(getCompleteEquivalence(ce));
    }
    if (config.isAddDirectInferredEdges()) {
      changes.addAll(getDirectInferredEdges(ce));
    }
  }

  logger.info("Applying reasoned axioms: " + changes.size());
  manager.applyChanges(changes);
  logger.info("Completed applying reasoning changes");
  removeRedundantAxioms();
  reasoner.dispose();
  return true;
}
 
Example #13
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Hierarchy getSubClassesOf(ValueFactory vf, ModelFactory mf) {
    long start = getStartTime();
    try {
        Hierarchy hierarchy = new Hierarchy(vf, mf);
        Set<OWLClass> classes = getDeclaredClasses(Imports.INCLUDED).collect(Collectors.toSet());
        threadPool.submit(() -> classes.parallelStream()
                .forEach(owlClass -> {
                    if (owlClass.isTopEntity()) {
                        return;
                    }
                    IRI classIRI = SimpleOntologyValues.mobiIRI(owlClass.getIRI());
                    hierarchy.addIRI(classIRI);
                    getSubClassesFor(owlClass, true)
                            .forEach(subclassIRI -> hierarchy.addParentChild(classIRI, subclassIRI));
                })).get();
        return hierarchy;
    } catch (InterruptedException | ExecutionException e) {
        throw new MobiOntologyException("Error retrieving getSubClassesOf", e);
    } finally {
        logTrace("getSubClassesOf()", start);
    }
}
 
Example #14
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Deprecated
private Set<Node<OWLClass>> getNamedLowestCommonSubsumersNaive(OWLClass a,
		OWLClass b) throws UnknownOWLClassException {
	// currently no need to cache this, as only called from
	// getLowestCommonSubsumerIC, which does its own caching
	Set<Node<OWLClass>> commonSubsumerNodes = getNamedCommonSubsumers(a, b);
	Set<Node<OWLClass>> rNodes = new HashSet<Node<OWLClass>>();

	// remove redundant
	for (Node<OWLClass> node : commonSubsumerNodes) {
		rNodes.addAll(getReasoner().getSuperClasses(
				getDeterministicRepresentative(node), false).getNodes());
	}
	commonSubsumerNodes.removeAll(rNodes);
	return commonSubsumerNodes;
}
 
Example #15
Source File: EcoTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Wrapper method for the reasoner.
 * 
 * @param sources
 * @param reflexive
 * @return set of super classes
 */
public Set<OWLClass> getAncestors(Set<OWLClass> sources, boolean reflexive) {
	if (sources == null || sources.isEmpty()) {
		return Collections.emptySet();
	}
	Set<OWLClass> result = new HashSet<OWLClass>();
	for (OWLClass source : sources) {
		Set<OWLClass> set = reasoner.getSuperClasses(source, false).getFlattened();
		for (OWLClass cls : set) {
			if (cls.isBuiltIn() == false) {
				result.add(cls);
			}
		}
	}
	if (reflexive) {
		result.addAll(sources);
	}
	if (result.isEmpty()) {
		return Collections.emptySet();
	}
	return result;
	
}
 
Example #16
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleUnionOf(List<CheckWarning> warnings, Set<OWLOntology> allOntologies, 
		OWLEquivalentClassesAxiom axiom, OWLObjectUnionOf union, OWLPrettyPrinter pp) 
{
	List<OWLClassExpression> operands = union.getOperandsAsList();
	for(OWLClassExpression operand : operands) {
		if (!operand.isAnonymous()) {
			OWLClass operandCls = operand.asOWLClass();
			if (isDangling(operandCls, allOntologies)) {
				final IRI iri = operandCls.getIRI();
				String message = "Dangling reference "+iri+" in UNION_OF axiom: "+pp.render(axiom);
				warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_UNION_OF.getTag()));
			}
		}
		else {
			// not translatable to OBO
			handleGeneric(warnings, allOntologies, axiom, operand, pp);
		}
	}
}
 
Example #17
Source File: BasicAnnotationPropagator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Given a set of classes, create a new non-redundant set with respect to
 * the inferred super class hierarchy. Remove all classes which are
 * (inferred) super classes of another class in the given set.<br>
 * <br>
 * WARNING: This can be an expensive operation.
 * 
 * @param classes
 * @param reasoner
 * @return non redundant set, never null
 */
protected static Set<OWLClass> reduceToNonRedundant(Set<OWLClass> classes, OWLReasoner reasoner) {
	Set<OWLClass> nonRedundant = new HashSet<OWLClass>();
	for (OWLClass currentCls : classes) {
		Set<OWLClass> subClasses = reasoner.getSubClasses(currentCls, false).getFlattened();
		boolean noChildrenInLinks = true;
		for (OWLClass subClass : subClasses) {
			if (classes.contains(subClass)) {
				noChildrenInLinks = false;
				break;
			}
		}
		if (noChildrenInLinks) {
			nonRedundant.add(currentCls);
		}
	}
	return nonRedundant;
}
 
Example #18
Source File: GoIPICatalyticActivityRestrictionsRule.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GoIPICatalyticActivityRestrictionsRule(OWLGraphWrapper graph, TraversingEcoMapper eco) {
	this.message = MESSAGE;
	this.violationType = ViolationType.Warning;
	
	evidences = eco.getAllValidEvidenceIds("IPI", true);
	
	classSubSet = new HashSet<String>();
	
	OWLClass rootClass = graph.getOWLClassByIdentifier("GO:0003824"); // catalytic activity
	OWLReasonerFactory factory = new ElkReasonerFactory();
	OWLReasoner reasoner = factory.createReasoner(graph.getSourceOntology());
	try {
		NodeSet<OWLClass> nodeSet = reasoner.getSubClasses(rootClass, false);
		for(OWLClass cls : nodeSet.getFlattened()) {
			if (cls.isBottomEntity() || cls.isTopEntity()) {
				continue;
			}
			String oboId = graph.getIdentifier(cls);
			if (oboId != null) {
				classSubSet.add(oboId);
			}
		}
	}
	finally {
		reasoner.dispose();
	}
}
 
Example #19
Source File: QuotedEntityChecker.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Find a class with the given name, or create one. Quotation marks will be removed if necessary.
 *
 * @param name the name of the entity to find
 * @return a class, or null
 */
@Override
public OWLClass getOWLClass(@Nonnull String name) {
  IRI iri = getIRI(classes, name);
  if (iri != null) {
    return dataFactory.getOWLClass(iri);
  }
  if (ioHelper != null) {
    iri = ioHelper.createIRI(name, true);
    if (iri != null) {
      return dataFactory.getOWLClass(iri);
    }
  }
  return null;
}
 
Example #20
Source File: AbstractSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @return all named classes inferred to be direct types for the set of individuals
 */
protected Set<OWLClass> getAttributeClasses() {
	Set<OWLClass> types = new HashSet<OWLClass>();
	for (OWLNamedIndividual ind : this.outputOntology.getIndividualsInSignature(Imports.INCLUDED)) {
		types.addAll(getReasoner().getTypes(ind, true).getFlattened());
	}
	return types;
}
 
Example #21
Source File: BasicAnnotationPropagator.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Modify the given set and remove uninformative classes.
 * 
 * @param graph
 * @param nonRedundantLinks
 */
private void removeUninformative(OWLGraphWrapper graph, Set<OWLClass> nonRedundantLinks) {
	Iterator<OWLClass> linkIt = nonRedundantLinks.iterator();
	while (linkIt.hasNext()) {
		OWLClass link = linkIt.next();
		List<String> subsets = graph.getSubsets(link);
		if (subsets != null) {
			if (subsets.contains(gocheck_do_not_annotate)) {
				linkIt.remove();
			}
		}
	}
}
 
Example #22
Source File: ReleaseInferenceTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDescendantsQuery() throws Exception {
	OWLGraphWrapper  g =  getOntologyWrapper();
	OWLClass c = g.getOWLClass("http://purl.obolibrary.org/obo/NCBITaxon_10090");
	OWLObject i = g.getOWLObject("http://purl.obolibrary.org/obo/MGI_101761");
	System.out.println("Expecting "+i);
	boolean ok = false;
	for (OWLObject e : g.queryDescendants(c)) {
		System.out.println("ORG:"+e);
		if (e.equals(i))
			ok = true;
	}
	assertTrue(ok);
}
 
Example #23
Source File: GafCommandRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@CLIMethod("--extract-ontology-subset-by-gaf")
public void extractOntologySubsetByGaf(Opts opts) throws OWLOntologyCreationException {
	opts.info("", "makes an ontology subset using closure of all terms used in GAF");
	IRI subOntIRI = IRI.create("http://purl.obolibrary.org/obo/"+g.getOntologyId()+"-gaf-subset");
	while (opts.hasOpts()) {
		if (opts.nextEq("-u|--uri|--iri")) {
			subOntIRI = IRI.create(opts.nextOpt());
		}
		else {
			break;
		}
	}
	Mooncat m = new Mooncat(g);
	Set<OWLClass> cs = new HashSet<OWLClass>();
	LOG.info("Annotations: "+gafdoc.getGeneAnnotations().size());
	Set<String> unmatchedIds = new HashSet<String>();
	for (GeneAnnotation a : gafdoc.getGeneAnnotations()) {
		OWLClass c = g.getOWLClassByIdentifierNoAltIds(a.getCls());
		//LOG.info(" C:"+c);
		if (c == null) {
			unmatchedIds.add(a.getCls());
			continue;
		}
		cs.add(c);
	}
	if (unmatchedIds.size() > 0) {
		LOG.error("GAF contains "+unmatchedIds.size()+" unmatched IDs");
		for (String id : unmatchedIds) {
			LOG.error("UNMATCHED: "+id);
		}
	}
	LOG.info("Making subset ontology seeded from "+cs.size()+" classes");
	g.setSourceOntology(m.makeMinimalSubsetOntology(cs, subOntIRI, true));
	LOG.info("Made subset ontology; # classes = "+cs.size());
}
 
Example #24
Source File: SimSpeedTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<Node<OWLClass>> getNamedCommonSubsumers(OWLClass c, OWLClass d) {
	EWAHCompressedBitmap bmc = ancsBitmapCachedModifiable(c);
	EWAHCompressedBitmap bmd = ancsBitmapCachedModifiable(d);
	EWAHCompressedBitmap cad = bmc.and(bmd);
	Set<Node<OWLClass>> nodes = new HashSet<Node<OWLClass>>();
	for (int ix : cad.toArray()) {
		OWLClassNode node = new OWLClassNode(classArray[ix]);
		nodes.add(node);
	}
	return nodes;
}
 
Example #25
Source File: SimJSONTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSearchWithFullMatches() throws Exception {
	ParserWrapper pw = new ParserWrapper();
	sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath());
	g =  new OWLGraphWrapper(sourceOntol);
	parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);

	owlpp = new OWLPrettyPrinter(g);
	final int truncLen = 200;
	
	// assume buffering
	OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
	try {

		createOwlSim();
			//sos.setReasoner(reasoner);
		LOG.info("Reasoner="+owlsim.getReasoner());

		SimJSONEngine sj = new SimJSONEngine(g, owlsim);

		//sos.saveOntology("/tmp/z.owl");

		reasoner.flush();
		
		owlsim.createElementAttributeMapFromOntology();
		owlsim.computeSystemStats();
		
		
		for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
			Set<OWLClass> atts = owlsim.getAttributesForElement(i);
			String jsonStr = sj.search(atts, "MGI", true, 1000, true);				
			LOG.info(jsonStr);
		}
		
	}
	finally {
		reasoner.dispose();
	}
}
 
Example #26
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyEnumeration() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	// ObjectOneOf() = owl:Nothing
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(a, factory.getOWLObjectOneOf()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(b, factory.getOWLNothing()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(factory.getOWLObjectOneOf(), c));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, a));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, c));
}
 
Example #27
Source File: ClassTaxonMatrix.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Write a {@link ClassTaxonMatrix} using the specified delimiter.
 * 
 * Hint: Do not forget to close the writer after use.
 * 
 * @param matrix
 * @param graph required for rendering the OBO style identifiers
 * @param delimiter
 * @param writer
 * @throws IOException
 */
public static void write(ClassTaxonMatrix matrix, OWLGraphWrapper graph, char delimiter, BufferedWriter writer) throws IOException {

	// create sorted list of classes and taxa
	List<OWLClass> sortedClasses = createSortedClasses(matrix.matrixIndicies);
	List<OWLClass> sortedTaxa = createSortedClasses(matrix.matrixTaxonIndicies);

	// write header
	for (OWLClass taxon : sortedTaxa) {
		writer.append(delimiter);
		writer.append(graph.getIdentifier(taxon));
	}
	writer.newLine();

	// write lines
	for (int i = 0; i < sortedClasses.size(); i++) {
		writer.append(graph.getIdentifier(sortedClasses.get(i)));
		for (boolean b : matrix.matrix[i]) {
			writer.append(delimiter);
			writer.append(Boolean.toString(b));
		}
		writer.newLine();
	}

	// flush
	writer.flush();
}
 
Example #28
Source File: NCBI2OWLTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void testBacteria(OWLOntology ontology) {
	String curie = "ncbi:2";
	IRI iri = OWLConverter.format.getIRI(curie);
	OWLDataFactory df = ontology.getOWLOntologyManager().
		getOWLDataFactory();
	OWLClass taxon = df.getOWLClass(iri);
	assertTrue("Bacteria class in signature",
		ontology.containsClassInSignature(iri));

	// Check axioms
	Set<OWLClassAxiom> axioms = ontology.getAxioms(taxon, Imports.EXCLUDED);
	assertEquals("Count class axioms for Bacteria", 1, axioms.size());
	assertEquals("SubClassOf(<http://purl.obolibrary.org/obo/NCBITaxon_2> <http://purl.obolibrary.org/obo/NCBITaxon_131567>)", axioms.toArray()[0].toString());

	// Check annotations
	List<String> values = new ArrayList<String>();
	values.add(expandAnnotation(curie, "ncbitaxon:has_rank", OWLConverter.format.getIRI("ncbi:superkingdom")));
	values.add(expandAnnotation(curie, "oio:hasOBONamespace", "ncbi_taxonomy"));
	values.add(expandAnnotation(curie, "oio:hasDbXref", "GC_ID:11"));
	values.add(expandLabel(curie, "rdfs:label", "Bacteria"));
	values.add(expandSynonym(curie, "ncbitaxon:genbank_common_name", "oio:hasExactSynonym", "eubacteria"));
	values.add(expandSynonym(curie, "ncbitaxon:synonym", "oio:hasRelatedSynonym", "not Bacteria Haeckel 1894"));
	values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Prokaryota"));
	values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Monera"));
	values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Procaryotae"));
	values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Prokaryotae"));
	values.add(expandSynonym(curie, "ncbitaxon:blast_name", "oio:hasRelatedSynonym", "eubacteria"));

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

	checkAnnotations(annotations, values);
}
 
Example #29
Source File: CAROLCSTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConvertXPs() throws Exception {
	ParserWrapper pw = new ParserWrapper();
	OWLGraphWrapper g =
		pw.parseToOWLGraph(getResourceIRIString("lcstest1.owl"));
	OWLOntology ont = g.getSourceOntology();
	OWLObject o2 = g.getOWLObject("http://example.org#o2");

	LOG.debug("getting ancestors for: "+o2);
	for (OWLGraphEdge e : g.getOutgoingEdgesClosure(o2)) {
		LOG.debug(e);
	}
	for (OWLClass c : ont.getClassesInSignature()) {
		LOG.debug("getting individuals for "+c+" "+g.getLabel(c));
		for (OWLIndividual i : g.getInstancesFromClosure(c)) {
			LOG.debug("  "+i);
		}
	}

	/*
	for (OWLClass c : ont.getClassesInSignature()) {
		System.out.println("c="+c+" "+g.getLabel(c));
		for (OWLGraphEdge e : g.getOutgoingEdgesClosure(c)) {
			System.out.println("CLOSURE: "+e);
		}
	}
	*/
	/*
	OWLObject s = g.getOWLObjectByIdentifier("CARO:0000014");
	OWLObject t = g.getOWLObjectByIdentifier("CARO:0000000");
	assertTrue(g.getEdgesBetween(s, t).size() > 0);
	*/
}
 
Example #30
Source File: ElkConverter.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
public OWLClassNode convertClassNode(Node<ElkClass> node) {
	Set<OWLClass> owlClasses = new HashSet<OWLClass>();
	for (ElkClass cls : node) {
		owlClasses.add(convert(cls));
	}
	return new OWLClassNode(owlClasses);
}