org.semanticweb.owlapi.model.OWLOntology Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLOntology. 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: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Merge a specific ontology from the import closure into the main ontology.
 * Removes the import statement.
 * 
 * @param ontologyIRI id of the ontology to merge
 * @throws OWLOntologyCreationException
 */
public void mergeSpecificImport(IRI ontologyIRI) throws OWLOntologyCreationException {
	OWLOntologyManager manager = getManager();
	Set<OWLOntology> imports = sourceOntology.getImportsClosure();
	for (OWLOntology o : imports) {
		if (o.equals(sourceOntology))
			continue;
		Optional<IRI> currentIRI = o.getOntologyID().getOntologyIRI();
		if (currentIRI.isPresent() && currentIRI.get().equals(ontologyIRI)) {
			String comment = "Includes "+summarizeOntology(o);
			LOG.info(comment);
			addCommentToOntology(sourceOntology, comment);
			manager.addAxioms(sourceOntology, o.getAxioms());	
		}
	}
	Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
	for (OWLImportsDeclaration oid : oids) {
		if (ontologyIRI.equals(oid.getIRI())) {
			RemoveImport ri = new RemoveImport(sourceOntology, oid);
			getManager().applyChange(ri);
		}
	}
}
 
Example #2
Source File: MockFlexSolrDocumentLoaderTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public List<Map<String, Object>> mockLoad(String path) throws Exception {

       aconf = new ConfigManager();
       aconf.add("src/test/resources/test-ont-config.yaml");

       ParserWrapper pw = new ParserWrapper();
       OWLOntology testOwl = pw.parse(new File(path).getCanonicalPath());
       final OWLGraphWrapper g = new OWLGraphWrapper(testOwl);
       FlexCollection flex = new FlexCollection(aconf, g);

       ElkReasonerFactory rf = new ElkReasonerFactory();

       MockFlexSolrDocumentLoader l = new MockFlexSolrDocumentLoader(flex);
       l.load();


       List<Map<String, Object>> docs = l.getDocumentCollection().getDocuments();

       Gson gson = new GsonBuilder().setPrettyPrinting().create();
       for (Map<String, Object> doc : docs) {
           String json = gson.toJson(doc);
           System.out.println(json);

       }    
       return docs;
   }
 
Example #3
Source File: ElkReasonerFactory.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("static-method")
ElkReasoner createElkReasoner(OWLOntology ontology,
		boolean isBufferingMode, OWLReasonerConfiguration config)
		throws IllegalConfigurationException {
	LOGGER_.trace("createElkReasoner(OWLOntology, boolean, OWLReasonerConfiguration)");
	// here we check if the passed configuration also has ELK's parameters
	ElkReasonerConfiguration elkReasonerConfig;
	if (config != null) {
		if (config instanceof ElkReasonerConfiguration) {
			elkReasonerConfig = (ElkReasonerConfiguration) config;
		} else {
			elkReasonerConfig = new ElkReasonerConfiguration(config);
		}
	} else {
		elkReasonerConfig = new ElkReasonerConfiguration();
	}

	return new ElkReasoner(ontology, isBufferingMode, elkReasonerConfig);
}
 
Example #4
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 #5
Source File: TemplateTest.java    From robot with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test multiple templates in legacy format.
 *
 * @throws Exception if entities cannot be found
 */
@Test
public void testLegacyTemplates() throws Exception {
  Map<String, List<List<String>>> tables = new LinkedHashMap<>();
  String path = "/template-ids.csv";
  tables.put(path, TemplateHelper.readCSV(this.getClass().getResourceAsStream(path)));
  path = "/template-labels.csv";
  tables.put(path, TemplateHelper.readCSV(this.getClass().getResourceAsStream(path)));
  path = "/legacy-template-logical.csv";
  tables.put(path, TemplateHelper.readCSV(this.getClass().getResourceAsStream(path)));
  OWLOntology in = loadOntology("/simple_parts.owl");

  List<OWLOntology> ontologies = new ArrayList<>();
  OWLOntology out;
  for (String table : tables.keySet()) {
    Template t = new Template(table, tables.get(table), in);
    out = t.generateOutputOntology();
    ontologies.add(out);
    in = MergeOperation.merge(Lists.newArrayList(in, out));
  }

  OWLOntology template = MergeOperation.merge(ontologies);
  assertEquals("Count classes", 4, template.getClassesInSignature().size());
  assertEquals("Count logical axioms", 3, template.getLogicalAxiomCount());
  assertEquals("Count all axioms", 11, template.getAxiomCount());
}
 
