Java Code Examples for org.semanticweb.owlapi.model.OWLOntologyManager#getOntologies()

The following examples show how to use org.semanticweb.owlapi.model.OWLOntologyManager#getOntologies() . 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: Rules.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a list of rules extracted from the given OWL-2 ontology document.
 * 
 * @param src an ontology document
 * @return a list of rules
 */
public static List<Rule> fromOntology(OWLOntologyDocumentSource src) {
	try {
		// use OWL-API to get a OWLOntology document from source
		OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
		manager.loadOntologyFromOntologyDocument(src);
		Set<OWLOntology> ontologies = manager.getOntologies();
		if (ontologies.isEmpty()) {
			return Collections.EMPTY_LIST;
		} else {
			// use first ontology from given source
			return fromOntology(ontologies.iterator().next());
		}
	} catch (OWLOntologyCreationException ex) {
		throw new IllegalArgumentException(
				"Loading ontology stream failed", ex);
	}
}
 
Example 2
Source File: Rules.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a list of rules extracted from the given OWL-2 ontology document.
 * @param in an ontology document as stream
 * @return a list of rules
 */
public static List<Rule> fromOntology(InputStream in) {
	try {
		// use OWL-API to get a OWLOntology document from source
		OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
		manager.loadOntologyFromOntologyDocument(in);
		Set<OWLOntology> ontologies = manager.getOntologies();
		if (ontologies.isEmpty()) {
			return Collections.EMPTY_LIST;
		} else {
			// use first ontology from given source
			return fromOntology(ontologies.iterator().next());
		}
	} catch (OWLOntologyCreationException ex) {
		throw new IllegalArgumentException(
				"Loading ontology stream failed", ex);
	}
}
 
Example 3
Source File: OwlTestCase.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Before
public void loadOwl() throws Exception {
  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  String uri = Resources.getResource("ontologies/cases/" + getTestName() + ".owl").toURI()
      .toString();
  IRI iri = IRI.create(uri);
  OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
  if (performInference) {
    ReasonerConfiguration config = new ReasonerConfiguration();
    config.setFactory(ElkReasonerFactory.class.getCanonicalName());
    config.setAddDirectInferredEdges(true);
    ReasonerUtil util = new ReasonerUtil(config, manager, ont);
    util.reason();
  }
  OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies());

  GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, new ArrayList<MappedProperty>());
  walker.walkStructure(visitor);

  OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, Collections.<String, String>emptyMap());
  postprocessor.processSomeValuesFrom();

  drawGraph();
}
 
Example 4
Source File: HyperGeometricAnalyzerTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void loadPizza() throws Exception {
  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  String uri = Resources.getResource("pizza.owl").toURI().toString();
  IRI iri = IRI.create(uri);
  manager.loadOntologyFromOntologyDocument(iri);
  OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies());

  MappedProperty mappedProperty = new MappedProperty(NodeProperties.LABEL);
  List<String> properties = new ArrayList<String>();
  properties.add("http://www.w3.org/2000/01/rdf-schema#label");
  properties.add("http://www.w3.org/2004/02/skos/core#prefLabel");
  mappedProperty.setProperties(properties);

  ArrayList<MappedProperty> mappedPropertyList = new ArrayList<MappedProperty>();
  mappedPropertyList.add(mappedProperty);

  GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, mappedPropertyList);
  walker.walkStructure(visitor);
  Map<String, String> categories = new HashMap<>();
  categories.put("http://www.co-ode.org/ontologies/pizza/pizza.owl#NamedPizza", "pizza");
  categories.put("http://www.co-ode.org/ontologies/pizza/pizza.owl#PizzaTopping", "topping");
  try (Transaction tx = graphDb.beginTx()) {
    OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, categories);
    postprocessor.processCategories(categories);
    postprocessor.processSomeValuesFrom();
    tx.success();
  }

  Map<String, String> map = new HashMap<>();
  map.put("pizza", "http://www.co-ode.org/ontologies/pizza/pizza.owl#");
  util = new CurieUtil(map);
  CypherUtil cypherUtil = new CypherUtil(graphDb, util);
  analyzer = new HyperGeometricAnalyzer(graphDb, util, graph, cypherUtil);
}
 
