• Stars
    star
    56
  • Rank 530,104 (Top 11 %)
  • Language
    Scala
  • License
    MIT License
  • Created over 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Scala DSL for programming with the OWL API.

Scowl

status

Scowl provides a Scala DSL allowing a declarative approach to composing OWL expressions and axioms using the OWL API.

Usage

Since version 1.2.1, Scowl is available via Maven Central. Add the dependency to your build.sbt if you are using OWL API 4.x:

libraryDependencies += "org.phenoscape" %% "scowl" % "1.4.1"

For OWL API 5.x:

libraryDependencies += "org.phenoscape" %% "scowl-owlapi5" % "1.4.1"

Import org.phenoscape.scowl._, and Scowl implicit conversions will add pseudo Manchester syntax methods to native OWL API objects. Additionally, functional syntax-style constructors and extractors will be in scope.

Scowl 1.2+ is built with OWL API 4.x (and from 1.4.1, additionally OWL API 5.x). For OWL API 3.5, use Scowl 1.0.2. Scowl is cross-compiled to support Scala 2.13 and Scala 3.

Examples

The easiest way to get started is to see how the DSL can be used to implement all the examples from the OWL 2 Web Ontology Language Primer:

The examples below are also available in code.

Scowl expressions use and return native OWL API objects

import org.phenoscape.scowl._
// import org.phenoscape.scowl._

val hasParent = ObjectProperty("http://www.co-ode.org/roberts/family-tree.owl#hasParent")
// hasParent: org.semanticweb.owlapi.model.OWLObjectProperty = <http://www.co-ode.org/roberts/family-tree.owl#hasParent>

val isParentOf = ObjectProperty("http://www.co-ode.org/roberts/family-tree.owl#isParentOf")
// isParentOf: org.semanticweb.owlapi.model.OWLObjectProperty = <http://www.co-ode.org/roberts/family-tree.owl#isParentOf>

val isSiblingOf = ObjectProperty("http://www.co-ode.org/roberts/family-tree.owl#isSiblingOf")
// isSiblingOf: org.semanticweb.owlapi.model.OWLObjectProperty = <http://www.co-ode.org/roberts/family-tree.owl#isSiblingOf>

val Person = Class("http://www.co-ode.org/roberts/family-tree.owl#Person")
// Person: org.semanticweb.owlapi.model.OWLClass = <http://www.co-ode.org/roberts/family-tree.owl#Person>

val FirstCousin = Class("http://www.co-ode.org/roberts/family-tree.owl#FirstCousin")
// FirstCousin: org.semanticweb.owlapi.model.OWLClass = <http://www.co-ode.org/roberts/family-tree.owl#FirstCousin>

val axiom = FirstCousin EquivalentTo (Person and (hasParent some (Person and (isSiblingOf some (Person and (isParentOf some Person))))))
// axiom: org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom = EquivalentClasses(<http://www.co-ode.org/roberts/family-tree.owl#FirstCousin> ObjectIntersectionOf(<http://www.co-ode.org/roberts/family-tree.owl#Person> ObjectSomeValuesFrom(<http://www.co-ode.org/roberts/family-tree.owl#hasParent> ObjectIntersectionOf(<http://www.co-ode.org/roberts/family-tree.owl#Person> ObjectSomeValuesFrom(<http://www.co-ode.org/roberts/family-tree.owl#isSiblingOf> ObjectIntersectionOf(<http://www.co-ode.org/roberts/family-tree.owl#Person> ObjectSomeValuesFrom(<http://www.co-ode.org/roberts/family-tree.owl#isParentOf> <http://www.co-ode.org/roberts/family-tree.owl#Person>)))))) )

Add some axioms and programmatically generated GCIs to an ontology