Example #6
Source File: SpeciesSubsetterUtilTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testSubsetterSpecies() throws Exception {
	ParserWrapper p = new ParserWrapper();
	p.setCheckOboDoc(false);
	OWLOntology owlOntology = p.parse(getResourceIRIString("speciesMergeTest.obo"));
	OWLGraphWrapper graph = new OWLGraphWrapper(owlOntology);
	OWLReasonerFactory rf = new ElkReasonerFactory();
	OWLReasoner reasoner = rf.createReasoner(graph.getSourceOntology());
	SpeciesSubsetterUtil smu = new SpeciesSubsetterUtil(graph);
	//smu.viewProperty = graph.getOWLObjectPropertyByIdentifier("BFO:0000050");
	smu.taxClass = graph.getOWLClassByIdentifier("T:1");
	smu.reasoner = reasoner;
	smu.removeOtherSpecies();
	
	p.saveOWL(smu.ont, new OBODocumentFormat(), "target/speciesSubset.obo");
	//p.saveOWL(smu.ont,  getResourceIRIString("target/speciesSubset.owl"));
	
	assertNull(graph.getOWLClassByIdentifier("U:24"));
}
 
Example #7
Source File: OboOntologyReleaseRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createModule(String ontologyId, String moduleName, Set<OWLEntity> signature)
		throws OWLOntologyCreationException, IOException, OWLOntologyStorageException 
{
	// create a new manager, avoid unnecessary change events
	final OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	
	// extract module
	SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, mooncat.getOntology(), ModuleType.BOT);
	Set<OWLAxiom> moduleAxioms = sme.extract(signature);
	
	OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
	m.addAxioms(module, moduleAxioms);
	
	// save module
	OutputStream moduleOutputStream = null;
	try {
		moduleOutputStream = getOutputSteam(getModuleFileName(ontologyId, moduleName));
		m.saveOntology(module, moduleOutputStream);
	}
	finally {
		IOUtils.closeQuietly(moduleOutputStream);
	}
}
 
Example #8
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 #9
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 #10
Source File: ChEBIParser.java    From act with GNU General Public License v3.0 6 votes vote down vote up
private ChEBIParser(OWLOntology _ontology) {
  ontology = _ontology;
  out = System.out;
  err = System.err;
  entryTypes = new HashMap<String, EntryTypes>();
  entryTypes.put("http://purl.obolibrary.org/obo#Synonym",    EntryTypes.Synonym );
  entryTypes.put("http://purl.obolibrary.org/obo#Definition", EntryTypes.Definition );
  entryTypes.put("http://purl.obolibrary.org/obo#SMILES",     EntryTypes.SMILES );
  entryTypes.put("http://purl.obolibrary.org/obo#xref",       EntryTypes.xref );
  entryTypes.put("http://purl.obolibrary.org/obo#InChI",      EntryTypes.InChI );
  entryTypes.put("http://purl.obolibrary.org/obo#InChIKey",   EntryTypes.InChIKey );

  entryTypes.put("http://purl.obolibrary.org/obo#has_role",   EntryTypes.has_role );
  entryTypes.put("http://purl.obolibrary.org/obo#has_part",   EntryTypes.has_part );
  entryTypes.put("http://purl.obolibrary.org/obo#has_functional_parent",      EntryTypes.has_functional_parent );
  entryTypes.put("http://purl.obolibrary.org/obo#has_parent_hydride",         EntryTypes.has_parent_hydride );
  entryTypes.put("http://purl.obolibrary.org/obo#is_conjugate_acid_of",       EntryTypes.is_conjugate_acid_of );
  entryTypes.put("http://purl.obolibrary.org/obo#is_conjugate_base_of",       EntryTypes.is_conjugate_base_of );
  entryTypes.put("http://purl.obolibrary.org/obo#is_enantiomer_of",           EntryTypes.is_enantiomer_of );
  entryTypes.put("http://purl.obolibrary.org/obo#is_substituent_group_from",  EntryTypes.is_substituent_group_from );
  entryTypes.put("http://purl.obolibrary.org/obo#is_tautomer_of",             EntryTypes.is_tautomer_of );
}
 