Example 5
Source File: EquivalentToInverseTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {

  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  String uri =
      Resources.getResource("ontologies/cases/TestEquivalentToInverse.owl").toURI().toString();
  IRI iri = IRI.create(uri);
  manager.loadOntologyFromOntologyDocument(iri);
  OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies());

  MappedProperty mappedProperty = new MappedProperty(NodeProperties.LABEL);
  List<String> properties = new ArrayList<String>();
  properties.add("http://www.w3.org/2000/01/rdf-schema#label");
  properties.add("http://www.w3.org/2004/02/skos/core#prefLabel");
  mappedProperty.setProperties(properties);

  ArrayList<MappedProperty> mappedPropertyList = new ArrayList<MappedProperty>();
  mappedPropertyList.add(mappedProperty);

  GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, mappedPropertyList);
  walker.walkStructure(visitor);
  Map<String, String> categories = new HashMap<>();
  try (Transaction tx = graphDb.beginTx()) {
    OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, categories);
    postprocessor.processCategories(categories);
    postprocessor.processSomeValuesFrom();
    tx.success();
  }
}
 
Example 6
Source File: InverseOfTautologyTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {

  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  String uri =
      Resources.getResource("ontologies/cases/TestInverseOfTautology.owl").toURI().toString();
  IRI iri = IRI.create(uri);
  manager.loadOntologyFromOntologyDocument(iri);
  OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies());

  MappedProperty mappedProperty = new MappedProperty(NodeProperties.LABEL);
  List<String> properties = new ArrayList<String>();
  properties.add("http://www.w3.org/2000/01/rdf-schema#label");
  properties.add("http://www.w3.org/2004/02/skos/core#prefLabel");
  mappedProperty.setProperties(properties);

  ArrayList<MappedProperty> mappedPropertyList = new ArrayList<MappedProperty>();
  mappedPropertyList.add(mappedProperty);

  GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, mappedPropertyList);
  walker.walkStructure(visitor);
  Map<String, String> categories = new HashMap<>();
  try (Transaction tx = graphDb.beginTx()) {
    OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, categories);
    postprocessor.processCategories(categories);
    postprocessor.processSomeValuesFrom();
    tx.success();
  }
}
 
Example 7
Source File: CliqueOntologyTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  CliqueConfiguration cliqueConfiguration = new CliqueConfiguration();
  Set<String> rel = new HashSet<String>();
  rel.add(OwlRelationships.OWL_EQUIVALENT_CLASS.name());
  cliqueConfiguration.setRelationships(rel);
  cliqueConfiguration.setLeaderAnnotation("http://www.monarchinitiative.org/MONARCH_cliqueLeader");
  clique = new Clique(graphDb, cliqueConfiguration);

  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  String uri = Resources.getResource("ontologies/equivalence-cliques-test.owl").toURI().toString();
  IRI iri = IRI.create(uri);
  manager.loadOntologyFromOntologyDocument(iri);
  OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies());

  MappedProperty mappedProperty = new MappedProperty(NodeProperties.LABEL);
  List<String> properties = new ArrayList<String>();
  properties.add("http://www.w3.org/2000/01/rdf-schema#label");
  properties.add("http://www.w3.org/2004/02/skos/core#prefLabel");
  mappedProperty.setProperties(properties);

  ArrayList<MappedProperty> mappedPropertyList = new ArrayList<MappedProperty>();
  mappedPropertyList.add(mappedProperty);

  GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, mappedPropertyList);
  walker.walkStructure(visitor);
  Map<String, String> categories = new HashMap<>();
  try (Transaction tx = graphDb.beginTx()) {
    OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, categories);
    postprocessor.processCategories(categories);
    postprocessor.processSomeValuesFrom();
    tx.success();
  }
}