val manager = OWLManager.createOWLOntologyManager()
val ontology = manager.createOntology()
val PartOf = ObjectProperty("http://example.org/part_of")
val HasPart = ObjectProperty("http://example.org/has_part")
val DevelopsFrom = ObjectProperty("http://example.org/develops_from")
val Eye = Class("http://example.org/eye")
val Head = Class("http://example.org/head")
val Tail = Class("http://example.org/tail")

manager.addAxiom(ontology, Eye SubClassOf (PartOf some Head))
manager.addAxiom(ontology, Eye SubClassOf (not(PartOf some Tail)))

val gcis = for {
  term <- ontology.getClassesInSignature(true)
} yield {
  (not(HasPart some term)) SubClassOf (not(HasPart some (DevelopsFrom some term)))
}
manager.addAxioms(ontology, gcis)

Using pattern matching extractors to implement negation normal form

def nnf(expression: OWLClassExpression): OWLClassExpression = expression match {
  case Class(_)                                                          => expression
  case ObjectComplementOf(Class(_))                                      => expression
  case ObjectComplementOf(ObjectComplementOf(expression))                => nnf(expression)
  case ObjectUnionOf(operands)                                           => ObjectUnionOf(operands.map(nnf))
  case ObjectIntersectionOf(operands)                                    => ObjectIntersectionOf(operands.map(nnf))
  case ObjectComplementOf(ObjectUnionOf(operands))                       => ObjectIntersectionOf(operands.map(c => nnf(ObjectComplementOf(c))))
  case ObjectComplementOf(ObjectIntersectionOf(operands))                => ObjectUnionOf(operands.map(c => nnf(ObjectComplementOf(c))))
  case ObjectAllValuesFrom(property, filler)                             => ObjectAllValuesFrom(property, nnf(filler))
  case ObjectSomeValuesFrom(property, filler)                            => ObjectSomeValuesFrom(property, nnf(filler))
  case ObjectMinCardinality(num, property, filler)                       => ObjectMinCardinality(num, property, nnf(filler))
  case ObjectMaxCardinality(num, property, filler)                       => ObjectMaxCardinality(num, property, nnf(filler))
  case ObjectExactCardinality(num, property, filler)                     => ObjectExactCardinality(num, property, nnf(filler))
  case ObjectComplementOf(ObjectAllValuesFrom(property, filler))         => ObjectSomeValuesFrom(property, nnf(ObjectComplementOf(filler)))
  case ObjectComplementOf(ObjectSomeValuesFrom(property, filler))        => ObjectAllValuesFrom(property, nnf(ObjectComplementOf(filler)))
  case ObjectComplementOf(ObjectMinCardinality(num, property, filler))   => ObjectMaxCardinality(math.max(num - 1, 0), property, nnf(filler))
  case ObjectComplementOf(ObjectMaxCardinality(num, property, filler))   => ObjectMinCardinality(num + 1, property, nnf(filler))
  case ObjectComplementOf(ObjectExactCardinality(num, property, filler)) => ObjectUnionOf(ObjectMinCardinality(num + 1, property, nnf(filler)), ObjectMaxCardinality(math.max(num - 1, 0), property, nnf(filler)))
  case _                                                                 => ???
}

Using pattern matching extractors in for comprehensions

// Print all properties and fillers used in existential restrictions in subclass axioms
for {
  SubClassOf(_, subclass, ObjectSomeValuesFrom(property, filler)) <- ontology.getAxioms
} yield {
  println(s"$property $filler")
}

// Make an index of language tags to label values
val langValuePairs = for {
  AnnotationAssertion(_, RDFSLabel, _, value @@ Some(lang)) <- ontology.getAxioms(Imports.INCLUDED)
} yield {
  lang -> value
}
val langToValues: Map[String, Set[String]] = langValuePairs.foldLeft(Map.empty[String, Set[String]]) {
  case (langIndex, (lang, value)) =>
    langIndex.updated(lang, langIndex.getOrElse(value, Set.empty) ++ Set(value))
}

Question or problem?