Example #11
Source File: OWLHandler.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private OWLOntology resolveOntology(Param p) {
	String oid = getParam(p);
	for (OWLOntology ont : graph.getManager().getOntologies()) {
		Optional<IRI> ontologyIRI = ont.getOntologyID().getOntologyIRI();
		if (ontologyIRI.isPresent()) {
			String iri = ontologyIRI.get().toString();
			// HACK
			if (iri.endsWith("/"+oid)) {
				return ont;
			}
		}
	}
	return null;
}
 
Example #12
Source File: RelaxCommand.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Given an input state and command line arguments, run a reasoner, and add axioms to the input
 * ontology, returning a state with the updated ontology.
 *
 * @param state the state from the previous command, or null
 * @param args the command-line arguments
 * @return the state with inferred axioms added to the ontology
 * @throws Exception on any problem
 */
public CommandState execute(CommandState state, String[] args) throws Exception {
  CommandLine line = CommandLineHelper.getCommandLine(getUsage(), getOptions(), args);
  if (line == null) {
    return null;
  }

  if (state == null) {
    state = new CommandState();
  }

  IOHelper ioHelper = CommandLineHelper.getIOHelper(line);
  state = CommandLineHelper.updateInputOntology(ioHelper, state, line);
  OWLOntology ontology = state.getOntology();

  // Override default reasoner options with command-line options
  Map<String, String> relaxOptions = RelaxOperation.getDefaultOptions();
  for (String option : relaxOptions.keySet()) {
    if (line.hasOption(option)) {
      relaxOptions.put(option, line.getOptionValue(option));
    }
  }

  RelaxOperation.relax(ontology, relaxOptions);

  CommandLineHelper.maybeSaveOutput(line, ontology);

  return state;
}
 
Example #13
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * gets the OBO-style ID of the specified object. e.g., "GO:0008150"
 * SerializationUtils.clone is used to avoid memory leaks.
 * 
 * @param iriId
 * @return OBO-style identifier, using obo2owl mappings or the literals extracted from oboInowl#id.
 */
public String getIdentifier(IRI iriId) {
	if (iriId.toString().startsWith(Obo2OWLConstants.DEFAULT_IRI_PREFIX))
		return (String) SerializationUtils.clone(Owl2Obo.getIdentifier(iriId));

	final OWLAnnotationProperty oboIdInOwl = getDataFactory().getOWLAnnotationProperty(Obo2Owl.trTagToIRI(OboFormatTag.TAG_ID.getTag()));
	for (OWLOntology o : getAllOntologies()) {
		Collection<OWLAnnotation> oas = EntitySearcher.getAnnotations(iriId, o);
		if (oas == null) continue;

		for (OWLAnnotation oa: oas) {
			// We specifically look for the annotation property, oboInOwl:id; ignore others.
			if (oa.getProperty().equals(oboIdInOwl) != true)
				continue;

			// We then get the object value of this property, which is supposed to be a literal.
			OWLAnnotationValue objValue = oa.getValue();
			if (objValue.isLiteral() != true) {
				LOG.warn("Odd. " + objValue + " of oboInOwl#id for "+ iriId + ", is supposed to be an literal, but it is not.");
				continue;
			}

			Optional<OWLLiteral> literalOpt = objValue.asLiteral();
			if (literalOpt.isPresent() != true) {
				LOG.warn("Odd. " + objValue + " of oboInOwl#id for "+ iriId + ", does not exist.");
				continue;
			}

			OWLLiteral literal = literalOpt.get();
			return (String) SerializationUtils.clone(literal.getLiteral());
		}
	}

	// In the case where the input class does not have oboInOwl#id, we return its original URL.
	LOG.warn("Unable to retrieve the value of oboInOwl#id as the identifier for " + iriId + "; we will use an original iri as the identifier.");
	return (String) SerializationUtils.clone(iriId.toString());
}
 
Example #14
Source File: Similarity.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * translates similarity results into OWL Axioms and saves axioms into an OWL Ontology
 *
 * @param ont
 */
public void addResultsToOWLOntology(OWLOntology ont) {
	if (!isComparable)
		return;
	OWLGraphWrapper graph = simEngine.getGraph();
	for (OWLAxiom axiom: translateResultsToOWLAxioms()) {
		AddAxiom aa = new AddAxiom(ont, axiom);
		graph.getManager().applyChange(aa);
	}
}
 
Example #15
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public OWLObjectProperty getOWLObjectProperty(IRI iri) {
	OWLObjectProperty p = getDataFactory().getOWLObjectProperty(iri);
	for (OWLOntology o : getAllOntologies()) {
		if (o.getDeclarationAxioms(p).size() > 0) {
			return p;
		}
	}
	return null;
}
 
Example #16
Source File: EquivalentClassReasoningTest.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test no equivalences allowed with inferred equiv axioms. Pass if false.
 *
 * @throws IOException on error
 */
@Test
public void testReasonNoEquivalencesAllowed() throws IOException {
  OWLOntology inferred = loadOntology("/inferred-equiv.owl");
  OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
  OWLReasoner reasoner = reasonerFactory.createReasoner(inferred);
  EquivalentClassReasoning noneAllowedReasoning =
      new EquivalentClassReasoning(inferred, reasoner, EquivalentClassReasoningMode.NONE);

  assertFalse(noneAllowedReasoning.reason());
}
 
Example #17
Source File: BasicOWLOntologyLoader.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
protected OWLReasoner getOWLReasoner(OWLOntology ontology) throws OWLOntologyCreationException {
	if (this.reasoner == null) {
		this.reasoner = reasonerFactory.buildReasoner(config, ontology);
	}

	return reasoner;
}
 
Example #18
Source File: UnmergeCommand.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Given an input state and command line arguments, unmerge all ontology axioms into the first
 * ontology and return a state with the unmerged ontology.
 *
 * @param state the state from the previous command, or null
 * @param args the command-line arguments
 * @return the state with the unmerged ontology
 * @throws Exception on any problem
 */
public CommandState execute(CommandState state, String[] args) throws Exception {

  CommandLine line = CommandLineHelper.getCommandLine(getUsage(), getOptions(), args);
  if (line == null) {
    return null;
  }

  IOHelper ioHelper = CommandLineHelper.getIOHelper(line);

  if (state == null) {
    state = new CommandState();
  }

  List<OWLOntology> inputOntologies = new ArrayList<>();
  boolean notEmpty = false;
  if (state.getOntology() != null) {
    notEmpty = true;
    inputOntologies.add(state.getOntology());
  }
  inputOntologies.addAll(CommandLineHelper.getInputOntologies(ioHelper, line, notEmpty));

  OWLOntology outputOntology = UnmergeOperation.unmerge(inputOntologies);

  CommandLineHelper.maybeSaveOutput(line, outputOntology);

  state.setOntology(outputOntology);
  return state;
}
 
Example #19
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLClassExpression> getSuperClasses(OWLClass subCls, Set<OWLOntology> ontologies) {
	Set<OWLClassExpression> result;
	if (subCls != null && ontologies != null && ontologies.isEmpty() == false) {
		result = new HashSet<>();
		for(OWLOntology ont : ontologies) {
			result.addAll(getSuperClasses(subCls, ont));
		}
	}
	else {
		result = Collections.emptySet();
	}
	return result;
}
 