If you have questions about how to use Scowl, feel free to send an email to [email protected], or open an issue on the tracker. Contributions are welcome.

Funding

Development of Scowl has been supported by National Science Foundation grant DBI-1062404 to the University of North Carolina.

License

Scowl is open source under the MIT License. See LICENSE for more information.

More Repositories

1

owlery

Owlery is a set of REST web services which allow querying of an OWL reasoner containing a configured set of ontologies.
Scala
16
star
2

owlet

A little OWL in SPARQL.
Scala
13
star
3

Phenex

Phenex is an application for annotating character matrix files with ontology terms using the Entity-Quality syntax for describing phenotypes.
Java
10
star
4

phenoscape-nlp

Source for the CharaParser application, which uses natural language processing to propose EQ-based phenotype annotations.
Java
7
star
5

sparql-utils

Scala SPARQL utilities
Scala
5
star
6

scate-shortcourse

Package for the "Phylogenetic comparative analysis of integrated anatomical traits" short course
R
5
star
7

rphenoscape

R package to make phenotypic traits from the Phenoscape Knowledgebase available from within R.
R
5
star
8

taxrank

Taxonomic rank ontology
Makefile
4
star
9

pheno-repo

Repository of OWL-based phenotypic descriptions
Makefile
4
star
10

phenoscape-owl-tools

OWL-based reasoning and data processing utilities for assembling the Phenoscape RDF knowledgebase.
Scala
4
star
11

KB-DataFest-2017

Promoting Phenoscape KB Data Access and Interoperability Codefest, 2017
3
star
12

charaparser-unsupervised

Java implementation of the unsupervised bootstrapping algorithm used within the CharaParser application.
Java
3
star
13

TraitFest-2023

Main repository for information advertising and documenting the 2023 SCATE TraitFest
R
3
star
14

PhenoscapeWeb

Web application for exploring the OBD-based Phenoscape Knowledgebase.
JavaScript
3
star
15

pheno-jsonld

notes on an interoperable format for expressing phenotypic data for taxa
2
star
16

vertebrate-taxonomy-ontology

The Vertebrate Taxonomy Ontology aims to provide one comprehensive hierarchy for both extinct and extant vertebrates
2
star
17

phenoscape-data

NeXML data files annotated by Phenoscape curators.
Java
2
star
18

vue2owl

Convert a VUE document to an OWL ontology.
Scala
2
star
19

phenoscape-kb-rdf-data

RDF/XML serialization of the Phenoscape RDF knowledgebase.
2
star
20

phenoscaperb

Phenoscape Ruby gem
Ruby
2
star
21

PhenoscapeDataLoader

Data processing utilities for assembling the legacy OBD-based Phenoscape knowledgebase.
Java
2
star
22

PhenoscapeOBD-WS

Phenoscape data services web application for the legacy OBD-based knowledgebase.
Java
2
star
23

teleost-taxonomy-ontology

An ontology covering the taxonomy of teleosts (bony fish). Now superseded by Vertebrate Taxonomy Ontology.
1
star
24

phenoscape-kb-services

Web services application for the Phenoscape RDF knowledgebase.
Scala
1
star
25

nexldrb

NeXML - JSON-LD converter
Ruby
1
star
26

phenoscape.github.com

Phenoscape website
JavaScript
1
star
27

synctool-oboedit

Synchronization tool for OBO-Edit. This plugin is being obsoleted by mappings provided by the Uberon project.
Java
1
star
28

EnviroPackets

exploration of using phenopackets to describe environments
Shell
1
star
29

blazegraph-docker

Docker image for running a Blazegraph server
Dockerfile
1
star
30

Phenotype-Matching-Queries

Queries on the OBD-based Phenoscape KB to suggest possible matching phenotypes and profiles (sets of phenotypes).
Java
1
star
31

pipeline-tools

Command-line environment needed to build Phenoscape Knowledgebase
Dockerfile
1
star