Example #20
Source File: RenameOperationTest.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test renaming of partial IRIs.
 *
 * @throws Exception on any problem
 */
@Test
public void testPartialRename() throws Exception {
  OWLOntology ont = loadOntology("/simple.owl");
  Map<String, String> mappings = new HashMap<>();
  mappings.put(
      "https://github.com/ontodev/robot/robot-core/src/test/resources/simple.owl#",
      "http://foo.bar/");

  RenameOperation.renamePrefixes(ont, new IOHelper(), mappings);

  assertIdentical("/rename_partial.owl", ont);
}
 
Example #21
Source File: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addCommentToOntology(OWLOntology ont, String cmt) {
	OWLDataFactory df = getDataFactory();
	OWLAnnotationProperty p = 
			df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI());
	OWLLiteral v = df.getOWLLiteral(cmt);
	OWLAnnotation ann = df.getOWLAnnotation(p, v);
	AddOntologyAnnotation addAnn = 
			new AddOntologyAnnotation(ont, ann);
	getManager().applyChange(addAnn);
}
 
Example #22
Source File: InferenceBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Only create inferences for an {@link OWLClass}, if this method returns true.
 * 
 * @param cls 
 * @param ont
 * @return boolean
 */
protected boolean doInferencesForClass(OWLClass cls, OWLOntology ont) {
	if (!filters.isEmpty()) {
		for (OWLClassFilter filter : filters) {
			boolean use = filter.useOWLClass(cls, ont);
			if (!use) {
				return false;
			}
		}
	}
	return true;
}
 
Example #23
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLClassExpression> getEquivalentClasses(OWLClass cls, OWLOntology ont) {
	Set<OWLClassExpression> expressions;
	if (cls != null && ont != null) {
		Set<OWLEquivalentClassesAxiom> axioms = ont.getEquivalentClassesAxioms(cls);
		expressions = new HashSet<>(axioms.size());
		for(OWLEquivalentClassesAxiom ax : axioms) {
			expressions.addAll(ax.getClassExpressions());
		}
		expressions.remove(cls); // set should not contain the query cls
	}
	else {
		expressions = Collections.emptySet();
	}
	return expressions;
}
 
Example #24
Source File: LocalMirrorIRIMapperTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testParseCatalogXML4() throws Exception {
	LocalMirrorIRIMapper m = new LocalMirrorIRIMapper("src/test/resources/owl-mirror.txt");
	ParserWrapper p = new ParserWrapper();
	p.addIRIMapper(m);
	if (verbose) {
		p.manager.addOntologyLoaderListener(new PrintingOntologLoaderListener());
	}
	OWLOntology owlOntology = p.parse(getResourceIRIString("mutual-import-1.owl"));
	assertNotNull(owlOntology);
}
 
Example #25
Source File: RepairCommand.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Given an input state and command line arguments, repair a new ontology and return an new state.
 * The input ontology is not changed.
 *
 * @param state the state from the previous command, or null
 * @param args the command-line arguments
 * @return a new state with the repaired ontology
 * @throws Exception on any problem
 */
public CommandState execute(CommandState state, String[] args) throws Exception {
  OWLOntology outputOntology;

  CommandLine line = CommandLineHelper.getCommandLine(getUsage(), getOptions(), args);
  if (line == null) {
    return null;
  }

  IOHelper ioHelper = CommandLineHelper.getIOHelper(line);
  state = CommandLineHelper.updateInputOntology(ioHelper, state, line);
  OWLOntology inputOntology = state.getOntology();

  IRI outputIRI = CommandLineHelper.getOutputIRI(line);
  if (outputIRI == null) {
    outputIRI = inputOntology.getOntologyID().getOntologyIRI().orNull();
  }

  boolean mergeAxiomAnnotations =
      CommandLineHelper.getBooleanValue(line, "merge-axiom-annotations", false);

  OWLDataFactory factory = inputOntology.getOWLOntologyManager().getOWLDataFactory();
  Set<OWLAnnotationProperty> properties =
      CommandLineHelper.getTerms(
              ioHelper, line, "annotation-property", "annotation-properties-file")
          .stream()
          .map(factory::getOWLAnnotationProperty)
          .collect(Collectors.toSet());

  RepairOperation.repair(inputOntology, ioHelper, mergeAxiomAnnotations, properties);
  outputOntology = inputOntology;
  if (outputIRI != null) {
    outputOntology.getOWLOntologyManager().setOntologyDocumentIRI(outputOntology, outputIRI);
  }

  CommandLineHelper.maybeSaveOutput(line, outputOntology);

  state.setOntology(outputOntology);
  return state;
}
 
Example #26
Source File: BigFastOwlSimTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void load(String idspace, OwlSimFactory simfactory) throws OWLOntologyCreationException, OBOFormatParserException, IOException {
	msg("Loading");
	ParserWrapper pw = new ParserWrapper();
	String base;
	//base = "/Users/cjm/repos/phenotype-ontologies/src/ontology/";
	base = "http://purl.obolibrary.org/obo/";
	OWLOntology ontology = pw.parseOBO(base+idspace+".obo");
	//ElkReasonerFactory reasonerFactory = new ElkReasonerFactory();
	//OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
	owlsim = simfactory.createOwlSim(ontology);
	msg("Loaded. Root = " + owlsim.getSourceOntology());
}
 
Example #27
Source File: ReduceOperationTest.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testRemoveRedundantSubClassAxiomsComplete()
    throws IOException, OWLOntologyCreationException {
  OWLOntology reasoned = loadOntology("/redundant_subclasses.owl");
  OWLReasonerFactory reasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory();

  Map<String, String> options = new HashMap<String, String>();
  options.put("remove-redundant-subclass-axioms", "true");
  options.put("preserve-annotated-axioms", "false");

  ReduceOperation.reduce(reasoned, reasonerFactory, options);
  assertIdentical("/without_redundant_subclasses2.owl", reasoned);
}
 
Example #28
Source File: MergeOperationTest.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test merging two ontologies without imports. Result should equal simpleParts.
 *
 * @throws IOException on file problem
 */
@Test
public void testMergeTwo() throws IOException {
  OWLOntology simple = loadOntology("/simple.owl");
  OWLOntology simpleParts = loadOntology("/simple_parts.owl");
  List<OWLOntology> ontologies = new ArrayList<>();
  ontologies.add(simple);
  ontologies.add(simpleParts);
  OWLOntology merged = MergeOperation.merge(ontologies);
  assertIdentical("/simple_parts.owl", merged);
}
 
Example #29
Source File: NCBIOWL.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add an alternative identifier for a main term.
 * 
 * @param ontology
 * @param merged the main term
 * @param altId the alternate id to be added
 * @param ap annotation property as generated by the setup method
 * 
 * @see NCBIOWL#setupAltIdProperty(OWLOntology)
 */
public static void addAltId(OWLOntology ontology, String merged, String altId, OWLAnnotationProperty ap) {
	altId = altId.trim();
	merged = merged.trim();
	
	// add alternate id information to owl class
	IRI mergedIRI = createNCBIIRI(merged);
	OWLLiteral value = dataFactory.getOWLLiteral("NCBITaxon:"+altId);
	OWLAxiom axiom = dataFactory.getOWLAnnotationAssertionAxiom(ap, mergedIRI, value);
	manager.addAxiom(ontology, axiom);
}
 
Example #30
Source File: OwlOntologyLoader.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
private void initImportsClosure() {
	Set<OWLOntology> importsClosure = owlOntology_.getImportsClosure();
	importsClosureIterator_ = importsClosure.iterator();
	importsClosureCount_ = importsClosure.size();
	importsClosureProcessed_ = 0;
	updateStatus();
	if (importsClosureIterator_.hasNext())
		initAxioms(importsClosureIterator_.next());
	else
		axiomsIterator_ = Collections.<OWLAxiom> emptySet().iterator();
}